:root {
  --asphalt: #202629;
  --asphalt-deep: #121719;
  --asphalt-soft: #30383b;
  --pit-blue: #234a5d;
  --pit-blue-dark: #173442;
  --enamel: #f4f5f0;
  --enamel-muted: #dce1dd;
  --steel: #aeb8b5;
  --steel-dark: #66716f;
  --ink: #12191c;
  --amber: #e3a12b;
  --amber-dark: #80520c;
  --signal-green: #1a9364;
  --signal-green-dark: #0d523a;
  --foul-red: #b63e35;
  --foul-red-dark: #76231e;
  --focus: #ffd35a;
  --white: #ffffff;
  --radius-panel: 12px;
  --radius-control: 8px;
  --z-header: 10;
  --z-dropdown: 20;
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans TC", sans-serif;
  --font-display: "Arial Narrow", "Roboto Condensed", "Noto Sans TC", system-ui, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, "Liberation Mono", monospace;
  color-scheme: dark;
  font-family: var(--font-ui);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  color: var(--enamel);
  background: var(--asphalt);
  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;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 50%;
  z-index: calc(var(--z-dropdown) + 1);
  padding: 10px 16px;
  color: var(--ink);
  background: var(--focus);
  border: 2px solid var(--ink);
  border-radius: var(--radius-control);
  font-weight: 850;
  text-decoration: none;
  transform: translate(-50%, -160%);
}

.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:
    max(10px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.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(1180px, 100%);
  min-width: 0;
  margin: 0 auto;
}

.header-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 13px;
  color: var(--enamel);
  background: var(--asphalt-soft);
  border: 1px solid #596366;
  border-radius: var(--radius-control);
  font-size: 0.88rem;
  font-weight: 750;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition:
    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 {
  background: #3a4447;
  border-color: #7d888a;
}

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

.back-link {
  justify-self: start;
}

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

.app-identity > span:last-child {
  min-width: 0;
}

.app-identity h1 {
  margin: 0;
  overflow: hidden;
  color: var(--enamel);
  font-family: var(--font-display);
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-subtitle {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: #c8d1cf;
  font-size: 0.7rem;
  font-weight: 650;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-mark {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 5px);
  align-items: end;
  gap: 3px;
  width: 35px;
  height: 35px;
  flex: 0 0 auto;
  padding: 6px;
  background: var(--pit-blue);
  border: 2px solid var(--enamel);
  border-radius: 6px;
}

.tree-mark::after {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 7px;
  height: 7px;
  background: var(--signal-green);
  border: 1px solid var(--enamel);
  border-radius: 50%;
}

.tree-mark i {
  display: block;
  width: 5px;
  background: var(--amber);
  border-radius: 1px;
}

.tree-mark i:nth-child(1) {
  height: 9px;
}

.tree-mark i:nth-child(2) {
  height: 14px;
}

.tree-mark i:nth-child(3) {
  height: 19px;
}

.tree-mark i:nth-child(4) {
  height: 24px;
}

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

.settings > summary {
  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(--enamel);
  border: 2px solid var(--asphalt-deep);
  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;
  color: #3e4847;
  border-top: 1px solid var(--steel);
  font-size: 0.75rem;
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(440px, 1fr) minmax(250px, 310px);
  gap: 14px;
  width: min(1180px, 100%);
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
}

.timing-rig,
.timing-ledger {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius-panel);
}

.timing-rig {
  display: grid;
  grid-template-rows: 46px minmax(0, 1fr) 34px;
  color: var(--enamel);
  background: var(--pit-blue);
  border: 2px solid var(--asphalt-deep);
}

.rig-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 6px 10px;
  color: var(--enamel);
  background: var(--asphalt-deep);
  border-bottom: 3px solid var(--amber);
}

.lane-plate {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  color: #dce3e1;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-style: normal;
  letter-spacing: 0.08em;
}

.lane-plate b,
.lane-plate i {
  font-style: normal;
}

.lane-plate b {
  color: var(--amber);
  font-size: 0.78rem;
}

.status-readout {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  font-size: 0.68rem;
  font-weight: 700;
}

.status-readout > span:not(.status-dot) {
  color: #b9c4c1;
}

.status-readout strong {
  max-width: 18ch;
  overflow: hidden;
  color: var(--white);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  background: var(--steel-dark);
  border: 2px solid var(--asphalt-soft);
  border-radius: 50%;
}

.rig-body {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
  padding: 14px;
}

.timing-tree {
  position: relative;
  display: grid;
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 4px;
  min-height: 0;
  padding: 16px 8px;
  color: var(--enamel);
  background: var(--asphalt-deep);
  border: 3px solid #06090a;
  border-radius: 8px;
}

.timing-tree::before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 29px;
  width: 5px;
  background: var(--steel-dark);
}

.tree-cap,
.tree-base {
  position: absolute;
  left: 13px;
  width: 37px;
  height: 8px;
  background: var(--steel);
  border: 2px solid #090c0d;
}

.tree-cap {
  top: 6px;
}

.tree-base {
  bottom: 6px;
}

.lamp-row {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 4px;
  min-height: 0;
}

.lamp-pair {
  display: flex;
  gap: 3px;
  justify-content: center;
}

.lamp-pair i {
  display: block;
  width: 20px;
  height: 20px;
  background: #2d3538;
  border: 3px solid #050707;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px #465053;
}

.lamp-label {
  overflow: hidden;
  color: #aeb8b5;
  font-family: var(--font-mono);
  font-size: 0.54rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pad-column {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 9px;
  min-width: 0;
  min-height: 0;
}

.reaction-pad {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: clamp(18px, 4vh, 36px);
  overflow: hidden;
  color: var(--ink);
  background: var(--enamel);
  border: 4px solid var(--asphalt-deep);
  border-radius: 10px;
  box-shadow: inset 0 0 0 3px var(--steel);
  text-align: center;
  cursor: pointer;
}

.reaction-pad:hover {
  box-shadow:
    inset 0 0 0 3px var(--steel),
    inset 0 -7px 0 rgba(18, 25, 28, 0.08);
}

.reaction-pad:active {
  box-shadow:
    inset 0 0 0 3px var(--steel),
    inset 0 5px 0 rgba(18, 25, 28, 0.16);
}

.pad-bolts i {
  position: absolute;
  width: 9px;
  height: 9px;
  background: var(--steel-dark);
  border: 2px solid var(--ink);
  border-radius: 50%;
}

.pad-bolts i:nth-child(1) {
  top: 10px;
  left: 10px;
}

.pad-bolts i:nth-child(2) {
  top: 10px;
  right: 10px;
}

.pad-bolts i:nth-child(3) {
  right: 10px;
  bottom: 10px;
}

.pad-bolts i:nth-child(4) {
  bottom: 10px;
  left: 10px;
}

.pad-state {
  position: absolute;
  top: 15px;
  left: 18px;
  max-width: calc(100% - 36px);
  overflow: hidden;
  color: var(--pit-blue-dark);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.signal-disc {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(84px, 15vh, 132px);
  height: clamp(84px, 15vh, 132px);
  flex: 0 0 auto;
  margin-bottom: clamp(12px, 2.5vh, 22px);
  background: var(--asphalt);
  border: 8px solid var(--steel);
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px var(--asphalt-deep);
}

.signal-disc::before,
.signal-disc::after {
  content: "";
  position: absolute;
  background: var(--enamel);
}

.signal-disc::before {
  width: 38%;
  height: 5px;
}

.signal-disc::after {
  width: 5px;
  height: 38%;
}

.signal-disc i {
  width: 28%;
  height: 28%;
  background: var(--amber);
  border: 3px solid var(--asphalt-deep);
  border-radius: 50%;
}

.message {
  max-width: 20ch;
  margin: 0;
  overflow-wrap: anywhere;
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 4rem);
  font-weight: 850;
  letter-spacing: -0.03em;
  line-height: 0.96;
  text-wrap: balance;
}

.sub-message {
  max-width: 42ch;
  margin-top: 12px;
  color: #334044;
  font-size: clamp(0.76rem, 1.5vw, 0.95rem);
  font-weight: 650;
  line-height: 1.45;
  text-wrap: pretty;
}

.time-readout {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
  color: var(--ink);
  font-family: var(--font-display);
}

.time-readout strong {
  font-size: clamp(4rem, 9vw, 8rem);
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  letter-spacing: -0.04em;
  line-height: 0.82;
}

.time-readout small {
  font-family: var(--font-mono);
  font-size: clamp(0.9rem, 2vw, 1.25rem);
  font-weight: 800;
}

.rating {
  margin-top: 16px;
  padding: 7px 12px;
  color: var(--enamel);
  background: var(--pit-blue);
  border-radius: 5px;
  font-size: 0.88rem;
  font-weight: 800;
}

.press-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
  min-height: 38px;
  margin: 0;
  padding: 4px 10px;
  overflow: hidden;
  color: #d6dedb;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.input-glyphs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.input-glyphs i,
.input-glyphs kbd {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 5px;
  color: var(--ink);
  background: var(--enamel);
  border: 0;
  border-bottom: 2px solid var(--steel-dark);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-style: normal;
  font-weight: 850;
}

.rig-footer {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  color: #c7d1ce;
  background: var(--asphalt-deep);
}

.rig-footer span {
  height: 4px;
  background: var(--steel-dark);
  border-radius: 1px;
}

.rig-footer b {
  position: absolute;
  right: 12px;
  padding-left: 8px;
  color: var(--amber);
  background: var(--asphalt-deep);
  font-family: var(--font-mono);
  font-size: 0.54rem;
  letter-spacing: 0.07em;
}

.timing-ledger {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  color: var(--ink);
  background: var(--enamel);
  border: 2px solid var(--asphalt-deep);
}

.ledger-header {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
  padding: 13px 14px;
  color: var(--enamel);
  background: var(--pit-blue);
  border-bottom: 4px solid var(--amber);
}

.ledger-index {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--amber);
  background: var(--asphalt-deep);
  border-radius: 5px;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 850;
}

.ledger-header h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 0.94rem;
  line-height: 1.05;
}

.ledger-header p {
  display: -webkit-box;
  margin: 4px 0 0;
  overflow: hidden;
  color: #d4dcda;
  font-size: 0.64rem;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.latest-slip {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 14px 0;
  padding: 10px 12px;
  color: var(--ink);
  background: #ffffff;
  border: 2px solid var(--ink);
  border-radius: 5px;
  animation: feed-slip 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.latest-slip span {
  color: #485452;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.latest-slip output {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 12px 14px 0;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}

.stats > div {
  min-width: 0;
  padding: 9px 7px;
  text-align: center;
}

.stats > div + div {
  border-left: 1px solid var(--steel-dark);
}

.stats dt {
  overflow: hidden;
  color: #4f5b58;
  font-size: 0.62rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats dd {
  margin: 4px 0 0;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 1.18rem;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-track {
  position: relative;
  min-height: 0;
  margin: 12px 14px 14px;
  overflow: auto;
  overscroll-behavior: contain;
}

.history-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: timing-slip;
}

.history-list li {
  counter-increment: timing-slip;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  padding: 6px 8px;
  color: var(--ink);
  background: #ffffff;
  border-bottom: 1px solid var(--steel);
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

.history-list li::before {
  content: counter(timing-slip, decimal-leading-zero);
  color: #5b6664;
  font-size: 0.58rem;
}

.history-list strong {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.history-list span {
  overflow: hidden;
  color: #53605d;
  font-size: 0.58rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-empty {
  max-width: 28ch;
  margin: 16px auto 0;
  color: #4c5855;
  font-size: 0.74rem;
  line-height: 1.45;
  text-align: center;
  text-wrap: pretty;
}

/* State colors snap immediately; the timed stimulus never fades. */
.game-shell[data-phase="waiting"] .lamp-row--pre .lamp-pair i {
  background: var(--enamel);
  box-shadow: inset 0 0 0 2px #ffffff;
}

.game-shell[data-phase="ready"] .reaction-pad {
  color: var(--white);
  background: var(--pit-blue);
  box-shadow: inset 0 0 0 3px #4d7181;
}

.game-shell[data-phase="ready"] .pad-state,
.game-shell[data-phase="ready"] .sub-message {
  color: #e2e8e6;
}

.game-shell[data-phase="ready"] .signal-disc i {
  background: var(--amber);
}

.game-shell[data-phase="ready"] .lamp-row--pre .lamp-pair i,
.game-shell[data-phase="ready"] .lamp-row--stage .lamp-pair i,
.game-shell[data-phase="ready"] .lamp-row--amber .lamp-pair i {
  background: var(--amber);
  box-shadow: inset 0 0 0 2px #ffd674;
  animation: stage-breathe 900ms ease-in-out infinite alternate;
}

.game-shell[data-phase="go"] .status-dot,
.game-shell[data-phase="go"] .lamp-row--go .lamp-pair i {
  background: var(--signal-green);
  box-shadow: inset 0 0 0 2px #58d49e;
}

.game-shell[data-phase="go"] .reaction-pad {
  color: #071a12;
  background: var(--signal-green);
  border-color: #071a12;
  box-shadow: inset 0 0 0 3px #46bf8b;
  cursor: crosshair;
}

.game-shell[data-phase="go"] .pad-state,
.game-shell[data-phase="go"] .sub-message {
  color: #071a12;
}

.game-shell[data-phase="go"] .signal-disc {
  background: #e7fff4;
  border-color: #0c412f;
}

.game-shell[data-phase="go"] .signal-disc::before,
.game-shell[data-phase="go"] .signal-disc::after {
  background: var(--signal-green-dark);
}

.game-shell[data-phase="go"] .signal-disc i {
  background: var(--signal-green);
}

.game-shell[data-phase="result"] .status-dot {
  background: var(--amber);
  box-shadow: inset 0 0 0 2px #ffd674;
}

.game-shell[data-phase="result"] .reaction-pad {
  background: var(--enamel);
}

.game-shell[data-phase="result"] .signal-disc,
.game-shell[data-phase="result"] .message {
  display: none;
}

.game-shell[data-phase="result"] .sub-message {
  order: 4;
  margin-top: 14px;
}

.game-shell[data-phase="too-soon"] .status-dot,
.game-shell[data-phase="too-soon"] .lamp-row--foul .lamp-pair i {
  background: var(--foul-red);
  box-shadow: inset 0 0 0 2px #f18177;
}

.game-shell[data-phase="too-soon"] .reaction-pad {
  color: var(--white);
  background: var(--foul-red);
  border-color: var(--foul-red-dark);
  box-shadow: inset 0 0 0 3px #d66c64;
  animation: foul-shake 200ms cubic-bezier(0.22, 1, 0.36, 1);
}

.game-shell[data-phase="too-soon"] .pad-state,
.game-shell[data-phase="too-soon"] .sub-message {
  color: #ffffff;
}

.game-shell[data-phase="too-soon"] .signal-disc {
  background: var(--foul-red-dark);
  border-color: #f1a49e;
}

.game-shell[data-phase="too-soon"] .signal-disc i {
  background: var(--foul-red);
}

@keyframes stage-breathe {
  from {
    filter: brightness(0.78);
  }
  to {
    filter: brightness(1.2);
  }
}

@keyframes feed-slip {
  from {
    clip-path: inset(0 0 100% 0);
    transform: translateY(-8px);
  }
  to {
    clip-path: inset(0);
    transform: translateY(0);
  }
}

@keyframes foul-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  35% {
    transform: translateX(-6px);
  }
  70% {
    transform: translateX(5px);
  }
}

@media (max-width: 719px) {
  .app-shell {
    grid-template-rows: 52px minmax(0, 1fr);
    gap: 7px;
    padding:
      max(7px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(9px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

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

  .timing-rig {
    grid-template-rows: 40px minmax(0, 1fr) 27px;
  }

  .rig-header {
    padding: 4px 8px;
  }

  .rig-body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 64px minmax(0, 1fr);
    gap: 7px;
    padding: 7px;
  }

  .timing-tree {
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 3px;
    padding: 5px 7px;
  }

  .timing-tree::before,
  .tree-cap,
  .tree-base {
    display: none;
  }

  .lamp-row {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
  }

  .lamp-pair i {
    width: 18px;
    height: 18px;
    border-width: 2px;
  }

  .lamp-label {
    width: 100%;
    text-align: center;
  }

  .pad-column {
    gap: 3px;
  }

  .reaction-pad {
    padding: 20px 14px 12px;
  }

  .pad-state {
    top: 10px;
    left: 13px;
    font-size: 0.56rem;
  }

  .signal-disc {
    width: clamp(64px, 10vh, 90px);
    height: clamp(64px, 10vh, 90px);
    margin-bottom: 8px;
    border-width: 6px;
  }

  .message {
    font-size: clamp(1.8rem, 9vw, 2.7rem);
  }

  .sub-message {
    margin-top: 7px;
    font-size: 0.72rem;
  }

  .time-readout strong {
    font-size: clamp(3.4rem, 18vw, 5.3rem);
  }

  .rating {
    margin-top: 9px;
    padding: 5px 9px;
    font-size: 0.72rem;
  }

  .press-hint {
    min-height: 32px;
    padding: 2px 6px;
    font-size: 0.62rem;
  }

  .input-glyphs i,
  .input-glyphs kbd {
    min-width: 21px;
    height: 21px;
    padding: 0 3px;
  }

  .rig-footer {
    padding: 5px 8px;
  }

  .timing-ledger {
    grid-template-rows: 48px 40px 50px minmax(0, 1fr);
  }

  .ledger-header {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 7px;
    padding: 6px 9px;
    border-bottom-width: 3px;
  }

  .ledger-index {
    width: 31px;
    height: 31px;
    font-size: 1.05rem;
  }

  .ledger-header h2 {
    font-size: 0.82rem;
  }

  .ledger-header p {
    margin-top: 2px;
    font-size: 0.58rem;
    -webkit-line-clamp: 1;
  }

  .latest-slip {
    margin: 4px 8px 0;
    padding: 5px 8px;
  }

  .latest-slip output {
    font-size: 1.15rem;
  }

  .stats {
    margin: 4px 8px 0;
  }

  .stats > div {
    padding: 5px 4px;
  }

  .stats dt {
    font-size: 0.55rem;
  }

  .stats dd {
    margin-top: 2px;
    font-size: 0.92rem;
  }

  .history-track {
    margin: 4px 8px 7px;
    overflow: hidden;
  }

  .history-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(105px, 1fr);
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 3px;
    height: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }

  .history-list li {
    grid-template-columns: 20px minmax(0, 1fr) auto;
    gap: 4px;
    padding: 3px 5px;
    font-size: 0.6rem;
  }

  .history-list span {
    display: none;
  }

  .history-empty {
    margin-top: 7px;
    font-size: 0.64rem;
  }
}

@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 {
    gap: 7px;
  }

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

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

  .lamp-pair i {
    width: 16px;
    height: 16px;
  }

  .press-hint > span:last-child {
    max-width: 20ch;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .rig-footer b {
    display: none;
  }
}

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

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

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

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

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

  .app-subtitle {
    display: none;
  }

  .game-shell {
    grid-template-columns: minmax(300px, 1fr) minmax(200px, 260px);
    grid-template-rows: minmax(0, 1fr);
    gap: 8px;
    width: min(980px, 100%);
  }

  .timing-rig {
    grid-template-rows: 36px minmax(0, 1fr) 24px;
  }

  .rig-header {
    padding: 3px 7px;
    border-bottom-width: 2px;
  }

  .rig-body {
    grid-template-columns: 78px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 7px;
    padding: 7px;
  }

  .timing-tree {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: repeat(5, minmax(0, 1fr));
    gap: 1px;
    padding: 9px 4px;
  }

  .timing-tree::before {
    display: block;
    left: 22px;
    width: 4px;
  }

  .tree-cap,
  .tree-base {
    display: block;
    left: 9px;
    width: 31px;
    height: 6px;
  }

  .lamp-row {
    display: grid;
    grid-template-columns: 39px minmax(0, 1fr);
    flex-direction: initial;
    justify-content: initial;
    gap: 2px;
  }

  .lamp-pair {
    gap: 2px;
  }

  .lamp-pair i {
    width: 17px;
    height: 17px;
    border-width: 2px;
  }

  .lamp-label {
    width: auto;
    font-size: 0.46rem;
    text-align: left;
  }

  .pad-column {
    gap: 2px;
  }

  .reaction-pad {
    padding: 15px 10px 8px;
    border-width: 3px;
  }

  .pad-state {
    top: 8px;
    left: 11px;
    font-size: 0.5rem;
  }

  .signal-disc {
    width: 62px;
    height: 62px;
    margin-bottom: 5px;
    border-width: 5px;
  }

  .message {
    font-size: 1.65rem;
  }

  .sub-message {
    display: -webkit-box;
    max-width: 44ch;
    margin-top: 4px;
    overflow: hidden;
    font-size: 0.64rem;
    line-height: 1.25;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .time-readout strong {
    font-size: 3.45rem;
  }

  .rating {
    margin-top: 6px;
    padding: 4px 8px;
    font-size: 0.64rem;
  }

  .press-hint {
    min-height: 28px;
    padding: 1px 5px;
    font-size: 0.58rem;
  }

  .input-glyphs i,
  .input-glyphs kbd {
    min-width: 19px;
    height: 19px;
    padding: 0 3px;
    font-size: 0.48rem;
  }

  .rig-footer {
    padding: 4px 7px;
  }

  .timing-ledger {
    grid-template-rows: 43px 36px 45px minmax(0, 1fr);
  }

  .ledger-header {
    grid-template-columns: 29px minmax(0, 1fr);
    gap: 6px;
    padding: 4px 7px;
    border-bottom-width: 3px;
  }

  .ledger-index {
    width: 27px;
    height: 27px;
    font-size: 0.95rem;
  }

  .ledger-header h2 {
    font-size: 0.76rem;
  }

  .ledger-header p {
    display: none;
  }

  .latest-slip {
    margin: 3px 7px 0;
    padding: 3px 7px;
  }

  .latest-slip output {
    font-size: 1rem;
  }

  .stats {
    margin: 3px 7px 0;
  }

  .stats > div {
    padding: 3px;
  }

  .stats dt {
    font-size: 0.48rem;
  }

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

  .history-track {
    margin: 3px 7px 6px;
    overflow: auto;
  }

  .history-list {
    grid-auto-flow: row;
    grid-auto-columns: auto;
    grid-template-rows: none;
    gap: 2px;
    height: auto;
    overflow-x: visible;
  }

  .history-list li {
    grid-template-columns: 19px minmax(0, 1fr) auto;
    gap: 4px;
    padding: 2px 4px;
    font-size: 0.55rem;
  }

  .history-list li::before,
  .history-list span {
    display: initial;
    font-size: 0.48rem;
  }

  .history-empty {
    margin-top: 6px;
    font-size: 0.59rem;
  }
}

@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;
  }
}
