:root {
  color-scheme: light dark;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #666b75;
  --line: #dedbd3;
  --accent: #2456c9;
  --accent-soft: #e4ebfb;
  --hit: #fff1b8;
  --now: #cfe0ff;
  --danger: #b3261e;
  --ok: #1b7a43;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1e2126;
    --text: #e8e9ec;
    --muted: #9aa0ab;
    --line: #32363e;
    --accent: #8fb0ff;
    --accent-soft: #263352;
    --hit: #5a4a12;
    --now: #2b4275;
    --danger: #ff8a80;
    --ok: #6fd39a;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

button, .button, input, select { font: inherit; color: inherit; }
button, .button {
  display: inline-block; padding: 0.45rem 0.9rem; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); cursor: pointer; text-decoration: none; text-align: center;
}
button:hover, .button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; }
button.danger { color: var(--danger); }
button.quiet { border-color: transparent; background: none; color: var(--muted); }
input, select {
  padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- pasek górny --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.6rem 1.25rem; border-bottom: 1px solid var(--line); background: var(--surface);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; padding: 0.45rem 0.9rem; border: 1px solid var(--line); border-radius: 8px;
}
.menu summary::-webkit-details-marker { display: none; }
.menu-body {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(20rem, 90vw);
  display: grid; gap: 0.5rem; padding: 1rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);
}
.menu-body hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 0.25rem 0; }
.menu-body button, .menu-body .button { width: 100%; }
.stack { display: grid; gap: 0.5rem; }
.stack label, .login-card label { display: grid; gap: 0.2rem; font-size: 0.9rem; color: var(--muted); }
.stack input, .login-card input { color: var(--text); width: 100%; }

/* --- logowanie --- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card {
  width: min(22rem, 100%); padding: 2rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.login-card form { display: grid; gap: 0.9rem; margin-top: 1.25rem; }
.login-card p { margin: 0.25rem 0 0; }
.alert {
  padding: 0.6rem 0.8rem; border-radius: 8px; color: var(--danger);
  border: 1px solid currentColor; margin-top: 1rem !important;
}

/* --- lista notatek --- */
.index { max-width: 52rem; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.empty { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.empty h1 { color: var(--text); font-size: 1.4rem; margin-bottom: 0.5rem; }
.search { margin-bottom: 1.5rem; }
.search input { width: 100%; }
.subject { margin-bottom: 2rem; }
.subject h2 { font-size: 1.15rem; margin-bottom: 0.6rem; }
.count { color: var(--muted); font-weight: 400; font-size: 0.9rem; margin-left: 0.25rem; }
.notes {
  list-style: none; margin: 0; padding: 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.notes li + li { border-top: 1px solid var(--line); }
.notes a {
  display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 1rem; align-items: center;
  padding: 0.8rem 1rem; color: inherit; text-decoration: none;
}
.notes a:hover { background: var(--accent-soft); }
.note-title { font-weight: 600; }
.note-meta { grid-column: 1; color: var(--muted); font-size: 0.88rem; }
.badge {
  grid-column: 2; grid-row: 1 / span 2; padding: 0.15rem 0.6rem; border-radius: 999px;
  font-size: 0.8rem; white-space: nowrap; background: var(--accent-soft); color: var(--accent);
}
.badge.failed { background: none; border: 1px solid currentColor; color: var(--danger); }

/* --- widok notatki --- */
.note-page { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.note-head { padding: 0.9rem 1.25rem 0.5rem; }
.note-head h1 { font-size: 1.45rem; }
.note-head p { margin: 0.2rem 0 0; }

.status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem;
  margin: 0.25rem 1.25rem 0.5rem; padding: 0.7rem 1rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.status.failed { border-color: var(--danger); }
.status.failed strong { color: var(--danger); }
.status form { margin-left: auto; }
.status progress { width: 12rem; accent-color: var(--accent); }

.player {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem;
  padding: 0.5rem 1.25rem; border-block: 1px solid var(--line); background: var(--surface);
}
.player audio { flex: 1 1 18rem; min-width: 0; height: 40px; }
.player label { font-size: 0.9rem; color: var(--muted); white-space: nowrap; }
.player select { padding: 0.2rem 0.4rem; color: var(--text); }

.tabs { display: none; }
.columns { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.pane { overflow-y: auto; padding: 1rem 1.25rem 4rem; }
.pane + .pane { border-left: 1px solid var(--line); }
.pane h2 {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  margin: 1.5rem 0 0.5rem;
}
.pane h2:first-child { margin-top: 0; }
.pane p { margin: 0 0 0.7rem; }
.hint { color: var(--muted); font-size: 0.88rem; }

.topic {
  padding: 0.8rem 1rem; margin-bottom: 0.7rem; background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius);
}
.topic.playing { border-left-color: var(--accent); }
.topic h3 { font-size: 1.05rem; margin-bottom: 0.35rem; }
.topic ul { margin: 0.4rem 0 0; padding: 0; list-style: none; display: grid; gap: 0.35rem; }
.topic li, .topic h3, .terms dt { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem; align-items: baseline; }

.ref {
  padding: 0; border: 0; background: none; text-align: left; font: inherit; color: inherit; border-radius: 4px;
}
.ref:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.chip {
  padding: 0 0.45rem; min-width: 3.2rem; border-radius: 999px; font-size: 0.78rem; font-weight: 500;
  font-variant-numeric: tabular-nums; color: var(--accent); background: var(--accent-soft);
  border-color: transparent; line-height: 1.5rem;
}
.chip::before { content: "▶ "; font-size: 0.6rem; vertical-align: 0.1em; }
.terms { margin: 0; }
.terms dt { font-weight: 600; margin-top: 0.6rem; }
.terms dd { margin: 0.1rem 0 0 3.7rem; }

.para { position: relative; padding-left: 3.7rem; }
.stamp {
  position: absolute; left: 0; top: 0.2rem; font-size: 0.78rem; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.seg { cursor: pointer; border-radius: 3px; padding: 0.1em 0; scroll-margin-top: 1rem; }
.seg:hover { background: var(--accent-soft); }
.seg.hit { background: var(--hit); }
.seg.now { background: var(--now); }

@media (max-width: 820px) {
  .note-page { height: auto; display: block; }
  .dock { position: sticky; top: 0; z-index: 10; }
  .seg { scroll-margin-top: 10rem; }
  .tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--surface); }
  .tabs button { flex: 1; border: 0; border-radius: 0; border-bottom: 3px solid transparent; background: none; }
  .tabs button.active { border-bottom-color: var(--accent); font-weight: 600; }
  .columns { display: block; }
  .pane { overflow: visible; }
  .pane + .pane { border-left: 0; }
  .columns[data-tab="note"] .transcript, .columns[data-tab="transcript"] .note { display: none; }
}
