:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --purple: #bc8cff;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}

.hidden { display: none !important; }
.spacer { flex: 1; }

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; }
#whoami { color: var(--muted); }

.view { padding: 24px; max-width: 1100px; margin: 0 auto; }

/* AUTH */
#view-auth { display: flex; justify-content: center; align-items: center; min-height: calc(100vh - 60px); }
.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
}
.auth-card h1 { font-size: 26px; margin-bottom: 6px; }
.subtitle { color: var(--muted); margin-bottom: 20px; font-size: 14px; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1;
  padding: 8px;
  background: var(--bg3);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.tab.active { color: var(--text); border-color: var(--accent); }

form label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
input {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
input:focus { outline: none; border-color: var(--accent); }

.btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: filter 0.15s;
}
.btn:hover { filter: brightness(1.2); }
.btn.primary { background: var(--accent); color: #0d1117; font-weight: 600; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.full { width: 100%; }
.btn.toggle.on { background: var(--amber); color: #0d1117; font-weight: 700; border-color: transparent; }
.btn.danger { background: var(--red); color: #fff; border-color: transparent; font-weight: 600; }
.btn.rec.recording { background: var(--red); color: #fff; font-weight: 700; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }

.error { color: var(--red); font-size: 13px; margin-bottom: 10px; }

/* LOBBY */
.lobby-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.create-room { display: flex; gap: 8px; margin-bottom: 20px; }
.create-room input { flex: 1; }

.rooms-list { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.rooms-list li {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.room-name { font-weight: 600; }
.room-meta { color: var(--muted); font-size: 12px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge.leader { background: var(--purple); color: #0d1117; }
.badge.live { background: var(--red); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; margin-right: 4px; }

.empty { color: var(--muted); padding: 24px; text-align: center; grid-column: 1 / -1; }

/* STAGE */
.stage-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.presence { color: var(--muted); font-size: 13px; }

.panels { display: grid; grid-template-columns: 2fr 1.5fr 1.5fr; gap: 12px; margin-bottom: 16px; }
.panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.panel-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }

.chord-big { font-size: 56px; font-weight: 800; line-height: 1.1; color: var(--accent); min-height: 62px; }
.bass-tonic { font-size: 22px; font-weight: 700; color: var(--amber); }
.chord-roman {
  font-size: 20px;
  font-weight: 700;
  color: var(--purple);
  min-height: 26px;
}
.chord-roman:empty { min-height: 0; }
.key-big { font-size: 28px; font-weight: 700; line-height: 1.2; min-height: 34px; }

.actions-panel { display: flex; flex-direction: column; gap: 10px; }
.midi-inputs { color: var(--muted); font-size: 12px; line-height: 1.5; }

/* KEYBOARD */
.keyboard-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  overflow-x: auto;
}
.keyboard { position: relative; height: 150px; user-select: none; min-width: 900px; }
.key.white {
  position: absolute;
  top: 0;
  bottom: 0;
  background: linear-gradient(#f8f9fa, #dee2e6);
  border: 1px solid #999;
  border-radius: 0 0 6px 6px;
  transition: background 0.05s;
}
.key.black {
  position: absolute;
  top: 0;
  height: 60%;
  background: linear-gradient(#333, #000);
  border-radius: 0 0 5px 5px;
  z-index: 2;
  box-shadow: 0 3px 5px rgba(0,0,0,0.5);
}
.key .key-label {
  position: absolute;
  bottom: 6px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  color: #666;
  pointer-events: none;
}
.key.on.white { background: linear-gradient(#7ee787, var(--green)); }
.key.on.black { background: linear-gradient(var(--green), #1a7f37); }
.key.root.hint-white { background: linear-gradient(#ffd766, var(--amber)); }
.key.root.hint-black { background: linear-gradient(var(--amber), #9e6a03); }
.key.ghost { opacity: 0.25; }

/* RECORDER */
.recorder { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.recorder h3 { font-size: 15px; margin-left: 12px; }
.rec-status { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.recordings-list { list-style: none; margin-top: 8px; }
.recordings-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-size: 14px;
}
.rec-name { font-weight: 600; }
.rec-meta { color: var(--muted); font-size: 12px; }

/* PROGRESSIONS */
.prog-wrap { margin-top: 20px; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.prog-log { list-style: none; margin-top: 8px; max-height: 180px; overflow-y: auto; }
.prog-log li {
  font-family: ui-monospace, monospace;
  font-size: 15px;
  padding: 6px 10px;
  border-left: 3px solid var(--amber);
  background: var(--bg3);
  border-radius: 0 6px 6px 0;
  margin-bottom: 6px;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--amber);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6);
  z-index: 100;
  max-width: 90vw;
}

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(1, 4, 9, 0.75);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.15s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: min(420px, 92vw);
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
}
.modal h3 { font-size: 18px; margin-bottom: 14px; }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.modal-body p { color: var(--muted); font-size: 14px; line-height: 1.5; }
.modal-body label { margin-bottom: 0; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); cursor: pointer; }
.check-row input { width: auto; margin: 0; accent-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.field-hint { color: var(--muted); font-size: 12px; }

@media (max-width: 800px) {
  .panels { grid-template-columns: 1fr; }
}
