:root {
  --ink: #eaf3ff;
  --panel: #0f2339;
  --panel-border: #2d4f72;
  --accent: #ffc95a;
  --accent-2: #2dd4bf;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --app-height: 100dvh;
}

* {
  box-sizing: border-box;
}

*::selection {
  background: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: auto;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  background: #0a1628;
  color: var(--ink);
}

.app-shell.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: var(--app-height);
  overflow: hidden;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  background: #0b1322;
  touch-action: none;
}

.hud-goal {
  display: none !important;
}

.overlay-screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  pointer-events: auto;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, rgba(36, 73, 115, 0.88), rgba(5, 14, 26, 0.95));
}

.overlay-screen.visible {
  display: flex;
}

.panel {
  background: linear-gradient(180deg, var(--panel), #0b1a2e);
  border: 2px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
}

.splash-card,
.menu-card {
  width: min(560px, calc(100vw - 40px));
  padding: 22px;
}

.splash-card h1 {
  margin: 0 0 10px;
  font-size: clamp(1.9rem, 4.3vw, 3.1rem);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fdf4b5;
}

.splash-card p {
  margin: 0 0 22px;
  color: #bfd8f1;
}

.menu-card h2,
.menu-card h3 {
  margin: 0 0 10px;
}

label {
  display: block;
  margin-bottom: 6px;
  color: #c8ddf2;
}

input[type="text"] {
  width: 100%;
  border: 2px solid #4d6d90;
  border-radius: 12px;
  padding: 10px;
  font-size: 1rem;
  margin-bottom: 12px;
  background: #0a1a2d;
  color: #e8f3ff;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  color: #10223a;
  background: linear-gradient(180deg, #ffdf7f, #ffc95b);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button:active {
  transform: translateY(1px);
}

.slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.slot-btn {
  text-align: left;
  color: #f4fbff;
  background: linear-gradient(180deg, #294e74, #1b3451);
}

.slot-btn.active {
  outline: 2px solid var(--accent);
}

.slot-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.overlay-top {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: calc(14px + var(--safe-right));
  z-index: 25;
  display: none;
}

#introHud {
  top: calc(14px + var(--safe-top) + 44px);
}

.hud-menu-wrap {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: calc(14px + var(--safe-right));
  z-index: 35;
  display: none;
}

.hud-menu-btn {
  width: 48px;
  height: 44px;
  border: 2px solid rgba(192, 216, 240, 0.35);
  border-radius: 12px;
  font-size: 1.2rem;
  color: rgba(242, 248, 255, 0.62);
  background: linear-gradient(180deg, rgba(39, 74, 112, 0.34), rgba(23, 48, 76, 0.34));
  box-shadow: 0 6px 14px rgba(4, 11, 20, 0.12);
  backdrop-filter: blur(0.5px);
}

.hud-menu-panel {
  margin-top: 8px;
  padding: 8px;
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  background: linear-gradient(180deg, #102842, #0a1d32);
  display: none;
  width: 190px;
}

.hud-menu-panel.open {
  display: block;
}

.hud-menu-panel button {
  width: 100%;
  margin-top: 6px;
}

.hud-menu-panel button:first-child {
  margin-top: 0;
}

.hud-menu-panel button.is-muted {
  opacity: 0.78;
  border-color: rgba(248, 113, 113, 0.7);
  color: #fecaca;
}

.hud-menu-panel button.is-active {
  border-color: rgba(134, 239, 172, 0.75);
  color: #dcfce7;
}

.small-panel {
  width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
}

.small-panel strong {
  display: block;
  margin-bottom: 4px;
  color: #f9e293;
}

.small-panel p {
  margin: 0;
  color: #d7e6f7;
}

.touch-controls {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(14px, calc(10px + var(--safe-bottom)));
  z-index: 24;
  display: grid;
  grid-template-columns: repeat(4, minmax(90px, 1fr));
  gap: 10px;
  width: min(720px, calc(100vw - 20px - var(--safe-left) - var(--safe-right)));
  touch-action: none;
}

.ctrl {
  min-height: 54px;
  font-size: 0.95rem;
  color: #f7fbff;
  border: 2px solid rgba(255, 255, 255, 0.25);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.ctrl.move {
  background: linear-gradient(180deg, #2d8dff, #165dbf);
}

.ctrl.jump {
  background: linear-gradient(180deg, #31d898, #158a61);
}

.ctrl.laser {
  background: linear-gradient(180deg, #ff6b6b, #cb2d2d);
}

@media (max-width: 860px) {
  .touch-controls {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: calc(100vw - 16px - var(--safe-left) - var(--safe-right));
  }

  .ctrl {
    min-height: 56px;
    font-size: 1rem;
  }
}
