/* Studio. Quiet, reading-first. One typeface, ink on paper, one status colour for warnings and errors. */
:root {
  --bg: #fff; --ink: #16181d; --body: #2a2d34; --mute: #686c75; --rule: #e7e7ea; --edge: #8e929b; --box: #f5f5f7; --warn: #b42318;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #111214; --ink: #f1f1f3; --body: #d5d6da; --mute: #9699a2; --rule: #26282d; --edge: #666a74; --box: #1a1b1f; --warn: #ff8f80;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--body); font: 400 16px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { color: var(--ink); margin: 0; letter-spacing: -0.015em; line-height: 1.25; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.022em; }
h2 { font-size: 19px; font-weight: 600; margin-bottom: 14px; }
h3 { font-size: 16px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; color: var(--mute); letter-spacing: 0; margin-bottom: 6px; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }
a { color: var(--ink); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
strong { color: var(--ink); font-weight: 600; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--ink); color: var(--bg); }

.muted { color: var(--mute); }
.warn-text, .error-text, .warn-text strong { color: var(--warn); }
.error-text { font-weight: 500; overflow-wrap: anywhere; }
.small { font-size: 14px; }
.meta { font-size: 14px; color: var(--mute); margin: 4px 0 0; overflow-wrap: anywhere; }
.hint { font-size: 13px; color: var(--mute); }
.break { overflow-wrap: anywhere; word-break: break-word; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.sr-only, .offscreen { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -60px; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: 6px; z-index: 50; }
.skip:focus { top: 12px; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.side { position: sticky; top: 0; align-self: start; height: 100vh; height: 100dvh; overflow-y: auto; padding: 32px 24px; border-right: 1px solid var(--rule); display: flex; flex-direction: column; }
.side-top { display: flex; align-items: center; justify-content: space-between; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.02em; color: var(--ink); text-decoration: none; }
.brand span, .login h1 span { font-weight: 400; color: var(--mute); }
.menu-btn { display: none; }
#nav { display: flex; flex-direction: column; flex: 1; margin-top: 28px; }
#nav a { color: var(--mute); text-decoration: none; font-size: 15px; padding: 6px 0; }
#nav a:hover { color: var(--ink); }
#nav a[aria-current="page"] { color: var(--ink); font-weight: 600; }
.side-foot { margin-top: auto; padding-top: 28px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.shadow-chip { font-size: 12px; font-weight: 600; color: var(--ink); border: 1px solid var(--edge); border-radius: 999px; padding: 2px 10px; }
main { min-width: 0; padding: 44px clamp(16px, 5vw, 64px) 120px; }
main:focus { outline: none; }
.page { max-width: 720px; }
.page.wide { max-width: 1160px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 24px; margin-bottom: 28px; }
.page-head p { margin-top: 6px; }
.crumb { font-size: 14px; margin-bottom: 14px; }
.crumb a { color: var(--mute); }
.section { margin-top: 40px; }

/* ---------- controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 15px; border: 1px solid var(--edge); border-radius: 8px; background: transparent; color: var(--ink); font-size: 15px; font-weight: 500; line-height: 1.2; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { opacity: 0.88; }
.btn.danger { color: var(--warn); border-color: var(--warn); }
.btn.small { min-height: 34px; padding: 5px 11px; font-size: 14px; }
.btn.large { min-height: 48px; padding: 12px 26px; font-size: 16px; font-weight: 600; }
.btn.block { width: 100%; }
.btn:disabled, .btn[disabled] { opacity: 0.45; cursor: default; }
.btn[aria-pressed="true"] { background: var(--box); border-color: var(--ink); }
.link-btn { background: none; border: 0; padding: 0; color: var(--mute); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; min-height: 24px; }
.link-btn:hover { color: var(--ink); }
.side-foot .link-btn { text-decoration: none; font-size: 15px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }

input[type="text"], input[type="password"], input[type="search"], input[type="url"], input[type="number"], select, textarea {
  display: block; width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--edge); border-radius: 8px; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.5;
}
textarea { resize: vertical; }
textarea.auto { field-sizing: content; resize: none; overflow: hidden; min-height: 42px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--ink); outline-offset: 0; border-color: var(--ink); border-radius: 8px; }
input[aria-invalid="true"] { border-color: var(--warn); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; margin: 0; accent-color: var(--ink); flex: none; }
input.narrow { width: 84px; }
::placeholder { color: var(--mute); opacity: 0.8; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label, legend.label { font-size: 13px; font-weight: 600; color: var(--mute); padding: 0; }
.form { display: flex; flex-direction: column; gap: 16px; }
.form.inset { margin-top: 12px; padding-left: 14px; border-left: 2px solid var(--rule); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.choices { display: flex; flex-wrap: wrap; gap: 8px 24px; }
.choices legend { margin-bottom: 8px; }
.choices.column { flex-direction: column; gap: 4px; }
.choice { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; cursor: pointer; }
.choice > input[type="checkbox"], .choice > input[type="radio"] { margin-top: 4px; }
.choice > input[type="text"] { flex: 1; margin-top: -4px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 20px; }
.filters { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-bottom: 16px; }
.filters:has(> :only-child) { grid-template-columns: minmax(0, 260px); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.inline-form { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.savebar, .stickybar { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 44px; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--rule); }
.save-state { font-size: 14px; color: var(--mute); overflow-wrap: anywhere; min-width: 0; }
.save-state.is-error { color: var(--warn); font-weight: 500; }

/* ---------- pieces ---------- */
.tag { display: inline-block; font-size: 11.5px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; line-height: 1.5; padding: 1px 8px; border: 1px solid var(--rule); border-radius: 999px; color: var(--mute); white-space: nowrap; vertical-align: 1px; }
.tag.st-running, .tag.st-draft, .tag.st-approved { color: var(--ink); border-color: var(--edge); }
.tag.st-failed { color: var(--warn); border-color: var(--warn); }
.tag.story { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 12.5px; white-space: normal; overflow-wrap: anywhere; }
.banner { margin: 0 0 20px; padding: 12px 16px; border: 1px solid var(--edge); border-radius: 8px; background: var(--box); color: var(--ink); }
.banner.is-error { border-color: var(--warn); background: transparent; }
.banner .actions { margin-top: 10px; }
.state { padding: 36px 0; color: var(--mute); }
.state.is-error { color: var(--warn); }
.state .btn { margin-top: 6px; }
.hero { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px 24px; }
.hero > div { min-width: 0; flex: 1 1 260px; }
.hero-title { font-size: 22px; font-weight: 700; color: var(--ink); letter-spacing: -0.02em; line-height: 1.25; margin: 0; }
.kvs { margin: 0; display: flex; flex-direction: column; }
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 4px 16px; padding: 12px 0; border-top: 1px solid var(--rule); }
.kv:first-child { border-top: 0; padding-top: 0; }
.kv dt { color: var(--mute); font-size: 14px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv .sub { display: block; font-size: 14px; color: var(--mute); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 20px 24px; }
.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 26px; font-weight: 600; color: var(--ink); letter-spacing: -0.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 13px; color: var(--mute); }
.stat.is-warn .stat-value { color: var(--warn); }
.list, .flags, .plain { list-style: none; margin: 0; padding: 0; }
.plain li { padding: 2px 0 2px 14px; position: relative; }
.plain li::before { content: "–"; position: absolute; left: 0; color: var(--mute); }
.row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px 24px; padding: 16px 0; border-top: 1px solid var(--rule); }
.list > :first-child { border-top: 0; padding-top: 0; }
.row-main { flex: 1 1 300px; min-width: 0; }
.row-title { font-weight: 600; color: var(--ink); margin: 0; overflow-wrap: anywhere; }
a.row-title { text-decoration: none; }
a.row-title:hover { text-decoration: underline; }
.row-side { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-size: 14px; }
[role="tabpanel"] > .actions { margin-bottom: 24px; }
[role="tabpanel"]:focus-visible { outline-offset: 6px; }
.tabs { display: flex; gap: 4px 22px; border-bottom: 1px solid var(--rule); margin-bottom: 24px; overflow-x: auto; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 10px 0; color: var(--mute); font-size: 15px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"], .tab[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th { text-align: left; font-size: 13px; font-weight: 600; color: var(--mute); padding: 0 16px 8px 0; border-bottom: 1px solid var(--rule); white-space: nowrap; }
td { padding: 12px 16px 12px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
td:first-child { min-width: 220px; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th:last-child, td:last-child { padding-right: 0; }

/* ---------- dialogs, toasts, login ---------- */
.dialog { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 24px; border: 1px solid var(--edge); border-radius: 12px; background: var(--bg); color: var(--body); overflow: auto; }
.dialog::backdrop { background: rgba(10, 11, 13, 0.55); }
.dialog-title { font-size: 20px; margin-bottom: 14px; }
.dialog-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.dialog.wide { width: min(1100px, calc(100vw - 24px)); height: calc(100dvh - 24px); display: none; flex-direction: column; }
.dialog.wide[open] { display: flex; }
.dialog.wide .dialog-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.toasts { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: 11px 16px; border-radius: 8px; background: var(--ink); color: var(--bg); font-size: 15px; font-weight: 500; }
.toast.is-error { background: var(--bg); color: var(--warn); border: 1px solid var(--warn); }
.login { position: fixed; inset: 0; z-index: 40; overflow: auto; background: var(--bg); display: flex; align-items: flex-start; justify-content: center; padding: clamp(40px, 16vh, 160px) 20px 40px; }
.login-form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 18px; }
.login h1 { font-size: 24px; }

/* ---------- run view ---------- */
.live-note { font-size: 14px; min-height: 22px; margin: 6px 0 0; }
.panes { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 36px; margin-top: 20px; }
.pane h2 { margin-bottom: 10px; }
.pane h2 span { font-weight: 400; font-size: 14px; }
.feed { position: relative; }
.feed-scroll { height: calc(100dvh - 300px); min-height: 320px; overflow-y: auto; overscroll-behavior: contain; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding-right: 8px; }
.feed-jump { position: absolute; right: 12px; bottom: 12px; background: var(--bg); }
.feed-empty { padding: 20px 0; }
.post { padding: 16px 0; border-top: 1px solid var(--rule); }
.post:first-child { border-top: 0; }
.post-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin-bottom: 6px; font-size: 15px; }
.post-time { margin-left: auto; font-size: 13px; color: var(--mute); }
.body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.body.code { font: 13px/1.55 var(--mono); background: var(--box); border-radius: 6px; padding: 10px 12px; }
.body.clamp { max-height: calc(12 * 1.6em); overflow: hidden; }
.body.code.clamp { max-height: calc(12 * 1.55em + 20px); }
.ev { display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 10px; padding: 5px 0; font-size: 14px; }
.ev-time { color: var(--mute); font-size: 12.5px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.ev-main { overflow-wrap: anywhere; white-space: pre-wrap; }
.ev-agent { font-weight: 600; color: var(--ink); }
.ev-stage { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--rule); }
.ev-stage:first-child { margin-top: 0; border-top: 0; }
.ev-stage .ev-body { font-weight: 700; color: var(--ink); font-size: 15px; }
.ev-tool .ev-main, .ev-tool .ev-agent { color: var(--mute); font-weight: 400; }
.ev-tool .ev-body { font: 12.5px/1.5 var(--mono); }
.ev-error .ev-body { color: var(--warn); font-weight: 500; }

/* ---------- review ---------- */
.toolbar { margin-top: 20px; }
.editor { margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.stack > .btn { align-self: flex-start; }
.item { display: flex; flex-direction: column; gap: 4px; }
.item.pair { gap: 6px; padding-bottom: 6px; }
.item-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 24px; }
.small-link { font-size: 14px; color: var(--mute); }
.heading-input { font-size: 20px !important; font-weight: 600; letter-spacing: -0.015em; line-height: 1.3 !important; }
.scene { padding: 28px 0 32px; border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: 18px; scroll-margin-top: 72px; }
.scene:first-child { border-top: 0; padding-top: 0; }
.scene.has-flag, .scene.has-high { padding-left: 14px; border-left: 2px solid var(--edge); }
.scene.has-high { border-left-color: var(--warn); }
.scene-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.scene-head h3 { font-size: 13px; font-weight: 600; color: var(--mute); letter-spacing: 0.04em; text-transform: uppercase; }
.grid-label { display: grid; grid-template-columns: minmax(0, 180px) minmax(0, 1fr); gap: 14px; align-items: start; }
.group { display: flex; flex-direction: column; }
.flag { padding: 12px 0 12px 14px; border-left: 2px solid var(--edge); margin-top: 12px; font-size: 15px; }
.flag p { margin-bottom: 4px; overflow-wrap: anywhere; }
.flag-head { font-size: 13.5px; }
.flag .sev { font-weight: 600; color: var(--ink); }
.flag.is-high { border-left-color: var(--warn); }
.flag.is-high .sev { color: var(--warn); text-transform: uppercase; letter-spacing: 0.04em; font-size: 12.5px; }
.flag-claim { color: var(--mute); }
.scene .flags .flag:first-child { margin-top: 0; }
/* Read-only or locked: text stays fully legible, editing controls go away. */
.editor:disabled input[type="text"], .editor:disabled input[type="url"], .editor:disabled textarea { opacity: 1; color: var(--ink); -webkit-text-fill-color: var(--ink); background: transparent; border-color: var(--rule); }
.editor:disabled .btn, .editor:disabled .link-btn, .editor:disabled .choice:has(> input[type="text"]:placeholder-shown) { display: none; }
.preview { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.preview .tabs { margin-bottom: 12px; flex: none; }
.preview-stage > .state { padding: 24px; }
.preview-stage { flex: 1; min-height: 300px; display: flex; justify-content: center; background: var(--box); border: 1px solid var(--rule); border-radius: 8px; overflow: auto; }
.preview-frame { width: 100%; height: 100%; min-height: 300px; border: 0; background: #fff; }
.preview-stage.is-phone .preview-frame { width: 375px; max-width: 100%; border-left: 1px solid var(--rule); border-right: 1px solid var(--rule); }

/* ---------- coach, social ---------- */
.idea, .draft { padding: 24px 0; border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: 12px; }
.idea h3, .draft h3 { font-size: 18px; }
.idea .meta { margin: 0; }
.notes { padding-left: 14px; border-left: 2px solid var(--rule); }
.split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 28px; }
.split .actions { margin-top: 10px; }
.thread { max-height: calc(100dvh - 380px); min-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding: 4px 4px 16px 0; }
.msg { max-width: 86%; }
.msg-user { align-self: flex-end; background: var(--box); border-radius: 12px; padding: 10px 14px; }
.msg-who { font-size: 13px; color: var(--mute); margin-bottom: 2px; }
.msg.is-failed { border: 1px solid var(--warn); }
.chat-form { display: flex; gap: 10px; align-items: flex-end; padding-top: 14px; border-top: 1px solid var(--rule); }
.chat-form textarea { flex: 1; }

/* ---------- chart ---------- */
.figure { margin: 28px 0 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 10px; }
.chart-scale { display: flex; flex-direction: column; justify-content: space-between; height: 180px; padding: 4px 0; font-size: 12.5px; color: var(--mute); text-align: right; font-variant-numeric: tabular-nums; }
.chart { display: block; width: 100%; height: 180px; }
.chart-line { fill: none; stroke: var(--ink); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.chart-axis { stroke: var(--rule); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-days { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--mute); margin-top: 6px; }

/* ---------- phones and small tablets ---------- */
@media (max-width: 860px) {
  .app { display: block; }
  .side { position: sticky; top: 0; z-index: 20; height: auto; max-height: 100dvh; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--rule); background: var(--bg); }
  .menu-btn { display: inline-flex; align-items: center; min-height: 40px; padding: 6px 12px; border: 1px solid var(--edge); border-radius: 8px; background: transparent; color: var(--ink); font-size: 15px; font-weight: 500; cursor: pointer; }
  #nav { display: none; margin-top: 8px; padding-bottom: 10px; }
  .side.open #nav { display: flex; }
  #nav a { padding: 11px 0; font-size: 16px; border-top: 1px solid var(--rule); }
  .side-foot { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 22px; padding-top: 14px; border-top: 1px solid var(--rule); }
  .side-foot .link-btn { min-height: 40px; }
  main { padding: 26px 16px 110px; }
  h1 { font-size: 24px; }
  .panes, .split { grid-template-columns: minmax(0, 1fr); }
  .feed-scroll { height: 58dvh; }
  .thread { max-height: 56dvh; }
}
@media (max-width: 560px) {
  .filters, .grid-2, .grid-label { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .btn.small { min-height: 40px; padding: 7px 13px; }
  .link-btn { min-height: 36px; }
  .dialog { padding: 20px 16px; }
  .dialog.wide { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; padding: 14px 12px; }
  .dialog-foot .btn { flex: 1 1 auto; }
  .section { margin-top: 36px; }
  .hero .btn.large { width: 100%; }
  .stickybar .btn { min-height: 46px; padding-inline: 20px; }
  .msg { max-width: 94%; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
@media print { .side, .stickybar, .savebar, .toasts { display: none; } .app { display: block; } }
