:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --panel2: #16213a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
}

* {
  box-sizing: border-box;
}

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

body {
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid #1f2a44;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  flex-direction: column;
  min-width: 150px;
}

.logo {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.3px;
}

.sub {
  font-size: 11px;
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  flex: 1;
}

.ctl {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

select,
input[type='range'] {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid #243352;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  outline: none;
}

input[type='range'] {
  width: 110px;
  padding: 0;
}

.val {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 42px;
}

#stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

#viewArea {
  flex: 1;
  min-height: 0;
  position: relative;
}

.view-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#keyboardArea {
  height: 150px;
  border-top: 1px solid #1f2a44;
  background: var(--panel);
  position: relative;
}

.vkeys {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.vk {
  position: absolute;
  top: 0;
  border-radius: 0 0 4px 4px;
  user-select: none;
  cursor: pointer;
}

.vk-white {
  height: 100%;
  background: #e2e8f0;
  border: 1px solid #0f172a;
  z-index: 1;
}

.vk-white.on {
  background: var(--accent);
}

.vk-black {
  height: 62%;
  background: #1e293b;
  border: 1px solid #0f172a;
  z-index: 2;
}

.vk-black.on {
  background: var(--accent);
}

.vk-label {
  position: absolute;
  bottom: 4px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 9px;
  line-height: 1;
  pointer-events: none;
  color: #475569;
}

.vk-black .vk-label {
  color: #cbd5e1;
  bottom: 5px;
}

.vk.on .vk-label {
  color: #0f172a;
}

.vk-black.on .vk-label {
  color: #fff;
}

#resultsOverlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(5, 10, 20, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
}

#resultsOverlay[hidden] {
  display: none;
}

.modal {
  background: var(--panel);
  border: 1px solid #24304d;
  border-radius: 12px;
  padding: 20px 26px;
  min-width: 340px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.modal-song {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0 18px;
}

.results-grid div {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 8px 4px;
}

.results-grid dt {
  font-size: 11px;
  color: var(--muted);
}

.results-grid dd {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#hint {
  position: absolute;
  bottom: 4px;
  right: 10px;
  font-size: 10px;
  color: var(--muted);
  background: rgba(11, 18, 32, 0.7);
  padding: 3px 8px;
  border-radius: 6px;
  pointer-events: none;
  z-index: 5;
}

#bottombar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-top: 1px solid #1f2a44;
  flex-wrap: wrap;
}

.btn {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid #243352;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}

.btn:hover {
  background: #1d2a4a;
}

.btn.primary {
  background: #0e7490;
  border-color: #0e7490;
  font-weight: 600;
}

.btn.primary:hover {
  background: #0891b2;
}

.chk {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.sep,
.spacer {
  flex: 0 0 auto;
}

.spacer {
  flex: 1;
}

.score {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.score b {
  color: var(--text);
}

.time {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.status {
  font-size: 12px;
  color: var(--muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#toast {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: #7f1d1d;
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 100;
  max-width: 80vw;
}

#toast.show {
  opacity: 1;
}
