:root {
  color-scheme: dark;
  --ink: #111714;
  --deep: #0b2223;
  --petrol: #143637;
  --petrol-light: #285252;
  --paper: #f2e5c5;
  --paper-muted: #c8bc9d;
  --orange: #f06a2b;
  --orange-dark: #9c351d;
  --yellow: #f2c84b;
  --red: #db3f2d;
  --line-dark: rgba(17, 23, 20, 0.2);
  --line-light: rgba(242, 229, 197, 0.18);
  --shadow: rgba(0, 0, 0, 0.34);
  --topbar-h: 68px;
  --scorebar-h: 72px;
}

* {
  box-sizing: border-box;
}

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

body {
  min-width: 280px;
  min-height: 320px;
  background: var(--deep);
  color: var(--paper);
  font-family: "Bahnschrift", "Arial Narrow", "Microsoft JhengHei", "PingFang TC",
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button,
a {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  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;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: var(--deep);
}

.topbar {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto minmax(150px, 1fr);
  align-items: center;
  min-width: 0;
  padding: 0 max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line-light);
  background: #102c2d;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  color: var(--paper);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  background: var(--orange);
  color: var(--ink);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  transform: rotate(-3deg);
}

.brand-word,
.serial-label,
.eyebrow,
.panel-kicker,
.score-label,
.status-light + span,
.key-hint,
.meter-head,
.round-notes dt {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.brand-word {
  font-size: 0.72rem;
  font-weight: 700;
}

.title-lockup {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  min-width: 0;
}

.title-lockup h1 {
  margin: 0;
  color: var(--paper);
  font-size: clamp(1.05rem, 1.8vw, 1.42rem);
  font-stretch: condensed;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
}

.serial-label {
  color: var(--paper-muted);
  font-size: 0.62rem;
  white-space: nowrap;
}

.sound-toggle {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--paper);
  cursor: pointer;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}

.sound-dot {
  width: 8px;
  height: 8px;
  border: 1px solid var(--paper-muted);
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 3px rgba(242, 200, 75, 0.12);
}

.sound-toggle[aria-pressed="false"] .sound-dot {
  background: transparent;
  box-shadow: none;
}

.game-layout {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(248px, 23vw, 336px);
  min-height: 0;
}

.stage-column {
  display: grid;
  grid-template-rows: var(--scorebar-h) minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.score-ribbon {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 132px)) minmax(120px, 1fr);
  align-items: stretch;
  min-width: 0;
  border-bottom: 1px solid var(--line-light);
  background: #0e2829;
}

.score-cell {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 14px 16px;
  border-right: 1px solid var(--line-light);
}

.score-cell--primary {
  background: var(--orange);
  color: var(--ink);
}

.score-label {
  color: var(--paper-muted);
  font-size: 0.62rem;
  font-weight: 700;
}

.score-cell--primary .score-label {
  color: rgba(17, 23, 20, 0.7);
}

.score-value {
  color: var(--paper);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: clamp(1.3rem, 2.2vw, 2rem);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  letter-spacing: -0.08em;
  line-height: 1;
}

.score-cell--primary .score-value {
  color: var(--ink);
}

.shift-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
  padding: 0 20px;
  color: var(--paper-muted);
  font-size: 0.66rem;
  white-space: nowrap;
}

.status-light {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #71817a;
}

.shift-status.is-live {
  color: var(--paper);
}

.shift-status.is-live .status-light {
  background: var(--orange);
  box-shadow: 0 0 0 4px rgba(240, 106, 43, 0.16);
  animation: status-pulse 900ms steps(2, end) infinite;
}

.shift-status.is-done .status-light {
  background: var(--yellow);
}

@keyframes status-pulse {
  50% {
    opacity: 0.35;
  }
}

.arena-shell {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background: #163839;
  cursor: crosshair;
  touch-action: none;
}

.arena-shell::before {
  position: absolute;
  z-index: 4;
  inset: 0;
  border: 1px solid rgba(242, 229, 197, 0.08);
  content: "";
  pointer-events: none;
}

#game-canvas {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: 0;
}

.arena-grain {
  position: absolute;
  z-index: 3;
  inset: 0;
  opacity: 0.12;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.72' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.34'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

.lamp-run {
  position: absolute;
  z-index: 8;
  top: 18px;
  left: 50%;
  display: flex;
  gap: clamp(12px, 3vw, 38px);
  transform: translateX(-50%);
  pointer-events: none;
}

.lamp-run i {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7d6e43;
  box-shadow: 0 0 0 3px rgba(17, 23, 20, 0.42);
  transition: background-color 120ms ease, box-shadow 120ms ease;
}

.arena-shell.is-playing .lamp-run i,
.arena-shell.is-attract .lamp-run i:nth-child(3n + 1) {
  background: var(--yellow);
  box-shadow: 0 0 12px rgba(242, 200, 75, 0.72), 0 0 0 3px rgba(17, 23, 20, 0.42);
}

.arena-shell.combo-hot .lamp-run i {
  background: var(--orange);
  box-shadow: 0 0 16px rgba(240, 106, 43, 0.85), 0 0 0 3px rgba(17, 23, 20, 0.42);
}

.start-panel {
  position: absolute;
  z-index: 12;
  bottom: 24px;
  left: 24px;
  width: min(390px, calc(100% - 48px));
  padding: 22px 24px 20px;
  background: var(--paper);
  color: var(--ink);
  clip-path: polygon(0 0, calc(100% - 20px) 0, 100% 20px, 100% 100%, 0 100%);
  cursor: default;
  transition: opacity 180ms ease, transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.arena-shell.is-playing .start-panel {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

.panel-kicker {
  margin: 0 0 12px;
  color: var(--orange-dark);
  font-size: 0.68rem;
  font-weight: 800;
}

.start-panel h2 {
  max-width: 11ch;
  margin: 0;
  color: var(--ink);
  font-size: clamp(2rem, 4.8vw, 3.35rem);
  font-stretch: condensed;
  font-weight: 900;
  letter-spacing: -0.055em;
  line-height: 0.96;
}

.panel-copy {
  max-width: 35em;
  margin: 14px 0 18px;
  color: #46504a;
  font-size: 0.88rem;
  line-height: 1.65;
}

.start-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 52px;
  padding: 0 16px 0 18px;
  border: 0;
  border-radius: 0;
  background: var(--orange);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.start-button:hover {
  background: var(--yellow);
}

.start-button:active {
  transform: translateY(2px);
}

.button-arrow {
  font-size: 1.2rem;
}

.key-hint {
  margin: 12px 0 0;
  color: #677069;
  font-size: 0.62rem;
}

kbd {
  min-width: 36px;
  padding: 2px 6px;
  border: 1px solid rgba(17, 23, 20, 0.36);
  border-bottom-width: 2px;
  background: rgba(17, 23, 20, 0.04);
  color: var(--ink);
  font: inherit;
}

.combo-stamp {
  position: absolute;
  z-index: 10;
  top: 34px;
  right: 24px;
  display: grid;
  min-width: 112px;
  padding: 12px 18px 10px;
  place-items: center;
  background: var(--orange);
  color: var(--ink);
  clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
  opacity: 0;
  pointer-events: none;
  transform: rotate(2deg) scale(0.72);
}

.combo-stamp.is-visible {
  animation: stamp-in 420ms cubic-bezier(0.18, 0.84, 0.28, 1) both;
}

.combo-stamp span {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 1.85rem;
  font-weight: 900;
  letter-spacing: -0.08em;
  line-height: 1;
}

.combo-stamp small {
  margin-top: 2px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

@keyframes stamp-in {
  0% {
    opacity: 0;
    transform: rotate(-8deg) scale(1.45);
  }
  28% {
    opacity: 1;
    transform: rotate(3deg) scale(0.94);
  }
  70% {
    opacity: 1;
    transform: rotate(2deg) scale(1);
  }
  100% {
    opacity: 0;
    transform: rotate(2deg) scale(1);
  }
}

.score-pop-layer {
  position: absolute;
  z-index: 11;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.score-pop {
  position: absolute;
  color: var(--paper);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: clamp(1.25rem, 3vw, 2.15rem);
  font-weight: 900;
  text-shadow: 3px 3px 0 var(--ink);
  animation: score-rise 680ms cubic-bezier(0.15, 0.8, 0.25, 1) both;
}

@keyframes score-rise {
  from {
    opacity: 0;
    transform: translate(-50%, 4px) scale(0.7) rotate(-8deg);
  }
  22% {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translate(-50%, -64px) scale(1.12) rotate(2deg);
  }
}

.countdown-flash {
  position: absolute;
  z-index: 14;
  top: 50%;
  left: 50%;
  color: var(--paper);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: clamp(5rem, 18vw, 12rem);
  font-weight: 900;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  text-shadow: 8px 8px 0 var(--orange-dark);
  transform: translate(-50%, -50%);
}

.countdown-flash.is-visible {
  animation: count-hit 520ms ease-out both;
}

@keyframes count-hit {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.7);
  }
  26% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.82);
  }
}

.webgl-fallback {
  position: absolute;
  z-index: 18;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  padding: 24px;
  background: var(--petrol);
  color: var(--paper);
  cursor: default;
  text-align: center;
}

.webgl-fallback[hidden] {
  display: none;
}

.webgl-fallback strong {
  font-size: 1.2rem;
}

.webgl-fallback span {
  max-width: 34em;
  color: var(--paper-muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

.brief-panel {
  position: relative;
  z-index: 22;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: clamp(24px, 4vh, 42px) clamp(22px, 2.5vw, 36px);
  border-left: 1px solid var(--line-dark);
  background: var(--paper);
  color: var(--ink);
}

.brief-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  padding-top: 7px;
  color: var(--orange-dark);
  font-size: 0.68rem;
  font-weight: 800;
}

.brief-number {
  color: var(--orange);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: clamp(2.8rem, 5vw, 5rem);
  font-weight: 900;
  letter-spacing: -0.12em;
  line-height: 0.78;
}

.brief-rule {
  height: 6px;
  margin: 24px 0;
  background: var(--ink);
}

.brief-lead {
  margin: 0;
  font-size: clamp(1.7rem, 3.1vw, 2.8rem);
  font-stretch: condensed;
  font-weight: 900;
  letter-spacing: -0.05em;
  line-height: 1.05;
}

.combo-meter {
  margin-top: clamp(30px, 5.5vh, 56px);
}

.meter-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.66rem;
  font-weight: 800;
}

.meter-head strong {
  color: var(--orange-dark);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 1rem;
}

.meter-track {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  background: rgba(17, 23, 20, 0.15);
}

.meter-track span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--orange);
  transform-origin: left;
  transform: scaleX(0.12);
  transition: transform 160ms ease;
}

.combo-meter p {
  margin: 10px 0 0;
  color: #57615b;
  font-size: 0.75rem;
  line-height: 1.55;
}

.round-notes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 28px 0 0;
  border-top: 1px solid var(--line-dark);
  border-bottom: 1px solid var(--line-dark);
}

.round-notes div {
  padding: 14px 0;
}

.round-notes div + div {
  padding-left: 16px;
  border-left: 1px solid var(--line-dark);
}

.round-notes dt {
  color: #6b746e;
  font-size: 0.58rem;
}

.round-notes dd {
  margin: 5px 0 0;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.76rem;
  font-weight: 800;
}

.control-note {
  position: absolute;
  right: clamp(22px, 2.5vw, 36px);
  bottom: clamp(24px, 4vh, 42px);
  left: clamp(22px, 2.5vw, 36px);
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: start;
  gap: 12px;
}

.control-note p {
  margin: 0;
  color: #57615b;
  font-size: 0.74rem;
  line-height: 1.55;
}

.mouse-glyph {
  position: relative;
  width: 20px;
  height: 28px;
  border: 2px solid var(--ink);
  border-radius: 10px;
}

.mouse-glyph::before {
  position: absolute;
  top: 4px;
  left: 50%;
  width: 2px;
  height: 6px;
  background: var(--orange);
  content: "";
  transform: translateX(-50%);
}

.arena-shell:focus-visible,
.sound-toggle:focus-visible,
.brand-link:focus-visible,
.start-button:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: -3px;
}

.sound-toggle:focus-visible,
.brand-link:focus-visible {
  outline-offset: 4px;
}

@media (max-width: 900px) {
  :root {
    --topbar-h: 60px;
    --scorebar-h: 66px;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr) 234px;
  }

  .topbar {
    grid-template-columns: 1fr auto;
  }

  .title-lockup {
    display: none;
  }

  .score-ribbon {
    grid-template-columns: repeat(3, minmax(82px, 1fr));
  }

  .shift-status {
    display: none;
  }

  .brief-panel {
    padding: 24px 20px;
  }

  .brief-lead {
    font-size: 1.7rem;
  }

  .control-note {
    right: 20px;
    bottom: 24px;
    left: 20px;
  }
}

@media (max-width: 700px) {
  :root {
    --topbar-h: 56px;
    --scorebar-h: 64px;
  }

  .topbar {
    padding-right: max(14px, env(safe-area-inset-right));
    padding-left: max(14px, env(safe-area-inset-left));
  }

  .brand-word {
    font-size: 0.65rem;
  }

  .sound-toggle {
    min-width: 40px;
    justify-content: flex-end;
  }

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

  .game-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .brief-panel {
    display: none;
  }

  .score-cell {
    padding: 10px clamp(10px, 4vw, 18px);
  }

  .score-label {
    font-size: 0.56rem;
  }

  .score-value {
    font-size: clamp(1.22rem, 5vw, 1.65rem);
  }

  .start-panel {
    bottom: max(14px, env(safe-area-inset-bottom));
    left: 14px;
    width: calc(100% - 28px);
    padding: 18px 18px 16px;
  }

  .start-panel h2 {
    font-size: clamp(1.8rem, 10vw, 2.8rem);
  }

  .panel-copy {
    margin: 10px 0 14px;
    font-size: 0.8rem;
    line-height: 1.52;
  }

  .start-button {
    min-height: 48px;
  }

  .combo-stamp {
    top: 26px;
    right: 14px;
  }
}

@media (max-height: 560px) {
  :root {
    --topbar-h: 46px;
    --scorebar-h: 52px;
  }

  .brand-mark {
    width: 26px;
    height: 26px;
  }

  .serial-label {
    display: none;
  }

  .score-cell {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .score-value {
    font-size: 1.25rem;
  }

  .start-panel {
    bottom: 10px;
    left: 10px;
    width: min(320px, calc(100% - 20px));
    padding: 13px 15px 12px;
  }

  .panel-kicker {
    margin-bottom: 6px;
    font-size: 0.56rem;
  }

  .start-panel h2 {
    max-width: 14ch;
    font-size: 1.55rem;
    line-height: 1;
  }

  .panel-copy,
  .key-hint {
    display: none;
  }

  .start-button {
    min-height: 40px;
    margin-top: 10px;
    font-size: 0.78rem;
  }

  .lamp-run {
    top: 10px;
  }

  .brief-panel {
    padding: 16px 18px;
  }

  .brief-number {
    font-size: 2.4rem;
  }

  .brief-rule {
    height: 4px;
    margin: 12px 0;
  }

  .brief-lead {
    font-size: 1.35rem;
  }

  .combo-meter {
    margin-top: 18px;
  }

  .combo-meter p,
  .control-note {
    display: none;
  }

  .round-notes {
    margin-top: 16px;
  }
}

@media (max-width: 420px) and (max-height: 700px) {
  .panel-copy {
    display: none;
  }

  .start-button {
    margin-top: 14px;
  }
}

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