:root {
  color-scheme: light;
  --navy-950: #071a38;
  --navy-900: #0b234c;
  --navy-800: #123463;
  --navy-700: #1c4779;
  --gold-600: #a97920;
  --gold-500: #c29439;
  --gold-100: #f6ead1;
  --blue-100: #eaf3ff;
  --blue-500: #3a82c4;
  --paper: #fffdf8;
  --surface: #ffffff;
  --surface-soft: #f5f7fa;
  --line: #dce3ec;
  --text: #12233f;
  --muted: #69768a;
  --success: #267447;
  --success-bg: #e8f6ed;
  --warning: #9b6d13;
  --warning-bg: #fff4da;
  --danger: #a73333;
  --danger-bg: #fff0f0;
  --shadow: 0 10px 30px rgba(12, 37, 73, .08);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --tap: 44px;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f8fbff 0%, var(--paper) 34%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(194, 148, 57, .32); outline-offset: 2px; }

.app-shell { width: min(100%, 760px); min-height: 100vh; margin: 0 auto; position: relative; }
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(255, 253, 248, .94);
  border-bottom: 1px solid rgba(220, 227, 236, .9);
  backdrop-filter: blur(16px);
}
.brand-lockup { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-icon {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--navy-800), var(--navy-950));
  box-shadow: 0 6px 16px rgba(7, 26, 56, .2);
}
.brand-play {
  display: block;
  width: 0;
  height: 0;
  margin-left: 3px;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 15px solid var(--gold-500);
}
.brand-lockup h1 { margin: 0; font-size: 18px; line-height: 1.1; letter-spacing: -.02em; }
.brand-lockup p { margin: 3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.25; max-width: 270px; }
.header-status { flex: 0 0 auto; width: 10px; height: 10px; border-radius: 99px; background: #8aa0b9; }
.header-status.is-online { background: #3f9b61; }
.header-status.is-offline { background: #c47a2e; }

.main-content { padding: 22px 16px calc(92px + env(safe-area-inset-bottom)); }
.view[hidden] { display: none !important; }
.page-heading { margin-bottom: 18px; }
.page-heading .eyebrow { margin: 0 0 4px; color: var(--gold-600); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
.page-heading h2 { margin: 0; font-size: clamp(24px, 7vw, 32px); line-height: 1.05; letter-spacing: -.035em; }
.page-heading > p:last-child { margin: 8px 0 0; max-width: 560px; color: var(--muted); line-height: 1.45; }
.compact-heading { margin: 14px 0 14px; }
.compact-heading h2 { font-size: 25px; }

.extract-form { display: grid; gap: 10px; }
.url-row {
  min-height: 54px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 7px 6px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 6px 18px rgba(13, 40, 76, .04);
}
.youtube-mark { color: #ef2424; font-size: 15px; }
.url-row input { min-width: 0; width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; }
.url-row input::placeholder { color: #8d98a7; }
.field-error { margin: -2px 2px 2px; color: var(--danger); font-size: 13px; }

.button {
  min-height: var(--tap);
  border: 0;
  border-radius: var(--radius-md);
  padding: 10px 15px;
  font-weight: 750;
  cursor: pointer;
}
.button[disabled] { cursor: not-allowed; opacity: .55; }
.button-primary { color: #fff; background: linear-gradient(135deg, var(--gold-500), #a87518); box-shadow: 0 7px 16px rgba(169, 121, 32, .2); }
.button-primary:active { transform: translateY(1px); }
.button-ghost { color: var(--navy-800); background: #edf4fb; }
.button-inline { min-height: 38px; padding: 8px 11px; font-size: 13px; }
.button-block { width: 100%; display: flex; justify-content: center; align-items: center; gap: 9px; min-height: 50px; }

.demo-banner, .stage-message, .quiet-card {
  margin-top: 14px;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-soft);
}
.demo-banner { display: flex; gap: 7px; flex-direction: column; border-color: #ead7a7; background: #fff8e9; }
.demo-banner strong { color: var(--warning); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.demo-banner span, .quiet-card p { color: var(--muted); font-size: 13px; line-height: 1.45; }
.quiet-card { margin-top: 22px; }
.quiet-card strong { display: block; margin-bottom: 4px; }
.quiet-card p { margin: 0; }

.processing-card { margin-top: 18px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--surface); box-shadow: var(--shadow); }
.video-summary, .video-compact { display: flex; gap: 12px; align-items: center; }
.video-thumb { width: 104px; aspect-ratio: 16/9; flex: 0 0 auto; object-fit: cover; border-radius: 11px; background: #d9e2ec; }
.video-compact .video-thumb { width: 82px; }
.video-copy { min-width: 0; }
.video-title { margin: 0; font-size: 15px; line-height: 1.25; font-weight: 800; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.video-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; color: var(--muted); font-size: 12px; }
.meta-chip { padding: 4px 7px; border-radius: 999px; background: #eef3f8; color: #46617f; }

.processing-steps { list-style: none; padding: 8px 0 0; margin: 14px 0 0; border-top: 1px solid var(--line); }
.processing-step { position: relative; display: grid; grid-template-columns: 24px 1fr; gap: 10px; padding: 8px 0; }
.processing-step:not(:last-child)::after { content: ""; position: absolute; left: 11px; top: 32px; bottom: -7px; width: 2px; background: var(--line); }
.step-dot { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; border: 2px solid #b9c5d3; color: #7d8da0; background: #fff; font-size: 12px; font-weight: 900; z-index: 1; }
.processing-step.is-done .step-dot { color: #fff; border-color: var(--blue-500); background: var(--blue-500); }
.processing-step.is-active .step-dot { border-color: var(--gold-500); color: var(--gold-600); box-shadow: 0 0 0 5px rgba(194, 148, 57, .12); }
.processing-step.is-error .step-dot { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }
.step-copy strong { display: block; font-size: 14px; }
.step-copy small { color: var(--muted); line-height: 1.35; }
.processing-step.is-active .step-copy strong { color: var(--gold-600); }
.processing-step.is-error .step-copy strong { color: var(--danger); }

.video-compact { padding: 10px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-lg); }
.segmented-control { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 14px; background: #eff3f7; }
.segment { min-height: 40px; border: 0; border-radius: 10px; background: transparent; color: #5c6b7e; font-weight: 800; cursor: pointer; }
.segment.is-active { color: #fff; background: var(--gold-500); box-shadow: 0 4px 12px rgba(169, 121, 32, .18); }
.stage-message { color: var(--muted); font-size: 13px; }
.stage-message.is-error { border-color: #ecc8c8; background: var(--danger-bg); color: var(--danger); }
.stage-message.is-processing { border-color: #ead7a7; background: var(--warning-bg); color: #7b5b1c; }

.read-tools { display: grid; gap: 10px; margin: 14px 0 10px; }
.search-field { min-height: 46px; display: flex; gap: 9px; align-items: center; padding: 0 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); }
.search-field > span:first-child { color: #76879a; font-size: 20px; }
.search-field input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }
.toggle-row { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; }
.toggle-row input { width: 20px; height: 20px; accent-color: var(--gold-500); }
.search-meta { min-height: 20px; color: var(--muted); font-size: 12px; }

.transcript-list { display: grid; gap: 2px; }
.transcript-row {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 8px;
  padding: 10px 8px;
  border-radius: 10px;
  scroll-margin-top: 165px;
  transition: background .2s ease, box-shadow .2s ease;
}
.transcript-row:hover { background: rgba(234, 243, 255, .52); }
.transcript-row.no-time { grid-template-columns: 1fr; }
.transcript-time { color: #4486be; font-size: 12px; font-weight: 750; padding-top: 2px; font-variant-numeric: tabular-nums; }
.transcript-text { line-height: 1.55; font-size: 15px; }
.transcript-text mark { background: #ffeaa5; color: inherit; padding: 0 1px; border-radius: 3px; }
.transcript-row.is-anchor { background: #fff1cf; box-shadow: inset 3px 0 var(--gold-500); }

.explore-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 14px -16px 0; padding: 0 16px 7px; border-bottom: 1px solid var(--line); }
.explore-tabs::-webkit-scrollbar { display: none; }
.explore-tab { min-height: 40px; flex: 0 0 auto; padding: 0 12px; border: 1px solid transparent; border-radius: 12px; background: transparent; color: #5f6f83; font-size: 13px; font-weight: 800; cursor: pointer; }
.explore-tab.is-active { color: #fff; background: var(--navy-900); box-shadow: 0 4px 12px rgba(11, 35, 76, .12); }
.explore-panel { padding-top: 16px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 10px; }
.section-title h3 { margin: 0; font-size: 18px; }
.section-title span { color: var(--muted); font-size: 12px; }
.overview-summary { padding: 16px; border-radius: var(--radius-lg); background: linear-gradient(135deg, #f8f4e8, #fff); border: 1px solid #eadfc2; line-height: 1.52; }
.overview-summary p { margin: 0; }
.theme-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.theme-chip { padding: 6px 9px; border-radius: 999px; background: var(--blue-100); color: #2c6b9f; font-size: 12px; font-weight: 700; }
.counter-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0 18px; }
.counter-card { min-width: 0; padding: 11px 7px; text-align: center; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.counter-card strong { display: block; font-size: 19px; color: var(--navy-900); }
.counter-card span { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; overflow: hidden; text-overflow: ellipsis; }

.explore-list { display: grid; gap: 8px; }
.explore-item { width: 100%; display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: start; text-align: left; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: inherit; cursor: pointer; }
.explore-item:hover { border-color: #c5d6e8; box-shadow: 0 5px 14px rgba(12, 37, 73, .05); }
.explore-item-static { cursor: default; }
.explore-number { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: #eef3f8; color: var(--navy-800); font-weight: 850; font-size: 12px; }
.explore-item-copy { min-width: 0; }
.explore-item-copy strong { display: block; font-size: 14px; line-height: 1.3; }
.explore-item-copy p { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.42; }
.explore-time { color: #4f84b3; font-size: 11px; white-space: nowrap; padding-top: 2px; }
.explore-section { margin-top: 18px; }

.library-search { margin-bottom: 14px; }
.library-list { display: grid; gap: 10px; }
.library-card { width: 100%; display: grid; grid-template-columns: 108px 1fr; gap: 11px; padding: 10px; text-align: left; color: inherit; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); cursor: pointer; box-shadow: 0 5px 14px rgba(12, 37, 73, .035); }
.library-card .video-thumb { width: 108px; }
.library-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.status-badge { flex: 0 0 auto; padding: 4px 7px; border-radius: 999px; font-size: 10px; font-weight: 850; }
.status-ready { color: var(--success); background: var(--success-bg); }
.status-processing { color: var(--warning); background: var(--warning-bg); }
.status-partial { color: #8a5b21; background: #fff0d9; }
.library-meta { margin-top: 6px; color: var(--muted); font-size: 11px; line-height: 1.35; }

.empty-state { margin: 28px 0; padding: 28px 20px; text-align: center; border: 1px dashed #c8d3df; border-radius: var(--radius-xl); background: rgba(255,255,255,.65); }
.empty-icon { width: 50px; height: 50px; display: grid; place-items: center; margin: 0 auto 10px; border-radius: 15px; color: var(--gold-600); background: var(--gold-100); font-size: 24px; }
.empty-state h2 { margin: 0; font-size: 20px; }
.empty-state p { margin: 7px auto 15px; max-width: 360px; color: var(--muted); line-height: 1.45; }

.toast { position: fixed; left: 50%; bottom: calc(82px + env(safe-area-inset-bottom)); z-index: 50; width: min(calc(100% - 32px), 520px); transform: translateX(-50%); padding: 12px 14px; border-radius: 13px; color: #fff; background: rgba(7, 26, 56, .94); box-shadow: var(--shadow); font-size: 13px; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  width: min(100%, 760px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, .96);
  backdrop-filter: blur(16px);
}
.nav-item { min-height: 48px; display: grid; justify-items: center; align-content: center; gap: 2px; border: 0; border-radius: 12px; color: #637388; background: transparent; font-size: 10px; font-weight: 750; cursor: pointer; }
.nav-icon { font-size: 20px; line-height: 1; }
.nav-item.is-active { color: var(--gold-600); background: rgba(246, 234, 209, .45); }

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

@media (min-width: 640px) {
  .main-content { padding-left: 24px; padding-right: 24px; }
  .explore-tabs { margin-left: -24px; margin-right: -24px; padding-left: 24px; padding-right: 24px; }
  .read-tools { grid-template-columns: 1fr auto; align-items: center; }
  .counter-grid { grid-template-columns: repeat(7, 1fr); }
}

@media (prefers-reduced-motion: no-preference) {
  .is-anchor { animation: anchorPulse 1.2s ease-out; }
  @keyframes anchorPulse {
    0% { box-shadow: inset 3px 0 var(--gold-500), 0 0 0 0 rgba(194,148,57,.3); }
    100% { box-shadow: inset 3px 0 var(--gold-500), 0 0 0 12px rgba(194,148,57,0); }
  }
}
