/* takes: one stylesheet for every page. System fonts only, no external resources (REQ-SEC-4);
   light and dark follow the system (prefers-color-scheme). Colours are custom properties, which
   static/js/player.js also reads for the waveform (--wave, --wave-progress, --cursor, ...).
   Tag and section colours come from data-color, set as --tag-color / --section-color by
   static/js/review.js and player.js (templates carry no style attributes). */

:root {
  color-scheme: light dark;
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f2f2ef;
  --text: #1d1f23;
  --muted: #646a73;
  --border: #d9dad6;
  --accent: #2f62b0;
  --accent-text: #ffffff;
  --link: #2a5ca8;
  --danger: #b3261e;
  --ok: #2e7d32;
  --warn: #b26a00;
  --focus: #2f62b0;
  --current: #fff4c8;
  --focus-bg: #e7efff;
  --wave: #9aa3b2;
  --wave-progress: #2f62b0;
  --cursor: #d32f2f;
  --selection: rgba(47, 98, 176, 0.18);
  --minimap-overlay: rgba(47, 98, 176, 0.18);
  --mark: #e0a000;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1d2024;
    --surface-2: #262a2f;
    --text: #e6e7e9;
    --muted: #9aa1ab;
    --border: #363b42;
    --accent: #6b9be6;
    --accent-text: #0b1220;
    --link: #8db4f0;
    --danger: #f2827a;
    --ok: #7cc47f;
    --warn: #f0b75c;
    --focus: #8db4f0;
    --current: #3a3420;
    --focus-bg: #1f2c44;
    --wave: #5f6875;
    --wave-progress: #6b9be6;
    --cursor: #ff6b6b;
    --selection: rgba(107, 155, 230, 0.22);
    --minimap-overlay: rgba(107, 155, 230, 0.2);
    --mark: #f0b75c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--link); text-underline-offset: 2px; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: .25rem 0 .75rem; }
h2 { font-size: 1.15rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Forms */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]), select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .35rem .5rem; max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
input[type="color"] {
  width: 2.5rem; height: 2rem; padding: 0 .1rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); vertical-align: middle;
}
button, a.button {
  display: inline-block; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .3rem .7rem; cursor: pointer; text-decoration: none; color: var(--text); line-height: 1.3;
}
button:hover, a.button:hover { border-color: var(--muted); }
button:disabled { opacity: .55; cursor: default; }
button.primary, a.button { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem 1rem; margin: 0 0 1rem; }
legend { padding: 0 .3rem; color: var(--muted); }
label { cursor: pointer; }
details > summary { cursor: pointer; color: var(--link); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .9em; }

/* Site header and layout */
header.site {
  display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: center; padding: .5rem 1rem;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
header.site .brand { font-weight: 700; text-decoration: none; color: inherit; letter-spacing: .02em; }
header.site nav a { text-decoration: none; }
header.site nav a:hover { text-decoration: underline; }
main { padding: 1rem; max-width: 72rem; margin: 0 auto; }
nav.identity { margin-left: auto; display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; }
nav.identity form.logout { display: inline; margin: 0; }
nav.review { display: flex; gap: 1rem; }
.error { color: var(--danger); }
.notice { padding: .5rem .75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
code.secret {
  display: inline-block; padding: .25rem .5rem; user-select: all; word-break: break-all;
  background: var(--surface-2); border-radius: 4px;
}
.identity table, .review table { background: var(--surface); }
.identity.login { max-width: 24rem; margin: 2rem auto; }

/* Review pages */
.review .crumbs { margin: 0; font-size: .9em; color: var(--muted); }
.review .meta, .review .hint, .review .author, .review .rev { color: var(--muted); }
.review .hint { font-size: .9em; }
.review .empty { color: var(--muted); font-style: italic; }
.review form.inline { display: inline; margin: 0; }
.review form.filters { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin: .5rem 0 1rem; }
.review fieldset.tag-filter { display: flex; flex-wrap: wrap; gap: .25rem .5rem; border: 0; padding: 0; margin: 0; }
.review fieldset.tag-filter legend { float: left; margin-right: .5rem; padding: 0; }
.review label.chip { border: 1px solid var(--border); border-radius: 1em; padding: 0 .5rem; background: var(--surface); }
.review ul.tags { display: inline-flex; flex-wrap: wrap; gap: .25rem; list-style: none; margin: 0; padding: 0; vertical-align: middle; }
.tag {
  --tag-color: var(--muted);
  display: inline-flex; align-items: center; gap: .2rem; padding: 0 .5rem; border-radius: 1em; font-size: .85em;
  border: 1px solid var(--tag-color); background: color-mix(in srgb, var(--tag-color) 14%, transparent);
}
.tag button { border: 0; background: none; padding: 0 .1rem; color: var(--muted); line-height: 1; }
.review .tag.added { --tag-color: var(--ok); }
.review .tag.removed { --tag-color: var(--danger); text-decoration: line-through; }
.review .badge {
  display: inline-block; padding: 0 .4rem; border-radius: 4px; font-size: .78em;
  background: var(--surface-2); color: var(--muted); vertical-align: middle;
}
.review .badge.current { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--text); }
.review .verify-verified { background: color-mix(in srgb, var(--ok) 22%, transparent); color: var(--text); }
.review .verify-drift, .review .map-unmapped, .review .map-assumed {
  background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--text);
}
.review .verify-mismatch, .review .badge.clipped { background: color-mix(in srgb, var(--danger) 22%, transparent); color: var(--text); }
.review .banner { padding: .5rem .75rem; border-radius: var(--radius); margin: .5rem 0; }
.review .banner.mismatch { background: color-mix(in srgb, var(--danger) 12%, transparent); border: 1px solid var(--danger); }
.review .banner.unmapped { background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid var(--warn); }
.review .body, .review .notes, .review .snapshot { white-space: pre-line; margin: .25rem 0; overflow-wrap: anywhere; }
.review .page-links { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin: .5rem 0; }
.review section.collection { margin-bottom: 1.5rem; }
.review section.collection h2 time { color: var(--muted); font-weight: normal; font-size: .9em; margin-left: .5rem; }
.review table.recordings td:nth-child(2), .review table.recordings td:nth-child(4) { font-variant-numeric: tabular-nums; white-space: nowrap; }
.review details.composer, .review section.composer {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem 1rem; margin: 1rem 0;
}
.review section.composer h2 { margin-top: .25rem; }
.review .composer.open { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.review .form-status { color: var(--muted); font-size: .9em; }

/* Recording page */
.review .recording-header h1 { margin-bottom: .4rem; }
.review .header-tags { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.review nav.versions ol { display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; list-style: none; padding: 0; margin: .75rem 0 .25rem; }
.review nav.versions li.chosen > a { font-weight: 700; }
.review details.mapping { margin: .5rem 0; }
.review .player {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .75rem;
  margin: .75rem 0; box-shadow: var(--shadow);
}
.review .player audio { width: 100%; }
.review .player .download { margin: .25rem 0 0; font-size: .9em; }
.waveform-area { display: flex; flex-direction: column; gap: .25rem; }
.waveform-area .minimap { min-height: 36px; }
.waveform-area .waveform { min-height: 146px; }
.section-lane { position: relative; height: 1.5rem; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.section-lane .lane-section {
  --section-color: var(--accent);
  position: absolute; top: 0; bottom: 0; min-width: 3px; padding: 0 .3rem; border: 0; border-radius: 0;
  border-left: 2px solid var(--section-color); background: color-mix(in srgb, var(--section-color) 30%, transparent);
  color: var(--text); font-size: .75rem; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* wavesurfer draws in a shadow root; its parts can be styled from here. */
/* A fixed width, not 100%: markers are zero-width regions whose label must still show. */
.waveform > div::part(region-content) {
  max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem;
  color: var(--text); background: color-mix(in srgb, var(--surface) 72%, transparent); border-radius: 3px;
}
.transport { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; padding: .5rem 0 .25rem; }
.transport button { min-width: 2.4rem; min-height: 2.2rem; }
.transport button.play { min-width: 4.5rem; font-weight: 600; }
.transport button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.transport .clock { font-variant-numeric: tabular-nums; padding: 0 .4rem; min-width: 9.5rem; }
.transport .clock .total { color: var(--muted); }
.transport .zoom { display: inline-flex; gap: .2rem; }
.player-status { min-height: 1.3em; margin: .2rem 0 0; font-size: .9em; color: var(--muted); }
.player-status.error { color: var(--danger); }
.shortcuts-hint { margin: 0; font-size: .8em; color: var(--muted); }
.live-notice { padding: .4rem .75rem; border: 1px solid var(--accent); border-radius: var(--radius); background: var(--focus-bg); }

.review-columns { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 1.5rem; }
.review ol.annotation-list, .review ol.replies { list-style: none; padding: 0; margin: 0; }
.review ol.annotation-list[data-group="shown"] {
  position: relative; max-height: 65vh; overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.review li.annotation { padding: .5rem .75rem; border-bottom: 1px solid var(--border); scroll-margin: 1rem; }
.review ol.annotation-list > li:last-child { border-bottom: 0; }
.review li.annotation.current { background: var(--current); box-shadow: inset 3px 0 0 var(--mark); }
.review li.annotation.focus { background: var(--focus-bg); }
.review li.annotation.current.focus { background: var(--current); }
.review li.annotation.resolved { opacity: .7; }
.review li.annotation > header { display: flex; flex-wrap: wrap; gap: .25rem .5rem; align-items: baseline; }
.review li.annotation .time { font-variant-numeric: tabular-nums; font-weight: 600; }
.review li.annotation .time[role="button"] { cursor: pointer; color: var(--link); }
.review li.annotation .kind { text-transform: uppercase; font-size: .7em; letter-spacing: .04em; color: var(--muted); }
.review li.kind-section > header .kind, .review li.kind-marker > header .kind { color: var(--accent); }
.review ol.replies { margin: .25rem 0 0 1rem; border-left: 2px solid var(--border); }
.review ol.replies li.annotation { padding: .25rem .5rem; border-bottom: 0; }
.review .actions { display: flex; flex-wrap: wrap; gap: .4rem .75rem; align-items: baseline; font-size: .88em; margin-top: .25rem; }
.review .actions button, .review li.annotation details button { padding: .1rem .5rem; }
.review .actions details[open] { flex-basis: 100%; }
.review details.not-in-version { margin-top: 1rem; }
.review details.not-in-version > summary { color: var(--muted); }

@media (min-width: 64rem) {
  .review-columns { grid-template-columns: minmax(0, 2fr) minmax(18rem, 1fr); align-items: start; }
  .review-columns .composers { position: sticky; top: 1rem; }
  .review-columns .composers > :first-child { margin-top: 3.2rem; }
}

/* History, sections, tags */
.review dl.diff { display: grid; grid-template-columns: max-content 1fr; gap: .1rem .75rem; margin: .25rem 0; }
.review dl.diff dd { margin: 0; }
.review del { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.review ins { background: color-mix(in srgb, var(--ok) 18%, transparent); text-decoration: none; }
.review .changeset {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .25rem .75rem; margin: .75rem 0;
}
.review .changeset h2 { font-size: 1rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; margin: .5rem 0; }
.review .changeset h2 time { color: var(--muted); font-weight: normal; font-size: .9em; }
.review .changeset ul { list-style: none; padding-left: .5rem; }

/* Upload page */
.upload-page .indent { margin-left: 1.6rem; }
.upload-page .upload-progress progress { width: 100%; height: 1rem; }
.upload-page .upload-status { font-variant-numeric: tabular-nums; }
.upload-page .resume-list { padding-left: 1.2rem; }

/* Phones (REQ-UI-3): one column, the transport sticks to the bottom of the screen. */
@media (max-width: 40rem) {
  main { padding: .75rem; }
  h1 { font-size: 1.35rem; }
  .review table.recordings thead { display: none; }
  .review table.recordings tr {
    display: grid; grid-template-columns: 1fr auto; gap: 0 .5rem; padding: .4rem 0; border-bottom: 1px solid var(--border);
  }
  .review table.recordings td { border: 0; padding: .1rem .25rem; }
  .review table.recordings td:nth-child(n+3) { font-size: .85em; color: var(--muted); }
  .review table.recordings td:nth-child(4)::before { content: "Comments: "; }
  .review table.recordings td:nth-child(5)::before { content: "Version: "; }
  body.has-player { padding-bottom: 8rem; }
  body.has-player .transport {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; justify-content: center;
    padding: .4rem .5rem calc(.4rem + env(safe-area-inset-bottom)); background: var(--surface);
    border-top: 1px solid var(--border); box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.12);
  }
  body.has-player .transport .clock { order: -1; flex-basis: 100%; text-align: center; min-width: 0; }
  body.has-player .transport button { min-height: 2.6rem; }
  .shortcuts-hint { display: none; }
  .review ol.annotation-list[data-group="shown"] { max-height: 55vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
