:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f1eee6;
  --ink: #1b2233;
  --ink-2: #4a5268;
  --muted: #7a8196;
  --line: #e2ddd0;
  --navy: #14213d;
  --gold: #b8872b;
  --gold-2: #d9a441;
  --accent: #1f5f8b;
  --ok: #2e7d4f;
  --warn: #a86a00;
  --err: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 8px 24px rgba(20, 33, 61, .06);
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1320; --surface: #151c2e; --surface-2: #1c2438; --ink: #eef0f6; --ink-2: #c3c8d6;
    --muted: #8d94a8; --line: #273049; --navy: #0b1122; --accent: #6fb3e0; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1320; --surface: #151c2e; --surface-2: #1c2438; --ink: #eef0f6; --ink-2: #c3c8d6;
  --muted: #8d94a8; --line: #273049; --navy: #0b1122; --accent: #6fb3e0; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
img, video, canvas { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
.serif { font-family: var(--serif); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45em; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 600 .92rem/1 var(--sans); padding: .72em 1.05em; border-radius: 10px; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { border-color: var(--gold); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
:root[data-theme="dark"] .btn.primary { background: var(--gold); border-color: var(--gold); color: #14100a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { background: var(--gold); border-color: var(--gold); color: #14100a; } }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--err); }
.btn.sm { padding: .5em .75em; font-size: .82rem; }
.btn svg { width: 1.1em; height: 1.1em; }
label { display: block; font-weight: 600; font-size: .86rem; margin: 0 0 .35em; color: var(--ink-2); }
input[type=text], input[type=url], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .65em .8em; }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--gold-2); outline-offset: 1px; }
.field { margin-bottom: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: .35em; font-size: .75rem; font-weight: 600; padding: .25em .6em; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.pill.ok { background: rgba(46,125,79,.12); color: var(--ok); }
.pill.warn { background: rgba(168,106,0,.12); color: var(--warn); }
.pill.err { background: rgba(179,38,30,.12); color: var(--err); }
.pill.run { background: rgba(31,95,139,.12); color: var(--accent); }

/* App shell */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--navy); color: #fff; }
.topbar .inner { max-width: 1280px; margin: 0 auto; padding: .7rem 16px; display: flex; align-items: center; gap: .75rem; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; font-weight: 700; }
.brand small { display: block; font-weight: 500; opacity: .7; font-size: .72rem; }
.brand .logo { width: 34px; height: 34px; flex: none; }
.topnav { display: flex; gap: .25rem; margin-left: auto; }
.topnav .btn { background: transparent; color: #dfe3ee; border-color: transparent; }
.topnav .btn:hover, .topnav .btn[aria-current="page"] { background: rgba(255,255,255,.1); color: #fff; }
.main { max-width: 1280px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
@media (max-width: 640px) { .topnav .btn span { display: none; } .brand small { display: none; } }

.banner { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; font-size: .92rem; }
.banner.err { background: rgba(179,38,30,.08); border-color: rgba(179,38,30,.3); color: var(--err); }
.banner.warn { background: rgba(168,106,0,.08); border-color: rgba(168,106,0,.3); color: var(--warn); }
.banner.info { background: rgba(31,95,139,.08); border-color: rgba(31,95,139,.25); color: var(--accent); }

/* Drop zone */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 2rem 1rem; text-align: center; background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s; }
.drop.over, .drop:hover { border-color: var(--gold); }
.drop strong { display: block; font-size: 1.05rem; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; font: 600 .88rem var(--sans); color: var(--ink-2); padding: .55em .9em; border-radius: 8px; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.progress { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--gold-2)); transition: width .3s; }

/* Workspace */
.ws-head { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: 1rem; }
.ws-head h1 { font-family: var(--serif); font-size: clamp(1.5rem, 3vw, 2.1rem); margin: 0; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: .8em 1em; font: 600 .95rem var(--sans); color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--gold); }

.content-grid { display: grid; grid-template-columns: 270px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .content-grid { grid-template-columns: 1fr; } }
.fmt-list { display: flex; flex-direction: column; gap: .35rem; }
.fmt-item { display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left; border: 1px solid transparent; background: transparent; padding: .7rem .75rem; border-radius: 10px; cursor: pointer; font: 600 .92rem var(--sans); color: var(--ink); }
.fmt-item:hover { background: var(--surface-2); }
.fmt-item[aria-selected="true"] { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow); }
.fmt-item .ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); flex: none; font-size: 1rem; }
.fmt-item .st { margin-left: auto; }
.output { min-height: 420px; }
.output-toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; padding-bottom: .9rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.md { font-size: 1rem; line-height: 1.65; overflow-wrap: anywhere; }
.md h1 { font-family: var(--serif); font-size: 1.7rem; }
.md h2 { font-family: var(--serif); font-size: 1.3rem; margin-top: 1.4em; }
.md h3 { font-size: 1.05rem; margin-top: 1.2em; }
.md blockquote { margin: 1em 0; padding: .5em 1em; border-left: 4px solid var(--gold); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.5em 0; }
.md ul, .md ol { padding-left: 1.4em; }
.md code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
.streaming::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--gold); }
@keyframes blink { 50% { opacity: 0; } }
.editor { min-height: 520px; font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.transcript { min-height: 560px; font: 15px/1.7 var(--sans); }

/* Clips */
.clips-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .clips-layout { grid-template-columns: 1fr; } }
.clip { border: 1px solid var(--line); border-radius: 12px; padding: 1rem; background: var(--surface); margin-bottom: .8rem; }
.clip.active { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(184,135,43,.2); }
.clip .times { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.clip .times input { width: 92px; }
.clip-title { font-weight: 700; }
.player { width: 100%; background: #000; border-radius: 12px; max-height: 360px; }
.render-out video { width: 100%; max-height: 520px; background: #000; border-radius: 12px; }
.canvas-preview { width: 100%; height: auto; border-radius: 10px; background: #000; display: block; }

/* Quotes */
.quote-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.quote-card { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: .75rem; display: flex; flex-direction: column; gap: .6rem; }
.quote-card textarea { min-height: 80px; font-size: .9rem; }

/* Library */
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.lib-card { cursor: pointer; transition: border-color .15s, transform .15s; }
.lib-card:hover { border-color: var(--gold); transform: translateY(-2px); }
.lib-card h3 { font-family: var(--serif); font-size: 1.15rem; margin-bottom: .25rem; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: .75rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); z-index: 100; font-size: .92rem; max-width: calc(100vw - 32px); }
.gate { max-width: 460px; margin: 8vh auto; text-align: center; }
.gate .card { text-align: left; }
details summary { cursor: pointer; font-weight: 600; }
