:root {
  color-scheme: dark;
  --ink: #182033;
  --paper: #f8fbff;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-border: rgba(23, 35, 64, 0.2);
  --accent: #ffb22e;
  --accent-2: #1ebbd7;
  --danger: #ee4747;
  --lcd-darkest: #0f380f;
  --lcd-dark: #306230;
  --lcd-mid: #8bac0f;
  --lcd-light: #9bbc0f;
  --ui-radius: 12px;
  --control-width: 145px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  align-items: start;
  justify-items: center;
  gap: 12px;
  min-height: 100vh;
  padding: 12px 16px;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 219, 94, 0.22), transparent 28%),
    linear-gradient(135deg, #78d8ff 0%, #d7f2ff 48%, #fff2cf 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.hud {
  width: min(100%, 960px);
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: center;
  justify-items: center;
  padding: 18px;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 12px 28px rgba(28, 46, 80, 0.16);
  backdrop-filter: blur(12px);
}

.brand {
  display: grid;
  gap: 2px;
  min-width: 0;
  justify-items: center;
  text-align: center;
}

.brand strong {
  font-size: 1.05rem;
}

.brand span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #38445f;
  font-size: 0.88rem;
}

.stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
  font-size: 0.86rem;
}

.stats span {
  min-width: 0;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid rgba(24, 32, 51, 0.12);
  border-radius: var(--ui-radius);
  background: rgba(255, 255, 255, 0.52);
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
}

.stats b {
  font-variant-numeric: tabular-nums;
}

.actions {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: stretch;
  gap: 10px;
  width: 100%;
}

.knob-control,
.palette-control {
  min-width: 0;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 7px;
  border: 1px solid rgba(24, 32, 51, 0.12);
  border-radius: var(--ui-radius);
  background: rgba(255, 255, 255, 0.52);
  font-size: 0.78rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.knob-control b {
  display: inline-block;
  inline-size: 3ch;
  text-align: right;
}

.palette-control {
  cursor: pointer;
}

.palette-control select {
  min-width: 0;
  width: clamp(70px, 45%, 94px);
  border: 0;
  border-radius: 8px;
  padding: 5px 22px 5px 7px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
}

.palette-control select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button {
  min-width: 0;
  min-height: 34px;
  border: 0;
  border-radius: var(--ui-radius);
  padding: 7px 10px;
  background: #19243b;
  color: white;
  font: inherit;
  font-weight: 700;
  line-height: 1.08;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.22);
}

.rotary-knob {
  position: relative;
  flex: 0 0 30px;
  width: 30px;
  min-height: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 32%, #ffffff 0 9%, #cfd7e6 10% 17%, #465778 18% 100%);
  --knob-angle: 13deg;
  touch-action: none;
  cursor: grab;
}

.rotary-knob:hover {
  background:
    radial-gradient(circle at 38% 32%, #ffffff 0 9%, #dce3ef 10% 17%, #526488 18% 100%);
}

.rotary-knob:active {
  cursor: grabbing;
}

.rotary-knob::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: rgba(14, 22, 40, 0.28);
}

.knob-indicator {
  position: absolute;
  left: 13px;
  top: 4px;
  z-index: 1;
  width: 4px;
  height: 12px;
  border-radius: 2px;
  background: #fff6bd;
  transform: rotate(var(--knob-angle));
  transform-origin: 2px 11px;
}

button:hover {
  background: #273656;
}

button:active {
  transform: translateY(1px);
}

.stage-wrap {
  position: relative;
  width: min(100%, 960px);
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: #0d1224;
  box-shadow: 0 20px 50px rgba(19, 31, 58, 0.34);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #8adfff;
}

.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  display: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.15) 0,
    rgba(0, 0, 0, 0.15) 1px,
    transparent 1px,
    transparent 4px
  );
  mix-blend-mode: multiply;
}

.score-entry {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(10, 16, 32, 0.48);
}

.score-entry[hidden] {
  display: none;
}

.score-entry form {
  width: min(100%, 520px);
  display: grid;
  gap: 10px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 18px 40px rgba(7, 12, 24, 0.28);
}

.score-entry h2,
.score-entry p {
  margin: 0;
}

.score-entry h2 {
  font-size: 1.25rem;
}

.score-entry label {
  font-size: 0.82rem;
  font-weight: 800;
}

.score-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: stretch;
  gap: 8px;
}

.score-row input {
  min-width: 0;
  min-height: 38px;
  border: 1px solid rgba(24, 32, 51, 0.2);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.score-row button {
  min-width: 86px;
  inline-size: auto;
}

.score-status {
  min-height: 1.2em;
  color: #38445f;
  font-size: 0.82rem;
  font-weight: 700;
}

body.oldschool {
  background: var(--lcd-darkest);
  color: var(--lcd-light);
  font-family: "Courier New", ui-monospace, monospace;
}

body.oldschool .hud {
  border-color: var(--lcd-mid);
  border-radius: 0;
  background: var(--lcd-dark);
  color: var(--lcd-light);
  box-shadow: none;
  backdrop-filter: none;
}

body.oldschool .stats,
body.oldschool .actions {
  gap: 8px;
}

body.oldschool .stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

body.oldschool .actions {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

body.oldschool .brand span {
  color: var(--lcd-mid);
}

body.oldschool .stats span {
  border-radius: 0;
  border-color: var(--lcd-darkest);
  background: var(--lcd-mid);
  color: var(--lcd-darkest);
  box-shadow: inset -2px -2px 0 var(--lcd-darkest);
  font-size: 0.88rem;
  min-height: 34px;
  padding-inline: 8px;
  overflow: hidden;
  white-space: normal;
}

body.oldschool .stats span:last-child {
  grid-column: span 2;
}

body.oldschool .knob-control,
body.oldschool .palette-control {
  border-radius: 0;
  border-color: var(--lcd-darkest);
  background: var(--lcd-mid);
  color: var(--lcd-darkest);
  box-shadow: inset -2px -2px 0 var(--lcd-darkest);
  font-size: 0.82rem;
  line-height: 1.05;
  overflow: hidden;
}

body.oldschool .palette-control select {
  border-radius: 0;
  border: 1px solid var(--lcd-dark);
  background: var(--lcd-light);
  color: var(--lcd-darkest);
  font-size: 0.76rem;
  line-height: 1;
  width: clamp(68px, 48%, 92px);
}

body.oldschool button {
  border-radius: 0;
  background: var(--lcd-mid);
  color: var(--lcd-darkest);
  box-shadow: inset -2px -2px 0 var(--lcd-dark);
  font-size: 0.88rem;
  line-height: 1.05;
  white-space: nowrap;
}

body.oldschool .rotary-knob {
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 32%, var(--lcd-light) 0 9%, var(--lcd-mid) 10% 17%, var(--lcd-dark) 18% 100%);
  box-shadow: inset -2px -2px 0 var(--lcd-darkest);
}

body.oldschool .rotary-knob:hover {
  background:
    radial-gradient(circle at 38% 32%, var(--lcd-light) 0 9%, var(--lcd-mid) 10% 17%, var(--lcd-dark) 18% 100%);
}

body.oldschool .rotary-knob::after {
  background: color-mix(in srgb, var(--lcd-darkest) 70%, transparent);
}

body.oldschool .knob-indicator {
  background: var(--lcd-light);
}

body.oldschool button:hover {
  background: var(--lcd-light);
}

body.oldschool .stage-wrap {
  border-radius: 0;
  background: var(--lcd-darkest);
  overflow: hidden;
  box-shadow: 0 0 0 8px var(--lcd-dark), 0 0 0 12px var(--lcd-mid);
}

body.oldschool canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

body.oldschool .scanlines {
  display: block;
}

body.oldschool .score-entry form {
  border-radius: 0;
  border-color: var(--lcd-mid);
  background: var(--lcd-dark);
  color: var(--lcd-light);
  box-shadow: 0 0 0 4px var(--lcd-darkest);
}

body.oldschool .score-row input {
  border-radius: 0;
  border-color: var(--lcd-darkest);
  background: var(--lcd-light);
  color: var(--lcd-darkest);
}

body.oldschool .score-status {
  color: var(--lcd-mid);
}

@media (max-width: 840px) {
  body {
    padding: 8px;
    gap: 8px;
  }

  .hud {
    padding: 14px;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .score-row {
    grid-template-columns: 1fr;
  }

  .score-row button {
    inline-size: 100%;
  }
}

@media (max-width: 560px) {
  .stats,
  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 380px) {
  .stats,
  .actions {
    grid-template-columns: 1fr;
  }
}
