:root {
  --canvas: #eef1f5;
  --card: #ffffff;
  --ink: #17212b;
  --ink-soft: #64707d;
  --line: #e2e7ed;
  --field: #f6f8fa;
  --accent: #2554d4;
  --accent-ink: #ffffff;
  --accent-soft: #e6edff;
  --check: #9a5b00;
  --check-bg: #fff1cc;
  --check-line: #e0a100;
  --danger: #c0352b;
  --shadow: 0 1px 2px rgba(23, 33, 43, 0.06), 0 8px 24px -12px rgba(23, 33, 43, 0.18);
  --r-card: 18px;
  --r-ctl: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #0f1419;
    --card: #182028;
    --ink: #e6ebf0;
    --ink-soft: #95a2af;
    --line: #2a3540;
    --field: #1f2932;
    --accent: #7aa2ff;
    --accent-ink: #0b1530;
    --accent-soft: rgba(122, 162, 255, 0.16);
    --check: #ffcf66;
    --check-bg: rgba(255, 191, 64, 0.16);
    --check-line: #c98f00;
    --danger: #ff8a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --canvas: #0f1419;
  --card: #182028;
  --ink: #e6ebf0;
  --ink-soft: #95a2af;
  --line: #2a3540;
  --field: #1f2932;
  --accent: #7aa2ff;
  --accent-ink: #0b1530;
  --accent-soft: rgba(122, 162, 255, 0.16);
  --check: #ffcf66;
  --check-bg: rgba(255, 191, 64, 0.16);
  --check-line: #c98f00;
  --danger: #ff8a80;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: clamp(17px, 0.35vw + 12px, 20px)/1.5 "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
.grow { flex: 1; }

/* Icons */
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Buttons */
.btn, .icon-btn {
  font: inherit; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: var(--r-ctl);
  background: var(--card); color: var(--ink);
  cursor: pointer; transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active:not(:disabled), .icon-btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled, .icon-btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); white-space: nowrap; }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 16px; }
.btn.danger { color: var(--danger); }
.icon-btn { width: 44px; padding: 0; border-color: transparent; background: transparent; color: var(--ink-soft); }
.icon-btn:hover:not(:disabled) { background: var(--field); color: var(--ink); }
.icon-btn.small { width: 36px; min-height: 36px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input, textarea {
  font: inherit; color: var(--ink);
  background: var(--field); border: 1px solid transparent; border-radius: var(--r-ctl);
  padding: 12px 14px; width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--card); }
label { font-weight: 500; font-size: 15px; color: var(--ink-soft); }
.error { color: var(--danger); font-size: 15px; }
.error:empty { display: none; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 32px; display: grid; gap: 10px; }
.login-card h1 { font-size: 26px; margin-bottom: 10px; }

/* Layout */
.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 0.75fr) minmax(0, 2fr);
  gap: clamp(14px, 1vw, 24px);
  padding: clamp(14px, 1vw, 24px);
}
.col { display: flex; flex-direction: column; gap: 16px; min-height: 0; }
@media (min-width: 761px) {
  .workspace { height: 100dvh; }
  .notes-card, .report-card { flex: 1; min-height: 0; }
}
@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; padding: 0 16px 16px; }
  .notes-card { min-height: 60vh; }
  .report-card { min-height: 70vh; }
}

.confirm-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 20px 14px; padding: 12px 16px;
  background: var(--card); border-radius: var(--r-ctl); box-shadow: var(--shadow);
  border-left: 4px solid var(--accent);
}
.confirm-bar p { flex: 1 1 260px; }

/* Cards */
.card { background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow); display: flex; flex-direction: column; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 56px; padding: 0 12px 0 20px; flex: none; }
.card-head h2 { font-size: 18px; }
.tools { display: flex; align-items: center; gap: 4px; }
.card-foot { display: flex; align-items: center; gap: 10px; padding: 12px 16px 16px; flex: none; flex-wrap: wrap; }

/* Segmented control */
.segmented { display: inline-flex; padding: 3px; background: var(--field); border-radius: 11px; }
.segmented label { position: relative; color: var(--ink-soft); font-size: 15px; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: block; padding: 7px 14px; border-radius: 8px; }
.segmented input:checked + span { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); }

/* Notes */
#notes {
  flex: 1; min-height: 220px; resize: none; font-size: clamp(17px, 0.4vw + 12px, 21px);
  margin: 0 16px; width: calc(100% - 32px);
  line-height: 1.6; padding: 16px 18px;
}
.phi-warning { display: flex; gap: 10px; margin: 12px 16px 0; padding: 12px 14px; background: var(--check-bg); color: var(--ink); border-radius: var(--r-ctl); }
.phi-warning .i { color: var(--check); margin-top: 2px; }
.phi-warning p { margin-bottom: 8px; font-size: 15px; }
#notes-error { margin: 10px 18px 0; }
.mic { width: 48px; min-height: 48px; border-radius: 50%; border: 1px solid var(--line); color: var(--ink); background: var(--card); }
.mic .on-live { display: none; }
.mic[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); color: #fff; }
.mic[aria-pressed="true"] .on-idle { display: none; }
.mic[aria-pressed="true"] .on-live { display: block; fill: currentColor; }
.mic-label { color: var(--danger); font-size: 15px; font-weight: 500; }
@media (prefers-reduced-motion: no-preference) {
  .mic[aria-pressed="true"] { animation: ring 1.6s ease-out infinite; }
  @keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(192, 53, 43, 0.45); } 100% { box-shadow: 0 0 0 14px rgba(192, 53, 43, 0); } }
}
#generate { min-height: 48px; padding: 0 28px; margin-left: auto; }

/* Review panel */
.review {
  flex: none; max-height: 42%; overflow-y: auto;
  background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow);
  border-top: 4px solid var(--check-line);
  padding: 16px 20px 18px;
}
.review h2 { display: flex; align-items: center; gap: 8px; font-size: 17px; margin-bottom: 10px; }
.review h2 .i { color: var(--check); }
.review-group + .review-group { margin-top: 14px; }
.review h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.review-note { color: var(--ink-soft); font-size: 14px; margin: 2px 0 8px; }
.count { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--check-bg); color: var(--check); font-size: 13px; }
.pill-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.pill-list button { font: inherit; font-size: 15px; font-weight: 700; padding: 4px 12px; border-radius: 8px; border: none; background: var(--check-bg); color: var(--check); cursor: pointer; }
.missing-list { margin: 8px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.missing-list li { display: flex; gap: 10px; font-size: 15px; line-height: 1.4; }
.missing-list li::before { content: ""; width: 6px; height: 6px; margin-top: 8px; border-radius: 50%; background: var(--check-line); flex: none; }

/* Report */
.sheet { flex: 1; min-height: 0; overflow-y: auto; padding: 0 24px 10px 20px; }
.report {
  font-size: clamp(17px, 0.4vw + 12px, 22px); line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
  outline: none; border-radius: 8px;
}
.report:empty { display: none; }
.report.drop-target { box-shadow: 0 0 0 2px var(--accent-soft), 0 0 0 4px var(--accent); }
.empty { color: var(--ink-soft); max-width: 46ch; margin-top: 6px; display: grid; gap: 8px; }
.empty p:first-child { font-size: 20px; color: var(--ink); font-weight: 500; }
.working { color: var(--ink-soft); }
.check-num { background: var(--check-bg); color: var(--check); border-bottom: 2px dotted var(--check-line); border-radius: 3px; padding: 0 2px; font-weight: 700; }
.changed { background: var(--accent-soft); border-radius: 3px; }

/* Saved text tray */
.tray { flex: none; display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding: 10px 10px 10px 20px; }
.tray h3 { font-size: 15px; flex: none; }
.tray .chips { flex: 1; min-width: 0; }
.tray-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.tray-head h3 { font-size: 15px; }
.hint { color: var(--ink-soft); font-size: 14px; flex: 1; }
.chips { list-style: none; margin: 0; padding: 0 0 2px; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips li { flex: none; }
.chip {
  font: inherit; font-size: 15px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 16px 0 10px;
  background: var(--field); color: var(--ink);
  border: 1px solid var(--line); border-radius: 22px;
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  cursor: grab;
}
.chip .i { width: 16px; height: 16px; color: var(--ink-soft); }
.chip.add { color: var(--accent); background: transparent; border-style: dashed; cursor: pointer; padding-left: 12px; }
.chip.add .i { color: var(--accent); }
.chips.managing .chip:not(.add) { border-color: var(--accent); cursor: pointer; }
.drag-ghost {
  position: fixed; z-index: 10; pointer-events: none;
  max-width: 300px; padding: 10px 14px; border-radius: var(--r-ctl);
  background: var(--card); color: var(--ink); font-size: 14px; line-height: 1.4;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.45); border: 1px solid var(--line);
}
.drop-caret { position: fixed; z-index: 9; width: 3px; background: var(--accent); pointer-events: none; border-radius: 2px; }

.status {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 20;
  transform: translate(-50%, 8px); opacity: 0; pointer-events: none;
  max-width: min(560px, calc(100vw - 32px)); padding: 12px 18px; border-radius: 14px;
  background: var(--ink); color: var(--card); font-size: 15px; font-weight: 500;
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.45);
  transition: opacity 0.2s, transform 0.2s;
}
.status.show { opacity: 1; transform: translate(-50%, 0); }

/* Floating Change button under a selection */
.change-pill {
  position: fixed; z-index: 8;
  font: inherit; font-weight: 700; font-size: 16px;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 18px 0 14px;
  border: none; border-radius: 22px;
  background: var(--ink); color: var(--card);
  box-shadow: 0 10px 24px -8px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}
.change-pill .i { width: 18px; height: 18px; }

/* Dialogs */
.dialog {
  border: none; border-radius: 20px; padding: 24px;
  width: min(540px, calc(100vw - 32px));
  background: var(--card); color: var(--ink); box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.5);
}
.dialog::backdrop { background: rgba(15, 20, 25, 0.4); backdrop-filter: blur(3px); }
.dialog form { display: grid; gap: 8px; }
.dialog h2 { font-size: 20px; margin-bottom: 6px; }
.dialog blockquote { margin: 0 0 8px; padding: 10px 14px; background: var(--accent-soft); border-radius: var(--r-ctl); font-size: 16px; }
.dialog textarea { min-height: 120px; resize: vertical; }
.field-with-mic { position: relative; }
.field-with-mic textarea { padding-right: 64px; }
.field-with-mic .mic { position: absolute; right: 8px; bottom: 8px; }
.dialog-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; }

@media print {
  @page { margin: 18mm; }
  body { background: #fff; color: #000; }
  body * { visibility: hidden; }
  .report, .report * { visibility: visible; }
  .workspace, .col, .card, .report-card, .sheet { display: block; height: auto; min-height: 0; overflow: visible; box-shadow: none; padding: 0; margin: 0; background: none; }
  .workspace > .col:first-child, .card-head, .tray, .status, .empty, .working, .change-pill, .confirm-bar, dialog { display: none !important; }
  .report { position: absolute; left: 0; top: 0; width: 100%; font-size: 12pt; line-height: 1.5; color: #000; }
  .check-num, .changed { background: none; color: inherit; border: none; padding: 0; font-weight: inherit; }
}
