/* Colors that differ by scheme are light-dark(light, dark), resolved by the root's color-scheme: light dark, so the OS
   picks, unless the viewer pinned one and wrapper.js set data-theme. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f6f7f9, #0d1117);
  --panel: light-dark(#ffffff, #161b22);
  --line: light-dark(#e3e6ea, #30363d);
  --line-strong: light-dark(#c7ccd4, #484f58);
  --text: light-dark(#1d2330, #e6edf3);
  --muted: light-dark(#667085, #9198a1);
  --accent: light-dark(#2563eb, #60a5fa);
  --accent-soft: light-dark(#e8efff, rgba(96, 165, 250, .16));
  /* Fills under white text stay dark enough in both schemes; --accent and --danger lighten for text on dark. */
  --accent-fill: #2563eb;
  --accent-fill-hover: #1d4ed8;
  --warn: light-dark(#b45309, #fbbf24);
  --warn-soft: light-dark(#fff4e5, rgba(251, 191, 36, .12));
  --warn-line: light-dark(#f5d7a8, rgba(251, 191, 36, .4));
  --ok: light-dark(#15803d, #4ade80);
  --ok-soft: light-dark(#e8f6ee, rgba(74, 222, 128, .12));
  --ok-line: light-dark(#bfe3cc, rgba(74, 222, 128, .4));
  --agent: light-dark(#7c3aed, #a78bfa);
  --agent-soft: light-dark(#f3ecff, rgba(167, 139, 250, .14));
  --agent-line: light-dark(#ddd0fb, rgba(167, 139, 250, .4));
  --danger: light-dark(#b91c1c, #f87171);
  --danger-fill: #b91c1c;
  --flash: light-dark(#fde68a, rgba(250, 204, 21, .55));
  --toast: light-dark(#111827, #e6edf3);
  --toast-text: light-dark(#ffffff, #0d1117);
  --backdrop: light-dark(rgba(17, 24, 39, .35), rgba(0, 0, 0, .6));
  --radius: 8px;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
button:hover { border-color: var(--line-strong); }
a.button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 5px 10px; color: inherit;
  text-decoration: none;
}
a.button:hover { border-color: var(--line-strong); }
button.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
button.primary:hover { background: var(--accent-fill-hover); }
button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
textarea {
  width: 100%; min-height: 64px; resize: vertical; border: 1px solid var(--line); border-radius: 6px; padding: 8px;
  background: var(--panel);
}
textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.shell { display: grid; grid-template-rows: 52px 1fr; height: 100vh; }
.bar {
  display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .02em; color: var(--accent); text-decoration: none; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.chip.latest { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.chip.old { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.chip.agent { background: var(--agent-soft); color: var(--agent); border-color: var(--agent-line); }
.spacer { flex: 1; }
.bar select, .homebar select { border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; background: var(--panel); }
.theme { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.theme select { color: var(--text); font-size: 14px; }

.main { display: grid; grid-template-columns: 1fr 380px; min-height: 0; }
.stage { position: relative; min-height: 0; padding: 12px; }
/* The frame inherits the viewer's scheme, which the browser gives the page as its prefers-color-scheme. Behind a page in
   that scheme the frame's Canvas shows through; behind one in the other, such as a page that declares no scheme in a
   dark frame, browsers paint an opaque canvas in the page's own scheme. Safari does not start painting it when a live
   change creates the mismatch (WPT color-scheme-iframe-background-mismatch-dynamic), so there such a page sits on this
   Canvas until it reloads. */
.stage iframe {
  width: 100%; height: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: Canvas;
}
.stage.picking iframe { outline: 3px solid var(--accent); outline-offset: -1px; }
.pickhint {
  position: absolute; top: 20px; left: 50%; transform: translateX(-50%); background: var(--accent-fill); color: #fff;
  padding: 6px 12px; border-radius: 999px; font-size: 13px; box-shadow: 0 4px 12px rgba(37, 99, 235, .3);
}

.side { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; border: 0; border-radius: 0; padding: 12px; background: transparent; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.count { margin-left: 6px; background: var(--bg); border-radius: 999px; padding: 0 7px; font-size: 12px; }
.newversion {
  padding: 8px 12px; background: var(--accent-soft); color: var(--accent); border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.newversion a { color: var(--accent); font-weight: 600; }
.panel { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.toolbar { display: flex; gap: 8px; align-items: center; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }

.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--panel); }
.card.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 4px var(--flash); } to { box-shadow: 0 0 0 0 transparent; } }
.card.resolved { opacity: .65; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.anchor {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--accent);
  background: var(--accent-soft); border: 0; padding: 1px 6px; border-radius: 4px; cursor: pointer;
}
.quote { color: var(--muted); border-left: 3px solid var(--line); padding-left: 8px; margin: 6px 0; font-size: 13px; }
.body { margin: 6px 0 0; white-space: pre-wrap; word-wrap: break-word; }
.reply { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.actions { display: flex; gap: 6px; margin-top: 8px; }
.composer { border: 1px solid var(--accent); border-radius: var(--radius); padding: 10px; background: var(--accent-soft); }
.composer .meta { margin-bottom: 6px; }

.question { font-weight: 600; margin-bottom: 8px; }
.option {
  display: flex; gap: 8px; align-items: flex-start; padding: 8px; border: 1px solid var(--line); border-radius: 6px;
  margin-bottom: 6px; cursor: pointer;
}
.option.picked { border-color: var(--ok); background: var(--ok-soft); }
.option.mine { border-color: var(--accent); }
.option .label { font-weight: 500; }
.option .desc { color: var(--muted); font-size: 13px; }
.option .tally { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-open { color: var(--accent); }
.status-closed { color: var(--ok); }
.note { margin-top: 6px; }
.note input { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: var(--panel); }

.home { max-width: 1040px; margin: 32px auto; padding: 0 16px; }
.home h1 { font-size: 22px; margin: 0; }
.homebar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.home .toolbar { margin-bottom: 12px; flex-wrap: wrap; }
.search { width: 260px; border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; background: var(--panel); }
.search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.filter { border-radius: 999px; }
table.artifacts {
  width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.artifacts th, .artifacts td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.artifacts tbody tr:last-child td { border-bottom: 0; }
.artifacts tbody tr:hover { background: var(--bg); }
.artifacts th { background: var(--bg); font-weight: 600; font-size: 12px; color: var(--muted); }
.artifacts .num { text-align: right; font-variant-numeric: tabular-nums; }
.artifacts a { color: inherit; text-decoration: none; }
.artifacts a:hover strong { color: var(--accent); }
button.sort { border: 0; background: none; padding: 0; color: inherit; font-weight: inherit; }
.rowactions { text-align: right; white-space: nowrap; }
.home .more { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 12px; }
.rowactions button { padding: 3px 8px; font-size: 12px; }
.rowactions button + button { margin-left: 6px; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--toast); color: var(--toast-text);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast.error { background: var(--danger-fill); color: #fff; }
.marker {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent-fill); color: #fff; font-size: 11px; font-weight: 600;
}
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: 12px; }
button.link:hover { text-decoration: underline; }
.backdrop {
  position: fixed; inset: 0; background: var(--backdrop); display: flex; align-items: flex-start;
  justify-content: center; padding-top: 10vh; z-index: 10;
}
.dialog {
  width: min(560px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .2);
}
.dialoghead { display: flex; align-items: center; }
.dialog .toolbar { flex-wrap: wrap; }
.dialog select { border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; background: var(--panel); width: auto; flex: none; }
.dialog .search { width: 160px; flex: 1; }
.grants { display: flex; flex-direction: column; gap: 6px; }
.grant { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.chip.asks { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); margin-left: 4px; }
.requests { display: flex; flex-direction: column; gap: 6px; }
.requests:empty { display: none; }
.asknote { color: var(--muted); font-size: 13px; white-space: pre-wrap; word-wrap: break-word; }
.askaccess { width: 480px; max-width: 100%; }
.sent { color: var(--ok); font-weight: 600; }
