@font-face { font-family: 'Orbitron'; font-weight: 700 900; font-display: swap; src: url(fonts/orbitron-900.woff2) format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-weight: 400; font-display: swap; src: url(fonts/jbm-400-ext.woff2) format('woff2'); unicode-range: U+0100-02BA, U+1E00-1E9F; }
@font-face { font-family: 'JetBrains Mono'; font-weight: 400; font-display: swap; src: url(fonts/jbm-400.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: 'JetBrains Mono'; font-weight: 700; font-display: swap; src: url(fonts/jbm-700-ext.woff2) format('woff2'); unicode-range: U+0100-02BA, U+1E00-1E9F; }
@font-face { font-family: 'JetBrains Mono'; font-weight: 700; font-display: swap; src: url(fonts/jbm-700.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: 'Inter'; font-weight: 100 900; font-display: swap; src: url(fonts/inter-ext.woff2) format('woff2'); unicode-range: U+0100-02BA, U+1E00-1E9F; }
@font-face { font-family: 'Inter'; font-weight: 100 900; font-display: swap; src: url(fonts/inter.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }

:root {
  --bg: #0a0a0f;
  --panel: #12121b;
  --panel-2: #191925;
  --line: #2a2a3a;
  --text: #ececf4;
  --dim: #9494a6;
  --cyan: #00f0ff;
  --violet: #7b2fff;
  --pink: #ff2d7b;
  --green: #00ff88;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --brand: 'Orbitron', 'JetBrains Mono', monospace;
  --top: max(14px, env(safe-area-inset-top));
  --bottom: max(16px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--bg); overscroll-behavior: none; }
body {
  color: var(--text);
  font: 400 15px/1.45 var(--sans);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
a { color: var(--cyan); }

#app {
  position: relative;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background:
    linear-gradient(rgba(0, 240, 255, .028) 1px, transparent 1px) 0 0 / 100% 32px,
    linear-gradient(90deg, rgba(0, 240, 255, .028) 1px, transparent 1px) 0 0 / 32px 100%,
    var(--bg);
  overflow: hidden;
}
@media (min-width: 520px) { #app { border-inline: 1px solid var(--line); } }

.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  padding: var(--top) 16px var(--bottom);
  animation: rise .28s ease-out;
}
.screen.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.bar-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.brand { font: 900 14px/1 var(--brand); letter-spacing: .14em; }
.brand b { color: var(--cyan); font-weight: 900; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 12px;
  font: 700 13px/1 var(--mono); letter-spacing: .04em;
  color: var(--text);
  border: 1px solid var(--line); border-radius: 22px; background: var(--panel);
}
.pill.on { border-color: var(--cyan); color: var(--cyan); }
.pill svg { width: 16px; height: 16px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 22px; border: 1px solid var(--line); background: var(--panel); }
.icon-btn svg { width: 20px; height: 20px; stroke: var(--text); fill: none; stroke-width: 1.8; }
.row { display: flex; gap: 8px; align-items: center; }

/* The System */
.eye-wrap { display: grid; place-items: center; flex: 0 0 auto; }
.eye-wrap canvas { width: var(--eye, min(58vw, 34dvh, 280px)); height: var(--eye, min(58vw, 34dvh, 280px)); display: block; }

.say {
  min-height: 2.9em;
  font: 400 16px/1.42 var(--mono);
  text-align: center;
  color: var(--text);
  padding: 0 6px;
  text-wrap: balance;
}
.say.pop { animation: say .22s ease-out; }
@keyframes say { from { opacity: .2; } }

/* Home */
.home-main { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 12px; min-height: 0; }
.level { text-align: center; }
.level .k { font: 700 12px/1 var(--mono); letter-spacing: .24em; color: var(--dim); }
.level .n { font: 900 54px/1.05 var(--brand); letter-spacing: .02em; }
.level .m { font: 700 13px/1 var(--mono); letter-spacing: .18em; color: var(--cyan); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 58px; padding: 0 16px;
  font: 700 16px/1.1 var(--mono); letter-spacing: .16em;
  color: #04040a; background: var(--cyan);
  border-radius: 14px;
  transition: transform .08s;
}
.btn:active { transform: scale(.98); }
.btn.ghost { background: var(--panel); color: var(--text); border: 1px solid var(--line); font-size: 14px; letter-spacing: .04em; min-height: 50px; }
.btn.hot { background: transparent; color: var(--cyan); border: 1px solid var(--cyan); font-size: 14px; letter-spacing: .04em; min-height: 50px; }
.btn[disabled] { opacity: .45; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.tile {
  text-align: left; padding: 12px 13px; min-height: 72px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  display: flex; flex-direction: column; justify-content: center; gap: 3px;
}
.tile .a { font: 700 12px/1.25 var(--mono); letter-spacing: .05em; }
.tile .b { font: 400 12px/1.25 var(--mono); color: var(--dim); }
.tile.done .b { color: var(--green); }

/* Play */
.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.hud .where { font: 700 12px/1.3 var(--mono); letter-spacing: .1em; min-width: 0; }
.hud .where span { display: block; color: var(--cyan); font-weight: 400; letter-spacing: .08em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tug { margin: 8px 0 2px; }
.tug .labels { display: flex; justify-content: space-between; font: 700 11px/1 var(--mono); letter-spacing: .16em; margin-bottom: 6px; }
.tug .labels .s { color: var(--pink); }
.tug .labels .e { color: var(--cyan); }
.tug .track { height: 12px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); overflow: hidden; }
.tug .fill { height: 100%; width: 50%; background: linear-gradient(90deg, var(--violet), var(--cyan)); transition: width .26s cubic-bezier(.3, 1.4, .5, 1); }

.play-mid { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 6px; }
.play-mid .eye-wrap { --eye: min(46vw, 25dvh, 220px); }
.seal {
  font: 400 12px/1.2 var(--mono); color: var(--dim); letter-spacing: .06em;
  display: flex; gap: 12px; justify-content: center; min-height: 15px;
}
.seal b { color: var(--text); font-weight: 700; }
.timer { height: 3px; background: var(--panel-2); border-radius: 2px; overflow: hidden; margin: 8px 0; flex: 0 0 auto; }
.timer i { display: block; height: 100%; background: var(--cyan); transform-origin: left; transform: scaleX(1); }
.timer.low i { background: var(--pink); }

.choices { flex: 0 0 auto; height: 34dvh; display: grid; gap: 10px; grid-template-rows: minmax(0, 1fr); }
.choices.c2 { grid-template-columns: 1fr 1fr; }
.choices.c3 { grid-template-columns: repeat(3, 1fr); }
.choices.c9 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 8px; }
.choice {
  position: relative;
  width: 100%; height: 100%;
  display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  font: 700 19px/1 var(--mono); letter-spacing: .12em;
  overflow: hidden;
}
.c9 .choice { font: 900 26px/1 var(--brand); letter-spacing: 0; }
.choice:active { background: var(--panel-2); }
.choice.door { border-radius: 60px 60px 12px 12px; font: 900 30px/1 var(--brand); }
.choice.warned { border-color: rgba(255, 45, 123, .55); }
.choice .tag { position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; font: 700 10px/1.2 var(--mono); letter-spacing: .08em; color: var(--pink); }
.c9 .choice .tag { display: none; }
.choice.picked { border-color: var(--cyan); background: rgba(0, 240, 255, .12); }
.choice.sealed { border-color: var(--pink); background: rgba(255, 45, 123, .13); color: var(--pink); }
.choice.sealed.picked { background: rgba(255, 45, 123, .3); color: #fff; }
.locked .choice { pointer-events: none; }

.sweep { flex: 0 0 auto; height: 34dvh; position: relative; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: minmax(0, 1fr); gap: 6px; }
.sweep .zone {
  display: grid; place-items: center;
  font: 700 13px/1 var(--mono); letter-spacing: .1em;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  position: relative;
}
.sweep .zone .tag { position: absolute; bottom: 10px; left: 0; right: 0; text-align: center; font: 700 10px/1 var(--mono); color: var(--pink); }
.sweep .zone.picked { border-color: var(--cyan); background: rgba(0, 240, 255, .12); }
.sweep .zone.sealed { border-color: var(--pink); background: rgba(255, 45, 123, .13); color: var(--pink); }
.sweep .zone.sealed.picked { background: rgba(255, 45, 123, .3); color: #fff; }
.sweep .light { position: absolute; top: 0; bottom: 0; left: 0; width: 4px; border-radius: 2px; background: var(--cyan); box-shadow: 0 0 16px 3px var(--cyan); pointer-events: none; will-change: transform; }

.fog-on .eye-wrap { filter: blur(3px) saturate(.5); transition: filter .2s; }

.shake { animation: shake .3s; }
@keyframes shake { 20% { transform: translateX(-7px); } 45% { transform: translateX(6px); } 70% { transform: translateX(-3px); } }

#flash { position: fixed; inset: 0; background: var(--pink); opacity: 0; pointer-events: none; z-index: 20; }
#flash.go { animation: flash .34s ease-out; }
@keyframes flash { from { opacity: .38; } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom) + 16px); transform: translate(-50%, 20px);
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px; border-radius: 10px;
  font: 700 13px/1.3 var(--mono); text-align: center;
  background: var(--panel-2); border: 1px solid var(--cyan);
  opacity: 0; pointer-events: none; transition: .2s; z-index: 40;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* Overlays */
.veil {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: flex-end;
  padding: 16px 16px var(--bottom);
  background: rgba(5, 5, 10, .74);
  animation: fade .18s;
}
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; padding: 18px 16px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; display: flex; flex-direction: column; gap: 10px; }
.sheet h2 { font: 700 15px/1.3 var(--mono); letter-spacing: .14em; color: var(--cyan); }
.sheet p { font: 400 15px/1.5 var(--sans); color: var(--text); }

/* Result */
.result-main { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; min-height: 0; }
.verdict { font: 700 36px/1.05 var(--mono); letter-spacing: .08em; text-align: center; }
.verdict.win { color: var(--cyan); }
.verdict.lose { color: var(--pink); }
.verdict-sub { text-align: center; color: var(--dim); font: 400 14px/1.3 var(--mono); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.stat .k { font: 400 12px/1.25 var(--mono); color: var(--dim); }
.stat .v { font: 900 28px/1.15 var(--brand); margin-top: 4px; }
.note { padding: 12px; border-left: 2px solid var(--violet); background: var(--panel); border-radius: 0 12px 12px 0; }
.note .k { font: 700 11px/1.3 var(--mono); letter-spacing: .1em; color: var(--dim); margin-bottom: 3px; }
.note p { font: 400 14px/1.45 var(--sans); }
.actions { display: flex; flex-direction: column; gap: 8px; }

/* Subject file */
.file-head { text-align: center; padding: 10px 0 4px; }
.file-head h1 { font: 700 15px/1.2 var(--mono); letter-spacing: .2em; color: var(--dim); }
.file-head .rank { font: 700 30px/1.2 var(--mono); letter-spacing: .06em; color: var(--cyan); margin-top: 6px; }
.file-head .id { font: 400 12px/1.4 var(--mono); color: var(--dim); }
.file-head p { font: 400 14px/1.4 var(--sans); margin-top: 4px; }
.meter { padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.meter .top { display: flex; justify-content: space-between; font: 400 13px/1.2 var(--mono); }
.meter .top b { font-weight: 700; }
.meter .line { height: 6px; margin-top: 8px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.meter .line i { display: block; height: 100%; background: var(--cyan); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.small { font: 400 12px/1.4 var(--mono); color: var(--dim); text-align: center; }

/* Settings */
.title { font: 700 15px/1.2 var(--mono); letter-spacing: .14em; }
.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--panel); }
.item { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 8px 14px; text-align: left; width: 100%; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .l small { display: block; color: var(--dim); font-size: 12px; line-height: 1.3; }
.item .r { color: var(--dim); font: 400 13px/1 var(--mono); white-space: nowrap; }
.item.danger { color: var(--pink); }
.switch { width: 44px; height: 26px; border-radius: 13px; background: var(--panel-2); border: 1px solid var(--line); position: relative; flex: 0 0 auto; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--dim); transition: .14s; }
.switch.on { background: rgba(0, 240, 255, .25); border-color: var(--cyan); }
.switch.on::after { left: 21px; background: var(--cyan); }

/* Intro */
.intro { justify-content: center; align-items: flex-start; gap: 12px; padding-inline: 26px; }
.intro p { font: 400 19px/1.4 var(--mono); }
.intro p.dim { color: var(--dim); }
.intro .caret { display: inline-block; width: .55em; height: 1em; vertical-align: -.14em; background: var(--cyan); margin-left: 3px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.skip { position: absolute; top: var(--top); right: 16px; min-height: 44px; padding: 0 10px; color: var(--dim); font: 400 13px/1 var(--mono); }

@media (max-height: 640px) {
  .level .n { font-size: 40px; }
  .choices, .sweep { height: 30dvh; }
  .say { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Languages: long list scrolls; the board keeps its left/right geometry in RTL scripts. */
.lang-list { max-height: 56vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
[dir="rtl"] .choices, [dir="rtl"] .sweep, [dir="rtl"] .tug, [dir="rtl"] .track, [dir="rtl"] .timer, [dir="rtl"] .labels { direction: ltr; }
[dir="rtl"] .choice, [dir="rtl"] .zone { direction: rtl; }
/* Joined and complex scripts break with letter-spacing; uppercase does nothing for them. */
:is(:lang(ar), :lang(ur), :lang(he), :lang(hi), :lang(bn), :lang(mr), :lang(gu), :lang(pa), :lang(or), :lang(ta), :lang(te), :lang(kn), :lang(ml), :lang(th)) * { letter-spacing: 0 !important; }
