/* Shadow Echo — phosphor séance. Dark room, amber body, violet ghost. */

:root {
  --bg: #07070d;
  --surface: #0e0e18;
  --surface-2: #131322;
  --line: rgba(168, 162, 220, 0.09);
  --ink: #eae8f6;
  --dim: #716f8a;
  --player: #ffb648;
  --echo: #9a86ff;
  --exit: #2fe6c8;
  --ch0: #ff5d8f;
  --ch1: #58a6ff;
  --radius: 14px;
  --font-display: 'Syne', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* Atmosphere: séance glow + grain + vignette */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(60% 45% at 50% -5%, rgba(154, 134, 255, 0.13), transparent 70%),
    radial-gradient(45% 35% at 85% 100%, rgba(47, 230, 200, 0.05), transparent 70%);
}
body::after {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

.stage {
  position: relative; z-index: 1;
  max-width: 460px;
  margin: 0 auto;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
  min-height: 100%;
}

/* ---------- Header ---------- */

.top { display: flex; align-items: center; justify-content: space-between; }

.wordmark {
  position: relative;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(0.9rem, 4vw, 1.3rem);
  letter-spacing: 0.06em;
  color: var(--ink);
  user-select: none;
  white-space: nowrap;
}
/* the literal echo */
.wordmark::after {
  content: attr(data-echo);
  position: absolute; left: 4px; top: 3px; z-index: -1;
  color: var(--echo);
  opacity: 0.38;
  filter: blur(1.5px);
}

.top-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
  color: var(--dim);
  font-family: var(--font-mono); font-size: 1rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.1s;
}
.icon-btn:hover { color: var(--ink); border-color: rgba(168, 162, 220, 0.25); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.muted { text-decoration: line-through; }

/* ---------- HUD ---------- */

.hud {
  display: flex; align-items: center; gap: 14px;
  font-size: 0.72rem; letter-spacing: 0.12em;
  color: var(--dim);
}
.hud b { color: var(--ink); font-weight: 700; }
.hud-mid i { padding: 0 4px; color: var(--dim); font-style: normal; }
.hud-mid { flex: 1; text-align: center; }
.hud-streak b { color: var(--player); }
.hud-tier {
  font-size: 0.58rem; letter-spacing: 0.1em;
  border: 1px solid; border-radius: 5px;
  padding: 1px 5px; margin-left: 4px;
}
.tier-easy { color: var(--exit); border-color: rgba(47, 230, 200, 0.4); }
.tier-medium { color: var(--player); border-color: rgba(255, 182, 72, 0.4); }
.tier-hard { color: var(--ch0); border-color: rgba(255, 93, 143, 0.4); }

.hud-badge {
  font-size: 0.62rem; letter-spacing: 0.14em;
  color: var(--echo); border: 1px solid rgba(154, 134, 255, 0.35);
  border-radius: 6px; padding: 2px 7px;
}

/* ---------- Board ---------- */

.board-wrap { display: flex; justify-content: center; }

.board {
  position: relative;
  width: min(100%, 420px);
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 0 60px rgba(154, 134, 255, 0.07), 0 18px 50px rgba(0, 0, 0, 0.55);
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(7, 1fr);
  padding: 6px;
  gap: 3px;
  touch-action: none;
}

.cell {
  position: relative;
  border-radius: 7px;
  background: rgba(168, 162, 220, 0.035);
  transition: background 0.2s;
}

.cell.wall {
  background: linear-gradient(160deg, #23233a, #15151f 65%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 2px 6px rgba(0, 0, 0, 0.4);
}

.cell.exit {
  background: rgba(47, 230, 200, 0.05);
  box-shadow: inset 0 0 0 2px rgba(47, 230, 200, 0.7);
  animation: exit-pulse 2.2s ease-in-out infinite;
}
.cell.exit::after {
  content: '';
  position: absolute; inset: 26%;
  border-radius: 50%;
  border: 2px solid rgba(47, 230, 200, 0.8);
}
@keyframes exit-pulse {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(47, 230, 200, 0.7), 0 0 0 rgba(47, 230, 200, 0); }
  50% { box-shadow: inset 0 0 0 2px rgba(47, 230, 200, 1), 0 0 18px rgba(47, 230, 200, 0.35); }
}

.cell.button::after {
  content: '';
  position: absolute; inset: 28%;
  border-radius: 50%;
  border: 3px solid var(--chc);
  opacity: 0.85;
  transition: all 0.15s;
}
.cell.button.pressed { background: color-mix(in srgb, var(--chc) 14%, transparent); }
.cell.button.pressed::after {
  inset: 34%;
  background: var(--chc);
  box-shadow: 0 0 14px var(--chc);
}

.cell.door {
  background: repeating-linear-gradient(45deg,
    color-mix(in srgb, var(--chc) 55%, #0e0e18) 0 6px,
    color-mix(in srgb, var(--chc) 20%, #0e0e18) 6px 12px);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--chc) 70%, transparent);
  transition: opacity 0.22s, box-shadow 0.22s, background 0.22s;
}
.cell.door.open {
  background: color-mix(in srgb, var(--chc) 6%, transparent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--chc) 30%, transparent);
}
.cell.door::after {
  content: ''; position: absolute; inset: 40% 12%;
  border-radius: 3px; background: var(--chc);
  transition: transform 0.22s ease;
}
.cell.door.open::after { transform: scaleX(0.12); }

.cell.ch0 { --chc: var(--ch0); }
.cell.ch1 { --chc: var(--ch1); }

/* ---------- Entities ---------- */

.ent {
  position: absolute;
  width: calc((100% - 12px - 18px) / 7);
  aspect-ratio: 1;
  border-radius: 9px;
  pointer-events: none;
  transition: left 0.13s ease, top 0.13s ease, opacity 0.3s;
  z-index: 3;
}

.ent.player {
  background: radial-gradient(circle at 35% 30%, #ffd894, var(--player) 60%);
  box-shadow: 0 0 18px rgba(255, 182, 72, 0.55), 0 4px 10px rgba(0, 0, 0, 0.5);
}
.ent.player::after {
  content: ''; position: absolute; inset: 33%;
  border-radius: 50%; background: rgba(30, 16, 2, 0.55);
}

.ent.echo {
  background: transparent;
  box-shadow: inset 0 0 0 2.5px var(--echo), 0 0 16px rgba(154, 134, 255, 0.45);
  opacity: 0;
  z-index: 2;
}
.ent.echo.alive { opacity: 0.85; animation: echo-in 0.5s ease; }
.ent.echo::after {
  content: ''; position: absolute; inset: 33%;
  border-radius: 50%; border: 2px solid var(--echo); opacity: 0.7;
}
@keyframes echo-in {
  from { transform: scale(1.6); opacity: 0; filter: blur(4px); }
  to { transform: scale(1); opacity: 0.85; filter: blur(0); }
}

.echo-ghost {
  position: absolute;
  width: calc((100% - 12px - 18px) / 7);
  aspect-ratio: 1; border-radius: 9px;
  box-shadow: inset 0 0 0 2px var(--echo);
  pointer-events: none; z-index: 1;
  animation: ghost-fade 0.45s ease forwards;
}
@keyframes ghost-fade { from { opacity: 0.4; } to { opacity: 0; } }

.board.shake { animation: board-shake 0.22s; }
@keyframes board-shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* echo's upcoming path */
.cell.echo-path::before {
  content: '';
  position: absolute; inset: 38%;
  border-radius: 50%;
  background: var(--echo);
  opacity: 0.32;
  box-shadow: 0 0 10px rgba(154, 134, 255, 0.5);
  animation: path-breathe 1.6s ease-in-out infinite;
}
@keyframes path-breathe {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.45; }
}

/* unpressed buttons quietly beckon */
.cell.button:not(.pressed)::after {
  animation: btn-beckon 2.4s ease-in-out infinite;
}
@keyframes btn-beckon {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; box-shadow: 0 0 10px var(--chc); }
}

/* numbered hint steps */
.hint-step {
  position: absolute; z-index: 6;
  width: calc((100% - 12px - 18px) / 7);
  aspect-ratio: 1;
  display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 1rem;
  color: #081310;
  pointer-events: none;
}
.hint-step::before {
  content: ''; position: absolute; inset: 22%; z-index: -1;
  border-radius: 50%;
  background: var(--exit);
  box-shadow: 0 0 16px rgba(47, 230, 200, 0.7);
  animation: hint-pop 0.3s ease;
}
.hint-step.hint-wait { font-size: 0.5rem; letter-spacing: 0.05em; color: #14082e; }
.hint-step.hint-wait::before { inset: 14%; background: var(--echo); box-shadow: 0 0 16px rgba(154, 134, 255, 0.8); }
@keyframes hint-pop { from { transform: scale(0.3); } }

/* hint button attention pulse */
.ctrl-btn.attention {
  border-color: var(--exit);
  color: var(--ink);
  animation: attention-pulse 1.4s ease-in-out infinite;
}
@keyframes attention-pulse {
  0%, 100% { box-shadow: 0 0 0 rgba(47, 230, 200, 0); }
  50% { box-shadow: 0 0 16px rgba(47, 230, 200, 0.55); }
}

/* ---------- Echo strip ---------- */

.echo-strip {
  display: flex; align-items: center; gap: 10px;
  min-height: 28px;
  font-size: 0.72rem; letter-spacing: 0.1em;
}
.echo-label {
  color: var(--echo); font-weight: 700;
  border: 1px solid rgba(154, 134, 255, 0.35);
  border-radius: 6px; padding: 2px 8px;
}
.echo-state { color: var(--dim); }
.echo-queue { display: flex; gap: 5px; }
.echo-queue i {
  font-style: normal; color: var(--echo);
  width: 22px; height: 22px; display: grid; place-items: center;
  border: 1px solid rgba(154, 134, 255, 0.28); border-radius: 6px;
  background: rgba(154, 134, 255, 0.07);
  font-size: 0.8rem;
}
.echo-queue i.next { background: rgba(154, 134, 255, 0.28); color: var(--ink); }
.echo-queue i.w { font-size: 0.6rem; font-weight: 700; }

/* ---------- Controls ---------- */

.controls {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; margin-top: 2px;
}

.ctrl-side { display: flex; flex-direction: row; gap: 10px; }

.ctrl-btn {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.12em;
  color: var(--dim);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 14px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.1s;
}
.ctrl-btn:hover { color: var(--ink); border-color: rgba(168, 162, 220, 0.25); }
.ctrl-btn:active { transform: scale(0.95); }
.ctrl-btn b { color: var(--exit); }
.ctrl-btn:disabled { opacity: 0.35; cursor: default; }
.dev-btn { color: var(--ch0); border-color: rgba(255, 93, 143, 0.4); }

/* dev auto-solve: full solution strip + on-board move glyphs */
.solve-strip {
  display: flex; flex-wrap: wrap; gap: 4px; justify-content: center;
}
.solve-strip[hidden] { display: none; }
.solve-strip i {
  font-style: normal; font-size: 0.78rem;
  min-width: 20px; height: 20px; padding: 0 3px;
  display: grid; place-items: center;
  border: 1px solid rgba(255, 93, 143, 0.3); border-radius: 5px;
  color: var(--dim);
}
.solve-strip i.w {
  font-size: 0.55rem; font-weight: 700; letter-spacing: 0.08em;
  color: var(--echo); border-color: rgba(154, 134, 255, 0.45);
  background: rgba(154, 134, 255, 0.08);
}
.strip-label {
  font-size: 0.6rem; letter-spacing: 0.12em; color: var(--ch0);
  align-self: center; margin-right: 2px;
}
.solve-strip i.done { color: var(--ch0); background: rgba(255, 93, 143, 0.1); }
.solve-strip i.now {
  color: var(--ink); background: rgba(255, 93, 143, 0.35);
  box-shadow: 0 0 10px rgba(255, 93, 143, 0.5);
}

.solve-strip i.now {
  animation: attention-pulse 1.4s ease-in-out infinite;
}
.solve-strip.off-track i { border-color: rgba(255, 93, 143, 0.6); color: var(--ch0); }
.solve-strip.off-track::after {
  content: 'NO PATH FROM HERE — UNDO OR RESET';
  width: 100%; text-align: center;
  font-size: 0.62rem; letter-spacing: 0.14em; color: var(--ch0);
  padding-top: 4px;
}

.nav-btn {
  width: 22px; height: 22px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface);
  color: var(--dim); font-size: 0.9rem; line-height: 1;
  cursor: pointer; vertical-align: middle;
  transition: color 0.15s, border-color 0.15s;
}
.nav-btn:hover:not(:disabled) { color: var(--ink); border-color: rgba(168, 162, 220, 0.3); }
.nav-btn:disabled { opacity: 0.25; cursor: default; }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 6px;
}
.dpad-btn {
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink); font-size: 1.25rem; font-family: var(--font-mono);
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
  user-select: none;
}
.dpad-btn:active {
  transform: scale(0.9);
  background: #1c1c30;
  border-color: rgba(255, 182, 72, 0.5);
}
.dpad-wait {
  color: var(--echo);
  font-size: 0.6rem; font-weight: 700; letter-spacing: 0.1em;
  border-color: rgba(154, 134, 255, 0.35);
}

.foot {
  text-align: center; color: var(--dim);
  font-size: 0.66rem; letter-spacing: 0.12em;
  margin-top: auto;
}
.foot b { color: var(--ink); }

/* ---------- Modals ---------- */

.modal {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 4, 9, 0.72);
  backdrop-filter: blur(6px);
  padding: 20px;
}
.modal[hidden] { display: none; }

.modal-panel {
  width: min(100%, 400px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 2px solid var(--echo);
  border-radius: 16px;
  padding: 26px 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: panel-in 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  text-align: center;
}
@keyframes panel-in {
  from { transform: translateY(24px) scale(0.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.modal-title {
  font-family: var(--font-display); font-weight: 800;
  letter-spacing: 0.08em; font-size: 1.35rem;
  margin-bottom: 18px;
}
.modal-title.glow { color: var(--exit); text-shadow: 0 0 24px rgba(47, 230, 200, 0.5); }

.help-steps {
  text-align: left; list-style: none;
  display: flex; flex-direction: column; gap: 14px;
  font-size: 0.8rem; line-height: 1.55; color: var(--dim);
}
.help-steps b { color: var(--ink); }
.help-steps li { padding-left: 4px; }

.chip {
  display: inline-block; width: 12px; height: 12px;
  border-radius: 4px; vertical-align: -1px; margin-right: 2px;
}
.chip-player { background: var(--player); box-shadow: 0 0 8px rgba(255,182,72,.6); }
.chip-echo { background: transparent; box-shadow: inset 0 0 0 2px var(--echo); }
.chip-exit { background: transparent; box-shadow: inset 0 0 0 2px var(--exit); border-radius: 50%; }
.chip-door { background: repeating-linear-gradient(45deg, var(--ch0) 0 3px, transparent 3px 6px); box-shadow: inset 0 0 0 1px var(--ch0); }
.chip-btnc { background: transparent; box-shadow: inset 0 0 0 2px var(--ch0); border-radius: 50%; }

.help-hint {
  margin-top: 16px; font-size: 0.72rem; color: var(--dim); line-height: 1.5;
}
.help-hint b { color: var(--player); }

.big-btn {
  margin-top: 20px; width: 100%;
  font-family: var(--font-display); font-weight: 700;
  letter-spacing: 0.1em; font-size: 0.95rem;
  color: #0a0a12;
  background: linear-gradient(120deg, var(--player), #ffce7e);
  border: none; border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(255, 182, 72, 0.25);
  transition: transform 0.1s, box-shadow 0.15s;
}
.big-btn:hover { box-shadow: 0 8px 30px rgba(255, 182, 72, 0.4); }
.big-btn:active { transform: scale(0.97); }

.win-line { font-size: 0.9rem; color: var(--ink); }
.win-line.par-hit { color: var(--player); font-weight: 700; }
.win-streak { margin-top: 6px; font-size: 0.75rem; color: var(--dim); }
.share-done { margin-top: 8px; font-size: 0.7rem; color: var(--exit); }
.win-row { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.next-in { margin-top: 16px; font-size: 0.68rem; letter-spacing: 0.1em; color: var(--dim); }
.next-in b { color: var(--echo); }

.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
}
.stat {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 4px;
}
.stat b { display: block; font-size: 1.3rem; color: var(--ink); }
.stat span { font-size: 0.6rem; letter-spacing: 0.08em; color: var(--dim); }

@media (max-width: 380px) {
  .dpad { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); }
  .icon-btn { width: 31px; height: 31px; font-size: 0.85rem; }
  .stage { padding-left: 12px; padding-right: 12px; }
}
