:root {
  color-scheme: dark;
  --bg: #080a0d;
  --panel: #11161c;
  --panel-2: #171d25;
  --line: #2b3641;
  --text: #f1f5f9;
  --muted: #9aa7b4;
  --green: #36d399;
  --red: #fb7185;
  --yellow: #fbbf24;
  --cyan: #22d3ee;
  --blue: #60a5fa;
  --purple: #a78bfa;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body {
  overflow-x: hidden;
  touch-action: manipulation;
}

button,
select {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto minmax(560px, 1fr) auto;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, black);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 210px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #f7931a;
  color: #111;
  font-weight: 900;
  font-size: 25px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.chart-badge {
  height: 38px;
  min-width: 94px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

.chart-badge span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
}

.chart-badge strong {
  color: var(--text);
  font-size: 14px;
  line-height: 1;
}

.audio-time {
  min-width: 128px;
}

select,
button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
}

select {
  min-width: 130px;
  padding: 0 10px;
}

button {
  padding: 0 16px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

#startButton {
  border-color: color-mix(in srgb, var(--green) 65%, var(--line));
  background: color-mix(in srgb, var(--green) 18%, var(--panel-2));
}

.hud {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.hud > div {
  flex: 0 0 auto;
  min-width: 160px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.hud span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.hud strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(18px, 2.3vw, 28px);
  line-height: 1;
}

.stage {
  position: relative;
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #050608;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 560px;
}

.touch-pad {
  display: none;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  min-height: 64px;
}

.touch-key {
  height: 64px;
  padding: 0;
  border-color: color-mix(in srgb, var(--blue) 46%, var(--line));
  background:
    linear-gradient(180deg, rgba(96, 165, 250, 0.2), rgba(96, 165, 250, 0.06)),
    var(--panel-2);
  color: var(--text);
  font-size: clamp(22px, 4.8vw, 34px);
  font-weight: 900;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
}

.touch-key-space {
  font-size: clamp(14px, 2.4vw, 20px);
}

.touch-key.is-pressed,
.touch-key:active {
  transform: translateY(2px);
  border-color: var(--green);
  background:
    linear-gradient(180deg, rgba(54, 211, 153, 0.32), rgba(54, 211, 153, 0.08)),
    var(--panel-2);
}

.rotate-hint {
  display: none;
}

.ready-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 6, 8, 0.72);
  text-align: center;
}

.ready-overlay.hidden {
  display: none;
}

.ready-overlay h2 {
  font-size: clamp(24px, 5vw, 46px);
  line-height: 1;
}

.ready-overlay p {
  margin-top: 12px;
  color: var(--muted);
  font-size: 15px;
}

.lane-help {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
}

.result-dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 6, 8, 0.72);
  backdrop-filter: blur(8px);
}

.result-dialog.hidden {
  display: none;
}

.result-panel {
  width: min(360px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11161c;
  text-align: center;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.42);
}

.result-panel span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.result-panel h2 {
  margin-top: 8px;
  font-size: 24px;
}

.result-panel strong {
  display: block;
  margin: 18px 0;
  font-size: 54px;
  line-height: 1;
}

.result-panel button {
  min-width: 128px;
}

kbd {
  min-width: 46px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 800;
}

.space-key {
  min-width: 118px;
}

@media (max-width: 840px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .controls {
    justify-content: stretch;
  }

  .controls label,
  .chart-badge,
  .controls button {
    flex: 1 1 130px;
  }

  select,
  button {
    width: 100%;
  }

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

  .stage,
  canvas {
    min-height: 560px;
  }
}

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

  .lane-help {
    flex-wrap: wrap;
  }
}

@media (hover: none) and (pointer: coarse) {
  .touch-pad {
    display: grid;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 4px;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
    min-height: 36px;
    padding: 4px 6px;
    gap: 6px;
    border-radius: 6px;
  }

  .brand {
    min-width: 56px;
  }

  h1 {
    font-size: 15px;
  }

  .controls {
    flex: 1;
    flex-wrap: nowrap;
    gap: 4px;
  }

  .controls label {
    flex: 0 1 132px;
  }

  .controls label > span {
    display: none;
  }

  select,
  button {
    height: 30px;
    min-width: 0;
    padding: 0 8px;
    border-radius: 6px;
    font-size: 13px;
  }

  .controls button {
    flex: 0 0 auto;
    width: auto;
  }

  #langButton {
    width: 34px;
    padding: 0;
  }

  .hud {
    display: none;
  }

  .stage {
    min-height: 0;
    border-radius: 6px;
  }

  canvas {
    min-height: 0;
    height: 100%;
  }

  .touch-pad {
    display: grid;
    min-height: 44px;
    gap: 5px;
  }

  .touch-key {
    height: 44px;
    border-radius: 7px;
    font-size: clamp(19px, 4.6vw, 27px);
  }

  .touch-key-space {
    font-size: clamp(12px, 2.2vw, 15px);
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
  .app-shell {
    min-height: 100dvh;
    grid-template-rows: auto auto minmax(360px, 1fr) auto;
  }

  .touch-pad {
    display: grid;
    position: sticky;
    bottom: 8px;
    z-index: 8;
  }

  .rotate-hint {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(5, 6, 8, 0.88);
    color: var(--text);
    font-size: 22px;
    font-weight: 900;
    text-align: center;
  }
}
