@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --crimson: #841617;
  --crimson-dark: #6b1112;
  --crimson-light: #a93234;
  --crimson-subtle: #fdf2f2;
  --cream: #fdf5e6;
  --cream-dark: #f0e4d0;
  --surface: #ffffff;
  --bg: #fdf5e6;
  --text: #2c1810;
  --text-secondary: #5c4a42;
  --text-muted: #9a8a80;
  --border: #e0d5c8;
  --border-light: #efe8de;
  --success: #166534;
  --success-bg: #f0fdf4;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --warning: #92400e;
  --warning-bg: #fffbeb;
  --shadow-sm: 0 1px 2px rgba(44,24,16,0.04);
  --shadow-md: 0 4px 6px -1px rgba(44,24,16,0.06), 0 2px 4px -2px rgba(44,24,16,0.04);
  --shadow-lg: 0 10px 25px -3px rgba(44,24,16,0.08), 0 4px 10px -4px rgba(44,24,16,0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--crimson);
  z-index: 100;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

@media (max-width: 640px) {
  .container { padding: 24px 16px 60px; }
}

header {
  text-align: center;
  padding: 24px 0 40px;
  animation: fadeInDown 0.5s ease-out;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

header::before {
  display: none;
}

header h1 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 32px;
  font-weight: 400;
  color: var(--crimson);
  letter-spacing: -0.5px;
  margin-bottom: 8px;
  line-height: 1.2;
}

header::after {
  content: '';
  display: block;
  width: 48px;
  height: 2px;
  background: var(--crimson);
  margin: 16px auto 0;
  border-radius: 1px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.01em;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px;
  margin-bottom: 20px;
  border: 1px solid var(--border-light);
  animation: fadeInUp 0.4s ease-out;
  transition: box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--crimson);
  opacity: 0;
  transition: opacity var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card:hover::before {
  opacity: 1;
}

.card h2 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 22px;
  font-weight: 400;
  color: var(--crimson-dark);
  margin-bottom: 12px;
  letter-spacing: -0.3px;
}

.card p {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.7;
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--crimson);
  border: none;
  color: #ffffff;
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  font-family: inherit;
  letter-spacing: 0.01em;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(132,22,23,0.2);
  position: relative;
  overflow: hidden;
}

.primary-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.08));
  opacity: 0;
  transition: opacity var(--transition);
}

.primary-btn:hover {
  background: var(--crimson-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(132,22,23,0.3);
}

.primary-btn:hover::after {
  opacity: 1;
}

.primary-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(132,22,23,0.15);
}

.primary-btn:focus-visible {
  outline: 2px solid var(--crimson-light);
  outline-offset: 2px;
}

.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  font-size: 15px;
  font-family: inherit;
  transition: all var(--transition);
}

.secondary-btn:hover {
  border-color: var(--crimson-light);
  color: var(--crimson);
  background: var(--crimson-subtle);
}

.secondary-btn:focus-visible {
  outline: 2px solid var(--crimson-light);
  outline-offset: 2px;
}

/* The small button, and every small button.
 *
 * There is one of these in the app, not five. The rules page, the questions page, the
 * charge lists and the warnings toggle had each grown their own — 11.5px against 12px
 * against 13px, a hairline border against a light one, muted text against secondary —
 * near enough to look like a mistake and far enough apart to look like several. The
 * shape is settled here, with the same shared tokens the rest of the app uses, and the
 * pages say which buttons are small rather than what small looks like.
 *
 * Two variants earn their keep: `danger`, for something that throws work away, and the
 * warnings toggle, which carries the warning colour because that is what it is about.
 */
.small-btn,
.tool-btn,
.classify-btn,
.count-btn,
.warn-toggle {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.small-btn:hover,
.tool-btn:hover,
.classify-btn:hover,
.count-btn:hover,
.warn-toggle:hover {
  border-color: var(--crimson-light);
  color: var(--crimson);
  background: var(--crimson-subtle);
}

.small-btn:focus-visible,
.tool-btn:focus-visible,
.classify-btn:focus-visible,
.count-btn:focus-visible,
.warn-toggle:focus-visible {
  outline: 2px solid var(--crimson-light);
  outline-offset: 2px;
}

.small-btn:disabled,
.tool-btn:disabled,
.classify-btn:disabled,
.count-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.small-btn:disabled:hover,
.tool-btn:disabled:hover,
.classify-btn:disabled:hover,
.count-btn:disabled:hover {
  border-color: var(--border);
  color: var(--text-secondary);
  background: var(--surface);
}

/* Throws something away, so it says so on the way to being pressed rather than after. */
.small-btn.danger:hover,
.tool-btn.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-bg);
}

/* Sits inline in a sentence about one count, so it is the same button a size down —
 * everything about it is shared above except how much room it takes in the line. */
.count-btn {
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 10px;
}

/* Opens the warnings, and is the colour of a warning while it is worth opening. */
.warn-toggle {
  margin-top: 14px;
  border-color: rgba(146, 64, 14, 0.25);
  background: var(--warning-bg);
  color: var(--warning);
}

.warn-toggle:hover {
  border-color: var(--warning);
  color: var(--warning);
  background: var(--warning-bg);
}

/* A link that looks like a button. The petition page uses it to leave for the results
   page, which is a link and not an action. */
.button-link { text-decoration: none; }

.btn-row {
  margin-top: 24px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.error {
  color: var(--danger);
  background: var(--danger-bg);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(185,28,28,0.12);
  margin-bottom: 16px;
  font-weight: 500;
  font-size: 14px;
  min-height: 0;
  display: none;
  animation: fadeIn 0.3s ease-out;
}

.error:not(:empty) {
  display: block;
}

.hidden { display: none !important; }

.progress-bar {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 28px;
  animation: fadeIn 0.3s ease-out;
}

.progress-bar > div {
  flex: 1;
}

.progress-step {
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  transition: background var(--transition);
}

.progress-step.active {
  background: var(--crimson);
}

.progress-step.completed {
  background: var(--crimson-light);
}

.step-label {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 6px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.step-label.active {
  color: var(--crimson);
}

.step-label.completed {
  color: var(--crimson-light);
}

/* Which rules a page is working on. Three pages offer it — the rules, the questions,
 * and the screening — so it is defined once, here, rather than in each of their own
 * stylesheets. */
.ruleset-pick {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
}

.ruleset-pick[hidden] { display: none; }

.ruleset-pick:focus {
  outline: none;
  border-color: var(--crimson);
  box-shadow: 0 0 0 3px rgba(132, 22, 23, 0.08);
}

/* Out of here, from anywhere.
 *
 * Every page can be arrived at directly — a bookmark, a link from another page, a reload
 * halfway through something — so every page has to be leavable without the back button.
 * The same button in the same place on all of them, quiet enough not to compete with what
 * the page is actually for. On the rules, questions and drafting pages it is the first
 * thing in the toolbar; on the pages built out of a centred container it is this row.
 */
/* The way out, under the title rather than above the header.
 *
 * This was `.home-row`: a left-aligned flex row sitting above a centred header, so the one
 * button on it lined up with nothing. It sits in the header now, under the subtitle and over
 * the rule `header::after` draws — which is where the rules page keeps its own row of these
 * (`.ruleset-tools`), so the two pages put the way out in the same place. */
.head-tools {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* A popout. Used by the placing panel on the screening page and the list editor on the rules
   page, which is why it lives here rather than in either page's own stylesheet: both are a page
   of detail about one field, and a card for either would sit above everything it is detail
   about. */
.popout {
  /* Centred in the viewport. A modal `<dialog>` centres itself with the `margin: auto` the
     browser's own stylesheet gives it — and the reset at the top of this file (`* { margin: 0 }`)
     took that away, so every popout in this app has been opening pinned to the top-left corner.
     Named here rather than left to the browser, because the reset will win again otherwise. */
  margin: auto;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  max-width: 620px;
  width: calc(100% - 40px);
  max-height: 80vh;
  overflow-y: auto;
  color: var(--text);
}

/* Wider than a page of detail about one field: these hold the builder's rows and the model's
   proposals, both of which are read as lists of conditions rather than as prose. */
.popout-wide {
  max-width: 780px;
  max-height: 86vh;
}

.popout::backdrop {
  background: rgba(20, 16, 16, 0.45);
}

.popout-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
}

.popout-head h2 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 22px;
  font-weight: 400;
  color: var(--crimson-dark);
  letter-spacing: -0.3px;
}

/* One labelled field in a popout, stacked rather than inline — a list of offence names needs
   the full width and the label needs to be readable above it. */
.list-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}

.list-field > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.list-field input,
.list-field textarea {
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.list-field input:disabled {
  color: var(--text-secondary);
  background: var(--border-light);
}

.list-field textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
}

/* The first few entries of a list, so the section says what a list contains without becoming a
   page of offence names. */
.list-peek {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-top: 4px;
  /* Two lines, however long the entries are. One of these lists holds whole subsections of the
     controlled-substances act, and three of those ran to eight lines of body text in a card
     whose job is to say what the list is about. The editor has the rest. */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

/* The same spin as `.spinner` in `questions.css`, sized to sit inside a button — so a page that
   already has one idiom for "working" does not grow a second. Here rather than in either page's
   stylesheet because every page with a button that asks the model uses it. */
.spinner-inline {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 7px;
  vertical-align: -1px;
  border: 2px solid var(--cream-dark);
  border-top-color: var(--crimson);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

button:disabled .spinner-inline {
  border-color: var(--border);
  border-top-color: var(--text-muted);
}

/* `questions.css` owns the keyframes and not every page loads it. Declaring it twice is
   harmless — the later definition wins and they are identical — and the alternative is a page
   whose spinner sits still. */
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* The Thread bar held to the bottom of every page: the mark, which is the way home, what the app
 * promises about data, and the name. The same flat colour as the page, so there is no edge where
 * it starts. The home page carries its own copy of these rules. */
:root { --bar-h: 72px; }
body { padding-bottom: var(--bar-h); }

.bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bar-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--bar-h);
  max-width: 1200px;
  margin: 0 auto;
  padding-inline: 40px;
}

.bar-brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; }
.bar-brand svg { width: 38px; height: auto; display: block; fill: var(--crimson); }

.bar-name {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.5px;
  color: var(--text);
}

.bar-note {
  flex: 1;
  margin: 0 24px;
  text-align: center;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}

@media (max-width: 600px) {
  .bar-in { padding-inline: 16px; }
  .bar-note { margin: 0 12px; font-size: 14px; }
}

@media print {
  .bar { display: none; }
  body { padding-bottom: 0; }
}
