:root {
  --bg: #f3f0e9;
  --surface: #fffdf8;
  --ink: #18201e;
  --muted: #66716d;
  --line: #d9d6cd;
  --accent: #145e55;
  --accent-strong: #0b443e;
  --danger: #a42c24;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 0; line-height: 1.55; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; }
button, .button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  padding: .65rem 1.1rem;
  color: white;
  background: var(--accent);
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}
button:hover, .button:hover { background: var(--accent-strong); }
button.quiet { min-height: 36px; color: var(--ink); background: transparent; border: 1px solid var(--line); }
button.danger { background: var(--danger); }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: .65rem .8rem;
  color: var(--ink);
  background: var(--surface);
}
textarea { resize: vertical; }
label { display: block; margin-bottom: .35rem; font-size: .9rem; font-weight: 700; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

.site-header { display: flex; align-items: center; justify-content: space-between; max-width: 1100px; margin: auto; padding: 1rem clamp(1rem, 4vw, 2.5rem); }
.brand { color: var(--ink); font-size: 1.15rem; font-weight: 900; letter-spacing: -.04em; text-decoration: none; }
main { width: min(100% - 2rem, 1020px); margin: 1.5rem auto 5rem; }
h1, h2, h3 { line-height: 1.12; letter-spacing: -.03em; }
h1 { margin: .25rem 0 .75rem; font-size: clamp(2rem, 8vw, 4.2rem); }
h2 { margin-top: 0; }
.hero { max-width: 780px; padding: 3rem 0 2rem; }
.eyebrow { margin: 0; color: var(--accent); font-size: .78rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.lede { max-width: 55ch; color: var(--muted); font-size: 1.15rem; }
.muted { color: var(--muted); }
.panel, .notice, .empty-state { margin: 1rem 0; border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1rem, 3vw, 1.6rem); background: var(--surface); }
.login-panel { max-width: 430px; margin: 10vh auto; }
.login-panel button { width: 100%; margin-top: 1rem; }
.notice { background: #e7f3ef; }
.notice.error, .error { color: #84251f; background: #f9e9e7; }
.section-heading, .summary-heading, .card-topline, .composer-actions { display: flex; gap: .8rem; align-items: center; justify-content: space-between; }
.section-heading { margin-top: 2.5rem; }
.section-heading h2, .summary-heading h3 { margin: 0; }
.count { min-width: 2rem; border-radius: 999px; padding: .2rem .65rem; text-align: center; background: #dfe7e3; }
.library-hero { max-width: 680px; padding-bottom: 1rem; }
.add-video-panel { padding-block: 1rem; }
.add-video-panel > summary { cursor: pointer; font-size: 1.15rem; font-weight: 850; }
.add-video-panel[open] > summary { margin-bottom: 1.2rem; }
.load-form { display: grid; grid-template-columns: minmax(0, 1fr) 180px 130px auto; gap: .8rem; align-items: end; }
.library-manager { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 560px; margin-top: 1.5rem; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.library-sidebar { min-width: 0; border-right: 1px solid var(--line); padding: 1rem .75rem; background: color-mix(in srgb, var(--surface) 82%, var(--bg)); }
.sidebar-heading, .browser-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.sidebar-heading { padding: .35rem .5rem .8rem; }
.sidebar-heading h2, .browser-heading h2 { margin: 0; }
.folder-navigation { display: grid; gap: .15rem; }
.folder-tree { margin: 0; padding: 0; list-style: none; }
.folder-tree .folder-tree { margin-left: 1.05rem; border-left: 1px solid var(--line); padding-left: .3rem; }
.folder-node { border-radius: 9px; }
button.folder-button { width: 100%; min-height: 38px; display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: .5rem; justify-content: stretch; border-radius: 9px; padding: .42rem .55rem; color: var(--ink); background: transparent; text-align: left; font-weight: 650; }
button.folder-button:hover { color: var(--ink); background: color-mix(in srgb, var(--accent) 9%, transparent); }
button.folder-button[aria-current="true"] { color: var(--accent-strong); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.folder-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count { min-width: 1.6rem; border-radius: 999px; padding: .05rem .35rem; color: var(--muted); background: color-mix(in srgb, var(--line) 70%, transparent); font-size: .72rem; text-align: center; }
.folder-icon, .all-icon, .inbox-icon, .document-icon { position: relative; display: inline-block; width: 16px; height: 14px; flex: none; }
.folder-icon::before { content: ""; position: absolute; inset: 3px 0 1px; border-radius: 2px; background: #d4a94f; }
.folder-icon::after { content: ""; position: absolute; top: 1px; left: 1px; width: 8px; height: 4px; border-radius: 2px 2px 0 0; background: #d4a94f; }
.all-icon { border: 1.5px solid currentColor; border-radius: 3px; }
.all-icon::after { content: ""; position: absolute; left: 3px; right: 3px; top: 5px; border-top: 1.5px solid currentColor; box-shadow: 0 3px 0 currentColor; }
.inbox-icon { border: 1.5px solid currentColor; border-radius: 2px 2px 4px 4px; }
.inbox-icon::after { content: ""; position: absolute; left: 2px; right: 2px; top: 6px; height: 3px; border: 1.5px solid currentColor; border-top: 0; }
.folder-node.is-drop-target button { outline: 2px solid var(--accent); outline-offset: -2px; background: color-mix(in srgb, var(--accent) 18%, transparent); }
.new-folder-control { margin-top: 1rem; border-top: 1px solid var(--line); padding: .9rem .5rem 0; }
.new-folder-control > summary { cursor: pointer; color: var(--accent); font-weight: 750; }
.new-folder-form { display: grid; gap: .65rem; margin-top: .8rem; }
.new-folder-form label { margin-bottom: -.35rem; }
.new-folder-form button { width: 100%; }
.library-browser { min-width: 0; padding: 1.15rem; }
.library-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: .75rem; margin-bottom: 1.5rem; }
.browser-heading { margin-bottom: .75rem; }
.browser-heading .eyebrow { margin-bottom: .2rem; }
.library-flash { border-radius: 9px; padding: .65rem .8rem; color: var(--accent-strong); background: color-mix(in srgb, var(--accent) 13%, transparent); }
.library-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.library-row { display: grid; grid-template-columns: 18px minmax(240px, 1fr) auto minmax(165px, auto); gap: .75rem; align-items: center; min-width: 0; border-bottom: 1px solid var(--line); padding: .7rem .8rem; background: var(--surface); }
.library-row[hidden] { display: none; }
.library-row:last-child { border-bottom: 0; }
.library-row:hover { background: color-mix(in srgb, var(--accent) 4%, var(--surface)); }
.library-row.is-dragging { opacity: .45; }
.drag-handle { color: var(--muted); cursor: grab; font-weight: 900; letter-spacing: -.18em; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.library-item-link { display: flex; min-width: 0; gap: .75rem; align-items: center; color: var(--ink); text-decoration: none; }
.library-item-link:hover strong { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.document-icon { width: 18px; height: 22px; border: 1.5px solid var(--muted); border-radius: 2px; }
.document-icon::before { content: ""; position: absolute; top: -1.5px; right: -1.5px; width: 6px; height: 6px; border-left: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); background: var(--surface); }
.document-icon::after { content: ""; position: absolute; left: 3px; right: 3px; top: 10px; border-top: 1.5px solid var(--muted); box-shadow: 0 4px 0 var(--muted); }
.library-item-text { display: grid; min-width: 0; gap: .22rem; }
.library-item-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-metadata { display: flex; min-width: 0; flex-wrap: wrap; gap: .25rem .75rem; color: var(--muted); font-size: .78rem; }
.library-item-state { display: grid; justify-items: end; gap: .35rem; }
.item-folder { max-width: 150px; overflow: hidden; color: var(--muted); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.row-move-form { display: flex; align-items: center; gap: .4rem; }
.row-move-form select { min-width: 105px; min-height: 34px; padding: .35rem .5rem; font-size: .8rem; }
.row-move-form .button { min-height: 34px; padding: .35rem .65rem; }
.status { display: inline-block; border-radius: 999px; padding: .2rem .55rem; color: var(--muted); background: #e7e7e2; font-size: .75rem; font-weight: 900; text-transform: uppercase; }
.status-ready { color: #155a34; background: #daf0e2; }
.status-pending { color: #735713; background: #f6edc8; }
.status-failed { color: #84251f; background: #f8dedb; }
.video-id { color: var(--muted); font-family: ui-monospace, monospace; font-size: .78rem; }
.breadcrumbs { display: flex; gap: .5rem; align-items: center; margin: 2rem 0; color: var(--muted); font-size: .9rem; }
.video-heading h1, .conversation-heading h1 { max-width: 22ch; font-size: clamp(2rem, 7vw, 3.6rem); overflow-wrap: anywhere; }
.source-link { display: inline-block; margin-top: .25rem; }
.public-post { max-width: 860px; margin-inline: auto; }
.public-post-heading { padding: 2rem 0 1rem; }
.share-link-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .6rem; align-items: center; margin: 1rem 0 .25rem; }
.share-link-row input { min-width: 0; font-family: ui-monospace, monospace; font-size: .86rem; }
.summary { overflow: hidden; }
.summary-heading { border-bottom: 1px solid var(--line); padding-bottom: 1rem; }
.summary-actions { display: flex; flex-wrap: wrap; gap: .55rem; }
.summary-copy-source { position: fixed; top: -100vh; left: -100vw; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.summary-copy-status { min-height: 1.3em; margin: .55rem 0 0; color: var(--muted); font-size: .85rem; }
.button.secondary { min-height: 38px; color: var(--accent); background: transparent; border: 1px solid var(--accent); font-size: .85rem; }
.markdown { min-width: 0; overflow-wrap: anywhere; }
.summary .markdown { font-size: 1.0625rem; line-height: 1.65; }
.summary .markdown h1 { margin: 2.25rem 0 .9rem; font-size: clamp(1.75rem, 4vw, 2.25rem); }
.summary .markdown h2 { margin: 2rem 0 .75rem; font-size: clamp(1.4rem, 3vw, 1.75rem); }
.summary .markdown h3 { margin: 1.75rem 0 .65rem; font-size: clamp(1.15rem, 2.5vw, 1.35rem); }
.summary .markdown > :first-child { margin-top: 1.4rem; }
.summary .markdown hr { margin: 2rem 0; border: 0; border-top: 1px solid var(--line); }
.markdown pre { max-width: 100%; overflow-x: auto; border-radius: 10px; padding: 1rem; background: #202724; color: #f5f2e9; }
.markdown img { max-width: 100%; height: auto; }
.markdown blockquote { margin-left: 0; border-left: 3px solid var(--line); padding-left: 1rem; color: var(--muted); }
.inline-form { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; }
.inline-form input { flex: 1 1 240px; }
.inline-form select { width: auto; min-width: 130px; }
.conversation-list { padding-left: 1.2rem; }
.danger-zone { margin-top: 3rem; }
.danger-zone summary { cursor: pointer; color: var(--danger); font-weight: 700; }
.messages { display: grid; gap: 1rem; }
.message { width: min(88%, 760px); border-radius: var(--radius); padding: 1rem 1.2rem; background: var(--surface); }
.message.user { justify-self: end; color: white; background: var(--accent); }
.message.user a { color: white; }
.message-role, .message-status { margin: 0 0 .4rem; font-size: .76rem; font-weight: 900; text-transform: uppercase; opacity: .75; }
.message .markdown > :first-child { margin-top: 0; }
.message .markdown > :last-child { margin-bottom: 0; }
.sticky-composer { position: sticky; bottom: .75rem; margin-top: 1.5rem; box-shadow: 0 12px 45px rgb(19 32 28 / 13%); }
.question-form textarea { margin-bottom: .65rem; }
.composer-actions { justify-content: flex-end; }
.composer-actions select { width: auto; min-width: 140px; }
.clamp { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

@media (max-width: 720px) {
  main { width: min(100% - 1.25rem, 1020px); margin-top: .5rem; }
  .site-header { padding-inline: .75rem; }
  .hero { padding-top: 2rem; }
  .load-form { grid-template-columns: 1fr 1fr; }
  .load-form .wide-field { grid-column: 1 / -1; }
  .load-form button { grid-column: 1 / -1; }
  .summary-heading { align-items: flex-start; flex-direction: column; }
  .share-link-row { grid-template-columns: 1fr 1fr; }
  .share-link-row input { grid-column: 1 / -1; }
  .summary-actions { width: 100%; }
  .message { width: 94%; }
  .library-manager { grid-template-columns: 1fr; }
  .library-sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .folder-navigation { max-height: 260px; overflow-y: auto; }
  .library-row { grid-template-columns: 14px minmax(0, 1fr) auto; }
  .library-item-state { align-items: end; }
  .row-move-form { grid-column: 2 / -1; }
}

@media (max-width: 420px) {
  .load-form { grid-template-columns: 1fr; }
  .load-form .wide-field, .load-form button { grid-column: auto; }
  .inline-form, .composer-actions { align-items: stretch; flex-direction: column; }
  .inline-form select, .composer-actions select { width: 100%; }
  .button.secondary { width: 100%; }
  .library-toolbar { grid-template-columns: 1fr; }
  .library-browser { padding: .75rem; }
  .library-row { grid-template-columns: 12px minmax(0, 1fr); gap: .55rem; }
  .library-item-state { grid-column: 2; display: flex; justify-content: space-between; align-items: center; }
  .row-move-form { grid-column: 2; align-items: stretch; flex-direction: column; }
  .row-move-form select, .row-move-form .button { width: 100%; }
  .item-metadata span:last-child { display: none; }
}

@media (prefers-color-scheme: dark) {
  :root { --bg: #111715; --surface: #18201d; --ink: #edf4f0; --muted: #a5b2ad; --line: #35413d; --accent: #63c4b6; --accent-strong: #47ac9e; }
  button, .button { color: #10211d; }
  .count, .status { background: #2c3733; }
  .notice { background: #17342f; }
  .notice.error, .error { color: #f4b2ac; background: #3a201f; }
  .status-ready { color: #8dd5a8; background: #1d3a29; }
  .status-pending { color: #e2c76f; background: #3b331b; }
  .status-failed { color: #f0a5a0; background: #44221f; }
}
