:root {
  color-scheme: dark;
  --ink: #f4f2ff;
  --muted: #85809d;
  --panel: #11101d;
  --line: #2b2840;
  --cyan: #55f5ff;
  --magenta: #ff4db8;
  --yellow: #ffe357;
  --red: #ff5b6e;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #090813;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background-color: #090813;
  background-image:
    linear-gradient(rgba(85, 245, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(85, 245, 255, 0.025) 1px, transparent 1px);
  background-size: 32px 32px;
  font-family: "Arial Narrow", "Roboto Condensed", Impact, sans-serif;
}

button {
  font: inherit;
}

.shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px clamp(16px, 3vw, 42px) 16px;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 92px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.eyebrow,
.serial {
  margin: 0 0 5px;
  color: var(--cyan);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.24em;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 58px);
  font-weight: 900;
  line-height: 0.82;
  letter-spacing: -0.065em;
  transform: scaleX(0.88);
  transform-origin: left;
}

h1 span {
  color: transparent;
  -webkit-text-stroke: 1px var(--magenta);
}

.track-meta {
  text-align: right;
}

.track-meta p {
  margin: 0 0 5px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.track-meta span,
footer {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
}

.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(130px, 0.7fr) minmax(320px, 560px) minmax(150px, 0.8fr);
  align-items: center;
  gap: clamp(18px, 3vw, 44px);
  padding: 26px 0;
}

.score-panel,
.system-panel {
  align-self: stretch;
  padding: 9vh 0 5vh;
}

.metric {
  border-top: 1px solid var(--line);
  padding: 12px 0 20px;
}

.metric span,
.status-block span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  letter-spacing: 0.18em;
}

.metric strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(16px, 2vw, 25px);
  letter-spacing: -0.06em;
}

.metric.combo-metric strong {
  color: var(--yellow);
}

.metric.compact {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
}

.metric.compact span {
  margin: 0;
}

.metric.compact strong {
  font-size: 13px;
}

.metric.miss strong {
  color: var(--red);
}

.cabinet {
  width: 100%;
}

.screen-frame {
  position: relative;
  width: 100%;
  height: min(66vh, 690px);
  min-height: 470px;
  overflow: hidden;
  border: 1px solid #3c3855;
  border-radius: 2px;
  background: #070610;
  box-shadow:
    0 0 0 5px #0e0d19,
    0 0 0 6px #29263b,
    0 26px 70px rgba(0, 0, 0, 0.55),
    0 0 50px rgba(85, 245, 255, 0.07);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.health-hud {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 3;
  display: grid;
  grid-template-columns: auto minmax(90px, 150px) 34px;
  align-items: center;
  gap: 8px;
  color: var(--cyan);
  font: 700 9px ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.12em;
  pointer-events: none;
}

.health-hud > div {
  width: min(28vw, 150px);
  height: 6px;
  border: 1px solid rgba(85, 245, 255, 0.45);
  padding: 1px;
  background: rgba(7, 6, 16, 0.75);
}

.health-hud i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--cyan);
  box-shadow: 0 0 9px var(--cyan);
  transition: width 100ms linear, background 150ms, box-shadow 150ms;
}

.health-hud strong {
  font-size: 9px;
}

.health-hud.critical {
  color: var(--red);
}

.health-hud.critical > div {
  border-color: rgba(255, 91, 110, 0.55);
}

.health-hud.critical i {
  background: var(--red);
  box-shadow: 0 0 9px var(--red);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  text-align: center;
  background: rgba(7, 6, 16, 0.91);
  backdrop-filter: blur(8px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.overlay.hidden {
  visibility: hidden;
  opacity: 0;
}

.overlay h2 {
  margin: 6px 0 9px;
  font-size: clamp(34px, 6vw, 54px);
  font-weight: 900;
  line-height: 0.82;
  letter-spacing: -0.06em;
  transform: scaleX(0.82);
}

.overlay > p:not(.serial) {
  max-width: 430px;
  margin: 0 0 11px;
  color: #aaa5bd;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.overlay > button {
  border: 1px solid var(--cyan);
  margin-top: 14px;
  padding: 12px 24px;
  color: #070610;
  background: var(--cyan);
  font-weight: 900;
  letter-spacing: 0.11em;
  cursor: pointer;
  box-shadow: 6px 6px 0 var(--magenta);
  transition: transform 100ms ease, box-shadow 100ms ease;
}

.overlay > button:hover {
  transform: translate(2px, 2px);
  box-shadow: 3px 3px 0 var(--magenta);
}

.overlay > button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.overlay button:focus-visible,
.touch-controls button:focus-visible {
  outline: 2px solid white;
  outline-offset: 3px;
}

.overlay > small {
  margin-top: 14px;
  color: #6b667c;
  font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.12em;
}

.preview-hint {
  width: min(430px, 100%);
  margin-bottom: 7px;
  color: #767187;
  text-align: left;
  font: 8px ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.15em;
}

.preview-hint i {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--magenta);
  box-shadow: 0 0 8px var(--magenta);
}

.preview-hint.playing {
  color: var(--cyan);
}

.preview-hint.playing i {
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
  animation: preview-pulse 750ms ease-in-out infinite alternate;
}

@keyframes preview-pulse {
  from { opacity: 0.35; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1.25); }
}

.track-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  width: min(430px, 100%);
}

.track-option {
  min-width: 0;
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid #343047;
  padding: 0 9px;
  color: #9893aa;
  background: rgba(15, 13, 25, 0.9);
  font: 700 8px ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: left;
  cursor: pointer;
}

.track-option span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-option small {
  flex: 0 0 auto;
  color: #686378;
  font-size: 7px;
}

.track-option:hover {
  border-color: #716b8c;
  color: white;
}

.track-option.active {
  border-color: var(--cyan);
  color: #080711;
  background: var(--cyan);
  box-shadow: inset 3px 0 0 var(--magenta), 0 0 15px rgba(85, 245, 255, 0.12);
}

.track-option.active small {
  color: #315d62;
}

.difficulty-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  width: min(430px, 100%);
  margin-top: 8px;
}

.difficulty-picker button {
  height: 27px;
  border: 1px solid #343047;
  color: #777287;
  background: #0f0d19;
  font: 700 8px ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.difficulty-picker button:hover {
  border-color: var(--magenta);
  color: white;
}

.difficulty-picker button.active {
  border-color: var(--magenta);
  color: var(--magenta);
  background: rgba(255, 77, 184, 0.08);
  box-shadow: 0 0 12px rgba(255, 77, 184, 0.12);
}

.judgement {
  position: absolute;
  top: 54%;
  left: 50%;
  z-index: 4;
  min-width: 100%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: clamp(34px, 7vw, 62px);
  font-weight: 900;
  letter-spacing: -0.04em;
  pointer-events: none;
  opacity: 0;
  text-shadow: 0 0 20px currentColor;
}

.judgement.pop {
  animation: judgement-pop 280ms ease-out;
}

.judgement.perfect {
  color: var(--cyan);
}

.judgement.great {
  color: var(--magenta);
}

.judgement.good {
  color: var(--yellow);
}

.judgement.miss {
  color: var(--red);
}

.combo {
  position: absolute;
  top: 62%;
  left: 50%;
  z-index: 4;
  transform: translateX(-50%);
  color: white;
  font: 700 13px ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.14em;
  pointer-events: none;
}

@keyframes judgement-pop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(1.35); }
  30% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -58%) scale(0.96); }
}

.touch-controls {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-top: 12px;
}

.touch-controls button {
  height: 48px;
  border: 1px solid #312e45;
  color: #aaa6bd;
  background: #13111e;
  font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  cursor: pointer;
  touch-action: manipulation;
  transition: color 60ms, background 60ms, border-color 60ms;
}

.touch-controls button.active {
  border-color: var(--cyan);
  color: #090813;
  background: var(--cyan);
}

.touch-controls button.shutdown,
.touch-controls button:disabled {
  border-color: #1d1a29;
  color: #373341;
  background: #090811;
  cursor: not-allowed;
  opacity: 1;
}

.status-block {
  border-top: 1px solid var(--line);
  padding: 12px 0 20px;
}

.status-block strong {
  color: var(--cyan);
  font: 700 15px ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.1em;
}

.progress-wrap > span {
  color: var(--muted);
  font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.progress {
  height: 3px;
  margin-top: 8px;
  overflow: hidden;
  background: #242134;
}

.progress i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--magenta);
  box-shadow: 0 0 10px var(--magenta);
}

.instructions {
  margin-top: 42px;
  color: #9994aa;
  font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.instructions ul {
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  font-size: 9px;
  line-height: 2.1;
}

.dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 7px;
  border-radius: 50%;
}

.perfect-dot { background: var(--cyan); }
.great-dot { background: var(--magenta); }
.good-dot { background: var(--yellow); }
.hold-dot {
  border: 1px solid var(--cyan);
  background: transparent;
}

footer {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

@media (max-width: 800px) {
  .shell {
    padding-top: 14px;
  }

  .topbar {
    min-height: 70px;
  }

  .game-layout {
    grid-template-columns: 1fr;
    padding: 18px 0;
  }

  .score-panel,
  .system-panel {
    display: none;
  }

  .screen-frame {
    height: min(70vh, 650px);
    min-height: 430px;
  }

  footer span:last-child {
    display: none;
  }
}

@media (max-width: 480px) {
  .track-meta span {
    display: none;
  }

  .track-meta p {
    max-width: 100px;
    font-size: 10px;
  }

  .screen-frame {
    height: calc(100svh - 210px);
    min-height: 390px;
  }

  .overlay {
    padding: 18px;
  }

  .track-picker {
    gap: 3px;
  }

  .track-option {
    height: 33px;
    padding: 0 6px;
    font-size: 7px;
  }

  .touch-controls button {
    height: 44px;
    font-size: 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
