/* Shared YouTube transcript tool UI.
 *
 * One stylesheet for /youtube-transcript and the ten specialised transcript
 * pages. Every selector is scoped under `.ytx` and every custom property is
 * prefixed `--ytx-`, so the sheet cannot collide with a host page's own
 * variables or class names.
 *
 * The host page only needs to provide a mount point:
 *   <div id="tool" class="ytx-host" data-ytx='{"timestamps":false}'></div>
 * assets/yt-transcript-tool.js renders the interface into it.
 *
 * Dark mode covers all three conventions the site uses (html.dark,
 * html[data-theme="dark"], body.dark). */

.ytx {
  --ytx-bg: #ffffff;
  --ytx-surface: #f7f7f9;
  --ytx-surface-2: #eef0f3;
  --ytx-surface-3: #e4e7ec;
  --ytx-border: rgba(15, 23, 42, .10);
  --ytx-border-strong: rgba(15, 23, 42, .18);
  --ytx-text: #101114;
  --ytx-text-2: #4b5563;
  --ytx-text-3: #8b929e;
  --ytx-accent: #4f46e5;
  --ytx-accent-bg: rgba(79, 70, 229, .09);
  --ytx-accent-strong: rgba(79, 70, 229, .28);
  --ytx-teal: #0d9488;
  --ytx-green: #16a34a;
  --ytx-red: #dc2626;
  --ytx-amber: #b45309;
  --ytx-radius: 14px;
  --ytx-radius-lg: 20px;
  --ytx-shadow: 0 24px 60px -24px rgba(15, 23, 42, .28);

  color: var(--ytx-text);
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: -.011em;
  -webkit-font-smoothing: antialiased;
}

html.dark .ytx,
html[data-theme="dark"] .ytx,
body.dark .ytx {
  --ytx-bg: #0b0c0f;
  --ytx-surface: #14161a;
  --ytx-surface-2: #1a1d22;
  --ytx-surface-3: #22262c;
  --ytx-border: rgba(255, 255, 255, .09);
  --ytx-border-strong: rgba(255, 255, 255, .18);
  --ytx-text: #f4f5f7;
  --ytx-text-2: #a1a7b3;
  --ytx-text-3: #6b7280;
  --ytx-accent: #8b95f8;
  --ytx-accent-bg: rgba(139, 149, 248, .13);
  --ytx-accent-strong: rgba(139, 149, 248, .32);
  --ytx-teal: #5eead4;
  --ytx-green: #4ade80;
  --ytx-red: #f87171;
  --ytx-amber: #fbbf24;
  --ytx-shadow: 0 28px 70px -26px rgba(0, 0, 0, .85);
}

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

.ytx button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
.ytx input, .ytx select { font: inherit; color: inherit; }
.ytx ::selection { background: var(--ytx-accent); color: #fff; }

/* ---- Frame ---- */
.ytx-wrap {
  padding: 1px;
  border-radius: calc(var(--ytx-radius-lg) + 4px);
  background: linear-gradient(135deg, var(--ytx-accent-strong), var(--ytx-border) 38%, var(--ytx-border) 62%, rgba(94, 234, 212, .22));
  box-shadow: var(--ytx-shadow);
}
.ytx-tool {
  border-radius: calc(var(--ytx-radius-lg) + 3px);
  background: var(--ytx-surface);
  padding: 22px;
}

/* ---- URL row ---- */
.ytx-input-row { display: flex; gap: 10px; flex-wrap: wrap; }
.ytx-shell {
  flex: 1; min-width: 260px; height: 54px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 6px 0 15px;
  border-radius: 13px;
  border: 1px solid var(--ytx-border-strong);
  background: var(--ytx-bg);
  transition: border-color .18s, box-shadow .18s;
}
.ytx-shell:focus-within { border-color: var(--ytx-accent); box-shadow: 0 0 0 4px var(--ytx-accent-bg); }
.ytx-shell input {
  flex: 1; min-width: 0;
  background: none; border: none; outline: none;
  font-size: 14.5px; font-weight: 500;
}
.ytx-shell input::placeholder { color: var(--ytx-text-3); font-weight: 450; }
.ytx-clear {
  width: 26px; height: 26px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 7px; color: var(--ytx-text-3);
  transition: color .15s, background-color .15s;
}
.ytx-clear:hover { color: var(--ytx-text); background: var(--ytx-surface-2); }
.ytx-clear[hidden] { display: none; }

.ytx-go {
  height: 54px; padding: 0 26px;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  border-radius: 13px;
  font-size: 14.5px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap;
  background: linear-gradient(180deg, var(--ytx-accent), #6d6ae8);
  color: #fff;
  box-shadow: 0 12px 28px -12px var(--ytx-accent-strong), inset 0 1px 0 rgba(255, 255, 255, .22);
  transition: transform .18s, filter .18s;
}
.ytx-go:hover:not(:disabled) { transform: translateY(-1.5px); filter: brightness(1.06); }
.ytx-go:active:not(:disabled) { transform: translateY(0); }
.ytx-go:disabled { opacity: .7; cursor: not-allowed; }

.ytx-meta {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-top: 12px; font-size: 12.5px; color: var(--ytx-text-3);
}
.ytx-meta .ytx-sep { opacity: .4; }
.ytx-link-btn {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--ytx-accent); font-weight: 600; font-size: 12.5px;
}
.ytx-link-btn:hover { filter: brightness(1.15); }
.ytx-sample {
  display: none; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 650;
  background: rgba(251, 191, 36, .13);
  color: var(--ytx-amber);
  border: 1px solid rgba(251, 191, 36, .3);
}
.ytx-sample.on { display: inline-flex; }

/* ---- Panes ---- */
.ytx-panes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 18px; margin-top: 20px;
}
@media (max-width: 900px) { .ytx-panes { grid-template-columns: 1fr; } }

.ytx-player-wrap {
  position: relative; aspect-ratio: 16 / 9; width: 100%;
  border-radius: 13px; overflow: hidden;
  background: #000; border: 1px solid var(--ytx-border);
}
.ytx-player-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.ytx-video-meta { margin-top: 12px; display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.ytx-video-info { flex: 1; min-width: 0; }
.ytx-video-title {
  font-size: 14px; font-weight: 650; line-height: 1.4;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.ytx-chip {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  padding: 5px 11px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  border: 1px solid var(--ytx-border); background: var(--ytx-surface-2);
  color: var(--ytx-text-2);
}
.ytx-video-id { font-family: ui-monospace, 'JetBrains Mono', monospace; font-size: 11.5px; color: var(--ytx-text-3); margin-top: 2px; }

.ytx-pane {
  display: flex; flex-direction: column; min-width: 0;
  border: 1px solid var(--ytx-border);
  border-radius: 13px; background: var(--ytx-surface-2);
  overflow: hidden;
}
.ytx-tabs {
  display: flex; gap: 2px; padding: 8px 8px 0;
  border-bottom: 1px solid var(--ytx-border);
  flex-wrap: wrap; align-items: center;
}
.ytx-tab {
  padding: 9px 13px 11px; font-size: 13px; font-weight: 600;
  color: var(--ytx-text-2); border-radius: 9px 9px 0 0;
  position: relative; transition: color .15s;
}
.ytx-tab:hover { color: var(--ytx-text); }
.ytx-tab.on { color: var(--ytx-text); }
.ytx-tab.on::after {
  content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px;
  height: 2px; border-radius: 2px; background: var(--ytx-accent);
}
.ytx-tab-body { padding: 12px; flex: 1; min-height: 0; display: none; flex-direction: column; }
.ytx-tab-body.on { display: flex; }

/* ---- Search ---- */
.ytx-search {
  display: flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 10px; margin-bottom: 10px;
  border-radius: 9px; border: 1px solid var(--ytx-border);
  background: var(--ytx-bg);
  transition: border-color .15s;
}
.ytx-search:focus-within { border-color: var(--ytx-accent); }
.ytx-search input { flex: 1; min-width: 0; background: none; border: none; outline: none; font-size: 13px; }
.ytx-search input::placeholder { color: var(--ytx-text-3); }
.ytx-count { font-family: ui-monospace, 'JetBrains Mono', monospace; font-size: 11.5px; color: var(--ytx-text-3); white-space: nowrap; }
.ytx-mini {
  width: 24px; height: 24px; display: grid; place-items: center;
  border-radius: 6px; color: var(--ytx-text-3);
  transition: color .15s, background-color .15s;
}
.ytx-mini:hover { color: var(--ytx-text); background: var(--ytx-surface-3); }
.ytx-mini svg { width: 11px; height: 11px; }

/* ---- Segments ---- */
.ytx-segments {
  flex: 1; overflow-y: auto; max-height: 420px; min-height: 340px;
  padding-right: 4px;
  scrollbar-width: thin; scrollbar-color: var(--ytx-border-strong) transparent;
  overscroll-behavior: contain;
}
.ytx-segments::-webkit-scrollbar { width: 8px; }
.ytx-segments::-webkit-scrollbar-thumb {
  background: var(--ytx-border-strong); border-radius: 99px;
  border: 2px solid transparent; background-clip: content-box;
}
.ytx-seg {
  display: grid; grid-template-columns: 56px 1fr; gap: 12px;
  padding: 9px 11px; border-radius: 9px;
  cursor: pointer; border: 1px solid transparent;
  transition: background-color .13s, border-color .13s;
}
.ytx-seg:hover { background: var(--ytx-surface-3); }
.ytx-seg.active { background: var(--ytx-accent-bg); border-color: var(--ytx-accent-strong); }
.ytx-seg-time {
  font-family: ui-monospace, 'JetBrains Mono', monospace;
  font-size: 11.5px; font-weight: 600; color: var(--ytx-accent);
  padding-top: 2px; user-select: none; letter-spacing: -.02em;
}
.ytx-seg.active .ytx-seg-time { color: var(--ytx-text); }
.ytx-seg-text { font-size: 13.5px; line-height: 1.55; color: var(--ytx-text-2); }
.ytx-seg.active .ytx-seg-text { color: var(--ytx-text); }
.ytx-seg-text mark { background: rgba(251, 191, 36, .35); color: inherit; border-radius: 3px; padding: 0 2px; }
.ytx.timestamps-off .ytx-seg { grid-template-columns: 1fr; }
.ytx.timestamps-off .ytx-seg-time { display: none; }

/* ---- Empty / loading ---- */
.ytx-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 60px 20px; min-height: 340px;
  text-align: center; color: var(--ytx-text-3); font-size: 13.5px;
}
.ytx-empty .ytx-big { font-size: 30px; opacity: .5; }
.ytx-skel { padding: 10px 11px; display: grid; grid-template-columns: 56px 1fr; gap: 12px; }
.ytx-skel i {
  display: block; height: 11px; border-radius: 6px;
  background: linear-gradient(90deg, var(--ytx-surface-3) 25%, var(--ytx-border-strong) 50%, var(--ytx-surface-3) 75%);
  background-size: 200% 100%;
  animation: ytx-shimmer 1.3s infinite;
}
@keyframes ytx-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---- Summary / chapters ---- */
.ytx-pane-body {
  padding: 2px 4px; overflow-y: auto; max-height: 420px; min-height: 340px;
  font-size: 13.5px; line-height: 1.7;
  scrollbar-width: thin; scrollbar-color: var(--ytx-border-strong) transparent;
}
.ytx-pane-body::-webkit-scrollbar { width: 8px; }
.ytx-pane-body::-webkit-scrollbar-thumb {
  background: var(--ytx-border-strong); border-radius: 99px;
  border: 2px solid transparent; background-clip: content-box;
}
.ytx-pane-body h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--ytx-text-3); font-weight: 700;
  margin: 16px 0 9px; display: flex; align-items: center; gap: 8px;
}
.ytx-pane-body h4:first-child { margin-top: 2px; }
.ytx-pane-body ul { list-style: none; display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; }
.ytx-pane-body li {
  padding: 11px 14px; border-radius: 9px;
  background: var(--ytx-surface-3); border: 1px solid var(--ytx-border);
  color: var(--ytx-text-2); font-size: 13px; line-height: 1.6;
}
.ytx-pane-body li.ytx-chapter {
  display: flex; gap: 11px; align-items: flex-start; cursor: pointer;
  transition: border-color .14s, transform .14s, background-color .14s;
}
.ytx-pane-body li.ytx-chapter:hover {
  border-color: var(--ytx-border-strong);
  transform: translateX(2px);
  background: var(--ytx-surface-2);
}
.ytx-ts {
  font-family: ui-monospace, 'JetBrains Mono', monospace;
  font-size: 11.5px; font-weight: 600; color: var(--ytx-accent);
  flex-shrink: 0; padding-top: 2px;
}
.ytx-ai-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 6px;
  background: linear-gradient(120deg, var(--ytx-accent-bg), rgba(94, 234, 212, .13));
  color: var(--ytx-accent); border: 1px solid var(--ytx-accent-strong);
}
.ytx-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.ytx-stat {
  padding: 12px; border-radius: 9px; text-align: center;
  background: var(--ytx-surface-3); border: 1px solid var(--ytx-border);
}
.ytx-stat-value { font-size: 18px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.ytx-stat-label { font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ytx-text-3); margin-top: 2px; }

/* ---- Export bar ---- */
.ytx-export {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 10px; border-top: 1px solid var(--ytx-border);
  background: var(--ytx-surface);
}
.ytx-exp {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px;
  font-size: 12px; font-weight: 600;
  border: 1px solid var(--ytx-border);
  background: var(--ytx-surface-3); color: var(--ytx-text-2);
  transition: color .15s, border-color .15s, transform .15s, background-color .15s;
}
.ytx-exp:hover { color: var(--ytx-text); border-color: var(--ytx-border-strong); transform: translateY(-1px); background: var(--ytx-surface-2); }
.ytx-exp.primary { color: var(--ytx-text); border-color: var(--ytx-accent-strong); background: var(--ytx-accent-bg); }
.ytx-exp svg { width: 13px; height: 13px; flex-shrink: 0; }
.ytx-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  margin-left: auto; padding: 6px 11px; border-radius: 8px;
  font-size: 11.5px; font-weight: 650;
  border: 1px solid var(--ytx-border); background: var(--ytx-surface-3);
  color: var(--ytx-text-2);
}
.ytx-toggle .ytx-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ytx-text-3); transition: background-color .15s;
}
.ytx-toggle[aria-pressed="true"] .ytx-dot { background: var(--ytx-green); }

/* ---- Next-step workflow bar ---- */
.ytx-next {
  border-top: 1px solid var(--ytx-border);
  background: linear-gradient(180deg, var(--ytx-accent-bg), transparent);
  padding: 12px;
}
.ytx-next-label {
  display: block; font-size: 10.5px; font-weight: 800;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--ytx-accent); margin-bottom: 8px;
}
.ytx-next-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px; }
.ytx-next-card {
  display: flex; flex-direction: column; gap: 2px;
  padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--ytx-border);
  background: var(--ytx-bg);
  transition: border-color .15s, transform .15s;
}
.ytx-next-card:hover { border-color: var(--ytx-accent-strong); transform: translateY(-1px); }
.ytx-next-name { font-size: 12.5px; font-weight: 650; color: var(--ytx-text); }
.ytx-next-desc { font-size: 11px; color: var(--ytx-text-3); line-height: 1.4; }

/* ---- Toast ---- */
.ytx-toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translate(-50%, 24px);
  z-index: 500; max-width: calc(100vw - 40px);
  padding: 12px 20px; border-radius: 12px;
  display: flex; align-items: center; gap: 9px;
  font-size: 13.5px; font-weight: 600;
  background: #101114; color: #f4f5f7;
  box-shadow: 0 20px 50px -18px rgba(0, 0, 0, .5);
  opacity: 0; pointer-events: none;
  transition: opacity .3s, transform .3s;
}
.ytx-toast.show { opacity: 1; transform: translate(-50%, 0); }
.ytx-toast svg { flex-shrink: 0; }

/* ---- Spinner ---- */
.ytx-spinner {
  display: inline-block; width: 15px; height: 15px;
  border: 2px solid rgba(255, 255, 255, .3);
  border-top-color: #fff; border-radius: 50%;
  animation: ytx-spin .7s linear infinite;
}
@keyframes ytx-spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .ytx-tool { padding: 16px; }
  .ytx-go { width: 100%; }
  .ytx-toggle { margin-left: 0; }
}
