:root {
  --bg: #f3f2ef;
  --stage: #e7e5e0;
  --surface: #ffffff;
  --surface-2: #f6f5f2;
  --line: #dedbd4;
  --text: #1b1c1f;
  --muted: #6b6a66;
  --accent: #e8620c;
  --accent-ink: #ffffff;
  --pin: #2563eb;
  --circle: #dc2626;
  --sev-info: #0e7490;
  --sev-warning: #c2410c;
  --sev-critical: #b91c1c;
  --ok: #15803d;
  --shadow: 0 8px 28px rgba(20, 20, 18, .14);
  --radius: 14px;
  --bar-h: 56px;
  --panel-w: 380px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111215;
    --stage: #17191d;
    --surface: #1d1f24;
    --surface-2: #24272d;
    --line: #33363d;
    --text: #ecebe8;
    --muted: #9a9993;
    --accent: #ff7a1a;
    --accent-ink: #1a0d02;
    --pin: #60a5fa;
    --circle: #f87171;
    --sev-info: #22d3ee;
    --sev-warning: #fb923c;
    --sev-critical: #f87171;
    --ok: #4ade80;
    --shadow: 0 8px 28px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.ic { display: contents; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); font-weight: 600;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--sev-critical); }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 20px; height: 20px; flex: none; }

/* ---------- splash / notices ---------- */
.splash { height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.notice-page { max-width: 520px; margin: 0 auto; padding: 18vh 20px 40px; }
.notice-page h1 { font-size: 26px; margin: 14px 0 8px; }
.brand-mark { font-weight: 800; letter-spacing: .02em; color: var(--accent); }
.notice { padding: 16px; }

/* ---------- review layout ---------- */
.review {
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--bar-h) 1fr;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px 0 16px;
  padding-top: env(safe-area-inset-top);
  background: var(--surface); border-bottom: 1px solid var(--line);
  min-width: 0;
}
.topbar .brand-mark { flex: none; font-size: 14px; }
.topbar .title { flex: 1; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip {
  flex: none; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap;
}
.chip.approved { color: var(--ok); border-color: currentColor; }
.chip.changes_requested { color: var(--sev-warning); border-color: currentColor; }
.chip.draft { color: var(--muted); border-style: dashed; }

.stage { position: relative; min-height: 0; background: radial-gradient(ellipse at 50% 35%, var(--surface-2), var(--stage) 70%); }
.viewport { position: absolute; inset: 0; touch-action: none; }
.viewport canvas { display: block; width: 100%; height: 100%; outline: none; }
.stage-msg { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--muted); text-align: center; padding: 20px; pointer-events: none; }
.progress { width: 180px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

.hint {
  position: absolute; left: 0; right: 0; top: 12px; margin: 0 auto; width: fit-content;
  max-width: calc(100% - 24px);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; text-align: center;
}
.dims {
  position: absolute; left: 12px; top: 12px; font-size: 12px; color: var(--muted);
  background: color-mix(in srgb, var(--surface) 80%, transparent); padding: 4px 8px; border-radius: 6px;
}
.hint:not(.hidden) ~ .dims { display: none; }

/* toolbar floats at the bottom of the stage */
.toolbar {
  position: absolute; left: 0; right: 0; margin: 0 auto; width: fit-content;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; gap: 4px; padding: 5px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  max-width: calc(100% - 16px);
}
.tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 54px; min-height: 52px; padding: 4px 8px;
  border: 0; border-radius: 12px; background: transparent;
  font-size: 11px; font-weight: 650; color: var(--muted);
}
.tool svg { width: 22px; height: 22px; }
.tool[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.tool .count {
  min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  font-size: 11px; line-height: 18px;
}
.tool-sep { width: 1px; margin: 8px 2px; background: var(--line); }

/* ---------- panel: bottom sheet on phones, sidebar on desktop ---------- */
.panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  max-height: 78dvh; display: flex; flex-direction: column;
  background: var(--surface); border-top-left-radius: 18px; border-top-right-radius: 18px;
  box-shadow: 0 -10px 40px rgba(0,0,0,.25);
  transform: translateY(105%); transition: transform .25s ease;
}
.panel.open { transform: none; }
.panel-grab { display: flex; justify-content: center; padding: 8px 0 2px; border: 0; background: none; width: 100%; }
.panel-grab::before { content: ""; width: 42px; height: 5px; border-radius: 3px; background: var(--line); }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 6px 16px 10px; border-bottom: 1px solid var(--line); }
.panel-head h2 { flex: 1; margin: 0; font-size: 16px; }
.panel-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 12px 16px; }
.panel-foot { border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.panel-foot .row { display: flex; gap: 8px; }
.panel-foot .row > .btn { flex: 1; }
.scrim { position: fixed; inset: 0; z-index: 19; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.show { opacity: 1; pointer-events: auto; }

@media (min-width: 900px) {
  .review { grid-template-columns: minmax(0, 1fr) var(--panel-w); }
  .topbar { grid-column: 1 / -1; }
  .panel {
    position: static; transform: none; max-height: none; min-height: 0;
    border-radius: 0; box-shadow: none; border-left: 1px solid var(--line);
  }
  .panel-grab, .scrim, .tool.only-mobile { display: none; }
}

/* ---------- annotation cards ---------- */
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }
.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 4px 6px; }
.card {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  padding: 12px; margin-bottom: 8px; cursor: pointer;
}
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.card.resolved { opacity: .6; }
.card-head { display: flex; align-items: center; gap: 8px; }
.badge {
  flex: none; display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px;
  border-radius: 13px; color: #fff; font-size: 12px; font-weight: 800;
}
.badge.pin { background: var(--pin); }
.badge.circle { background: var(--circle); }
.badge.info { background: var(--sev-info); }
.badge.warning { background: var(--sev-warning); }
.badge.critical { background: var(--sev-critical); }
.card-kind { font-weight: 700; font-size: 13px; }
.card-meta { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.card-body { margin: 8px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.replies { margin: 10px 0 0; padding: 0 0 0 10px; border-left: 2px solid var(--line); display: grid; gap: 8px; }
.reply-author { font-size: 12px; font-weight: 700; }
.reply-author.team { color: var(--accent); }
.reply-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.reply-form { display: grid; gap: 6px; margin-top: 10px; }
.card-actions select { width: auto; padding: 0 8px; font-size: 13px; background: var(--surface); }

/* ---------- forms / dialogs ---------- */
textarea, input[type=text], input[type=password], input[type=search], select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); font-size: 16px; /* 16px stops iOS zooming on focus */
}
textarea { min-height: 96px; resize: vertical; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }

dialog {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  border: 1px solid var(--line); border-radius: 18px; padding: 0;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg { display: grid; gap: 12px; padding: 18px; }
.dlg h3 { margin: 0; font-size: 18px; }
.dlg .row { display: flex; gap: 8px; justify-content: flex-end; }
@media (max-width: 600px) {
  dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; border-bottom: 0; }
  .dlg { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .dlg .row > .btn { flex: 1; }
}

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 50; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-weight: 600; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.status-box { border-radius: 12px; padding: 10px 12px; background: var(--surface-2); font-size: 14px; }
.status-box strong { display: block; }

/* ---------- admin ---------- */
.admin-wrap { max-width: 980px; margin: 0 auto; padding: 16px; padding-bottom: 40px; }
.admin-top { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.admin-top h1 { flex: 1; margin: 0; font-size: 22px; }
.login { max-width: 360px; margin: 16vh auto 0; padding: 0 16px; display: grid; gap: 12px; }
.err { color: var(--sev-critical); font-weight: 600; }
.list { display: grid; gap: 8px; }
.row-card {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  padding: 12px 14px; text-decoration: none; color: inherit;
}
.row-card:hover { border-color: var(--accent); }
.row-card .t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-card .s { font-size: 13px; color: var(--muted); }
.row-card .chips { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.new-dot { color: var(--accent); font-weight: 800; }
.admin-tools { display: flex; flex-wrap: wrap; gap: 6px; }
