:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --text: #e7ecf3;
  --muted: #9aa8bc;
  --accent: #3d8bfd;
  --accent-2: #5ad1a5;
  --danger: #f07178;
  --warn: #e6c07b;
  --border: #2e3a4d;
  --focus: #ffd166;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); }
a:hover { text-decoration: underline; }
a.external::after { content: " ↗"; font-size: 0.85em; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--focus);
  color: #111;
  padding: 0.5rem 1rem;
  z-index: 1000;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
}
.nav a:hover, .nav a[aria-current="page"] {
  color: var(--text);
  background: var(--surface-2);
}

.nav-toggle {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
}

@media (max-width: 720px) {
  .nav-toggle { display: inline-block; }
  .nav { display: none; width: 100%; flex-direction: column; }
  .nav.is-open { display: flex; }
}

main {
  min-width: 1200px;
  max-width: 1800px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.75rem; margin: 0 0 1rem; }
h2 { font-size: 1.25rem; margin: 1.5rem 0 0.75rem; }

.section-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin: 1.5rem 0 0.75rem;
}
.section-heading h1,
.section-heading h2 {
  margin: 0;
}
.section-heading .btn-thumbs-toggle {
  flex-shrink: 0;
  font-size: 0.9rem;
  padding: 0.4rem 0.75rem;
}
section > .section-heading:first-child {
  margin-top: 0;
  margin-bottom: 1rem;
}

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 0.92em; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.metric-value {
  font-size: 1.6rem;
  font-weight: 700;
}
.metric-label { color: var(--muted); font-size: 0.9rem; }

.table-wrap { overflow-x: auto; }
.accordion {
  margin-top: 0.75rem;
}
.accordion summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
}
.accordion summary:hover {
  color: var(--accent);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--surface-2); }
th[data-sortable] { cursor: pointer; user-select: none; }
th[data-sortable]::after { content: ' \2195'; opacity: .3; }
th.sort-asc::after { content: ' \2191'; opacity: .7; }
th.sort-desc::after { content: ' \2193'; opacity: .7; }

.video-thumb {
  display: block;
  width: 176px;
  height: 99px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.video-thumb--broken {
  display: none;
}
.video-thumb--detail {
  width: 288px;
  height: 162px;
  border-radius: 6px;
}
.col-thumb {
  width: 176px;
  padding-right: 0.35rem;
  vertical-align: middle;
}
body.thumbs-hidden .col-thumb {
  display: none;
}
.col-nowrap {
  white-space: nowrap;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.thumb-preview-popup {
  position: fixed;
  z-index: 2000;
  width: 320px;
  height: 180px;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.thumb-preview-popup[hidden] {
  display: none !important;
}
.thumb-preview-popup img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
body.thumbs-hidden a[data-thumb-src] {
  text-decoration-style: dotted;
}
.video-detail-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}
.video-detail-header__text {
  min-width: 0;
  flex: 1;
}
.video-detail-header__text h1 {
  margin-bottom: 0.5rem;
}
@media (max-width: 720px) {
  .video-detail-header {
    flex-direction: column;
  }
  .video-thumb--detail {
    width: min(100%, 384px);
    height: auto;
    aspect-ratio: 16 / 9;
  }
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.badge.completed { border-color: var(--accent-2); color: var(--accent-2); }
.badge.in_progress { border-color: var(--warn); color: var(--warn); }
.badge.started, .badge.unknown { color: var(--muted); }

.btn, button, input[type="submit"] {
  appearance: none;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font: inherit;
  cursor: pointer;
}
.btn.secondary, button.secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn.danger,
button.danger,
input[type="submit"].danger {
  background: var(--danger);
}

button.danger.is-confirming,
input[type="submit"].danger.is-confirming {
  background: #d9575e;
  box-shadow: 0 0 0 3px rgba(217, 87, 94, 0.28);
}
.btn:hover, button:hover, input[type="submit"]:hover { filter: brightness(1.15); }
.btn.secondary:hover, button.secondary:hover { background: var(--border); }
.btn.danger:hover, button.danger:hover, input[type="submit"].danger:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-icon {
  background: transparent;
  border: none;
  padding: 0.3rem;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.btn-icon:hover {
  opacity: 1;
  color: var(--danger);
  background: rgba(240, 113, 120, 0.12);
}

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  width: 100%;
  max-width: 100%;
}
label { display: block; margin-bottom: 0.35rem; color: var(--muted); font-size: 0.9rem; }
.field { margin-bottom: 0.85rem; }
.form-row {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-bottom: 1rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}
.flash.error { border-color: var(--danger); color: #ffd0d3; }
.flash.ok { border-color: var(--accent-2); }

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

.timeline {
  display: flex;
  height: 1.25rem;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  margin: 0.5rem 0 1rem;
}
.timeline-seg {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--seg-left, 0%);
  width: var(--seg-width, 0%);
  background: var(--accent);
  opacity: 0.85;
}
.timeline-seg.attentive { background: var(--accent-2); }
.timeline-seg.speed-coverage {
  background: hsl(var(--speed-hue, 210), 65%, 52%);
}

.speed-timeline {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.15rem;
  margin: 0.75rem 0 1rem;
}
.speed-timeline-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.speed-timeline-label {
  flex: 0 0 2.75rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: right;
}
.speed-timeline-bar {
  flex: 1;
  margin: 0;
}

.coverage-cell {
  min-width: 5.5rem;
}
.coverage-pct {
  display: block;
  font-variant-numeric: tabular-nums;
}
.coverage-bar {
  display: flex;
  height: 0.35rem;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
  margin-top: 0.25rem;
  width: 100%;
  max-width: 6rem;
}
.coverage-bar-seg {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--seg-left, 0%);
  width: var(--seg-width, 0%);
  background: hsl(var(--coverage-hue, 210), 65%, 48%);
  border-radius: 1px;
}

.mt-1 { margin-top: 1rem; }
.mt-1-25 { margin-top: 1.25rem; }
.inline-form { display: inline; }
.input-narrow { width: 10rem; max-width: 100%; }
.field-end { align-self: end; }

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  padding: 1rem;
  text-align: center;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.last-updated {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.pair-code {
  font-family: var(--mono);
  font-size: 1.75rem;
  letter-spacing: 0.12em;
  text-align: center;
  padding: 1rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px dashed var(--border);
}

.col-actions { width: 2.5rem; padding: 0.35rem; text-align: center; }

.undo-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 1.1rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
  z-index: 1000;
  animation: toast-in 0.2s ease-out;
}
.undo-toast-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
}
.undo-toast-btn:hover {
  background: var(--surface-2);
  text-decoration: underline;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(0.5rem); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
