/* LOOP THIEF — neon arcade UI */
:root {
  --bg: #070b18; --bg2: #0c1228; --panel: rgba(16, 24, 54, .78); --line: rgba(110, 140, 255, .22);
  --text: #e6ecff; --dim: #8b97c4; --cyan: #22d3ee; --violet: #a78bfa; --pink: #f472b6;
  --gold: #fde047; --red: #ff3b5c; --green: #34d399; --amber: #f59e0b;
  --px: 'Press Start 2P', 'IBM Plex Mono', monospace;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans); color: var(--text); background: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 10% -10%, rgba(34, 211, 238, .12), transparent 60%),
    radial-gradient(900px 600px at 110% 10%, rgba(244, 114, 182, .10), transparent 60%),
    linear-gradient(rgba(110, 140, 255, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(110, 140, 255, .05) 1px, transparent 1px);
  background-size: auto, auto, 32px 32px, 32px 32px;
  overflow-x: hidden; -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
kbd { font-family: var(--mono); font-size: .8em; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); background: rgba(255,255,255,.06); }

/* ---------- top bar ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; max-width: 1240px; margin: 0 auto;
}
.back { font-family: var(--mono); font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); text-decoration: none; }
.back:hover { color: var(--cyan); }
.brand { font-family: var(--px); font-size: .9rem; letter-spacing: .1em; color: var(--cyan); text-shadow: 0 0 12px rgba(34,211,238,.6); }
.brand em { font-style: normal; color: var(--pink); text-shadow: 0 0 12px rgba(244,114,182,.6); margin-left: 6px; }
.top__btns { display: flex; gap: 8px; }
.icon {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; font-family: var(--mono); font-weight: 600; transition: border-color .2s, box-shadow .2s;
}
.icon:hover { border-color: var(--cyan); box-shadow: 0 0 14px rgba(34,211,238,.35); }

/* ---------- layout ---------- */
.game {
  max-width: 1240px; margin: 0 auto; padding: 0 16px 32px;
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start;
}
@media (max-width: 959px) { .game { grid-template-columns: minmax(0, 1fr); gap: 14px; } }

.stage, .panel-side { min-width: 0; }
.hud { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.hud__lvl { display: flex; align-items: center; gap: 12px; }
.hud__lvl h1 { font-family: var(--px); font-size: clamp(.85rem, 2.4vw, 1.15rem); margin: 0; line-height: 1.4; }
.tag { font-family: var(--mono); font-size: .72rem; padding: 4px 8px; border-radius: 6px; background: rgba(34,211,238,.12); color: var(--cyan); border: 1px solid rgba(34,211,238,.35); }
.hud__stats { display: flex; flex-wrap: wrap; gap: 6px 16px; font-family: var(--mono); font-size: .74rem; color: var(--dim); letter-spacing: .06em; align-items: center; }
.hud__stats b { color: var(--text); }
.status { padding: 3px 8px; border-radius: 6px; border: 1px solid currentColor; font-weight: 600; }
.status[data-mode="plan"] { color: var(--cyan); }
.status[data-mode="run"] { color: var(--gold); animation: blink 1s steps(2) infinite; }
.status[data-mode="result"] { color: var(--pink); }
.objective { margin: 8px 0 12px; color: var(--dim); font-size: .95rem; max-width: 70ch; }

.board {
  position: relative; display: flex; justify-content: center; padding: 10px;
  border-radius: 18px; background: rgba(5, 8, 20, .7); border: 1px solid var(--line);
  box-shadow: 0 0 0 1px rgba(0,0,0,.4) inset, 0 20px 60px -20px rgba(34,211,238,.25);
}
.board canvas { display: block; border-radius: 10px; image-rendering: auto; }
.coach {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 8px 14px; border-radius: 999px; text-align: center;
  font-family: var(--mono); font-size: .8rem; color: #0b1020; background: var(--gold);
  box-shadow: 0 0 20px rgba(253,224,71,.5); animation: bob 2s ease-in-out infinite; pointer-events: none;
}

@media (max-width: 959px) {
  .board { flex-direction: column; align-items: center; }
  .coach { position: static; transform: none; margin-top: 10px; animation: none; border-radius: 12px; }
  .back { white-space: nowrap; font-size: .7rem; }
  .brand { font-size: .72rem; }
}

/* ---------- side panel ---------- */
.panel-side { display: flex; flex-direction: column; gap: 12px; }
.hint { margin: 0; padding: 10px 12px; border-radius: 12px; font-size: .88rem; color: var(--text);
  background: rgba(253,224,71,.07); border: 1px solid rgba(253,224,71,.3); }
.hint b { font-family: var(--mono); font-size: .7rem; color: var(--gold); letter-spacing: .12em; margin-right: 4px; }
.tl-head { display: flex; justify-content: space-between; font-family: var(--mono); font-size: .72rem; letter-spacing: .12em; color: var(--dim); }
.tl-head b { color: var(--text); }
.timeline { display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); min-height: 52px; }
.timeline.shake { animation: shake .35s; }
.trow { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; gap: 8px; }
.trow b { font-family: var(--mono); font-size: .7rem; color: var(--gc, var(--text)); }
.trow--you b { color: #fff; }
.chips { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; scroll-behavior: smooth; }
.chips::-webkit-scrollbar { display: none; }
.chips em { font-style: normal; font-size: .78rem; color: var(--dim); }
.chip {
  flex: 0 0 auto; min-width: 24px; height: 26px; padding: 0 5px; display: grid; place-items: center;
  font-family: var(--mono); font-size: .85rem; border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--gc, #fff) 45%, transparent);
  background: color-mix(in srgb, var(--gc, #fff) 10%, transparent);
  transition: transform .15s, background .15s;
}
.trow--you .chip { border-color: rgba(255,255,255,.4); background: rgba(255,255,255,.08); animation: pop .18s ease-out; }
.chip.done { opacity: .35; }
.chip.now { transform: translateY(-2px) scale(1.12); background: var(--gc, #fff); color: #0b1020; box-shadow: 0 0 12px var(--gc, #fff); }

.controls { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; }
@media (max-width: 420px) { .controls { grid-template-columns: 1fr; justify-items: center; } }
.pad { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); gap: 6px; }
.key {
  border-radius: 12px; border: 1px solid var(--line); background: linear-gradient(180deg, #1a2550, #10183a);
  font-size: 1.3rem; font-weight: 600; cursor: pointer; box-shadow: 0 4px 0 #070b18, 0 0 0 1px rgba(0,0,0,.3) inset;
  display: grid; place-items: center; line-height: 1; touch-action: manipulation; transition: transform .06s, box-shadow .06s, border-color .2s;
}
.key small { display: block; font-family: var(--mono); font-size: .58rem; color: var(--dim); margin-top: 3px; }
.key--wait, .key--use { font-family: var(--mono); font-size: .66rem; letter-spacing: .08em; }
.key--up { grid-area: 1 / 2; } .key--left { grid-area: 2 / 1; } .key--wait { grid-area: 2 / 2; }
.key--right { grid-area: 2 / 3; } .key--down { grid-area: 3 / 2; } .key--use { grid-area: 3 / 3; color: var(--green); border-color: rgba(52,211,153,.4); }
.key:hover:not(:disabled) { border-color: var(--cyan); }
.key:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #070b18; }
.key:disabled, .abtn:disabled { opacity: .4; cursor: default; }
.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.abtn {
  min-height: 44px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel);
  font-family: var(--mono); font-size: .76rem; letter-spacing: .04em; cursor: pointer; transition: border-color .2s, box-shadow .2s, transform .1s;
}
.abtn:hover:not(:disabled) { border-color: var(--cyan); }
.abtn--run {
  grid-column: 1 / -1; min-height: 54px; font-family: var(--px); font-size: .85rem; letter-spacing: .12em; color: #0b1020;
  background: linear-gradient(90deg, var(--cyan), var(--violet)); border: 0; box-shadow: 0 0 20px rgba(34,211,238,.35);
}
.abtn--run.is-ready { animation: glow 1.6s ease-in-out infinite; }
.abtn--run:active:not(:disabled) { transform: scale(.98); }
.abtn--quiet { grid-column: 1 / -1; color: var(--dim); min-height: 36px; background: transparent; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(4, 6, 16, .78); backdrop-filter: blur(6px); animation: fade .25s ease-out;
}
.overlay[hidden] { display: none; }
.overlay .panel {
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; text-align: center;
  padding: 28px 24px; border-radius: 20px; background: linear-gradient(180deg, #111a3d, #0a1029);
  border: 1px solid var(--line); box-shadow: 0 0 0 1px rgba(34,211,238,.15), 0 30px 80px -20px rgba(0,0,0,.8), 0 0 60px -10px rgba(34,211,238,.25);
  animation: rise .35s cubic-bezier(.2,.8,.2,1);
}
.overlay h2 { font-family: var(--px); font-size: 1rem; line-height: 1.5; margin: 0 0 18px; color: var(--cyan); }
.overlay p { color: var(--dim); }
.overlay--title { background: radial-gradient(circle at 50% 40%, rgba(34,211,238,.12), rgba(4,6,16,.92) 70%); }
.overlay--title .panel { background: transparent; border: 0; box-shadow: none; }

.logo {
  position: relative; font-family: var(--px); font-size: clamp(2rem, 9vw, 3.6rem); line-height: 1.15; letter-spacing: .04em;
  color: #fff; text-shadow: 0 0 18px rgba(34,211,238,.8), 0 0 40px rgba(167,139,250,.5); margin: 10px 0 18px;
}
.logo::before, .logo::after { content: attr(data-text); position: absolute; inset: 0; pointer-events: none; }
.logo::before { color: var(--cyan); transform: translate(-3px, 0); clip-path: inset(0 0 55% 0); opacity: .8; animation: glitch 2.6s infinite steps(1); }
.logo::after { color: var(--pink); transform: translate(3px, 0); clip-path: inset(55% 0 0 0); opacity: .8; animation: glitch 3.1s infinite steps(1) reverse; }
.tagline { font-family: var(--mono); font-size: .9rem; color: var(--gold) !important; margin: 0 0 26px; }
.credits { font-family: var(--mono); font-size: .7rem; margin-top: 20px; opacity: .7; }

.pstack { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.pbtn {
  min-height: 46px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.04);
  font-family: var(--mono); font-size: .86rem; cursor: pointer; transition: border-color .2s, background .2s, transform .1s;
}
.pbtn:hover { border-color: var(--cyan); background: rgba(34,211,238,.08); }
.pbtn:active { transform: scale(.98); }
.pbtn--primary { font-family: var(--px); font-size: .78rem; letter-spacing: .06em; line-height: 1.6; color: #0b1020; border: 0;
  background: linear-gradient(90deg, var(--cyan), var(--violet)); box-shadow: 0 0 22px rgba(34,211,238,.4); }
.pbtn--primary:hover { background: linear-gradient(90deg, #67e8f9, #c4b5fd); }
.pbtn--ghost { flex: 1; font-size: .78rem; }
.pbtn--danger { color: var(--red); border-color: rgba(255,59,92,.35); }
.pbtn--small { min-height: 36px; font-size: .74rem; margin-top: 16px; }
.toggles { display: flex; gap: 10px; margin-top: 14px; }
.small { font-size: .8rem; margin: 2px 0; }
.warn { color: var(--amber) !important; }

.result { font-family: var(--px); font-size: clamp(1.4rem, 6vw, 2.2rem); line-height: 1.3; margin: 6px 0 14px; }
.result--win { color: var(--gold); text-shadow: 0 0 20px rgba(253,224,71,.7); animation: pulse 1.4s ease-in-out infinite; }
.result--fail { color: var(--red); text-shadow: 0 0 20px rgba(255,59,92,.6); animation: jolt .4s; }
.big { font-family: var(--mono); color: var(--text) !important; font-size: 1rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.stats div { padding: 12px 6px; border-radius: 12px; background: rgba(255,255,255,.04); border: 1px solid var(--line); }
.stats b { display: block; font-family: var(--px); font-size: 1.2rem; color: var(--cyan); }
.stats span { font-family: var(--mono); font-size: .7rem; color: var(--dim); }

.rules { text-align: left; padding-left: 20px; line-height: 1.6; color: var(--text); font-size: .92rem; }
.rules li { margin-bottom: 6px; }
.legend { display: grid; gap: 8px; text-align: left; margin: 16px 0; font-size: .84rem; color: var(--dim); }
.legend span { display: flex; align-items: center; gap: 10px; }
.lg { flex: 0 0 22px; height: 22px; border-radius: 6px; display: inline-block; }
.lg--plate { border: 2px solid var(--amber); background: rgba(245,158,11,.3); }
.lg--switch { border: 2px solid var(--green); border-radius: 50%; }
.lg--door { background: repeating-linear-gradient(90deg, #8f1d2c 0 8px, transparent 8px 14px); border: 2px solid #ef4444; }
.lg--laser { background: repeating-linear-gradient(45deg, rgba(255,59,92,.5) 0 3px, transparent 3px 7px); border: 1px solid var(--red); }
.lg--exit { background: var(--gold); transform: rotate(45deg) scale(.7); box-shadow: 0 0 10px var(--gold); }

/* how-to-play guide */
.overlay--help .panel { width: min(620px, 100%); text-align: left; }
.overlay--help h2 { margin-bottom: 14px; }
.help__step { font-family: var(--mono); font-size: .7rem; letter-spacing: .2em; color: var(--gold) !important; margin: 0 0 8px; }
.help__demo { position: relative; display: flex; justify-content: center; padding: 8px; margin-bottom: 14px; border-radius: 14px;
  background: #050816; border: 1px solid var(--line); }
.help__demo canvas { display: block; border-radius: 8px; }
.help__demo span { position: absolute; top: 6px; right: 10px; font-family: var(--mono); font-size: .58rem; letter-spacing: .14em; color: var(--red); animation: blink 1.4s steps(2) infinite; }
.help__body { font-size: .93rem; line-height: 1.6; color: var(--text); }
.help__body p { color: #b7c1e4; margin: 0 0 10px; }
.help__body b { color: #fff; }
.help__body .rules { margin: 0 0 12px; }
.rules--list { list-style: none; padding-left: 0; }
.rules--list li { position: relative; padding-left: 18px; }
.rules--list li::before { content: "▸"; position: absolute; left: 0; color: var(--cyan); }
.c-you { text-shadow: 0 0 8px var(--cyan); }
.help__body .c-gold { color: var(--gold); }
.help__body .c-ghost { color: var(--cyan); }
.tip { padding: 10px 12px; border-radius: 10px; background: rgba(34,211,238,.07); border: 1px solid rgba(34,211,238,.25); color: var(--text) !important; }
.keys { width: 100%; border-collapse: collapse; font-size: .84rem; margin: 4px 0 14px; }
.keys th { font-family: var(--mono); font-size: .66rem; letter-spacing: .12em; text-align: left; color: var(--dim); font-weight: 500; padding: 0 8px 6px 0; }
.keys td { padding: 7px 8px 7px 0; border-top: 1px solid var(--line); color: #b7c1e4; }
.keys td:first-child { color: #fff; }
.help__dots { display: flex; justify-content: center; gap: 8px; margin: 16px 0 12px; }
.dot { width: 10px; height: 10px; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.12); cursor: pointer; transition: background .2s, transform .2s; }
.dot.is-on { background: var(--cyan); box-shadow: 0 0 10px var(--cyan); transform: scale(1.2); }
.help__nav { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }

.lvlgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.lvl {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 14px; border-radius: 14px; text-align: left;
  border: 1px solid var(--line); background: rgba(255,255,255,.04); cursor: pointer; transition: border-color .2s, transform .15s;
}
.lvl:hover:not(:disabled) { border-color: var(--cyan); transform: translateY(-2px); }
.lvl:disabled { opacity: .45; cursor: default; }
.lvl.is-done { border-color: rgba(52,211,153,.45); }
.lvl__n { font-family: var(--px); font-size: .9rem; color: var(--cyan); }
.lvl__name { font-weight: 600; font-size: .92rem; }
.lvl__meta { font-family: var(--mono); font-size: .68rem; color: var(--dim); }
.lvl.is-done .lvl__meta { color: var(--green); }

.toast {
  position: fixed; left: 50%; bottom: 22px; z-index: 60; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 12px; max-width: calc(100% - 32px); text-align: center;
  font-family: var(--mono); font-size: .82rem; background: #111a3d; border: 1px solid var(--cyan); box-shadow: 0 0 22px rgba(34,211,238,.35);
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- animation ---------- */
@keyframes blink { 50% { opacity: .35; } }
@keyframes bob { 50% { transform: translate(-50%, -4px); } }
@keyframes glow { 50% { box-shadow: 0 0 34px rgba(34,211,238,.7), 0 0 60px rgba(167,139,250,.35); } }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(16px) scale(.97); opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes pulse { 50% { transform: scale(1.04); } }
@keyframes jolt { 0% { transform: translateX(-10px); } 25% { transform: translateX(8px); } 50% { transform: translateX(-5px); } 100% { transform: none; } }
@keyframes glitch {
  0%, 86%, 100% { transform: translate(0, 0); }
  88% { transform: translate(-4px, 1px); } 90% { transform: translate(3px, -1px); } 93% { transform: translate(-2px, 0); }
}

/* JS sets .reduced from the OS preference or the in-game setting */
.reduced *, .reduced *::before, .reduced *::after { animation: none !important; transition: none !important; }
