/*
 * Calm mode (« Mode calme »): larger, airier text, calmer colours, no motion.
 * Turned on by the visitor with the switch in the navigation, which puts the
 * `calm` class on <html> (saved in localStorage, applied before paint by the
 * head script in layouts/application.html.erb). Never turned on automatically.
 * Spec: docs/superpowers/specs/2026-11-30-calm-mode-design.md (§2.1, §2.2).
 * Values follow the British Dyslexia Association style guide; text is at
 * least 7:1 on its background (WCAG 1.4.6). /admin is out of scope.
 */

/* ─── §2.2 Colour tokens ─────────────────────────────────────── */
html.calm {
  /* Soft cream page, never pure white; near-black text. */
  --bg-r: 251; --bg-g: 248; --bg-b: 241;
  --surface-r: 255; --surface-g: 253; --surface-b: 248;
  --text-r: 31; --text-g: 31; --text-b: 31;
  --text-muted-r: 64; --text-muted-g: 64; --text-muted-b: 64;
  --calm-bg: #fbf8f1;
  --calm-ink: #1f1f1f;
  --calm-muted: #404040;
  --calm-link: #084a9c;
}

html.calm.dark {
  /* Soft dark page, never pure black; light grey text. */
  --bg-r: 30; --bg-g: 30; --bg-b: 30;
  --surface-r: 40; --surface-g: 40; --surface-b: 40;
  --text-r: 236; --text-g: 236; --text-b: 236;
  --text-muted-r: 214; --text-muted-g: 214; --text-muted-b: 214;
  --calm-bg: #1e1e1e;
  --calm-ink: #ececec;
  --calm-muted: #d6d6d6;
  --calm-link: #cfe4ff;
}

html.calm .applish-ui,
html.calm.dark .applish-ui {
  --applish-ink: var(--calm-ink);
  --applish-muted: var(--calm-muted);
  --applish-accent-text: var(--calm-link);
  --applish-accent-text-hover: var(--calm-ink);
}

/* Plain background: no colour blobs, dot grid or decorative panels behind text. */
html.calm body,
html.calm body.applish-ui,
html.calm.dark body.applish-ui {
  background: var(--calm-bg);
  background-image: none;
  color: var(--calm-ink);
}

html.calm body.applish-ui::before,
html.calm body.applish-ui::after,
html.calm [data-calm="decoration"],
html.calm .applish-backdrop,
html.calm .applish-grid,
html.calm [data-calm="secondary"] {
  display: none;
}

/* No light-grey text in calm mode: every muted colour is raised to ≥ 7:1. */
html.calm :is(.text-muted, .text-gray-400, .text-gray-500, .text-slate-400, .text-slate-500,
  .text-neutral-400, .text-neutral-500, .text-zinc-400, .text-zinc-500) {
  color: var(--calm-muted);
}

/* See-through coloured labels (e.g. text-emerald-700/80) lose contrast on the
   cream page: make them solid and darker. */
html.calm:not(.dark) [class*="text-emerald-700/"] { color: #065f46; }

/* `secondary` = extra sections and lines a page can do without (spec §2.3):
   calm mode keeps only the essentials, like a government task page. */

/* ─── §2.1 Reading ───────────────────────────────────────────── */
html.calm {
  font-size: 112.5%; /* 18 px base; everything sized in rem scales with it */
}

html.calm body {
  line-height: 1.6;
  letter-spacing: 0.04em;
  word-spacing: 0.12em;
}

html.calm :is(p, li, dd, blockquote) {
  line-height: 1.6;
  text-align: left;
}

html.calm p {
  max-width: 65ch;
}

html.calm p + p {
  margin-top: 1.5em;
}

html.calm :is(em, i, .italic):not(cite) {
  font-style: normal;
}

html.calm :is(.uppercase, [class*="uppercase"]) {
  text-transform: none;
}

html.calm a:not([class*="btn"]):not([role="button"]):not([role="switch"]):not(nav a):not(:has(img, svg)) {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ─── No motion ──────────────────────────────────────────────── */
html.calm *,
html.calm *::before,
html.calm *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

/* ─── The switch itself ──────────────────────────────────────── */
/* Floats just under the navigation bar, right side, on every page. Solid dark
   pill with white text (≥ 15:1) so it is easy to see on any background. */
.calm-float {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 1rem;
  z-index: 40;
}
.calm-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem 0.5rem 1rem;
  border-radius: 9999px;
  border: 2px solid #ffffff;
  background: #111827;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.calm-toggle:hover { background: #000000; }
.calm-toggle:focus-visible { outline: 4px solid #facc15; outline-offset: 3px; }

/* Small on/off track: knob left = off, right with yellow = on. */
.calm-toggle-state {
  position: relative;
  width: 2.5rem;
  height: 1.4rem;
  border-radius: 9999px;
  background: #6b7280;
  flex-shrink: 0;
}
.calm-toggle-state::after {
  content: "";
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1rem;
  height: 1rem;
  border-radius: 9999px;
  background: #ffffff;
}
.calm-toggle[aria-checked="true"] .calm-toggle-state { background: #facc15; }
.calm-toggle[aria-checked="true"] .calm-toggle-state::after { left: auto; right: 0.2rem; background: #111827; }

/* Dark page: invert so the pill still stands out. */
html.dark .calm-toggle { background: #ffffff; color: #111827; border-color: #111827; }
html.dark .calm-toggle:hover { background: #f3f4f6; }

/* First 5 seconds of a visit: a pulsing yellow ring draws the eye.
   Not for people who ask for less motion, and never in calm mode. */
@media (prefers-reduced-motion: no-preference) {
  html:not(.calm) .calm-toggle.calm-flash { animation: calm-flash 1s ease-in-out 5; }
}
@keyframes calm-flash {
  0%, 100% { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.9), 0 6px 18px rgba(0, 0, 0, 0.25); transform: scale(1); }
  50% { box-shadow: 0 0 0 10px rgba(250, 204, 21, 0), 0 6px 18px rgba(0, 0, 0, 0.25); transform: scale(1.06); }
}

/* ─── Calm home: one question, one answer per screen ─────────── */
/* Screens are anchors (pages/home/_calm_path): only the targeted one shows,
   the question shows when none is targeted. Back button works, no JS. */
.calm-path [data-calm-step] { display: none; scroll-margin-top: 6rem; }
.calm-path [data-calm-step]:target,
.calm-path:not(:has([data-calm-step]:target)) [data-calm-step="start"] { display: block; }

.calm-choice {
  display: block;
  padding: 1rem 1.25rem;
  border: 2px solid rgb(var(--text-rgb));
  border-radius: 0.75rem;
  color: rgb(var(--text-rgb));
  text-decoration: none !important;
}
.calm-choice:hover { background: rgba(var(--text-rgb), 0.06); }

.calm-main-action {
  display: inline-block;
  margin-top: 2rem;
  padding: 0.875rem 1.5rem;
  border-radius: 0.75rem;
  background: rgb(var(--text-rgb));
  color: rgb(var(--bg-rgb));
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none !important;
}

/* Choice cards: 70 % words on the left, 30 % picture on the right. */
.calm-card {
  display: flex;
  min-height: 9rem;
  overflow: hidden;
  border: 2px solid rgb(var(--text-rgb));
  border-radius: 1rem;
  background: rgb(var(--surface-r) var(--surface-g) var(--surface-b));
  color: rgb(var(--text-rgb));
  text-decoration: none !important;
}
.calm-card:hover { background: rgba(var(--text-rgb), 0.05); }
.calm-card:focus-visible { outline: 4px solid var(--calm-link); outline-offset: 3px; }
.calm-card-text { flex: 0 0 70%; padding: 1.25rem 1.5rem; display: flex; flex-direction: column; justify-content: center; }
.calm-card-go { margin-top: 0.75rem; font-size: 1.75rem; font-weight: 700; line-height: 1; }
.calm-card-visual {
  flex: 0 0 30%;
  display: flex; align-items: center; justify-content: center;
  border-left: 2px solid rgb(var(--text-rgb));
  background: rgba(var(--text-rgb), 0.06);
}

/* Bigger calm text makes the desktop menu too wide between 1024 and 1279 px
   (the logo and links overlapped): use the phone menu there instead. */
@media (min-width: 1024px) and (max-width: 1279px) {
  html.calm .nav-desktop { display: none; }
  html.calm .nav-burger { display: block; }
  html.calm #mobile-menu:not(.hidden) { display: block; }
}

/* Phones: icon + on/off track only (the name stays for screen readers),
   still a 44 px tap target. */
@media (max-width: 639px) {
  .calm-float { right: 0.75rem; top: calc(100% + 0.375rem); }
  .calm-toggle { gap: 0.375rem; min-height: 2.75rem; min-width: 2.75rem; padding: 0.375rem 0.625rem; font-size: 0.875rem; }
  .calm-toggle-state { width: 2rem; height: 1.15rem; }
  .calm-toggle-state::after { width: 0.8rem; height: 0.8rem; top: 0.175rem; left: 0.175rem; }
  .calm-toggle[aria-checked="true"] .calm-toggle-state::after { right: 0.175rem; }
}
