/* Policy Writing Workshop — shared styles.
   Calm, high-contrast, readable on a projector and on a laptop in a bright room. */

:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --surface-2: #f4f2ee;
  --border: #ddd8d0;
  --border-strong: #c3bcb1;
  --ink: #1c1a17;
  --ink-2: #4d4740;
  --ink-3: #7a736a;
  --accent: #1d4ed8;
  --accent-soft: #e8eeff;

  /* Status palette. Validated with the dataviz validator:
     CVD separation ΔE 19.2 (deutan), normal-vision ΔE 24.1, chroma and lightness pass.
     Green/red was rejected — it is the classic deuteranopia collision, and the pale
     tints first tried were ΔE 2.7 apart even to normal vision, i.e. unreadable at a
     glance across a grid. Colour is never alone: every cell and chip carries a glyph
     or a word. */
  --met: #1d4ed8;          /* fill */
  --met-ink: #ffffff;      /* glyph on fill */
  --met-text: #1d4ed8;     /* text on tint */
  --met-bg: #e4ecfd;       /* tint */
  --partial: #f59e0b;
  --partial-ink: #1c1a17;
  --partial-text: #92610a;
  --partial-bg: #fdf0d5;
  --missing: #dc2626;
  --missing-ink: #ffffff;
  --missing-text: #b91c1c;
  --missing-bg: #fde8e6;
  --none-bg: #eeeae4;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #201e1b;
    --surface-2: #2a2724;
    --border: #38342f;
    --border-strong: #4e4941;
    --ink: #f0ece5;
    --ink-2: #c3bcb1;
    --ink-3: #8e867b;
    --accent: #8fb0ff;
    --accent-soft: #23304f;

    /* Dark steps chosen against the dark surface, not flipped from light.
       Validated: CVD ΔE 15.4 (deutan), normal-vision ΔE 21.2, all ≥ 3:1 on #201e1b. */
    --met: #60a5fa;
    --met-ink: #171614;
    --met-text: #93c5fd;
    --met-bg: #1b2f52;
    --partial: #fbbf24;
    --partial-ink: #171614;
    --partial-text: #fcd34d;
    --partial-bg: #3a2e10;
    --missing: #f87171;
    --missing-ink: #171614;
    --missing-text: #fca5a5;
    --missing-bg: #3d1d1c;
    --none-bg: #2a2724;
  }
}

* { box-sizing: border-box; }

/* The browser's default [hidden] rule is display:none at the lowest specificity, so
   any class that sets display (.pill, .dot) silently defeats it and the element shows
   anyway. This must win. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ── Join screen ─────────────────────────────────────────────────────────── */

.gate-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 34px 32px 30px;
}
.gate-card h1 {
  font-family: var(--serif);
  font-size: 25px;
  margin: 0;
  letter-spacing: -0.015em;
}
.gate-card .sub {
  margin: 3px 0 28px;
  color: var(--ink-3);
  font-size: 14px;
}
.gate-card label {
  display: block;
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 3px;
}
.gate-card .help {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--ink-3);
}
.gate-card input {
  width: 100%;
  padding: 13px 15px;
  font-size: 19px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--bg);
  margin-bottom: 12px;
}
.gate-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#code-input {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 700;
  font-family: var(--mono);
}
.btn.big { width: 100%; padding: 12px; font-size: 15.5px; }
.gate-card .err { margin: 12px 0 0; color: var(--missing-text); font-size: 14px; min-height: 1em; }

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar .spacer { flex: 1; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--ink-2);
  white-space: nowrap;
}
.pill strong { color: var(--ink); font-weight: 600; }
.pill.open { background: var(--met-bg); border-color: transparent; color: var(--met); }
.pill.closed { background: var(--none-bg); color: var(--ink-3); }
.pill.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.pill.warn { background: var(--partial-bg); border-color: transparent; color: var(--partial-text); font-weight: 600; }

select, .btn {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  cursor: pointer;
}
select:hover, .btn:hover { border-color: var(--ink-3); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled, .btn.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}
.btn.small { padding: 3px 9px; font-size: 12.5px; }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 0;
  height: calc(100vh - 53px);
}
.split > * { overflow-y: auto; padding: 22px 26px 80px; }
.split > .left { border-right: 1px solid var(--border); }

@media (max-width: 940px) {
  .split { grid-template-columns: 1fr; height: auto; }
  .split > * { height: auto; }
  .split > .left { border-right: none; border-bottom: 1px solid var(--border); }
}

.wrap { max-width: 1400px; margin: 0 auto; padding: 22px 26px 80px; }

/* ── Round header ────────────────────────────────────────────────────────── */

.round-head { margin-bottom: 22px; }
.round-head .eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-3);
  font-weight: 600;
}
.round-head h2 {
  font-family: var(--serif);
  font-size: 25px;
  margin: 4px 0 6px;
  letter-spacing: -0.015em;
}
.round-head p { margin: 0; color: var(--ink-2); max-width: 62ch; }

/* ── Fields ──────────────────────────────────────────────────────────────── */

.field { margin-bottom: 22px; }
.field-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 5px;
}
.field-head label { font-weight: 600; font-size: 15px; }
.field-head .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
}
.field-head .count.over { color: var(--missing); font-weight: 600; }
.field .hint {
  margin: 0 0 8px;
  font-size: 13.5px;
  color: var(--ink-3);
  max-width: 68ch;
}

textarea {
  width: 100%;
  min-height: 130px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  resize: vertical;
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.6;
}
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
textarea.tall { min-height: 300px; }

.submit-row {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0 10px;
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.submit-note { font-size: 13px; color: var(--ink-3); }
.submit-note.err { color: var(--missing); font-weight: 500; }

/* ── Tabs ────────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 3px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 7px 13px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ink-3);
  font-size: 14px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected='true'] { color: var(--ink); border-bottom-color: var(--accent); }
.tab .dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 5px;
  vertical-align: middle;
}

/* ── Feedback ────────────────────────────────────────────────────────────── */

.overall {
  padding: 15px 17px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  margin-bottom: 18px;
}
.overall .headline {
  font-family: var(--serif);
  font-size: 17.5px;
  line-height: 1.45;
  margin: 0 0 10px;
}
.overall .fix { margin: 0; font-size: 14px; }
.overall .fix b { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-3); margin-bottom: 2px; }
.overall .tally { margin: 11px 0 0; font-size: 12.5px; color: var(--ink-3); font-weight: 600; }
.pill.strong { background: var(--ink); color: var(--bg); border-color: transparent; font-weight: 600; }

.crit {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin-bottom: 9px;
  background: var(--surface);
}
.crit-head { display: flex; align-items: center; gap: 9px; margin-bottom: 7px; }
.crit-head .label { font-weight: 600; font-size: 14.5px; }

.verdict {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.verdict.met { background: var(--met-bg); color: var(--met-text); }
.verdict.partial { background: var(--partial-bg); color: var(--partial-text); }
.verdict.missing { background: var(--missing-bg); color: var(--missing-text); }
/* The glyph is the primary encoding; colour reinforces it. */
.verdict::before { margin-right: 4px; font-weight: 900; }
.verdict.met::before { content: '✓'; }
.verdict.partial::before { content: '~'; }
.verdict.missing::before { content: '✕'; }

.crit blockquote {
  margin: 0 0 8px;
  padding: 5px 0 5px 12px;
  border-left: 3px solid var(--border-strong);
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: 14px;
}
.crit .why { margin: 0 0 8px; font-size: 14px; color: var(--ink-2); }
.crit .q {
  margin: 0;
  font-size: 14px;
  padding: 8px 11px;
  background: var(--surface-2);
  border-radius: 7px;
}
.crit .q b { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); display: block; margin-bottom: 2px; }

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-3);
  font-size: 14px;
}
.spinner {
  display: inline-block;
  width: 15px; height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  vertical-align: -2px;
  margin-right: 7px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Reader (evidence pack / client brief) ───────────────────────────────── */

.reader {
  font-family: var(--serif);
  font-size: 14.8px;
  line-height: 1.65;
  max-width: 74ch;
}
.reader h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.015em; }
.reader h2 { font-size: 17.5px; margin: 26px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.reader h3 { font-size: 15.5px; margin: 18px 0 6px; }
.reader table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13.3px; font-family: var(--sans); }
.reader th, .reader td { border: 1px solid var(--border); padding: 6px 9px; text-align: left; vertical-align: top; }
.reader th { background: var(--surface-2); font-weight: 600; }
.reader blockquote {
  margin: 12px 0; padding: 10px 14px;
  background: var(--surface-2); border-left: 3px solid var(--border-strong);
  border-radius: 0 7px 7px 0;
}
.reader code { font-family: var(--mono); font-size: 0.87em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.reader pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; }
.reader pre code { background: none; padding: 0; }
.reader hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.reader a { color: var(--accent); overflow-wrap: anywhere; }

/* ── Facilitator ─────────────────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.panel > h3 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-3);
  font-weight: 700;
}

.teach {
  background: var(--partial-bg);
  border: none;
  padding: 17px 19px;
}
.teach > h3 { color: var(--partial); }
.teach .crit-name { font-family: var(--serif); font-size: 20px; margin: 0 0 6px; letter-spacing: -0.01em; }
.teach .stat { font-size: 13.5px; color: var(--ink-2); }
.teach .standard { margin: 9px 0 0; font-size: 14px; color: var(--ink-2); max-width: 80ch; }

.grid-scroll { overflow-x: auto; }
table.heat { border-collapse: separate; border-spacing: 2px; font-size: 12px; }
table.heat th { font-weight: 600; color: var(--ink-2); text-align: left; padding: 4px 6px; }
table.heat th.rot {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  height: 132px;
  vertical-align: bottom;
  font-weight: 500;
  font-size: 11.5px;
  padding: 4px 2px;
  white-space: nowrap;
}
/* Cells carry a glyph as well as a fill — readable in greyscale, in print, and
   under any colour-vision deficiency. Never colour alone. */
table.heat td.cell {
  width: 30px; height: 27px;
  border-radius: 5px;
  background: var(--none-bg);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  line-height: 27px;
  color: var(--ink-3);
  cursor: default;
}
table.heat td.cell.met { background: var(--met); color: var(--met-ink); }
table.heat td.cell.partial { background: var(--partial); color: var(--partial-ink); }
table.heat td.cell.missing { background: var(--missing); color: var(--missing-ink); }
table.heat td.team {
  white-space: nowrap;
  padding-right: 10px;
  font-weight: 600;
  cursor: pointer;
}
table.heat td.team:hover { color: var(--accent); text-decoration: underline; }
table.heat td.team .who { font-weight: 400; color: var(--ink-3); font-size: 11px; }

table.codes { border-collapse: collapse; font-size: 14px; }
table.codes th {
  text-align: left; padding: 4px 22px 6px 0;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3);
}
table.codes td { padding: 5px 22px 5px 0; border-top: 1px solid var(--border); }
table.codes td.code {
  font-family: var(--mono); font-weight: 700; font-size: 17px;
  letter-spacing: 0.12em; color: var(--accent);
}
table.codes .muted { color: var(--ink-3); }

.legend { display: flex; gap: 14px; margin-top: 12px; font-size: 12px; color: var(--ink-3); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.qcard {
  border-left: 3px solid var(--accent);
  padding: 9px 0 9px 13px;
  margin-bottom: 13px;
}
.qcard .who { font-weight: 700; font-size: 13.5px; }
.qcard .who span { font-weight: 400; color: var(--ink-3); }
.qcard ul { margin: 5px 0 0; padding-left: 17px; }
.qcard li { margin-bottom: 4px; font-size: 13.5px; }
.qcard li em { color: var(--ink-3); font-style: normal; font-size: 12px; }

.controls { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }

dialog {
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  max-width: 780px;
  width: 92vw;
  max-height: 86vh;
  padding: 0;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog .dlg-head {
  position: sticky; top: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
dialog .dlg-head h3 { margin: 0; font-family: var(--serif); font-size: 18px; }
dialog .dlg-body { padding: 18px; overflow-y: auto; }
dialog .memo {
  font-family: var(--serif);
  white-space: pre-wrap;
  background: var(--surface-2);
  padding: 12px 14px;
  border-radius: 8px;
  margin: 4px 0 16px;
  font-size: 14.5px;
}
