:root {
  color-scheme: dark;
  --bg: #0a0a0c;
  --card: #111114;
  --canvas: #0c0c0f;
  --line: #2a2a30;
  --text: #f2f2f0;
  --dim: #a0a0aa;
  --accent: #ffb7c5;
  --mono: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: auto;
  background: radial-gradient(ellipse at 48% 35%, #1a1a1d 0, #111114 37%, var(--bg) 74%);
}
body.playing { overflow: hidden; overscroll-behavior: none; }
button, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, .stage:focus-visible, textarea:focus-visible {
  outline: 2px solid #ececf1;
  outline-offset: 3px;
}
button[aria-disabled="true"] { cursor: default; opacity: .65; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

.workspace {
  max-width: 820px;
  width: calc(100% - 24px);
  min-height: 100%;
  margin-inline: auto;
  padding-block: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  perspective: 1400px;
}
.outside {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 3px 8px;
  color: var(--dim);
  font: 12px var(--mono);
}
.home { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; color: inherit; text-decoration: none; }
.home:hover { color: var(--text); }
.home span { font-size: 16px; }
.window {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: linear-gradient(145deg, #17171b, #101013 70%);
  box-shadow: inset 0 0 0 1px #ffffff04, 0 25px 85px -32px #000, 0 0 46px -24px #ffffff28;
  backdrop-filter: blur(12px);
  transform: rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
  transition: transform .23s ease-out;
}
.window.steady { transform: none; transition: none; }
.titlebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 9px 0 14px;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
  font: 12px var(--mono);
  color: var(--dim);
}
.window-label, .window-tools, .tool-button { display: flex; align-items: center; }
.window-label { gap: 8px; color: #d0d0d6; }
.window-label svg, .tool-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.45;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.window-tools { gap: 3px; }
.tool-button {
  gap: 5px;
  justify-content: center;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 7px;
  color: var(--dim);
  min-height: 38px;
  min-width: 42px;
  padding: 0 8px;
}
.tool-button:hover { color: var(--text); background: #ffffff09; }
#sound[aria-pressed="false"] #sound-wave, #sound[aria-pressed="true"] #sound-cross { display: none; }

.window-body { padding: 16px 12px 0; }
.game-header { display: flex; align-items: end; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
h1, h2 { font-family: 'Space Grotesk', Inter, system-ui, sans-serif; }
h1 { font-size: clamp(1.68rem, 6.1vw, 3rem); letter-spacing: -.055em; line-height: 1; margin: 0; font-weight: 600; }
#game-label { margin: 8px 0 0; color: var(--dim); font-size: .75rem; min-height: 1em; }
.mode {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #0b0b0e;
  border: 1px solid var(--line);
  border-radius: 9px;
}
.mode button {
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--dim);
  padding: 0 7px;
  min-height: 34px;
  font-size: .78rem;
}
.mode button:hover { color: var(--text); }
.mode button[aria-pressed="true"] { color: var(--text); background: #242429; border-color: #37373e; }

.console {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--canvas);
}
.console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 43px;
  padding: 0 11px;
  border-bottom: 1px solid #202026;
  color: #c0c0c7;
  font-size: .76rem;
}
.rounds { display: flex; gap: 4px; list-style: none; padding: 0; margin: 0; }
.rounds li {
  width: 24px;
  height: 21px;
  display: grid;
  place-items: center;
  font-size: .64rem;
  border-radius: 4px;
  border: 1px solid #2c2c33;
  color: #85858f;
}
.rounds li[aria-current="step"] { color: var(--text); border-color: #85858e; }
.rounds li.scored { background: #e4e4e8; color: #151518; border-color: transparent; font-weight: 600; }

.playfield {
  height: clamp(148px, calc(100dvh - 400px), 315px);
  position: relative;
  isolation: isolate;
  background: radial-gradient(ellipse at 50% 42%, #151519 0, transparent 76%),
    radial-gradient(circle, #ffffff1b .55px, transparent 1px) 1px 3px / 16px 16px;
}
.playfield::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  background: radial-gradient(ellipse at 50% 52%, transparent 30%, #0c0c0f 94%);
  pointer-events: none;
}
.stage { position: absolute; inset: 0; touch-action: none; user-select: none; cursor: ew-resize; outline-offset: -3px !important; }
.stage.dragging { cursor: grabbing; }
.stage[aria-disabled="true"] { cursor: default; }
.stage svg { display: block; width: 100%; height: 100%; overflow: hidden; }
.ground { stroke: #55555e; stroke-width: 1; }
.ruler-tick { stroke: #52525e; stroke-width: 1; }
.guide { stroke: #676770; stroke-width: 1; stroke-dasharray: 2 4; opacity: .45; }
.support-rail { stroke: #a0a0aa; stroke-width: 1; opacity: .66; transition: opacity .18s ease-out; }
.support-rail.released { opacity: 0; }
.fulcrum { fill: #34343c; stroke: #c2c2ca; stroke-width: 1.2; stroke-linejoin: round; }
.stand-marker { fill: none; stroke: #b0b0ba; stroke-width: 1.25; stroke-linecap: round; stroke-linejoin: round; }
.shape { fill: #ededef; }
.centre-line { stroke: var(--accent); stroke-width: 1.45; stroke-dasharray: 4 4; }
.centre-dot { fill: var(--accent); stroke: #36242b; stroke-width: 1; }
.stage.locked .fulcrum { fill: #9a9aa5; }
.stage.locked .stand-marker { opacity: .45; }

.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  min-height: 68px;
  border-top: 1px solid #25252a;
  padding: 8px 10px;
}
.feedback { display: grid; gap: 5px; }
#status { font-size: .86rem; font-weight: 600; line-height: 1.22; }
#controls, #round-detail { font-size: .69rem; color: var(--dim); line-height: 1.3; }
#round-detail strong { color: var(--text); font-weight: 600; }
.keyboard-hint { display: none; }
kbd { font: inherit; border: 1px solid #414149; padding: 0 .22em; border-radius: 3px; }
.action-buttons { display: flex; align-items: center; gap: 6px; }
.primary, .secondary {
  border: 1px solid #ffffff26;
  border-radius: 7px;
  min-height: 42px;
  padding: 0 10px;
  white-space: nowrap;
  font-size: .78rem;
  font-weight: 600;
}
.primary { background: #efeff1; color: #161619; min-width: 78px; }
.primary:hover { background: #fff; }
.primary:active { background: #c5c5cb; }
.secondary { background: #232329; color: var(--text); }
.secondary:hover { background: #313139; }

.game-footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; padding: 9px 0; gap: 8px 12px; }
.stats { display: flex; justify-content: space-between; flex: 1 1 100%; gap: 5px; margin: 0; }
.stats > div { display: flex; flex-direction: column-reverse; gap: 3px; }
.stats dt, .reset span { font-size: .66rem; color: var(--dim); white-space: nowrap; }
.stats dd { margin: 0; font: 600 .95rem var(--mono); }
.reset { display: flex; align-items: baseline; gap: 8px; font-size: .76rem; }
.storage-note {
  position: fixed;
  bottom: 0;
  inset-inline: 12px;
  margin: 0;
  padding: 7px;
  text-align: center;
  background: #151519;
  color: var(--dim);
  font-size: .74rem;
}

.results {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px;
}
.results h2 { font-size: 1rem; font-weight: 500; margin: 0; color: var(--dim); }
.total { margin: 0; font: 600 clamp(2.6rem, 10vw, 4.9rem)/.92 'Space Grotesk', sans-serif; letter-spacing: -.07em; font-variant-numeric: tabular-nums; }
.total span + span { color: var(--dim); font: 500 .9rem var(--mono); letter-spacing: 0; }
.result-scores { list-style: none; padding: 0; margin: 4px 0 0; display: flex; gap: 5px; }
.result-scores li {
  min-width: 39px;
  border: 1px solid #414149;
  border-radius: 5px;
  background: #1a1a1f;
  font: .8rem var(--mono);
  text-align: center;
  padding: 6px 4px;
  box-shadow: inset 0 2px #ffffff37;
}
.result-scores li[data-band="high"] { box-shadow: inset 0 2px #f2f2f0; }
.result-scores li[data-band="middle"] { box-shadow: inset 0 2px #ffffff85; }

dialog {
  width: min(440px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: 16px 18px 18px;
  color: var(--text);
  background: #17171c;
  border: 1px solid #42424b;
  border-radius: 14px;
  box-shadow: 0 20px 90px #0009;
}
dialog::backdrop { background: #050506b8; backdrop-filter: blur(5px); }
dialog header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
dialog h2 { margin: 0; letter-spacing: -.035em; }
dialog header button { font-size: 1.4rem; }
dialog p, dialog li, dialog label { color: #ceced4; font-size: .95rem; line-height: 1.5; }
dialog ol { padding-left: 20px; }
dialog li + li { margin-top: 8px; }
dialog textarea { display: block; width: 100%; margin: 12px 0; resize: vertical; color: var(--text); background: #101013; border: 1px solid #575762; border-radius: 6px; padding: 8px; }

@media (min-width: 560px) {
  .workspace { width: calc(100% - 56px); }
  .titlebar { min-height: 48px; padding-inline: 16px 11px; }
  .window-body { padding: 22px 23px 0; }
  .game-header { margin-bottom: 17px; }
  #game-label { font-size: .81rem; }
  .mode button { min-height: 35px; padding-inline: 12px; font-size: .83rem; }
  .console-head { min-height: 47px; padding-inline: 15px; }
  .rounds { gap: 6px; }
  .rounds li { width: 33px; height: 23px; font-size: .72rem; }
  .playfield { height: clamp(152px, calc(100dvh - 380px), 315px); }
  .action-row { min-height: 71px; padding-inline: 14px; }
  #status { font-size: .97rem; }
  #controls, #round-detail { font-size: .73rem; }
  .primary, .secondary { min-width: 113px; padding-inline: 14px; font-size: .85rem; }
  .game-footer { flex-wrap: nowrap; gap: 20px; min-height: 68px; }
  .stats { flex: 1 1 auto; justify-content: start; gap: clamp(12px, 3.4vw, 31px); }
  .stats dt, .reset span { font-size: .72rem; }
  .stats dd { font-size: 1.04rem; }
  .reset { flex-direction: column-reverse; gap: 4px; text-align: right; align-items: end; }
  .reset time { font-size: .95rem; }
  .results { gap: 14px; }
  .result-scores li { min-width: 52px; }
}

@media (max-width: 399px) {
  .window-tools button span { display: none; }
}

@media (pointer: fine) {
  .keyboard-hint { display: inline; }
  .pointer-hint::after { content: ' · '; }
}

@media (pointer: fine) and (max-width: 559px) {
  .keyboard-hint { display: none; }
  .pointer-hint::after { content: none; }
}

@media (max-height: 540px) {
  .workspace { padding-block: 3px; }
  .outside { margin-bottom: 2px; }
  .outside a { min-height: 21px; }
  .titlebar { min-height: 36px; }
  .titlebar button { min-height: 32px; }
  .window-body { padding-top: 9px; }
  .game-header { margin-bottom: 7px; }
  h1 { font-size: 1.55rem; }
  #game-label { margin-top: 4px; }
  .mode button { min-height: 29px; }
  .console-head { min-height: 30px; }
  .playfield { height: clamp(73px, calc(100dvh - 251px), 200px); }
  .action-row { min-height: 48px; padding-block: 3px; }
  .action-row button { min-height: 36px; }
  .game-footer { padding-block: 5px; min-height: 0; }
  .results { gap: 2px; }
  .results h2 { font-size: .85rem; }
  .total { font-size: 1.8rem; }
  .result-scores li { padding-block: 1px; }
}

@media (prefers-reduced-motion: reduce) {
  .window { transform: none; transition: none; }
  .support-rail { transition: none; }
}
