:root {
  --bg: #f4f3f0; --surface: #ffffff; --surface-2: #efede8; --ink: #1a1917; --ink-2: #57544c; --ink-3: #8b877d; --line: #e2ded4;
  --accent: #c2410c; --accent-ink: #fff; --danger: #b42318;
  --wave: #b9b4a8; --wave-played: #1a1917; --region: rgba(194, 65, 12, .14); --marker: #c2410c; --head: #c2410c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211; --surface: #1c1c1a; --surface-2: #252522; --ink: #f0eee8; --ink-2: #b6b2a7; --ink-3: #85827a; --line: #302f2b;
    --accent: #fb923c; --accent-ink: #121211; --danger: #f97066;
    --wave: #4a4843; --wave-played: #f0eee8; --region: rgba(251, 146, 60, .16); --marker: #fb923c; --head: #fb923c;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.msg { min-height: 1.4em; margin: 8px 0 0; color: var(--ink-2); font-size: .9rem; }
.hint { color: var(--ink-3); font-size: .82rem; margin: 8px 0 0; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 6px 12px;
  border-radius: 8px; cursor: pointer; font-size: .9rem; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.round { width: 44px; height: 44px; justify-content: center; border-radius: 50%; padding: 0; font-size: 1.1rem; }
.link { background: none; border: 0; padding: 4px; color: var(--ink-2); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; font-size: .88rem; }
.link.danger { color: var(--danger); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* sign in */
.signin { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 16px; }
.signin-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; }
.signin-card h1 { margin: 0 0 4px; letter-spacing: -0.02em; }
.signin-card p { color: var(--ink-2); margin: 0 0 16px; }
.signin-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); margin-bottom: 10px; }
.signin-card button { width: 100%; padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; }

/* layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 16px; background: var(--surface); }
.brand { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.brand a { font-weight: 750; font-size: 1.3rem; text-decoration: none; letter-spacing: -0.02em; }
.side > .btn { width: 100%; justify-content: center; margin-bottom: 12px; }
.projects a { display: block; padding: 7px 10px; border-radius: 8px; text-decoration: none; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.projects a:hover { background: var(--surface-2); }
.projects a[aria-current="page"] { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.projects .count { color: var(--ink-3); font-size: .8rem; font-weight: 400; }
.main { padding: 20px 24px 120px; min-width: 0; max-width: 1000px; }
.empty-state { color: var(--ink-2); padding: 40px 0; }

.proj-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.proj-title { flex: 1; min-width: 0; font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; border: 1px solid transparent; background: none;
  border-radius: 8px; padding: 2px 6px; margin-left: -7px; }
.proj-title:hover, .proj-title:focus { border-color: var(--line); background: var(--surface); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.panel-head h3 { margin: 0; font-size: 1rem; flex: 1; }

.beats { list-style: none; margin: 0; padding: 0; }
.beats li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; }
.beats li + li { border-top: 1px solid var(--line); }
.beats li.on { background: var(--surface-2); }
.beats .pick { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; }
.beats .pick strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.beats .meta { color: var(--ink-3); font-size: .8rem; }
.beats .v { display: inline-block; min-width: 2.2em; color: var(--ink-3); font-size: .8rem; font-variant-numeric: tabular-nums; }
.beats a.link { white-space: nowrap; }

.player { position: sticky; top: 8px; z-index: 5; box-shadow: 0 6px 24px rgba(0,0,0,.06); }
.now { margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wave-wrap { position: relative; height: 88px; border-radius: 8px; background: var(--surface-2); overflow: hidden; touch-action: none; }
#wave { display: block; width: 100%; height: 100%; cursor: pointer; }
.controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.time { font-variant-numeric: tabular-nums; color: var(--ink-2); min-width: 7.5em; }
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 2px; }
.vol { display: inline-flex; align-items: center; gap: 6px; }
.vol input { width: 110px; accent-color: var(--accent); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button { border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 4px 12px; cursor: pointer; font-size: .88rem; max-width: 240px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.doc-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.doc-title { flex: 1; min-width: 140px; font-weight: 600; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--bg); }
.doc-bar select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--bg); max-width: 220px; }
.doc-body, .doc-render { width: 100%; min-height: 420px; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; background: var(--bg);
  font-size: 1.02rem; line-height: 1.65; }
.doc-body { resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .95rem; }
.md h2, .md h3, .md h4 { margin: .8em 0 .3em; }
.md h2:first-child, .md h3:first-child, .md p:first-child { margin-top: 0; }
.md p { margin: 0 0 1em; }
.md blockquote { margin: 0 0 1em; padding-left: 12px; border-left: 3px solid var(--accent); color: var(--ink-2); font-style: italic; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md .hd { display: inline-block; margin-top: .3em; }

.drop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(194, 65, 12, .18); border: 3px dashed var(--accent);
  font-size: 1.4rem; font-weight: 700; color: var(--ink); pointer-events: none; }

/* sharing */
.code-card { padding: 18px 24px; }
.code-card p { margin-bottom: 10px; }
.signin-card button.secondary { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.shares { list-style: none; margin: 0 0 14px; padding: 0; }
.shares li { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.shares li:first-child { border-top: 0; }
.shares .who { font-weight: 600; }
.shares .what { color: var(--ink-2); font-size: .88rem; flex: 1; min-width: 180px; }
.shares code { font-size: .85rem; background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }
.share-form { display: grid; gap: 10px; max-width: 460px; padding-top: 6px; }
.share-form h4 { margin: 0; font-size: .95rem; }
.share-form label { display: grid; gap: 4px; font-size: .9rem; color: var(--ink-2); }
.share-form label.chk { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.share-form input:not([type=checkbox]), .share-form select { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--bg); color: var(--ink); }
.share-form .btn.primary { justify-self: start; }
.pw-row { display: flex; gap: 8px; align-items: center; }
.pw-row input { flex: 1; font-family: ui-monospace, Menlo, monospace; }
.share-made { margin-top: 12px; padding: 12px; border-radius: 10px; background: var(--surface-2); }
.share-made p { margin: 0 0 8px; }
.share-made textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--surface); font-size: .9rem; resize: none; margin-bottom: 8px; }
.conflict { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 12px; margin-bottom: 8px; border-radius: 8px;
  background: var(--region); border: 1px solid var(--accent); }
.conflict span { flex: 1; min-width: 200px; }
.doc-body[readonly] { background: var(--surface-2); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .projects { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
  .projects a { flex: none; max-width: 200px; border: 1px solid var(--line); }
  .main { padding: 14px 16px 80px; }
  .proj-title { font-size: 1.35rem; }
  .player { top: 0; border-radius: 0 0 12px 12px; }
  .sep { display: none; }
  .beats li { flex-wrap: wrap; row-gap: 2px; }
  .beats .pick { flex: 1 1 calc(100% - 3em); }
  .beats li > .link:first-of-type { margin-left: 2.2em; }
  .doc-body, .doc-render { min-height: 300px; }
}

/* Phase 3: public page + tracks + rights requests */
.side-link { display: block; padding: 7px 10px; border-radius: 8px; text-decoration: none; color: var(--ink-2); font-size: .92rem; }
.side-link:hover { background: var(--surface-2); }
.side-link[aria-current="page"] { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.side-link .count:not(:empty) { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 7px; font-size: .75rem; font-weight: 700; }
.pub { flex: none; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--accent);
  border: 1px solid currentColor; border-radius: 99px; padding: 1px 7px; white-space: nowrap; }
.requests { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.requests li { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.requests li.done { opacity: .6; }
.requests .top { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.requests .who { font-weight: 600; }
.requests .use { color: var(--accent); font-size: .85rem; font-weight: 600; }
.requests .when { color: var(--ink-3); font-size: .82rem; margin-left: auto; }
.requests .text { white-space: pre-wrap; margin: 8px 0; overflow-wrap: anywhere; }
.requests .row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: .88rem; }
