/*
 * readonly.css — standalone stylesheet for the public, read-only transcript
 * viewer (Views/Transcript/Readonly.cshtml + ReadonlyNotFound.cshtml).
 *
 * Replaces the 341 KB legacy Bootstrap/Landkit `site.css`. This page is a
 * server-rendered MVC view with no Tailwind/portal bundle and no CI build
 * step, so the styles are hand-authored and committed (force-tracked in
 * .gitignore next to readonly-editor.min.js). The design tokens below mirror
 * the portal's shadcn/GitHub-Primer palette so the share page looks like the
 * rest of the product without pulling in React/Tailwind at runtime.
 *
 * Everything keys off CSS custom properties: theme (light/dark) swaps the
 * colour set; the reading-comfort controls overwrite --reading-* on <html>.
 */

:root {
  /* Primer palette (WCAG AA), matching portal/src/styles/tailwind.css */
  --gt-green: #1f883d;
  --gt-green-emphasis: #1a7f37;
  --gt-red: #cf222e;
  --gt-amber: #9a6700;
  --gt-blue: #0969da;

  /* Light theme surface + text */
  --bg: #ffffff;
  --bg-subtle: #f6f8fa;
  --bg-inset: #eef1f4;
  --surface: #ffffff;
  --fg: #1f2328;
  --fg-muted: #59636e;
  /* #636c76 ≈ 5:1 on --bg / ~5:1 on --bg-subtle (WCAG AA for small text) */
  --fg-subtle: #636c76;
  --border: #d1d9e0;
  --border-strong: #b7c0c9;
  --primary: var(--gt-green);
  --primary-fg: #ffffff;
  --accent: var(--gt-blue);
  --ring: #1f883d;
  --active-word: var(--gt-green);
  --active-word-bg: rgba(31, 136, 61, 0.12);
  --search-match: #fff3c4;
  --search-match-current: #ffd33d;
  --shadow: 0 1px 3px rgba(31, 35, 40, 0.12), 0 1px 2px rgba(31, 35, 40, 0.08);
  --shadow-lg: 0 8px 24px rgba(31, 35, 40, 0.2);
  --radius: 0.65rem;
  --radius-sm: 0.4rem;

  /* Reading-comfort controls (overridden inline by the theme module) */
  --reading-font-size: 1.0625rem;
  --reading-line-height: 1.7;
  --reading-measure: 70ch;

  --dim: 0.55;
  color-scheme: light;
}

/* Dark theme — applied via [data-theme="dark"] (explicit user choice) or the
   OS preference when the user hasn't chosen. The .dark-capable guard lets the
   explicit attribute always win over the media query. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --bg-subtle: #161b22;
    --bg-inset: #010409;
    --surface: #161b22;
    --fg: #e6edf3;
    --fg-muted: #9198a1;
    --fg-subtle: #8b95a5;
    --border: #30363d;
    --border-strong: #424a53;
    --primary: #3fb950;
    --primary-fg: #ffffff;
    --accent: #4493f8;
    --ring: #3fb950;
    --active-word: #3fb950;
    --active-word-bg: rgba(63, 185, 80, 0.18);
    --search-match: #594e16;
    --search-match-current: #9e7f0e;
    --shadow: 0 1px 3px rgba(1, 4, 9, 0.5);
    --shadow-lg: 0 8px 24px rgba(1, 4, 9, 0.7);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-subtle: #161b22;
  --bg-inset: #010409;
  --surface: #161b22;
  --fg: #e6edf3;
  --fg-muted: #9198a1;
  --fg-subtle: #8b95a5;
  --border: #30363d;
  --border-strong: #424a53;
  --primary: #3fb950;
  --primary-fg: #ffffff;
  --accent: #4493f8;
  --ring: #3fb950;
  --active-word: #3fb950;
  --active-word-bg: rgba(63, 185, 80, 0.18);
  --search-match: #594e16;
  --search-match-current: #9e7f0e;
  --shadow: 0 1px 3px rgba(1, 4, 9, 0.5);
  --shadow-lg: 0 8px 24px rgba(1, 4, 9, 0.7);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans",
    Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ---------- Accessibility helpers ---------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: var(--primary-fg);
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus {
  left: 0;
}

:where(button, a, input, [tabindex]):focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- App chrome ---------- */

.rd-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem clamp(0.75rem, 3vw, 1.5rem);
}

.rd-header__top {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: 1100px;
  margin: 0 auto;
}

.rd-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}
.rd-brand img {
  height: 32px;
  width: auto;
  display: block;
}
.rd-brand small {
  color: var(--fg-muted);
  font-size: 0.75rem;
}

.rd-title {
  flex: 1 1 240px;
  min-width: 0;
  margin: 0;
  font-size: clamp(1.05rem, 2.4vw, 1.5rem);
  font-weight: 600;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Toolbar + buttons ---------- */

.rd-toolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  max-width: 1100px;
  margin: 0.5rem auto 0;
}

.rd-toolbar__group {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}
.rd-toolbar__spacer {
  flex: 1 1 auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  white-space: nowrap;
}
.btn:hover {
  background: var(--bg-inset);
  border-color: var(--border-strong);
}
.btn:active {
  background: var(--bg-subtle);
}
.btn[aria-pressed="true"] {
  background: var(--active-word-bg);
  border-color: var(--primary);
  color: var(--primary);
}
.btn--icon {
  padding: 0.4rem;
}
.btn--icon i {
  font-size: 0.95rem;
  width: 1em;
  text-align: center;
}
.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-fg);
}
.btn--primary:hover {
  background: var(--gt-green-emphasis);
  border-color: var(--gt-green-emphasis);
  color: var(--primary-fg);
}
.btn--play {
  min-width: 5.5rem;
  justify-content: center;
}

.btn__label {
  font-size: 0.85rem;
}
@media (max-width: 720px) {
  .btn__label {
    display: none;
  }
}

/* ---------- Playback-speed dropdown (vanilla, no Bootstrap/Popper) ---------- */

.rd-dropdown {
  position: relative;
}
.rd-dropdown__menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 200;
  display: none;
  min-width: 9rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}
.rd-dropdown__menu.show {
  display: block;
}
.rd-dropdown__menu .playspeed {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  color: var(--fg);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.rd-dropdown__menu .playspeed:hover,
.rd-dropdown__menu .playspeed[aria-current="true"] {
  background: var(--bg-inset);
}
.rd-dropdown__menu .playspeed[aria-current="true"] {
  color: var(--primary);
  font-weight: 600;
}
.rd-dropdown__divider {
  height: 1px;
  margin: 0.35rem 0;
  background: var(--border);
}
.rd-dropdown__label {
  display: block;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-subtle);
}

/* ---------- Range slider (custom-range) ---------- */

input[type="range"].custom-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1.25rem;
  margin: 0.25rem 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"].custom-range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
}
input[type="range"].custom-range::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
}
input[type="range"].custom-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  margin-top: -6px;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow);
}
input[type="range"].custom-range::-moz-range-thumb {
  height: 14px;
  width: 14px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--primary);
}

/* ---------- Scrub / progress bar + time readout ---------- */

.rd-timeline {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: 1100px;
  margin: 0.5rem auto 0;
}
.rd-time {
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  color: var(--fg-muted);
  white-space: nowrap;
  min-width: 3ch;
}

.progress {
  position: relative;
  flex: 1 1 auto;
  height: 8px;
  background: var(--bg-inset);
  border-radius: 999px;
  cursor: pointer;
  overflow: visible;
}
.progress:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 3px;
}
.progress-bar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.08s linear;
}
.progress__thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow);
  transform: translateY(-50%);
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
}
.progress:hover .progress__thumb,
.progress:focus-visible .progress__thumb {
  opacity: 1;
}

/* ---------- Search panel ---------- */

.rd-search {
  display: none;
  align-items: center;
  gap: 0.4rem;
  max-width: 1100px;
  margin: 0.5rem auto 0;
  padding: 0.4rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.rd-search.show {
  display: flex;
}
.rd-search input[type="search"] {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  font-size: 0.9rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.rd-search__count {
  font-size: 0.8rem;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Reading-settings popover ---------- */

.rd-popover {
  position: absolute;
  right: clamp(0.75rem, 3vw, 1.5rem);
  z-index: 200;
  display: none;
  width: 17rem;
  margin-top: 4px;
  padding: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.rd-popover.show {
  display: block;
}
.rd-popover h2 {
  margin: 0 0 0.6rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-subtle);
}
.rd-field {
  margin-bottom: 0.8rem;
}
.rd-field > label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.3rem;
  color: var(--fg-muted);
}
.rd-segmented {
  display: flex;
  gap: 0.25rem;
}
.rd-segmented button {
  flex: 1 1 0;
  padding: 0.35rem;
  font-size: 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  cursor: pointer;
}
.rd-segmented button[aria-pressed="true"] {
  background: var(--active-word-bg);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

/* ---------- Transcript ---------- */

.rd-main {
  max-width: var(--reading-measure);
  margin: 1.5rem auto;
  padding: 0 clamp(0.75rem, 4vw, 1.5rem) 8rem;
}

#transcript {
  font-size: var(--reading-font-size);
  line-height: var(--reading-line-height);
}

.paragraph-details {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin: 1.25rem 0 0.25rem;
  font-size: 0.78em;
}
.paragraph-details .timestamp {
  font-variant-numeric: tabular-nums;
  color: var(--fg-subtle);
  cursor: pointer;
  border-radius: 0.3rem;
  padding: 0 0.15rem;
}
.paragraph-details .timestamp:hover {
  color: var(--accent);
  text-decoration: underline;
}
.paragraph-details .speaker-name {
  font-weight: 600;
  color: var(--speaker-color, var(--fg-muted));
}

/* deterministic speaker colour-coding (set via data-speaker-index in JS).
   The palette is theme-token-based so the dark set applies for BOTH an
   explicit [data-theme="dark"] and a system (prefers-color-scheme) dark. */
:root {
  --sp-0: #0969da; --sp-1: #8250df; --sp-2: #bf3989; --sp-3: #1a7f37; --sp-4: #9a6700;
  --sp-5: #cf222e; --sp-6: #1b7c83; --sp-7: #6e40c9; --sp-8: #953800; --sp-9: #57606a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --sp-0: #6cb6ff; --sp-1: #dcbdfb; --sp-2: #f9a8d4; --sp-3: #6fdd8b; --sp-4: #e3b341;
    --sp-5: #ff7b72; --sp-6: #76e3ea; --sp-7: #b88bff; --sp-8: #ffa657; --sp-9: #8b949e;
  }
}
:root[data-theme="dark"] {
  --sp-0: #6cb6ff; --sp-1: #dcbdfb; --sp-2: #f9a8d4; --sp-3: #6fdd8b; --sp-4: #e3b341;
  --sp-5: #ff7b72; --sp-6: #76e3ea; --sp-7: #b88bff; --sp-8: #ffa657; --sp-9: #8b949e;
}
.speaker-name[data-speaker-index="0"] { --speaker-color: var(--sp-0); }
.speaker-name[data-speaker-index="1"] { --speaker-color: var(--sp-1); }
.speaker-name[data-speaker-index="2"] { --speaker-color: var(--sp-2); }
.speaker-name[data-speaker-index="3"] { --speaker-color: var(--sp-3); }
.speaker-name[data-speaker-index="4"] { --speaker-color: var(--sp-4); }
.speaker-name[data-speaker-index="5"] { --speaker-color: var(--sp-5); }
.speaker-name[data-speaker-index="6"] { --speaker-color: var(--sp-6); }
.speaker-name[data-speaker-index="7"] { --speaker-color: var(--sp-7); }
.speaker-name[data-speaker-index="8"] { --speaker-color: var(--sp-8); }
.speaker-name[data-speaker-index="9"] { --speaker-color: var(--sp-9); }

.paragraph {
  margin: 0 0 0.4rem;
  transition: opacity 0.2s ease;
}
.paragraph span {
  cursor: pointer;
}
.paragraph span:hover {
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
}

/* karaoke: dim non-active paragraphs only while media is playing */
#transcript.is-playing .paragraph {
  opacity: var(--dim);
}
#transcript.is-playing .paragraph.is-active {
  opacity: 1;
}
.word--active {
  color: var(--active-word);
  background: var(--active-word-bg);
  border-radius: 0.2rem;
  font-weight: 600;
}

/* ---------- Rich fidelity: highlights / strikethrough / verify ---------- */

/* Highlight backgrounds are light pastels designed for a white page, so force
   dark word text regardless of theme to keep contrast readable. */
[data-highlight] {
  color: #1a1a1a;
  border-radius: 0.15rem;
  padding: 0 0.05em;
}
[data-highlight="h1"]  { background-color: rgba(255, 255, 186, 1); }
[data-highlight="h2"]  { background-color: rgba(255, 105, 97, 1); }
[data-highlight="h3"]  { background-color: rgba(186, 225, 255, 1); }
[data-highlight="h4"]  { background-color: rgba(3, 192, 60, 1); }
[data-highlight="h5"]  { background-color: rgba(170, 255, 195, 1); }
[data-highlight="h6"]  { background-color: rgba(255, 215, 180, 1); }
[data-highlight="h7"]  { background-color: rgba(150, 111, 214, 1); }
[data-highlight="h8"]  { background-color: rgba(0, 255, 255, 1); }
[data-highlight="h9"]  { background-color: rgba(230, 190, 255, 1); }
[data-highlight="h10"] { background-color: rgba(255, 209, 232, 1); }

[data-strike="true"] {
  text-decoration: line-through;
  text-decoration-color: var(--fg-subtle);
  opacity: 0.85;
}

#transcript[data-hide-timestamps="true"] .timestamp {
  display: none;
}
#transcript[data-hide-speakers="true"] .speaker-name {
  display: none;
}

/* paragraph verification status (read-only indicator) */
.paragraph-verify {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  font-size: 0.9em;
}
.paragraph-verify[data-status="1"] { color: var(--gt-green); }
.paragraph-verify[data-status="2"] { color: var(--gt-amber); }

/* ---------- Search matches ---------- */

.search-match {
  background: var(--search-match);
  color: #1a1a1a;
  border-radius: 0.15rem;
  box-shadow: 0 0 0 1px var(--search-match);
}
.search-match--current {
  background: var(--search-match-current);
  box-shadow: 0 0 0 2px var(--search-match-current);
  scroll-margin: 40vh;
}

/* ---------- Toast ---------- */

.rd-toast {
  position: fixed;
  left: 50%;
  bottom: 6.5rem;
  transform: translateX(-50%) translateY(0.5rem);
  z-index: 300;
  max-width: min(90vw, 24rem);
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  color: var(--primary-fg);
  background: #1f2328;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.rd-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Media player ---------- */

#media-player {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  display: flex;
  justify-content: center;
  padding: 0.5rem;
  background: color-mix(in srgb, var(--bg-subtle) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}
#media-player:empty {
  display: none;
}
#media {
  max-width: 400px;
  width: 100%;
}
video#media {
  max-width: min(640px, 90vw);
  max-height: 30vh;
  border-radius: var(--radius-sm);
}

/* ---------- Auto-scroll pill ---------- */

.auto-scroll {
  position: fixed;
  left: 50%;
  bottom: 5.5rem;
  transform: translateX(-50%);
  z-index: 150;
  box-shadow: var(--shadow-lg);
}
.auto-scroll.hide {
  display: none;
}

/* ---------- Loading / error ---------- */

.loading,
.error {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--fg-muted);
}
.error {
  color: var(--gt-red);
}

/* ---------- Not-found page ---------- */

.rd-notfound {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}
.rd-notfound__card {
  max-width: 32rem;
}
.rd-notfound__card img {
  height: 40px;
  margin-bottom: 1.5rem;
}
.rd-notfound__card h1 {
  font-size: clamp(1.4rem, 4vw, 2rem);
  margin: 0 0 0.75rem;
}
.rd-notfound__card p {
  color: var(--fg-muted);
  margin: 0 0 1.5rem;
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Print / reader view ---------- */

@media print {
  .rd-header,
  #media-player,
  .auto-scroll,
  .rd-search,
  .rd-popover,
  .skip-link {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
  }
  .rd-main {
    max-width: none;
    margin: 0;
    padding: 0;
  }
  #transcript.is-playing .paragraph,
  .paragraph {
    opacity: 1 !important;
  }
  .paragraph-details {
    break-after: avoid;
  }
  .paragraph {
    break-inside: avoid;
  }
  [data-highlight] {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
