:root {
  --stage: #111416;
  --stage-raised: #1b1f21;
  --roll: #e9eceb;
  --roll-muted: #d5d9d7;
  --roll-shadow: #b5bbb8;
  --ink: #111416;
  --key: #202326;
  --oxidized: #176b66;
  --oxidized-dark: #0d4b47;
  --copper: #a95b36;
  --copper-light: #d28a62;
  --miss: #c9363e;
  --miss-dark: #8f1f29;
  --focus: #f2b65c;
  --white: #ffffff;
  --muted-on-dark: #c5cdca;
  --line-on-dark: #41484a;
  --radius-panel: 12px;
  --radius-control: 8px;
  --z-header: 20;
  --z-dropdown: 40;
  --z-overlay: 10;
  --z-flash: 8;
  --tempo-duration: 1.1s;
  color-scheme: dark;
  font-family: "Atkinson Hyperlegible", "Noto Sans TC", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--stage);
  color: var(--roll);
  touch-action: manipulation;
  user-select: none;
}

button,
select {
  font: inherit;
}

button,
a,
summary,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
a:focus-visible,
summary:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 50%;
  z-index: calc(var(--z-dropdown) + 1);
  padding: 10px 16px;
  color: var(--ink);
  background: var(--focus);
  border-radius: var(--radius-control);
  font-weight: 800;
  transform: translate(-50%, -160%);
  transition: transform 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.skip-link:focus {
  transform: translate(-50%, 0);
}

.app-shell {
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  height: 100dvh;
  min-height: 0;
  padding: 10px 16px 14px;
}

.app-header {
  position: relative;
  z-index: var(--z-header);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  width: min(1120px, 100%);
  min-width: 0;
  margin: 0 auto;
}

.header-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 13px;
  color: var(--roll);
  background: var(--stage-raised);
  border: 1px solid var(--line-on-dark);
  border-radius: var(--radius-control);
  font-size: 0.9rem;
  font-weight: 720;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition:
    color 160ms cubic-bezier(0.22, 1, 0.36, 1),
    background-color 160ms cubic-bezier(0.22, 1, 0.36, 1),
    border-color 160ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.header-control:hover {
  color: var(--white);
  background: #252a2c;
  border-color: #626b6d;
}

.header-control:active {
  transform: translateY(1px);
}

.back-link {
  justify-self: start;
  gap: 8px;
}

.app-identity {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
  text-align: left;
}

.app-identity h1 {
  margin: 0;
  font-family: "Bahnschrift Condensed", "Arial Narrow", "Noto Sans TC", sans-serif;
  font-size: 1.2rem;
  font-stretch: condensed;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.app-subtitle {
  display: block;
  margin-top: 4px;
  color: var(--muted-on-dark);
  font-size: 0.72rem;
  line-height: 1;
}

.roll-mark {
  display: grid;
  grid-template-columns: repeat(4, 5px);
  gap: 3px;
  align-items: end;
  width: 34px;
  height: 34px;
  padding: 7px 6px;
  color: var(--ink);
  background: var(--roll);
  border: 2px solid var(--copper);
  border-radius: 6px;
}

.roll-mark i {
  display: block;
  height: 14px;
  background: var(--ink);
  border-radius: 1px;
}

.roll-mark i:nth-child(2) {
  height: 9px;
}

.roll-mark i:nth-child(3) {
  height: 17px;
}

.roll-mark i:nth-child(4) {
  height: 11px;
}

.settings {
  position: relative;
  justify-self: end;
}

.settings > summary {
  gap: 7px;
  list-style: none;
}

.settings > summary::-webkit-details-marker {
  display: none;
}

.settings-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: var(--z-dropdown);
  width: min(250px, calc(100vw - 24px));
  padding: 14px;
  color: var(--ink);
  background: var(--roll);
  border: 2px solid var(--ink);
  border-radius: var(--radius-control);
}

.settings-panel label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.82rem;
  font-weight: 800;
}

.settings-panel select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  color: var(--ink);
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
}

.settings-version {
  display: flex;
  justify-content: space-between;
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--roll-shadow);
  color: #4b5250;
  font-size: 0.75rem;
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(360px, 550px);
  gap: 14px;
  justify-content: center;
  width: min(1120px, 100%);
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
}

.performance-panel,
.instrument-shell {
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius-panel);
}

.performance-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  color: var(--ink);
  background: var(--roll);
  border: 2px solid #070808;
}

.score-rail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
  padding: 11px 12px;
  color: var(--roll);
  background: var(--ink);
  border-bottom: 4px solid var(--copper);
}

.score-rail > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
  padding: 5px 8px;
}

.score-rail dt {
  overflow: hidden;
  color: var(--muted-on-dark);
  font-size: 0.7rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-rail dd {
  margin: 0;
  color: var(--white);
  font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.score-rail output {
  font: inherit;
}

.panel-body {
  position: relative;
  min-height: 0;
  padding: clamp(18px, 4vh, 34px) clamp(18px, 2.4vw, 28px);
  overflow: auto;
  overscroll-behavior: contain;
}

.panel-body::before,
.panel-body::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: 1px;
  background: var(--roll-shadow);
  pointer-events: none;
}

.panel-body::before {
  top: 24%;
}

.panel-body::after {
  top: 76%;
}

.paper-label,
.run-panel,
.result-panel {
  position: relative;
  z-index: 1;
}

.paper-label {
  padding: 18px 16px 16px;
  border: 2px solid var(--ink);
  border-radius: 6px;
}

.label-fastener {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: var(--copper);
  border: 2px solid var(--ink);
  border-radius: 50%;
}

.panel-kicker {
  margin: 0 0 10px;
  color: var(--oxidized-dark);
  font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.panel-body h2 {
  max-width: 12ch;
  margin: 0;
  font-family: "Bahnschrift Condensed", "Arial Narrow", "Noto Sans TC", sans-serif;
  font-size: clamp(2rem, 4vw, 3.4rem);
  font-stretch: condensed;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 0.98;
  text-wrap: balance;
}

.panel-copy {
  max-width: 34ch;
  margin: 16px 0 20px;
  color: #3e4543;
  font-size: 0.9rem;
  line-height: 1.6;
  text-wrap: pretty;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 164px;
  min-height: 48px;
  padding: 11px 18px;
  color: var(--white);
  background: var(--oxidized);
  border: 0;
  border-radius: var(--radius-control);
  box-shadow: 0 4px 0 var(--oxidized-dark);
  font-weight: 850;
  cursor: pointer;
  transition:
    background-color 160ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 160ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.primary-action:hover {
  background: #1d7b75;
  transform: translateY(-1px);
  box-shadow: 0 5px 0 var(--oxidized-dark);
}

.primary-action:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--oxidized-dark);
}

.run-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.run-panel h2 {
  font-size: clamp(2.3rem, 5vw, 4rem);
}

.pulse-readout {
  display: flex;
  gap: 9px;
  margin-top: auto;
  padding-top: 16px;
}

.pulse-readout span {
  width: 13px;
  height: 13px;
  background: var(--ink);
  border-radius: 50%;
  animation: pulse-mark var(--tempo-duration) ease-in-out infinite alternate;
}

.pulse-readout span:nth-child(2) {
  animation-delay: calc(var(--tempo-duration) * -0.25);
}

.pulse-readout span:nth-child(3) {
  animation-delay: calc(var(--tempo-duration) * -0.5);
}

.pulse-readout span:nth-child(4) {
  animation-delay: calc(var(--tempo-duration) * -0.75);
}

@keyframes pulse-mark {
  from {
    transform: scale(0.62);
    background: var(--roll-shadow);
  }
  to {
    transform: scale(1);
    background: var(--oxidized);
  }
}

.result-heading {
  display: flex;
  align-items: center;
  gap: 14px;
}

.result-heading h2 {
  max-width: 10ch;
  font-size: clamp(1.8rem, 3.6vw, 2.8rem);
}

.medal {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  color: var(--roll);
  background: var(--ink);
  border: 3px solid var(--copper);
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 1.7rem;
}

#new-best {
  display: inline-block;
  margin: 6px 0 0;
  padding: 3px 7px;
  color: var(--white);
  background: var(--oxidized-dark);
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 800;
}

#new-best[hidden] {
  display: none;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 18px 0;
  padding: 1px;
  background: var(--roll-shadow);
}

.result-grid > div {
  min-width: 0;
  padding: 9px 10px;
  background: var(--roll);
}

.result-grid dt {
  color: #525957;
  font-size: 0.68rem;
  font-weight: 700;
}

.result-grid dd {
  margin: 3px 0 0;
  font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
}

.instruction-strip {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid var(--roll-shadow);
  background: #dde1df;
}

.instruction-strip p {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
  color: #383e3c;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.25;
}

.touch-glyph {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  color: var(--copper);
  border: 1px solid #767e7b;
  border-radius: 50%;
  font-size: 0.72rem;
}

.key-chord {
  display: inline-flex;
  gap: 2px;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 24px;
  padding: 0 4px;
  color: var(--roll);
  background: var(--key);
  border: 0;
  border-bottom: 2px solid #050606;
  border-radius: 3px;
  font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 800;
}

.sound-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 44px;
  min-height: 44px;
  padding: 7px 9px;
  color: var(--ink);
  background: transparent;
  border: 2px solid var(--ink);
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
  transition:
    color 160ms cubic-bezier(0.22, 1, 0.36, 1),
    background-color 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.sound-button:hover {
  color: var(--white);
  background: var(--ink);
}

.sound-button[aria-pressed="false"] .sound-icon {
  text-decoration: line-through;
}

@media (min-width: 720px) and (min-height: 481px) {
  .instruction-strip {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .instruction-strip p:nth-of-type(2) {
    grid-column: 1 / -1;
  }

  .instruction-strip .sound-button {
    grid-row: 1;
    grid-column: 2;
  }
}

@media (min-width: 720px) and (min-height: 481px) and (max-height: 620px) {
  .performance-panel {
    grid-template-rows: 56px minmax(0, 1fr) 52px;
  }

  .score-rail {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 4px;
    border-bottom-width: 3px;
  }

  .score-rail > div {
    display: block;
    padding: 3px;
    text-align: center;
  }

  .score-rail dt {
    font-size: 0.55rem;
  }

  .score-rail dd {
    margin-top: 2px;
    font-size: 0.95rem;
  }

  .panel-body {
    padding: 14px 18px;
  }

  .instruction-strip {
    grid-template-columns: 1fr 1fr 44px;
    gap: 5px;
    padding: 4px 6px;
  }

  .instruction-strip p:nth-of-type(2),
  .instruction-strip .sound-button {
    grid-row: auto;
    grid-column: auto;
  }

  .instruction-strip p {
    justify-content: center;
  }

  .instruction-strip p > span:last-child,
  .sound-button #sound-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .sound-button {
    width: 44px;
    min-width: 44px;
    padding: 5px;
  }
}

.instrument-shell {
  display: grid;
  grid-template-rows: 46px minmax(0, 1fr) 46px;
  overflow: hidden;
  background: #0a0c0d;
  border: 2px solid #070808;
  box-shadow: inset 0 0 0 3px #2b3032;
}

.machine-header {
  display: grid;
  grid-template-columns: 44px 1fr 60px 44px;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 5px 8px;
  color: var(--roll);
  background: var(--key);
  border-bottom: 2px solid var(--copper);
}

.spindle {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: #090b0c;
  border: 2px solid #5e6667;
  border-radius: 50%;
}

.spindle i {
  display: block;
  width: 13px;
  height: 13px;
  background: var(--copper);
  border: 3px solid #080909;
  border-radius: 50%;
}

.spindle--right {
  justify-self: end;
}

.machine-plate {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid #565d5f;
  border-radius: 3px;
}

.machine-plate span {
  color: var(--muted-on-dark);
  font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
  font-size: 0.56rem;
  letter-spacing: 0.12em;
}

.machine-plate strong {
  color: var(--copper-light);
  font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
  font-size: 0.7rem;
}

.tempo-dial {
  position: relative;
  width: 52px;
  height: 28px;
  overflow: hidden;
  border-bottom: 1px solid #747d7f;
}

.tempo-dial i {
  position: absolute;
  bottom: -9px;
  left: 50%;
  width: 19px;
  height: 19px;
  background: #080909;
  border: 2px solid var(--copper);
  border-radius: 50%;
  transform: translateX(-50%);
}

.tempo-hand {
  position: absolute;
  bottom: 5px;
  left: 50%;
  width: 2px;
  height: 24px;
  background: var(--copper-light);
  transform: translateX(-50%) rotate(-32deg);
  transform-origin: 50% 100%;
}

[data-phase="playing"] .tempo-hand {
  animation: tempo-swing var(--tempo-duration) cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}

@keyframes tempo-swing {
  from {
    transform: translateX(-50%) rotate(-32deg);
  }
  to {
    transform: translateX(-50%) rotate(32deg);
  }
}

.paper-roll {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--roll);
  cursor: crosshair;
  isolation: isolate;
}

.paper-roll::before,
.paper-roll::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 5;
  width: 9px;
  background: var(--roll-shadow);
  pointer-events: none;
}

.paper-roll::before {
  left: 0;
  border-right: 2px solid #9ea5a2;
}

.paper-roll::after {
  right: 0;
  border-left: 2px solid #9ea5a2;
}

.lane-grid,
.tile-layer,
.board-flash {
  position: absolute;
  inset: 0;
}

.lane-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  z-index: 1;
}

.lane {
  position: relative;
  min-width: 0;
  border-right: 1px solid #aab0ae;
}

.lane:last-child {
  border-right: 0;
}

.lane::before,
.lane::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 4px;
  height: 4px;
  background: #99a09d;
  border-radius: 50%;
  transform: translateX(-50%);
}

.lane::before {
  top: 12px;
}

.lane::after {
  bottom: 12px;
}

.tile-layer {
  z-index: 3;
  pointer-events: none;
}

.piano-tile {
  position: absolute;
  top: 0;
  left: calc(var(--lane) * 25%);
  width: 25%;
  height: var(--tile-height, 25%);
  padding: 5px 7px;
  background: transparent;
  border: 0;
  cursor: pointer;
  pointer-events: auto;
  will-change: transform;
}

.tile-face {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--roll);
  background: var(--ink);
  border: 2px solid #070808;
  border-radius: 5px;
  box-shadow:
    inset 0 -5px 0 #050606,
    inset 0 2px 0 #343a3c;
  transition:
    background-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
    border-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
    border-radius 180ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 180ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.tile-face::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid #697173;
  border-radius: 50%;
}

.piano-tile:hover .tile-face {
  background: #282d2f;
}

.piano-tile:active .tile-face {
  transform: scaleY(0.96);
}

.piano-tile.is-hit {
  pointer-events: none;
}

.piano-tile.is-hit .tile-face {
  background: var(--roll-muted);
  border-color: var(--copper);
  border-radius: 50%;
  box-shadow: inset 0 0 0 5px var(--roll);
  transform: scale(0.56, 0.35);
}

.piano-tile.is-hit .tile-face::before {
  background: var(--ink);
  border-color: var(--ink);
}

.piano-tile.is-missed .tile-face,
.piano-tile.is-wrong .tile-face {
  color: var(--white);
  background: var(--miss);
  border-color: var(--miss-dark);
  box-shadow: inset 0 -5px 0 var(--miss-dark);
  animation: wrong-note 210ms cubic-bezier(0.22, 1, 0.36, 1) 2 alternate;
}

@keyframes wrong-note {
  from {
    transform: translateX(-5px);
  }
  to {
    transform: translateX(5px);
  }
}

.tracker-rail {
  position: absolute;
  right: 0;
  bottom: 13%;
  left: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  height: 16px;
  padding: 0 9px;
  background: var(--copper);
  border-top: 2px solid #6c351f;
  border-bottom: 2px solid #6c351f;
  pointer-events: none;
}

.punch-mark {
  justify-self: center;
  width: 18px;
  height: 6px;
  background: #5f2e1c;
  border-radius: 50%;
}

.board-flash {
  z-index: var(--z-flash);
  opacity: 0;
  pointer-events: none;
}

.board-flash.is-hit {
  background: rgba(23, 107, 102, 0.22);
  animation: board-flash 180ms ease-out;
}

.board-flash.is-combo {
  background: rgba(169, 91, 54, 0.28);
  animation: board-flash 220ms ease-out;
}

.board-flash.is-miss {
  background: rgba(201, 54, 62, 0.34);
  animation: board-flash 260ms ease-out;
}

@keyframes board-flash {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.game-shell.is-shaking .instrument-shell {
  animation: instrument-shake 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes instrument-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  55% {
    transform: translateX(5px);
  }
  80% {
    transform: translateX(-2px);
  }
}

.lane-guide {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  padding: 5px 8px 7px;
  background: var(--key);
  border-top: 2px solid #050606;
}

.lane-guide > span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  color: var(--muted-on-dark);
  font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
  font-size: 0.64rem;
}

.lane-guide kbd {
  min-width: 27px;
  height: 27px;
  color: var(--ink);
  background: var(--roll);
  border-bottom-color: #969e9b;
}

.lane-guide i {
  font-style: normal;
}

[hidden] {
  display: none !important;
}

@media (max-width: 719px) {
  .app-shell {
    grid-template-rows: 52px minmax(0, 1fr);
    gap: 7px;
    padding: 7px 8px 9px;
  }

  .game-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 206px minmax(0, 1fr);
    gap: 7px;
  }

  .performance-panel {
    grid-template-rows: 48px minmax(0, 1fr) 48px;
  }

  .score-rail {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 4px 5px;
    border-bottom-width: 3px;
  }

  .score-rail > div {
    display: block;
    padding: 3px 4px;
    text-align: center;
  }

  .score-rail dt {
    display: block;
    font-size: 0.58rem;
  }

  .score-rail dd {
    margin-top: 2px;
    font-size: 1rem;
  }

  .panel-body {
    padding: 9px 12px;
    overflow: auto;
  }

  .paper-label {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto 1fr;
    column-gap: 12px;
    height: 100%;
    padding: 10px 12px;
  }

  .paper-label .panel-kicker {
    grid-column: 1;
    margin-bottom: 3px;
  }

  .paper-label h2 {
    grid-column: 1;
    font-size: 1.55rem;
  }

  .paper-label .panel-copy {
    display: -webkit-box;
    grid-column: 1;
    margin: 6px 0 0;
    overflow: hidden;
    color: #3f4644;
    font-size: 0.76rem;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .paper-label .primary-action {
    grid-row: 1 / -1;
    grid-column: 2;
    align-self: center;
    min-width: 124px;
    min-height: 44px;
    padding: 9px 12px;
  }

  .run-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-content: center;
    column-gap: 14px;
  }

  .run-panel .panel-kicker {
    margin-bottom: 3px;
  }

  .run-panel h2 {
    font-size: 1.65rem;
  }

  .run-panel .panel-copy {
    display: -webkit-box;
    margin: 5px 0 0;
    overflow: hidden;
    font-size: 0.75rem;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .pulse-readout {
    grid-row: 1 / 4;
    grid-column: 2;
    align-self: center;
    margin: 0;
    padding: 0;
  }

  .result-panel {
    display: grid;
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px 9px;
    height: 100%;
  }

  .result-panel > .panel-kicker {
    display: none;
  }

  .result-heading {
    min-width: 0;
    gap: 8px;
  }

  .result-heading > div {
    min-width: 0;
  }

  .medal {
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
  }

  .result-heading h2 {
    max-width: none;
    overflow-wrap: anywhere;
    font-size: 1.05rem;
    line-height: 1.05;
  }

  #new-best {
    margin-top: 2px;
    font-size: 0.62rem;
  }

  .result-grid {
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    margin: 0;
  }

  .result-grid > div {
    padding: 3px 5px;
  }

  .result-grid dt {
    overflow-wrap: anywhere;
    font-size: 0.5rem;
    line-height: 1.15;
  }

  .result-grid dd {
    margin-top: 1px;
    font-size: 0.82rem;
  }

  .result-panel .primary-action {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 7px 10px;
  }

  .game-shell[data-phase="gameover"] {
    grid-template-rows: 270px minmax(0, 1fr);
  }

  .instruction-strip {
    grid-template-columns: 1fr 1fr 44px;
    padding: 4px 6px;
  }

  .instruction-strip p {
    font-size: 0.62rem;
  }

  .sound-button {
    width: 44px;
    padding: 5px;
  }

  .sound-button #sound-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .instrument-shell {
    grid-template-rows: 40px minmax(0, 1fr) 40px;
  }

  .machine-header {
    grid-template-columns: 36px 1fr 56px 36px;
  }

  .spindle {
    width: 28px;
    height: 28px;
  }

  .spindle i {
    width: 11px;
    height: 11px;
  }
}

@media (max-width: 460px) {
  .app-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 7px;
  }

  .header-control {
    min-width: 42px;
    padding: 7px 10px;
  }

  .back-link span:last-child,
  .settings summary span:last-child,
  .app-subtitle {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .app-identity {
    justify-self: center;
    gap: 7px;
  }

  .app-identity h1 {
    font-size: 1.05rem;
  }

  .roll-mark {
    width: 30px;
    height: 30px;
    padding: 6px 5px;
  }

  .game-shell {
    grid-template-rows: 200px minmax(0, 1fr);
  }

  .paper-label .primary-action {
    min-width: 108px;
    font-size: 0.78rem;
  }

  .instruction-strip p > span:last-child {
    display: none;
  }

  .instruction-strip {
    grid-template-columns: 1fr 1fr 44px;
  }

  .instruction-strip p {
    justify-content: center;
  }

  .key-chord kbd {
    min-width: 19px;
    padding: 0 2px;
  }

  .machine-plate span {
    display: none;
  }
}

@media (min-width: 720px) and (max-height: 480px) {
  .app-shell {
    grid-template-rows: 42px minmax(0, 1fr);
    gap: 6px;
    padding: 6px 10px 8px;
  }

  .app-header {
    width: min(900px, 100%);
  }

  .header-control {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 0.76rem;
  }

  .roll-mark {
    width: 30px;
    height: 30px;
    padding: 5px;
  }

  .app-identity h1 {
    font-size: 1rem;
  }

  .app-subtitle {
    display: none;
  }

  .game-shell {
    grid-template-columns: 260px minmax(360px, 500px);
    gap: 8px;
    width: min(900px, 100%);
  }

  .performance-panel {
    grid-template-rows: 43px minmax(0, 1fr) 42px;
  }

  .score-rail {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 3px 4px;
    border-bottom-width: 3px;
  }

  .score-rail > div {
    display: block;
    padding: 2px 3px;
    text-align: center;
  }

  .score-rail dt {
    font-size: 0.52rem;
  }

  .score-rail dd {
    margin-top: 1px;
    font-size: 0.86rem;
  }

  .panel-body {
    padding: 9px 11px;
    overflow: auto;
  }

  .paper-label {
    height: 100%;
    padding: 9px 10px;
  }

  .panel-kicker {
    display: none;
  }

  .panel-body h2 {
    font-size: 1.45rem;
  }

  .panel-copy {
    display: -webkit-box;
    margin: 7px 0 10px;
    overflow: hidden;
    font-size: 0.68rem;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .primary-action {
    min-width: 132px;
    min-height: 38px;
    padding: 7px 11px;
    font-size: 0.75rem;
  }

  .run-panel h2 {
    margin-top: 4px;
  }

  .pulse-readout {
    padding-top: 6px;
  }

  .pulse-readout span {
    width: 10px;
    height: 10px;
  }

  .result-heading {
    gap: 7px;
  }

  .medal {
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
  }

  .result-heading h2 {
    font-size: 1.1rem;
  }

  .result-grid {
    margin: 7px 0 8px;
  }

  .result-grid > div {
    padding: 3px 5px;
  }

  .result-grid dt {
    font-size: 0.5rem;
  }

  .result-grid dd {
    font-size: 0.82rem;
  }

  #new-best {
    margin-top: 2px;
    padding: 2px 5px;
    font-size: 0.55rem;
  }

  .instruction-strip {
    grid-template-columns: 1fr 1fr 38px;
    padding: 3px 5px;
  }

  .instruction-strip p > span:last-child {
    display: none;
  }

  .instruction-strip p {
    justify-content: center;
  }

  .sound-button {
    width: 38px;
    min-width: 38px;
    min-height: 36px;
    padding: 4px;
  }

  .sound-button #sound-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .instrument-shell {
    grid-template-rows: 34px minmax(0, 1fr) 34px;
  }

  .machine-header {
    grid-template-columns: 28px 1fr 48px 28px;
    gap: 5px;
    padding: 2px 6px;
  }

  .spindle {
    width: 24px;
    height: 24px;
  }

  .spindle i {
    width: 9px;
    height: 9px;
    border-width: 2px;
  }

  .tempo-dial {
    width: 44px;
    height: 23px;
  }

  .lane-guide {
    padding: 2px 6px 3px;
  }

  .lane-guide kbd {
    min-width: 23px;
    height: 23px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .tempo-hand,
  .pulse-readout span {
    animation-name: none !important;
  }
}
