:root {
  font-family: 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  color: #f8f4ff;
  background: #15152b;
  font-synthesis: none;
  --ink: #17162c;
  --deep: #202044;
  --panel: #292957;
  --panel-2: #34346b;
  --pink: #ff5d8f;
  --cyan: #4de4d1;
  --yellow: #ffd166;
  --paper: #fff7e6;
  --muted: #b8b7d4;
}

* { box-sizing: border-box; }
html, body, #app { margin: 0; min-width: 320px; min-height: 100%; }
body {
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,93,143,.16), transparent 32rem),
    radial-gradient(circle at 82% 90%, rgba(77,228,209,.13), transparent 36rem),
    linear-gradient(145deg, #141429, #202044 55%, #181831);
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .2;
  background-image: repeating-linear-gradient(0deg, transparent 0 3px, rgba(255,255,255,.025) 4px);
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, #game-canvas:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

.topbar {
  height: 74px;
  padding: 0 clamp(16px, 3vw, 44px);
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto minmax(240px, 1fr);
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,.1);
  background: rgba(15,15,32,.72);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 44px; height: 31px; border-radius: 7px; background: var(--pink); display: flex; align-items: center; justify-content: space-around; padding: 7px; box-shadow: 0 7px 18px rgba(255,93,143,.23); transform: rotate(-2deg); }
.brand-mark i { width: 12px; height: 12px; border: 3px solid var(--ink); border-radius: 50%; }
.brand strong { display: block; font-size: 22px; letter-spacing: .14em; line-height: .95; }
.brand small { display: block; color: var(--muted); font: 500 10px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .13em; margin-top: 5px; }
.chapter-readout { text-align: center; }
.chapter-readout span { display: block; color: var(--muted); font: 500 10px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .16em; }
.chapter-readout b { font: 500 17px ui-monospace, 'SFMono-Regular', Consolas, monospace; color: var(--yellow); }
.top-actions { display: flex; justify-content: flex-end; gap: 10px; }
.icon-button { border: 1px solid rgba(255,255,255,.14); border-radius: 999px; padding: 9px 13px; background: rgba(255,255,255,.055); font: 500 10px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .08em; cursor: pointer; }
.icon-button:hover { background: rgba(255,255,255,.11); }

.layout { width: min(1600px, 100%); margin: 0 auto; padding: clamp(16px, 2vw, 28px); display: grid; grid-template-columns: minmax(620px, 1.55fr) minmax(320px, .72fr); gap: 22px; min-height: calc(100vh - 116px); }
.cassette-shell { align-self: start; position: relative; padding: clamp(18px, 2.6vw, 38px); border-radius: 42px; color: var(--ink); background: linear-gradient(145deg, #fff4df, #e9dfc9 60%, #d9ceb8); border: 1px solid #fffef3; box-shadow: 0 30px 70px rgba(3,3,13,.38), inset 0 2px 1px rgba(255,255,255,.85), inset 0 -4px 0 rgba(74,63,54,.15); }
.cassette-shell::before, .cassette-shell::after { content: ''; position: absolute; width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle, #6c655e 0 22%, #bdb2a2 24% 52%, #6f655b 54% 61%, #eee3ce 64%); box-shadow: inset 0 1px 2px rgba(0,0,0,.25); }
.cassette-shell::before { left: 22px; bottom: 22px; }
.cassette-shell::after { right: 22px; bottom: 22px; }
.cassette-label { text-align: center; margin-bottom: 14px; }
.cassette-label span { display: block; font: 500 10px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .18em; color: #655f58; }
.cassette-label strong { display: block; margin: 5px 0 1px; font-size: clamp(23px, 3vw, 40px); letter-spacing: -.045em; }
.cassette-label em { display: block; color: #6f675e; font-size: 13px; font-style: normal; }
.reel-row { height: 62px; display: grid; grid-template-columns: 62px minmax(120px, 240px) 62px; justify-content: center; align-items: center; gap: 10px; margin-bottom: 14px; }
.reel { width: 58px; height: 58px; border-radius: 50%; background: repeating-conic-gradient(#343143 0 11deg, #b9ac9b 12deg 24deg); border: 5px solid #302e3c; box-shadow: inset 0 0 0 5px #e5d8c2, 0 2px 4px rgba(0,0,0,.3); transition: transform .25s ease; }
.reel .hub { width: 18px; height: 18px; border-radius: 50%; margin: 15px; background: var(--paper); border: 4px dotted #3a3746; }
.tape-window { position: relative; height: 33px; border-radius: 5px; background: #292735; overflow: hidden; border: 3px solid #928777; box-shadow: inset 0 3px 5px rgba(0,0,0,.55); }
#tape-fill { position: absolute; inset: 0 auto 0 0; width: 0%; background: linear-gradient(90deg, #bc315c, var(--pink)); transition: width .22s ease; }
#tape-readout { position: absolute; inset: 0; display: grid; place-items: center; color: white; font: 500 12px ui-monospace, 'SFMono-Regular', Consolas, monospace; text-shadow: 0 1px 3px #000; }
.screen-bezel { position: relative; height: clamp(420px, 62vh, 680px); padding: clamp(10px, 1.3vw, 18px); border-radius: 24px; background: linear-gradient(145deg, #34313d, #191822); box-shadow: inset 0 0 0 4px #605a5a, inset 0 0 0 8px #1b1923, 0 5px 10px rgba(0,0,0,.34); }
#game-canvas { width: 100%; height: 100%; overflow: hidden; border-radius: 14px; background: radial-gradient(circle at 50% 20%, #40427b, #23244b 65%, #1a1a37); }
#game-canvas canvas { display: block; width: 100% !important; height: 100% !important; }
.mode-banner { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 2; border-radius: 999px; padding: 7px 13px; background: rgba(20,19,40,.82); border: 1px solid rgba(255,255,255,.17); color: var(--pink); font: 500 10px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .1em; pointer-events: none; backdrop-filter: blur(8px); }
.mode-banner.playback { color: var(--cyan); }
.cassette-footer { display: flex; justify-content: space-between; margin-top: 14px; color: #6f675e; font: 500 9px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .1em; }

.control-deck { display: grid; gap: 14px; align-content: start; }
.panel { padding: 17px; border: 1px solid rgba(255,255,255,.11); border-radius: 18px; background: linear-gradient(145deg, rgba(55,55,113,.88), rgba(36,36,78,.94)); box-shadow: 0 15px 35px rgba(3,3,15,.2), inset 0 1px 0 rgba(255,255,255,.08); }
.panel-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
.panel-title span { color: var(--muted); font: 500 10px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .15em; }
.panel-title b { color: var(--yellow); font: 500 12px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .08em; }
.objective-panel p, .hint-panel p { margin: 0; line-height: 1.42; font-size: 14px; }
.legend { display: flex; gap: 15px; margin-top: 14px; color: var(--muted); font: 500 10px ui-monospace, 'SFMono-Regular', Consolas, monospace; }
.legend span { display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; display: inline-block; border-radius: 50%; }
.dot-a { background: var(--pink); }.dot-b { background: var(--cyan); }.dot-goal { background: var(--yellow); }
.transport-buttons, .command-buttons { display: grid; gap: 8px; }
.transport-buttons { grid-template-columns: 1fr 1.35fr 1fr; }
.command-buttons { grid-template-columns: repeat(3, 1fr); margin-top: 8px; }
.transport-panel button, .hint-panel button, .complete-actions button { border: 1px solid rgba(255,255,255,.14); border-radius: 10px; min-height: 42px; background: rgba(255,255,255,.06); font: 600 10px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .06em; cursor: pointer; }
.transport-panel button span { display: block; font-size: 15px; margin-bottom: 2px; }
button.primary, #rewind-button.primary { color: var(--ink); background: var(--pink); border-color: #ff8faf; box-shadow: 0 7px 18px rgba(255,93,143,.22); }
button:hover { filter: brightness(1.12); transform: translateY(-1px); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .35; cursor: not-allowed; transform: none; }
#timeline { width: 100%; accent-color: var(--pink); }
.command-strip { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(20px, 1fr); gap: 4px; min-height: 31px; margin: 8px 0 13px; overflow: hidden; }
.command-chip { display: grid; place-items: center; min-width: 0; border-radius: 6px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.08); color: var(--muted); font: 500 11px ui-monospace, 'SFMono-Regular', Consolas, monospace; }
.command-chip.used { color: white; background: rgba(255,93,143,.2); border-color: rgba(255,93,143,.5); }
.command-chip.played { background: rgba(77,228,209,.24); border-color: rgba(77,228,209,.7); }
.speed-row { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font: 500 10px ui-monospace, 'SFMono-Regular', Consolas, monospace; }
.speed-row div { display: flex; gap: 5px; }
.speed-row button { border: 1px solid rgba(255,255,255,.11); border-radius: 999px; background: transparent; color: var(--muted); padding: 5px 9px; cursor: pointer; }
.speed-row button.selected { background: var(--cyan); color: var(--ink); border-color: var(--cyan); }
.hint-copy-revealed { color: var(--yellow); }
.hint-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 13px; }
.hint-actions button { grid-row: span 2; }
.hint-actions label { font: 500 10px ui-monospace, 'SFMono-Regular', Consolas, monospace; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.hint-actions input { accent-color: var(--cyan); }
.statusbar { min-height: 42px; padding: 0 clamp(16px, 3vw, 44px); display: flex; align-items: center; gap: 18px; border-top: 1px solid rgba(255,255,255,.1); color: var(--muted); font: 500 9px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .07em; }
kbd { display: inline-block; border: 1px solid rgba(255,255,255,.16); border-bottom-width: 2px; border-radius: 4px; padding: 2px 4px; color: white; background: rgba(255,255,255,.07); font: inherit; }
.statusbar b { margin-left: auto; color: var(--cyan); }

dialog { border: none; padding: 0; background: transparent; color: white; }
dialog::backdrop { background: rgba(6,5,18,.78); backdrop-filter: blur(7px); }
.dialog-card { width: min(560px, calc(100vw - 32px)); padding: 24px; border-radius: 22px; border: 1px solid rgba(255,255,255,.18); background: linear-gradient(145deg, #393973, #23234a); box-shadow: 0 35px 90px rgba(0,0,0,.5); }
.dialog-title { display: flex; justify-content: space-between; align-items: center; color: var(--yellow); font: 500 12px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .1em; }
.dialog-title button { border: 0; background: transparent; color: white; font-size: 26px; cursor: pointer; }
.dialog-card ol { padding-left: 22px; line-height: 1.5; }
.dialog-card li { margin: 10px 0; }
.dialog-card > p { color: var(--muted); font-size: 13px; line-height: 1.45; }
.complete-card { text-align: center; }
.success-badge { display: inline-block; padding: 7px 12px; border-radius: 999px; color: var(--ink); background: var(--cyan); font: 600 10px ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .11em; }
.complete-card h2 { margin: 17px 0 5px; font-size: 28px; }
.complete-stars { font-size: 42px; color: var(--yellow); letter-spacing: .12em; margin: 18px 0; text-shadow: 0 7px 22px rgba(255,209,102,.25); }
.complete-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (max-width: 1050px) {
  .layout { grid-template-columns: 1fr; }
  .control-deck { grid-template-columns: repeat(2, 1fr); }
  .screen-bezel { height: min(62vw, 620px); }
}
@media (max-width: 700px) {
  .topbar { height: auto; min-height: 68px; grid-template-columns: 1fr auto; padding-block: 10px; }
  .chapter-readout { display: none; }
  .top-actions .icon-button:first-child { display: none; }
  .layout { padding: 10px; }
  .cassette-shell { border-radius: 24px; padding: 18px 12px 24px; }
  .cassette-label em, .cassette-footer { display: none; }
  .reel-row { transform: scale(.88); margin-block: -4px 4px; }
  .screen-bezel { height: 74vw; min-height: 360px; padding: 8px; border-radius: 17px; }
  .control-deck { grid-template-columns: 1fr; }
  .statusbar span { display: none; }
  .statusbar b { margin: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
