:root {
  color-scheme: dark;
  --ink: #ecf5f4;
  --muted: #a9bec2;
  --deep: #060a0d;
  --panel: #0d171c;
  --panel-2: #142229;
  --iron: #4d5f68;
  --brass: #d5a64a;
  --brass-light: #f4dc88;
  --enamel: #5bd2e8;
  --danger: #ee685b;
  --success: #62d9a9;
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--deep); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 8%, #24404a 0, transparent 30rem),
    linear-gradient(135deg, #071014, #030608 70%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, a { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--enamel); outline-offset: 3px; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; background: white; color: black; padding: .8rem 1rem; border-radius: .5rem; }
.skip-link:focus { top: 1rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 72px;
  padding: .7rem clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid #77868b55;
  background: #071014e8;
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: .8rem; color: inherit; text-decoration: none; }
.brand img { filter: drop-shadow(0 8px 12px #0008); }
.brand span { display: grid; }
.brand small { color: var(--brass-light); font-weight: 800; letter-spacing: .13em; text-transform: uppercase; font-size: .66rem; }
.brand strong { font-family: Georgia, serif; font-size: 1.25rem; letter-spacing: .04em; }
.top-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .55rem; }
.top-actions button, .top-actions a {
  min-height: 40px;
  padding: .55rem .8rem;
  border: 1px solid #71808766;
  border-radius: 999px;
  color: var(--ink);
  background: #15232a;
  text-decoration: none;
  cursor: pointer;
}
.top-actions button[aria-pressed="true"] { border-color: var(--enamel); box-shadow: inset 0 0 0 1px #5bd2e855; }

.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 370px);
  gap: clamp(1rem, 2vw, 2rem);
  width: min(1540px, calc(100% - 2rem));
  margin: 0 auto;
  padding: clamp(1rem, 2vw, 2rem) 0 4rem;
}
.game-column, .instrument-panel > section {
  border: 1px solid #6f7f8655;
  border-radius: var(--radius);
  background: linear-gradient(145deg, #132129e8, #091116f4);
  box-shadow: 0 22px 70px #0007, inset 0 1px #ffffff0d;
}
.game-column { padding: clamp(.8rem, 2vw, 1.25rem); min-width: 0; }
.room-heading { display: flex; justify-content: space-between; gap: 1rem; align-items: end; margin-bottom: .8rem; }
.eyebrow { margin: 0 0 .25rem; color: var(--brass-light); font-size: .72rem; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: .25rem; font: 900 clamp(1.6rem, 4vw, 2.8rem)/.98 Georgia, serif; letter-spacing: .015em; }
.room-heading p:last-child { margin-bottom: 0; color: var(--muted); max-width: 68ch; }
.readout { display: flex; margin: 0; border: 1px solid #687a8255; border-radius: 12px; overflow: hidden; flex-shrink: 0; }
.readout div { min-width: 78px; padding: .55rem .7rem; text-align: center; background: #071014aa; border-left: 1px solid #687a8255; }
.readout div:first-child { border-left: 0; }
.readout dt { color: var(--muted); font-size: .65rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.readout dd { margin: .2rem 0 0; color: var(--brass-light); font-weight: 900; text-transform: capitalize; }

.status-message {
  min-height: 46px;
  display: grid;
  align-items: center;
  padding: .65rem .85rem;
  margin-bottom: .8rem;
  border: 1px solid #5e727a55;
  border-left: 5px solid var(--enamel);
  border-radius: 10px;
  color: #d9e8e9;
  background: #0a1419;
}
.status-message.danger { border-left-color: var(--danger); color: #ffd4cf; background: #281214; }
.status-message.success { border-left-color: var(--success); color: #ccffe9; background: #0d261d; }
.status-message.notice { border-left-color: var(--brass); color: #fff0ba; }

.game-canvas {
  width: 100%;
  aspect-ratio: 3 / 2;
  min-height: 300px;
  overflow: hidden;
  border: 1px solid #b78a3e66;
  border-radius: 14px;
  background: #071014;
  box-shadow: inset 0 0 50px #000a;
}
.game-canvas canvas { display: block; width: 100% !important; height: 100% !important; }

.controls { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: .9rem; }
.dpad { display: grid; grid-template-columns: repeat(5, minmax(42px, 56px)); gap: .45rem; }
.dpad button, .command-row button, .freeze-list button, .dialog-actions button {
  min-height: 46px;
  border: 1px solid #77889077;
  border-radius: 10px;
  background: linear-gradient(#25353d, #111b20);
  box-shadow: inset 0 1px #ffffff13, 0 6px 12px #0004;
  cursor: pointer;
}
.dpad button:hover, .command-row button:hover, .freeze-list button:hover, .dialog-actions button:hover { border-color: var(--brass-light); transform: translateY(-1px); }
.dpad #wait-button { color: var(--brass-light); }
.command-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
.command-row button { padding: .65rem .9rem; }
kbd { padding: .08rem .35rem; margin-left: .3rem; border: 1px solid #ffffff2b; border-radius: 4px; color: var(--brass-light); background: #0005; }
.keyboard-help { margin: .8rem 0 0; color: var(--muted); font-size: .82rem; }

.instrument-panel { display: grid; align-content: start; gap: 1rem; }
.instrument-panel > section { padding: 1rem; }
.instrument-panel p { color: var(--muted); font-size: .88rem; line-height: 1.5; }
.panel-title { display: flex; align-items: center; gap: .6rem; margin-bottom: .55rem; }
.panel-title span { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid var(--brass); border-radius: 50%; color: var(--brass-light); font-size: .68rem; font-weight: 900; }
.panel-title h2 { margin: 0; font: 800 1.03rem/1.1 Georgia, serif; }

.cycle-list { display: grid; gap: .6rem; }
.cycle-card { padding: .65rem; border: 1px solid #66777e55; border-radius: 10px; background: #071014aa; }
.cycle-heading { display: flex; gap: .5rem; align-items: baseline; margin-bottom: .5rem; }
.cycle-heading strong { color: var(--brass-light); }
.cycle-heading span { color: #dbe7e8; font-size: .82rem; }
.cycle-track { display: grid; grid-template-columns: repeat(4, 1fr); gap: .35rem; }
.cycle-frame { min-height: 30px; display: grid; place-items: center; border: 1px solid #55717b; border-radius: 6px; color: #bcebf2; background: #12313b; font-size: .72rem; font-weight: 900; }
.cycle-frame.danger { border-color: var(--danger); color: #ffd4cf; background: #4a1718; }

.freeze-list { display: flex; flex-wrap: wrap; gap: .45rem; }
.freeze-list button { padding: .55rem .7rem; font-size: .78rem; }
.freeze-list button.selected { border-color: var(--enamel); color: #ccf8ff; }
button:disabled { opacity: .4; cursor: not-allowed; transform: none !important; }

.hint-panel { border-color: #d5a64a88 !important; background: linear-gradient(145deg, #29220f, #11130e) !important; }
.hint-panel p { margin-bottom: 0; color: #fff0ba; }

.room-list { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; }
.room-list button {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: .4rem;
  align-items: center;
  min-height: 48px;
  padding: .4rem .5rem;
  border: 1px solid #5d707855;
  border-radius: 9px;
  color: #c4d3d5;
  background: #081116;
  text-align: left;
  cursor: pointer;
}
.room-list button span { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 50%; background: #23343c; color: var(--brass-light); font-size: .7rem; }
.room-list button strong { font-size: .73rem; line-height: 1.15; }
.room-list button.current { border-color: var(--enamel); box-shadow: inset 0 0 0 1px #5bd2e844; }
.room-list button.completed span::after { content: "✓"; }
.room-list button.completed span { font-size: 0; background: #1d6048; color: #d6ffec; }
.room-list button.completed span::after { font-size: .8rem; }
.room-list button.mastered { border-color: var(--brass); }
.room-list button.locked { opacity: .45; }

.completion-panel {
  width: min(520px, calc(100% - 2rem));
  padding: 2rem;
  border: 1px solid var(--brass);
  border-radius: 20px;
  color: var(--ink);
  background: linear-gradient(145deg, #1c2a30, #081014);
  box-shadow: 0 30px 100px #000c;
  text-align: center;
}
.completion-panel::backdrop { background: #020506c9; backdrop-filter: blur(8px); }
.completion-panel[open] { animation: rise .25s ease-out; }
.seal { width: 82px; height: 82px; display: grid; place-items: center; margin: 0 auto 1rem; border: 4px double var(--brass-light); border-radius: 50%; color: var(--brass-light); font-size: 2rem; background: #14333c; }
.completion-panel h2 { font: 900 2rem/1 Georgia, serif; }
.completion-panel p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: center; gap: .6rem; }
.dialog-actions button { padding: .7rem 1rem; }
.dialog-actions button:first-child { border-color: var(--brass); color: #1a1207; background: linear-gradient(#f0d980, #ba8230); font-weight: 900; }

@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; } }
@media (max-width: 1050px) {
  .game-shell { grid-template-columns: 1fr; width: min(980px, calc(100% - 1rem)); }
  .instrument-panel { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .topbar, .room-heading, .controls { align-items: stretch; flex-direction: column; }
  .top-actions { justify-content: flex-start; }
  .readout { width: 100%; }
  .readout div { flex: 1; min-width: 0; }
  .game-column { padding: .55rem; }
  .game-canvas { min-height: 250px; }
  .controls { display: grid; justify-items: center; }
  .command-row { justify-content: center; }
  .instrument-panel { grid-template-columns: 1fr; }
}
