:root {
  --bg: #06070a;
  --panel: #111620;
  --panel-2: #171e2b;
  --line: rgba(255, 255, 255, 0.18);
  --text: #f4f7fb;
  --muted: #9aa8ba;
  --cyan: #28d7ff;
  --red: #ff2b34;
  --green: #62ef9a;
  --lane-left: 8px;
  --lane-width: calc(100% - 16px);
  --judge-bottom: 164px;
  --gauge-direction: row;
  --gauge-text-left: auto;
  --gauge-text-right: 62px;
  --gauge-text-align: right;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

button,
input,
select {
  font: inherit;
}

button,
canvas,
.playfield-wrap,
.tap-deck,
.tap-button {
  -webkit-tap-highlight-color: transparent;
}

.playfield-wrap,
.tap-button,
.pause-button {
  touch-action: none;
  -webkit-user-drag: none;
  user-drag: none;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 14px;
  width: 100vw;
  height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.playfield-wrap {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, #0b111a 0 5%, #050608 5% 95%, #0b111a 95%),
    linear-gradient(180deg, #111820, #050608 58%, #111820);
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.5);
}

#chartCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  z-index: 3;
  top: 10px;
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  pointer-events: none;
}

.hud > div,
.control-panel,
.stats > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 12, 18, 0.76);
  backdrop-filter: blur(12px);
}

.hud > div {
  min-width: 0;
  padding: 8px 10px;
}

.hud strong {
  display: block;
  overflow: hidden;
  font-size: 18px;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.label {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pause-button {
  position: absolute;
  z-index: 4;
  top: 64px;
  right: max(16px, calc(100% - var(--lane-left) - var(--lane-width) + 14px));
  width: 92px;
  min-height: 52px;
  border: 2px solid white;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.62);
}

.pause-button::before,
.pause-button::after {
  content: "";
  position: absolute;
  top: 13px;
  width: 10px;
  height: 26px;
  background: white;
}

.pause-button::before {
  left: 34px;
}

.pause-button::after {
  left: 50px;
}

.judge-line {
  position: absolute;
  z-index: 2;
  left: var(--lane-left);
  width: var(--lane-width);
  bottom: var(--judge-bottom);
  height: 7px;
  background: linear-gradient(180deg, #f8ffff 0 18%, #ff2b34 20% 68%, #f4ffff 70% 100%);
  box-shadow: 0 0 18px rgba(40, 215, 255, 0.95);
}

.judge-display {
  position: absolute;
  z-index: 5;
  left: var(--lane-left);
  top: 50%;
  width: var(--lane-width);
  min-height: 92px;
  transform: translateY(-50%);
  color: #f2fff7;
  font-size: clamp(40px, 8vw, 88px);
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
  text-shadow:
    0 0 5px #00180b,
    0 0 12px currentColor,
    4px 4px 0 #01351c,
    -4px -4px 0 #dbfff0;
  opacity: 0;
  pointer-events: none;
}

.judge-display.is-showing {
  animation: judge-pop 360ms ease-out both;
}

.gamepad-status {
  position: absolute;
  z-index: 4;
  left: calc(var(--lane-left) + 10px);
  bottom: calc(var(--judge-bottom) + 12px);
  max-width: min(420px, calc(var(--lane-width) - 20px));
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.58);
  color: rgba(255, 255, 255, 0.78);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.judge-display.pgreat {
  color: white;
}

.judge-display.great {
  color: #ffe65b;
  text-shadow:
    0 0 6px #211800,
    0 0 14px #ffe65b,
    4px 4px 0 #6a4b00,
    -4px -4px 0 #fff9bf;
}

.judge-display.good {
  color: #77ff9f;
}

.judge-display.bad,
.judge-display.poor {
  color: #ff4a52;
  text-shadow:
    0 0 6px #260005,
    0 0 14px #ff4a52,
    4px 4px 0 #64000b,
    -4px -4px 0 #ffd6d9;
}

@keyframes judge-pop {
  0% {
    opacity: 0;
    transform: translateY(-50%) scale(0.88);
  }
  18% {
    opacity: 1;
    transform: translateY(-50%) scale(1.04);
  }
  100% {
    opacity: 0;
    transform: translateY(-50%) scale(1);
  }
}

.tap-deck {
  position: absolute;
  z-index: 4;
  left: var(--lane-left);
  bottom: 48px;
  width: var(--lane-width);
  height: 140px;
}

.tap-button {
  position: absolute;
  display: block;
  min-height: 0;
  padding: 0;
  border: 2px solid #111;
  border-radius: 3px;
  font-size: 0;
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.42),
    inset 0 -14px 20px rgba(0, 0, 0, 0.3),
    0 8px 14px rgba(0, 0, 0, 0.45);
  transform: translateY(0);
  transition: transform 70ms ease, filter 70ms ease;
}

.tap-button.white {
  bottom: 0;
  height: 96px;
  background: linear-gradient(180deg, #fdfdfd 0, #c6c8ca 54%, #8d8f91 100%);
}

.tap-button.black {
  top: 0;
  height: 100px;
  background: linear-gradient(180deg, #aeb2b8 0, #24262b 28%, #06070a 100%);
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.18),
    inset 0 -12px 18px rgba(0, 0, 0, 0.55),
    0 9px 14px rgba(0, 0, 0, 0.5);
}

.tap-button.scratch {
  top: 0;
  height: 126px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #4e5ad6 0 18%, #151a2e 19% 24%, #111 25% 63%, #e6e9ec 64% 69%, #2d3034 70% 100%);
  box-shadow:
    inset -10px -16px 28px rgba(0, 0, 0, 0.6),
    inset 8px 8px 18px rgba(255, 255, 255, 0.22),
    0 10px 18px rgba(0, 0, 0, 0.55);
}

.tap-button.is-down {
  filter: brightness(1.28);
  transform: translateY(5px);
}

.gauge {
  position: absolute;
  z-index: 3;
  left: 54px;
  right: 54px;
  bottom: 10px;
  display: flex;
  flex-direction: var(--gauge-direction);
  gap: 4px;
  height: 28px;
  padding: 5px;
  border: 2px solid #d6dde8;
  border-radius: 6px;
  background: #090a0d;
}

.gauge-text {
  position: absolute;
  z-index: 4;
  left: var(--gauge-text-left);
  right: var(--gauge-text-right);
  bottom: 14px;
  min-width: 56px;
  color: white;
  font-size: 18px;
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
  text-align: var(--gauge-text-align);
  text-shadow: 0 0 8px black, 0 0 10px rgba(40, 215, 255, 0.8);
  pointer-events: none;
}

.gauge span {
  flex: 1;
  opacity: 0.22;
  filter: grayscale(0.65);
  background: linear-gradient(180deg, #f0ffff, #19edf8 45%, #01858d);
  box-shadow: none;
}

.gauge span.is-lit {
  opacity: 1;
  filter: none;
  box-shadow: 0 0 8px rgba(40, 215, 255, 0.8);
}

.gauge span.is-red {
  background: linear-gradient(180deg, #fff4f4, #ff424a 48%, #8e1018);
}

.gauge span.is-lit.is-red {
  box-shadow: 0 0 8px rgba(255, 43, 52, 0.85);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  background: linear-gradient(180deg, rgba(20, 27, 39, 0.95), rgba(8, 12, 18, 0.96));
}

.control-panel h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.05;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #070b11;
}

button {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 800;
}

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

button.is-active,
button.primary {
  border-color: rgba(40, 215, 255, 0.55);
  background: linear-gradient(180deg, #1b9de3, #1066a7);
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.field span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.field strong {
  color: var(--text);
  font-size: 13px;
}

select,
input[type="number"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #070b11;
  color: var(--text);
  padding: 0 11px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--cyan);
}

.speed-row {
  display: grid;
  grid-template-columns: 1fr 76px;
  gap: 8px;
  align-items: center;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#resetButton {
  grid-column: 1 / -1;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: auto 0 0;
}

.stats > div {
  padding: 8px;
}

.stats dt {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.stats dd {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 900;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .control-panel {
    display: grid;
    grid-template-columns: 1fr 150px 1.2fr 1fr 110px;
    align-items: end;
    gap: 10px;
    padding: 10px;
  }

  .control-panel header,
  .stats {
    display: none;
  }
}

@media (max-width: 640px) {
  .hud {
    grid-template-columns: repeat(2, 1fr);
  }

  .control-panel {
    grid-template-columns: 1fr 1fr;
  }

  .button-grid {
    grid-column: 1 / -1;
  }

  .pause-button {
    top: 110px;
    width: 72px;
    min-height: 44px;
  }
}
