:root {
  --bg: #f7f5f1;
  --surface: #ffffff;
  --text: #1f1d1a;
  --muted: #6b665e;
  --border: #e3ded5;
  --accent: #7a2e2e;
  --accent-text: #ffffff;
  --chip: #efe9df;
  --mark: #f6e3a1;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #211f1c;
    --text: #ece8e1;
    --muted: #a39d93;
    --border: #36322d;
    --accent: #c9716b;
    --accent-text: #171614;
    --chip: #2e2a25;
    --mark: #6b5a1c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap { max-width: 960px; margin: 0 auto; padding-inline: 20px; }

.masthead { border-bottom: 1px solid var(--border); background: var(--surface); padding-block: 28px 22px; }
.masthead h1 { margin: 0; font: 600 1.9rem/1.2 Georgia, "Times New Roman", serif; letter-spacing: -0.01em; }
.subtitle { margin: 4px 0 0; color: var(--muted); }

.masthead-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.button {
  padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: var(--radius);
}
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button-quiet { background: transparent; color: var(--text); border: 1px solid var(--border); }

.dialog {
  width: min(520px, calc(100vw - 32px)); padding: 24px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog h2 { margin: 0 0 16px; font: 600 1.3rem/1.3 Georgia, "Times New Roman", serif; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field span { font-size: 0.85rem; color: var(--muted); }
.field input {
  padding: 9px 11px; font: inherit; color: inherit;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
.known { margin-bottom: 14px; }
.known summary { cursor: pointer; color: var(--muted); margin-bottom: 10px; }
.hint { margin: 0 0 12px; font-size: 0.85rem; color: var(--muted); }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 110px; margin-bottom: 14px; padding: 18px; text-align: center; cursor: pointer;
  border: 2px dashed var(--border); border-radius: var(--radius); color: var(--muted);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragging, .dropzone:focus-within { border-color: var(--accent); }
.dropzone.dragging { background: var(--chip); }
.dropzone strong { color: var(--accent); }
.dropzone.has-file { border-style: solid; border-color: var(--accent); background: var(--chip); }
.dropzone-file { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }

.upload-state { margin: 0 0 14px; padding: 10px 12px; border-radius: 8px; background: var(--chip); }
.upload-state progress { display: block; width: 100%; height: 8px; margin-bottom: 8px; accent-color: var(--accent); }
.upload-progress { margin: 0; font-size: 0.92rem; }
.upload-state.is-done { background: #e3f1e7; color: #1e5a33; }
.upload-state.is-error { background: #f8e1df; color: #8c1d16; }
@media (prefers-color-scheme: dark) {
  .upload-state.is-done { background: #1f3a28; color: #b8e3c4; }
  .upload-state.is-error { background: #3d201d; color: #f1bcb6; }
}

.card.flash { animation: flash 2.4s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.jobs {
  margin-top: 16px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.link-button { padding: 0; font: inherit; font-size: 0.85rem; color: var(--accent); background: none; border: 0; cursor: pointer; }
.link-button:hover { text-decoration: underline; }
.job-running .job-status::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: currentColor; animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 0.2; } to { opacity: 1; } }
.jobs-title { margin: 0 0 8px; font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.job-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.job { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 2px 12px; font-size: 0.92rem; }
.job-name { font-weight: 600; overflow-wrap: anywhere; }
.job-detail { grid-column: 2; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.job-status { font-size: 0.8rem; font-weight: 600; padding-top: 2px; }
.job-running .job-status, .job-queued .job-status { color: var(--muted); }
.job-done .job-status { color: #2f7d4a; }
.job-error .job-status { color: #b3261e; }
.job-dismiss { grid-column: 2; justify-self: start; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px)); padding: 12px 18px; z-index: 10;
  background: var(--text); color: var(--bg); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); font-size: 0.95rem;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

.search { padding-block: 24px 8px; }
.search-row { display: flex; gap: 8px; }
.search input {
  flex: 1; min-width: 0; padding: 12px 14px; font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.search input:focus, .filter select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.search button[type="submit"] {
  padding: 0 20px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: var(--radius);
}
.search button:disabled { opacity: 0.5; cursor: not-allowed; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.filter { display: flex; flex-direction: column; gap: 4px; flex: 1 1 180px; }
.filter-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.filter select {
  padding: 8px 10px; font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}

.status { color: var(--muted); margin: 12px 0; min-height: 1.5em; }

.results { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 16px; }

.pager { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; margin: 0 0 48px; }
.pager-button {
  min-width: 40px; padding: 7px 12px; font: inherit; font-size: 0.92rem; cursor: pointer; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.pager-button:hover:not(:disabled) { border-color: var(--accent); }
.pager-button[aria-current="page"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.pager-button:disabled:not([aria-current]) { opacity: 0.4; cursor: default; }
.pager-gap { color: var(--muted); padding: 0 2px; }
.card {
  display: grid; grid-template-columns: 280px 1fr; gap: 18px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.card h2 { margin: 0 0 8px; font: 600 1.2rem/1.3 Georgia, "Times New Roman", serif; }

.media { aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: var(--chip); max-width: 100%; }
.media iframe { width: 100%; height: 100%; border: 0; display: block; }
.media-missing, .media-link { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.9rem; }
.media-link { height: 100%; color: var(--accent); }
.thumb { position: relative; width: 100%; height: 100%; padding: 0; border: 0; cursor: pointer; background: #000; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0.9; }
.thumb:hover img { opacity: 1; }
.play {
  position: absolute; top: 50%; left: 50%; width: 60px; height: 42px; transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.7); border-radius: 10px;
}
.play::after {
  content: ""; position: absolute; top: 50%; left: 50%; transform: translate(-35%, -50%);
  border-style: solid; border-width: 9px 0 9px 15px; border-color: transparent transparent transparent #fff;
}

/* Web-copy players: audio is a short panel, video keeps 16:9. */
.media audio { display: block; width: 100%; margin-top: auto; }
.media video { display: block; width: 100%; height: 100%; background: #000; }
.media-audio { aspect-ratio: auto; min-height: 112px; display: flex; flex-direction: column; justify-content: center; padding: 10px; }
.media-audio .thumb, .media-video .thumb {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: transparent; color: var(--muted);
}
.media-video .thumb { background: #000; color: #ddd; }
/* position: relative anchors the triangle (::after) to the circle. */
.media-audio .play, .media-video .play { position: relative; top: auto; left: auto; transform: none; flex: none; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); }

/* Full-screen audio view (real full screen, or .fs-fallback filling the window). */
.media-audio { position: relative; }
.fs-toggle {
  position: absolute; top: 8px; right: 8px; padding: 3px 10px; font: inherit; font-size: 0.8rem; cursor: pointer;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
}
.fs-toggle:hover { border-color: var(--accent); }
.fs-info { display: none; }
.media-audio:fullscreen, .media-audio.fs-fallback {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 32px;
  padding: 48px 24px; background: var(--bg); color: var(--text);
}
.media-audio.fs-fallback { position: fixed; inset: 0; z-index: 20; border-radius: 0; }
.media-audio:fullscreen .fs-info, .media-audio.fs-fallback .fs-info { display: block; max-width: 960px; text-align: center; }
.fs-title { margin: 0 0 12px; font: 600 clamp(1.6rem, 4.5vw, 3.2rem)/1.2 Georgia, "Times New Roman", serif; }
.fs-sub { margin: 0; color: var(--muted); font-size: clamp(1rem, 2.2vw, 1.5rem); }
/* In full screen the player bar runs along the bottom edge, like a video player. */
.media-audio:fullscreen audio, .media-audio.fs-fallback audio {
  position: absolute; left: 32px; right: 32px; bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  width: auto; margin: 0;
}
.media-audio:fullscreen .fs-toggle, .media-audio.fs-fallback .fs-toggle { top: 16px; right: 16px; font-size: 0.95rem; padding: 6px 14px; }
.media-audio .play::after, .media-video .play::after { border-color: transparent transparent transparent var(--accent-text); }
.media-kind { font-size: 0.85rem; }
.media-audio .thumb:hover .play, .media-video .thumb:hover .play { filter: brightness(1.1); }

.card h2 a { color: inherit; text-decoration: none; }
.card h2 a:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.card-actions { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; margin-top: 10px; }
.card-actions .link-button { font-size: 0.92rem; font-weight: 600; }
.part-note { margin: 0; font-size: 0.85rem; color: var(--muted); }

.detail { padding-block: 24px 56px; display: grid; gap: 16px; }
.back-link { color: var(--accent); text-decoration: none; font-size: 0.92rem; justify-self: start; }
.back-link::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 8px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); }
.back-link:hover { text-decoration: underline; }
.detail-title { margin: 0; font: 600 1.7rem/1.25 Georgia, "Times New Roman", serif; }
.detail-media { max-width: 720px; }
.detail .button-quiet { justify-self: start; }
.detail h3 { margin: 16px 0 0; font: 600 1.15rem/1.3 Georgia, "Times New Roman", serif; }
.transcript { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.transcript li { display: grid; grid-template-columns: 64px 1fr; gap: 12px; }
.transcript p { margin: 0; }
.transcript .link-button { align-self: start; font-variant-numeric: tabular-nums; }

.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0 0 10px; font-size: 0.92rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-block; padding: 1px 9px; font: inherit; font-size: 0.85rem; color: inherit;
  background: var(--chip); border: 0; border-radius: 999px;
}
button.chip { cursor: pointer; }
button.chip:hover { background: var(--border); }

.snippet { margin: 0; color: var(--muted); font-size: 0.93rem; }
.snippet mark { background: var(--mark); color: var(--text); padding: 0 2px; border-radius: 3px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 680px) {
  .card { grid-template-columns: 1fr; }
  .detail-title { font-size: 1.4rem; }
  .transcript li { grid-template-columns: 1fr; gap: 2px; }
  .masthead h1 { font-size: 1.5rem; }
}
