:root {
  --bg: #07070b;
  --fg: #f2f2f6;
  --accent: #7dd3fc;
  --warn: #fca5a5;
  --muted: #71717a;
  --panel: rgba(10, 10, 14, 0.72);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, "SF Pro", "Pretendard", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { position: relative; }

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  background: #000;
  z-index: 0;
}

#skeleton {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 5;
}

#webcam {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* On-screen keyboard — click to pick a key. Selection only sets the scale root
   for DEGREE-mode chord generation; no audio plays from the click itself. */
.keyboard-wrap {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 20;
  padding: 12px 14px 10px;
  background: rgba(10, 10, 14, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.keyboard-wrap.has-selection {
  border-color: rgba(125, 211, 252, 0.45);
  box-shadow: 0 0 32px rgba(125, 211, 252, 0.18);
}

.keyboard-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, monospace;
}
.keyboard-title {
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--muted);
  text-transform: uppercase;
}
.keyboard-current {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  transition: color 0.15s;
}
.keyboard-wrap.has-selection .keyboard-current {
  color: var(--accent);
}

.keyboard {
  display: flex;
  gap: 4px;
}

.key {
  border: none;
  cursor: pointer;
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, monospace;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  padding: 12px 10px;
  min-width: 42px;
  border-radius: 8px;
  transition: transform 0.12s, background 0.15s, color 0.15s, box-shadow 0.2s;
  user-select: none;
}
.key.white {
  background: #f2f2f6;
  color: #222;
}
.key.black {
  background: #222831;
  color: #e8e8ef;
  min-width: 36px;
  padding: 10px 8px;
  font-size: 12px;
}
.key:hover { transform: translateY(-2px); }
.key.active {
  background: var(--accent);
  color: #000;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.85),
    0 0 28px rgba(125, 211, 252, 0.85),
    0 6px 18px rgba(125, 211, 252, 0.45);
  transform: translateY(-4px);
  font-weight: 800;
}
.key.active.black { background: var(--accent); color: #000; }

/* HUD overlay */
#hud {
  position: fixed;
  left: 24px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  z-index: 10;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.hud-row {
  display: flex;
  gap: 16px;
  align-items: center;
}

.hud-row.subtle { color: var(--muted); font-size: 12px; }

.badge {
  background: var(--accent);
  color: #000;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 700;
  letter-spacing: 0.08em;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}
.badge.muted {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--muted);
}

.meter label {
  display: inline-block;
  margin-right: 6px;
  color: var(--muted);
  letter-spacing: 0.1em;
  font-size: 10px;
}

/* Start Gate */
.gate {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: radial-gradient(ellipse at center, #0b0b15 0%, #000 100%);
  z-index: 100;
  transition: opacity 0.6s;
}
.gate.hidden { opacity: 0; pointer-events: none; }

.gate h1 {
  font-size: 64px;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #7dd3fc, #c4b5fd, #fda4af);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.gate .tagline {
  color: var(--muted);
  font-size: 15px;
}

.notes {
  list-style: none;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
  margin: 8px 0;
}

.gate-controls {
  display: flex;
  gap: 24px;
  margin: 12px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.field select,
.field input[type="checkbox"] {
  background: #1a1a22;
  color: var(--fg);
  border: 1px solid #2a2a35;
  padding: 8px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  text-transform: none;
  letter-spacing: normal;
}
.field input[type="checkbox"] {
  width: 20px;
  height: 20px;
  padding: 0;
  accent-color: var(--accent);
}

#start-btn {
  background: var(--fg);
  color: #000;
  border: none;
  padding: 14px 42px;
  font-size: 16px;
  font-weight: 700;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  letter-spacing: 0.02em;
}
#start-btn:hover { transform: scale(1.03); background: var(--accent); }
#start-btn:disabled { opacity: 0.5; cursor: wait; }

#gate-error {
  color: var(--warn);
  font-size: 13px;
  min-height: 1em;
  margin-top: 8px;
}

/* ── Mobile: shrink the bottom keyboard so all 12 keys fit on a phone, and
   respect the home-indicator safe area on iOS. HUD stacks above the keyboard.
*/
@media (max-width: 640px) {
  .keyboard-wrap {
    /* Span the screen so we can use real estate without overflow. */
    left: 8px;
    right: 8px;
    transform: none;
    bottom: calc(12px + env(safe-area-inset-bottom));
    padding: 10px 10px 8px;
    border-radius: 12px;
    gap: 6px;
  }
  .keyboard {
    /* Distribute 12 keys evenly across the available width. */
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 3px;
    width: 100%;
  }
  .key {
    min-width: 0;
    width: 100%;
    padding: 10px 0;
    font-size: 11px;
    border-radius: 6px;
  }
  .key.black {
    min-width: 0;
    padding: 9px 0;
    font-size: 10px;
  }
  .keyboard-header {
    gap: 8px;
  }
  .keyboard-title {
    font-size: 10px;
    letter-spacing: 0.14em;
  }
  .keyboard-current {
    font-size: 11px;
  }

  /* HUD — tuck above the keyboard, smaller, single-column. */
  #hud {
    left: 12px;
    right: 12px;
    bottom: auto;
    top: 12px;
    font-size: 11px;
    gap: 4px;
  }
  .hud-row { gap: 10px; flex-wrap: wrap; }
  .hud-row.subtle { font-size: 10px; }

  /* Start gate — keep readable on small screens. */
  .gate { padding: 24px 18px; gap: 14px; }
  .gate h1 { font-size: 44px; }
  .gate .tagline { font-size: 13px; }
  .notes { font-size: 12px; line-height: 1.6; }
  .gate-controls { flex-direction: column; gap: 12px; width: 100%; max-width: 280px; }
  .field { flex-direction: row; align-items: center; justify-content: space-between; }
  #start-btn { padding: 12px 36px; font-size: 15px; }
}

/* Very narrow phones (iPhone SE etc.) — drop a touch more. */
@media (max-width: 360px) {
  .keyboard-wrap { padding: 8px 8px 6px; }
  .keyboard { gap: 2px; }
  .key { padding: 8px 0; font-size: 10px; }
  .key.black { padding: 7px 0; font-size: 9px; }
}
