:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #ece9e2;
  --text: #1b1c20;
  --muted: #6b6a66;
  --line: #dcd8cf;
  --accent: #e8552a;
  --accent-text: #ffffff;
  --go: #1f9d55;
  --stop: #d93b3b;
  --focus: #2b6cdf;
  --radius: 14px;
  --tap: 52px;
  --shadow: 0 6px 24px rgb(0 0 0 / 0.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --surface: #1d2027;
    --surface-2: #272b34;
    --text: #f3efe8;
    --muted: #a19d95;
    --line: #343844;
    --accent: #ff6a3d;
    --go: #2fbf6d;
    --stop: #f05252;
    --focus: #7aa7ff;
    --shadow: 0 6px 24px rgb(0 0 0 / 0.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Layout */
.page { max-width: 720px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.topbar h1 { font-size: 1.5rem; margin: 0; flex: 1; }
.brand { font-weight: 800; letter-spacing: -0.02em; }
.brand b { color: var(--accent); }
.muted { color: var(--muted); }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }

/* Buttons */
.btn {
  min-height: var(--tap); padding: 0 20px; border: 0; border-radius: var(--radius);
  background: var(--surface-2); font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.go { background: var(--go); color: #fff; }
.btn.stop { background: var(--stop); color: #fff; }
.btn.ghost { background: transparent; border: 2px solid var(--line); }
.btn.big { min-height: 64px; font-size: 1.15rem; padding: 0 28px; }
.btn.block { width: 100%; }
.icon-btn { width: var(--tap); padding: 0; }

/* Cards and lists */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.list { display: grid; gap: 10px; padding: 0; margin: 0; list-style: none; }
.list-item { background: var(--surface); border-radius: var(--radius); padding: 10px 10px 10px 12px; display: flex; align-items: center; gap: 10px; }
.list-item .btn { padding: 0 14px; }
.list-item .icon-btn { padding: 0; width: 44px; min-height: 44px; }
.list-item .name { font-weight: 650; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }

/* Forms */
label.field { display: grid; gap: 6px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], select {
  min-height: var(--tap); border-radius: 12px; border: 2px solid var(--line); background: var(--surface);
  padding: 0 14px; width: 100%;
}
input:focus { border-color: var(--focus); outline: none; }
.error-text { color: var(--stop); font-weight: 600; min-height: 1.4em; }

/* Tabs (bottom navigation on phones) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tabbar button { flex: 1; min-height: 64px; border: 0; background: none; font-size: 0.78rem; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px 0; }
.tabbar button .ico { font-size: 1.3rem; line-height: 1; height: 1.3rem; overflow: hidden; }
.tabbar button[aria-current=page] { color: var(--accent); }

/* Sheets (bottom panels) */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--surface); width: 100%; max-width: 720px; max-height: 88vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 12px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet-handle { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 12px; font-size: 1.25rem; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 50; pointer-events: none; }
#toast .msg { background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow); max-width: 90vw; }

/* Call screen */
.call { position: fixed; inset: 0; background: #000; color: #fff; display: flex; flex-direction: column; }
.call .stage { position: relative; flex: 1; min-height: 0; }
.call video.remote { width: 100%; height: 100%; object-fit: contain; background: #000; }
.call video.local { position: absolute; right: 12px; top: calc(12px + env(safe-area-inset-top)); width: 28vw; max-width: 180px; aspect-ratio: 3/4; object-fit: cover; border-radius: 12px; border: 2px solid rgb(255 255 255 / 0.4); background: #222; transform: scaleX(-1); }
.call .status { position: absolute; left: 12px; top: calc(12px + env(safe-area-inset-top)); display: grid; gap: 6px; max-width: 60vw; }
.pill { background: rgb(0 0 0 / 0.6); color: #fff; padding: 6px 12px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; width: fit-content; }
.pill.live { background: var(--stop); }
.pill.delay { background: #1e57c8; }
.call .overlay-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; }
.call .controls { display: flex; gap: 8px; overflow-x: auto; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); background: #0d0e11; scrollbar-width: none; }
.call .controls::-webkit-scrollbar { display: none; }
.ctrl { flex: none; min-width: 68px; height: 64px; border: 0; border-radius: 14px; background: #262a33; color: #fff; display: grid; place-items: center; font-size: 0.72rem; font-weight: 600; padding: 6px 8px; }
.ctrl .ico { font-size: 1.35rem; line-height: 1; }
.ctrl.on { background: #fff; color: #111; }
.ctrl.end { background: var(--stop); }
.modebar { display: flex; gap: 6px; padding: 8px 10px 0; background: #0d0e11; }
.modebar button { flex: 1; min-height: 48px; border: 0; border-radius: 12px; background: #262a33; color: #fff; font-weight: 700; font-size: 0.9rem; }
.modebar button[aria-pressed=true] { background: var(--accent); }
.beat-flash { position: absolute; left: 50%; top: calc(14px + env(safe-area-inset-top)); width: 18px; height: 18px; margin-left: -9px; border-radius: 50%; background: #fff; opacity: 0; transition: opacity 0.08s; }
.beat-flash.on { opacity: 0.95; transition: none; }
.beat-flash.accent { background: var(--accent); }
.score-overlay { position: absolute; left: 0; right: 0; bottom: 0; max-height: 55%; overflow: auto; background: rgb(255 255 255 / 0.96); color: #111; border-radius: 16px 16px 0 0; }
.sheet-call { color: var(--text); }

/* Metronome */
.bpm-dial { display: flex; align-items: center; justify-content: center; gap: 12px; }
.bpm-value { font-size: 3.4rem; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 3.2ch; text-align: center; line-height: 1; }
.bpm-dial .btn { width: 64px; height: 64px; font-size: 1.6rem; padding: 0; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 36px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { min-height: 44px; padding: 0 14px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); font-weight: 600; }
.seg button[aria-pressed=true] { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }

/* Notation editor */
.editor-toolbar {
  position: sticky; bottom: 0; z-index: 2; display: grid; gap: 6px; margin-top: 10px;
  background: var(--bg); border-top: 1px solid var(--line);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
}
.editor-toolbar .palette { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.editor-toolbar .palette::-webkit-scrollbar { display: none; }
.editor-toolbar .palette > * { flex: none; }
.actions-row { display: flex; gap: 8px; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; margin-bottom: 12px; }
.actions-row > * { flex: none; }
.actions-row::-webkit-scrollbar { display: none; }
.score-wrap { background: #fff; color: #111; border-radius: var(--radius); overflow-x: auto; touch-action: manipulation; }
.score-wrap svg { display: block; }
.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.palette button { min-width: 46px; min-height: 46px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); font-weight: 700; padding: 0 10px; }
.palette button[aria-pressed=true] { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.palette .glyph { font-family: "Bravura", serif; font-size: 1.6rem; }
.kit-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.85rem; color: var(--muted); }
.editor-page { max-width: 1200px; }

/* Replay */
.replay video { width: 100%; max-height: 60vh; background: #000; border-radius: 12px; }

@media (min-width: 900px) {
  .call .stage.with-panel { margin-right: 420px; }
  .call .side-panel { position: fixed; right: 0; top: 0; bottom: 0; width: 420px; overflow: auto; background: var(--surface); color: var(--text); padding: 16px; }
}
@media print {
  body { background: #fff; }
  .no-print, .tabbar, #toast { display: none !important; }
  .score-wrap { box-shadow: none; overflow: visible; }
}
.print-only { display: none; }
@media print {
  .print-only { display: block; }
  .page { padding: 0; max-width: none; }
}
