* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg0: #070b14;
  --bg1: #10182a;
  --panel: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #7dd3fc;
  --accent2: #c4b5fd;
}

body {
  min-height: 100vh;
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse 70% 50% at 20% -10%, rgba(125, 211, 252, 0.12), transparent),
    radial-gradient(ellipse 50% 40% at 90% 10%, rgba(196, 181, 253, 0.1), transparent),
    linear-gradient(165deg, var(--bg0), var(--bg1) 55%, #0a1220);
  line-height: 1.45;
}

.frame {
  width: min(1180px, calc(100% - 1.25rem));
  margin: 0 auto;
  padding: 1.25rem 0 2rem;
}

.nav { margin-bottom: 0.65rem; font-size: 0.9rem; }
.nav a { color: var(--muted); text-decoration: none; }
.nav a:hover { color: var(--accent); }

.title-block { margin-bottom: 1rem; }
h1 {
  font-size: clamp(1.6rem, 3.5vw, 2.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(100deg, #e0f2fe, #c4b5fd 50%, #fde68a);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.tagline { color: var(--muted); margin-top: 0.25rem; font-size: 0.95rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 1rem;
  align-items: start;
}

.play-col { min-width: 0; }
.hud-strip { display: none; }
.panel-toggle { display: none; }

.diff-selector {
  display: flex;
  gap: 0.35rem;
  margin: 0 0 0.85rem;
  padding: 0.2rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
}
.diff-btn {
  flex: 1;
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 0.35rem;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.diff-btn.active {
  color: #0b1220;
  background: linear-gradient(90deg, #7dd3fc, #c4b5fd);
}
.diff-btn[data-diff="difficult"].active {
  background: linear-gradient(90deg, #fb7185, #f59e0b);
}
.panel-diff { margin-bottom: 0.75rem; }

.stage-wrap {
  position: relative;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: #04070f;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #050912;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 8, 16, 0.72);
  backdrop-filter: blur(4px);
  z-index: 2;
}
.overlay.hidden { display: none; }
.overlay-card {
  text-align: center;
  padding: 1.5rem 1.75rem;
  max-width: 22rem;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.9);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}
.overlay-card h2 {
  font-size: 1.45rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(90deg, #bae6fd, #ddd6fe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.overlay-card p { color: var(--muted); font-size: 0.95rem; margin-bottom: 1rem; }
.overlay-card button {
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1.5rem;
  font: inherit;
  font-weight: 700;
  color: #0b1220;
  background: linear-gradient(90deg, #7dd3fc, #c4b5fd);
  cursor: pointer;
}
.overlay-card button:hover { filter: brightness(1.06); }
.hint { margin-top: 0.85rem !important; margin-bottom: 0 !important; font-size: 0.8rem !important; }
.touch-hint { display: none; }
.desktop-hint { display: block; }

/* Virtual D-pad — sits under the map so it never covers play space */
.touch-controls {
  display: none;
  position: relative;
  z-index: 3;
  padding: 0.4rem 0.7rem max(0.55rem, env(safe-area-inset-bottom));
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem;
  background: rgba(7, 11, 20, 0.92);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 1rem 1rem;
}
.touch-controls .dpad,
.touch-controls .touch-actions {
  pointer-events: auto;
}

.dpad {
  display: grid;
  grid-template-columns: 44px 44px 44px;
  grid-template-rows: 44px 44px 44px;
  gap: 3px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.pad-btn {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.78);
  color: #e2e8f0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.pad-btn:active,
.pad-btn.active {
  background: rgba(125, 211, 252, 0.35);
  border-color: rgba(125, 211, 252, 0.55);
  color: #f8fafc;
}
.pad-up { grid-column: 2; grid-row: 1; }
.pad-left { grid-column: 1; grid-row: 2; }
.pad-center {
  grid-column: 2;
  grid-row: 2;
  opacity: 0.35;
  pointer-events: none;
  font-size: 0;
}
.pad-right { grid-column: 3; grid-row: 2; }
.pad-down { grid-column: 2; grid-row: 3; }

.touch-actions {
  display: flex;
  flex-direction: row;
  gap: 0.4rem;
}
.action-btn {
  min-width: 4.4rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 0.55rem 0.7rem;
  background: rgba(15, 23, 42, 0.82);
  color: #e2e8f0;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.action-btn:active {
  background: rgba(196, 181, 253, 0.3);
}

@media (hover: none), (pointer: coarse), (max-width: 900px) {
  .touch-controls { display: flex; }
  .touch-hint { display: block; }
  .desktop-hint { display: none; }
}

/* Always show pad when forced by class (JS can toggle) */
body.force-touch-ui .touch-controls { display: flex; }
body.force-touch-ui .touch-hint { display: block; }
body.force-touch-ui .desktop-hint { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .frame {
    width: 100%;
    margin: 0;
    padding: 0.45rem 0.55rem max(0.4rem, env(safe-area-inset-bottom));
  }
  .top {
    display: flex;
    align-items: baseline;
    gap: 0.65rem;
    margin-bottom: 0.35rem;
  }
  .nav { margin-bottom: 0; flex-shrink: 0; }
  .title-block { margin-bottom: 0; min-width: 0; }
  .title-block h1 { font-size: 1.2rem; }
  .tagline { display: none; }

  .hud-strip {
    display: flex;
    gap: 0.55rem;
    align-items: center;
    padding: 0.28rem 0.55rem;
    font-size: 0.78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #e2e8f0;
    background: rgba(4, 8, 16, 0.88);
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: 1rem 1rem 0 0;
  }
  .hud-strip span + span { opacity: 0.85; }
  #hud-diff { margin-left: auto; color: #c4b5fd; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }

  .stage-wrap {
    border-radius: 0;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-top: 0;
    border-bottom: 0;
  }
  #game {
    width: 100%;
    height: auto;
    max-height: none;
    object-fit: contain;
    vertical-align: top;
  }

  .overlay-card {
    padding: 0.85rem 0.95rem;
    max-width: 20rem;
  }
  .overlay-card h2 { font-size: 1.2rem; margin-bottom: 0.35rem; }
  .overlay-card p { font-size: 0.86rem; margin-bottom: 0.65rem; }
  .overlay-card button { padding: 0.55rem 1.15rem; }

  .panel {
    padding: 0.35rem 0.7rem 0.55rem;
  }
  .panel-toggle {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0.45rem 0.2rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
  }
  .panel:not(.open) .panel-body { display: none; }
}

.panel {
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 1rem 1.05rem 1.15rem;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
}
.panel h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0.85rem 0 0.5rem;
}
.panel h2:first-child { margin-top: 0; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}
.stats > div {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  padding: 0.45rem 0.55rem;
}
.stats dt {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.stats dd {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 0.1rem;
}

.legend {
  list-style: none;
  display: grid;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: #cbd5e1;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.swatch.you { background: #f8fafc; box-shadow: 0 0 8px #7dd3fc; }
.swatch.green { background: #4ade80; }
.swatch.blue { background: #38bdf8; }
.swatch.purple { background: #a78bfa; }
.swatch.yellow { background: #facc15; }
.swatch.cyan { background: #22d3ee; }
.swatch.orange { background: #fb923c; }
.swatch.red { background: #f87171; }
.swatch.predator { background: #ef4444; border-radius: 50%; }
.swatch.helper { background: #22c55e; border-radius: 50%; }
.swatch.thief { background: #0ea5e9; border-radius: 50%; }
.swatch.mimic { background: #8b5cf6; border-radius: 50%; }
.swatch.chaos { background: #eab308; border-radius: 50%; }

.log {
  margin-top: 0.9rem;
  padding: 0.65rem 0.7rem;
  border-radius: 0.65rem;
  border: 1px solid rgba(125, 211, 252, 0.2);
  background: rgba(14, 165, 233, 0.08);
  color: #bae6fd;
  font-size: 0.84rem;
  min-height: 2.8rem;
}
