:root {
  /* Instruction-leaflet world: paper ground, ink line-work, one confident
     accent (terracotta) reserved for the active step — blue is demoted to
     a quiet structural role, never competing with it. Depth comes from
     1-1.5px rules, not soft shadows: --shadow-* stay defined (many inline
     styles still reference them) but resolve to none everywhere. */
  --accent: #3C5A72;
  --accent-dark: #2C4A5E;
  --cta: #B35A33;
  --cta-dark: #8E4527;
  --bg: #FBFAF7;
  --surface: #FFFFFF;
  --text: #1C1A16;
  --text-soft: #6B6657;
  --accent-soft: #E7EAE3;
  --cta-soft: #F3DCCB;
  --border: #8E8167;
  --rule-strong: #1C1A16;
  --danger: #B3261E;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 8px;
  --radius-full: 999px;
  --shadow-sm: none;
  --shadow-md: none;
  --shadow-lg: none;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font-family: 'Atkinson Hyperlegible', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  position: relative;
}

/* Faint paper texture — adds depth without adding colour */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
body > * { position: relative; z-index: 1; }
/* On paper the texture becomes a full-page bitmap: ~3 MB per PDF page and a grey mottle. */
@media print { body::before { display: none; } }

a { color: inherit; text-decoration: none; }

h1, h2, h3 { text-wrap: balance; letter-spacing: -0.01em; }
p { text-wrap: pretty; }

::selection { background: var(--accent); color: #fff; }

/* Themed scrollbar (WebKit) */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-soft); }

:focus-visible {
  outline: 2.5px solid var(--cta);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Numbered sequence marker — the instruction-leaflet step number. Tabular
   mono is earned here: it measures a real position in a real sequence. */
.step-number {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text-soft);
}
.step-number.active { color: var(--cta); }

.topbar {
  width: 100%;
  border-bottom: 1.5px solid var(--text);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
}
.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  font-size: 18px;
  font-weight: 700;
  border-radius: var(--radius);
  margin-right: auto;
}
.logo svg { color: var(--accent); flex: 0 0 auto; }
.nav-links { display: flex; align-items: center; gap: 24px; }
.nav-links a:not(.btn) {
  font-size: 15px;
  color: var(--text-soft);
  padding: 10px 2px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}
.nav-links a:not(.btn):hover { color: var(--text); }
.nav-links a.active { color: var(--accent); font-weight: 700; border-bottom-color: var(--accent); }

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-toggle:hover { border-color: var(--text); }

@media (max-width: 640px) {
  .topbar-inner { gap: 10px; padding: 14px 16px; }
  .topbar-inner > .btn { flex: 0 0 auto; white-space: nowrap; padding: 9px 14px; min-height: 44px; font-size: 14px; }
  .nav-toggle { display: flex; }
  .nav-links { display: none; }
  .nav-links.open {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-height: 100vh;
    background: var(--surface);
    border-bottom: 1.5px solid var(--text);
    padding: 4px 24px 14px;
    gap: 0;
  }
  .nav-links.open a:not(.btn) {
    border-bottom: 1px solid var(--border);
    width: 100%;
  }
  .nav-links.open a:not(.btn):last-of-type { border-bottom: none; }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  border-radius: var(--radius-lg);
  font-size: 15px;
  font-weight: 700;
  border: 1.5px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--cta); color: #fff; border-color: var(--cta); }
.btn-primary:hover:not(:disabled) { background: var(--cta-dark); border-color: var(--cta-dark); }

.btn-secondary { background: transparent; color: var(--text); border-color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--text); color: var(--bg); }

.btn-accent { background: var(--surface); color: var(--accent); border-color: var(--accent); }
.btn-accent:hover:not(:disabled) { background: var(--accent); color: #fff; }

.btn-danger-outline { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger); color: #fff; }

.container { max-width: 1200px; margin: 0 auto; padding: 0 24px; }

.card {
  background: var(--surface);
  border: 1.5px solid var(--text);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.pill {
  border-radius: var(--radius);
  padding: 11px 18px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s var(--ease);
}
.pill:hover:not(.selected) { border-color: var(--text); }
.pill.selected { background: var(--text); color: var(--bg); border-color: var(--text); }

input[type="text"].search-input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border);
  background-color: var(--surface);
  font-size: 15px;
  color: var(--text);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.search-input:hover { border-color: #C7C0B0; }
.search-input:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); outline: none; }

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B6960' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

input[type="text"], select, textarea {
  font-family: inherit;
  padding: 11px 13px;
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border);
  font-size: 15px;
  color: var(--text);
  background-color: #fff;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
select { padding-right: 38px; }
input[type="text"]:hover, select:hover, textarea:hover { border-color: #C7C0B0; }
input[type="text"]:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  outline: none;
}

.symbol-badge {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1.5px solid var(--text);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.symbol-badge.proud { border-color: var(--cta); color: var(--cta); }

.result-card {
  transition: transform 0.18s var(--ease), border-color 0.18s var(--ease), background-color 0.18s var(--ease);
  border: 1.5px solid var(--border);
}
.result-card:hover {
  transform: translateY(-1px);
  border-color: var(--text);
  background-color: var(--surface);
}
.result-card:hover .result-arrow { transform: translateX(3px); color: var(--accent); }
.result-arrow { transition: transform 0.18s var(--ease), color 0.18s var(--ease); display: inline-flex; }

/* The one authored motion: read-aloud's own un-rushable reveal, each time a
   step changes. Nowhere else in the system animates on entrance. */
@keyframes storycue-reveal {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.step-reveal { animation: storycue-reveal 0.5s var(--ease) both; }

/* Below the width where all 4 steps fit in one row (4 x 220px min-basis),
   stack to a single column instead of a lopsided 3-up-plus-orphan row at
   tablet widths — confirmed live at 768px (iPad portrait). */
@media (max-width: 919px) {
  .step-sequence-item {
    flex-basis: 100% !important;
    padding: 20px 0 !important;
    border-right: none !important;
    border-top: 1px solid var(--border);
  }
  .step-sequence-item:first-child { border-top: none; }
}

.creator-form { flex: 1 1 360px; max-width: 420px; }
.creator-preview { flex: 999 1 480px; }

/* The creator's two columns (basis 360 + 480 + gap) need ~930px to sit
   side by side — including iPad portrait, a primary target device. Below
   that the preview wraps onto its own row, but the form's 420px cap used
   to stay in force, leaving a tall dead gap beside it instead of the form
   simply filling the row it's now alone on. */
@media (max-width: 960px) {
  .creator-form { max-width: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .step-reveal { animation: none; }
  .btn, .pill, input, select, textarea, .search-input, .nav-links a { transition: none; }
}
