/* Undercover Nerd Project design system (single source: design/ui.css).
   Copied into every deployable by tools/make-pages.py. Pattern guide: design/README.md.

   Principles: calm, spacious, one primary action per screen, short labels,
   help on demand (the "?" anchor) instead of paragraphs, mobile first. */

/* ---------- tokens ---------- */
:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --surface-2: #f2f0e9;
  --text: #15161a;
  --muted: #62666f;
  --border: #e4e1d7;
  --brand: #ffb900;           /* brand yellow: primary actions */
  --brand-text: #15161a;
  --link: #0b5cd5;
  --focus: #1f6feb;
  --tile: #f3d9a4;
  --tile-edge: #d9b266;
  --tile-text: #3b2a0a;
  --shadow: 0 1px 2px rgb(20 20 30 / 0.05), 0 8px 24px rgb(20 20 30 / 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px; --space-7: 48px;
  --container: 720px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121418; --surface: #1b1e24; --surface-2: #252932; --text: #eceef2; --muted: #a2a8b4; --border: #2f343e;
    --link: #8ab4ff; --focus: #8bb8ff; --tile: #c99f55; --tile-edge: #8f6d30; --tile-text: #1f1604;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121418; --surface: #1b1e24; --surface-2: #252932; --text: #eceef2; --muted: #a2a8b4; --border: #2f343e;
  --link: #8ab4ff; --focus: #8bb8ff; --tile: #c99f55; --tile-edge: #8f6d30; --tile-text: #1f1604;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.35);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--link); text-underline-offset: 3px; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.75rem, 5vw, 2.25rem); margin: 0; }
h2 { font-size: 1.25rem; margin: var(--space-6) 0 var(--space-2); }
h3 { font-size: 1.05rem; margin: var(--space-5) 0 var(--space-1); }
p, li { max-width: 68ch; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
kbd { font: 600 0.85em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 0.4em; }

/* ---------- layout ---------- */
.container { width: min(100% - 2rem, var(--container)); margin-inline: auto; }
.skip { position: absolute; left: -999px; top: 0; background: var(--brand); color: var(--brand-text); padding: var(--space-2) var(--space-4); z-index: 100; }
.skip:focus { left: 0; }
.page-head { padding: var(--space-5) 0 var(--space-4); }
.page-head .sub { margin: var(--space-1) 0 0; color: var(--muted); }
.title-row { display: flex; align-items: center; gap: var(--space-2); }
.stack > * + * { margin-top: var(--space-4); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-4); }

/* ---------- header / footer ---------- */
.app-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) 0 var(--space-1); }
.brand { display: inline-flex; align-items: center; gap: var(--space-2); min-width: 0; color: var(--text); font-weight: 700; text-decoration: none; }
.brand img { height: 36px; width: auto; flex: none; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-nav { display: flex; align-items: center; gap: 2px; }
.app-nav a { display: inline-flex; align-items: center; min-height: 40px; padding: 0 var(--space-3); border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-size: 0.93rem; font-weight: 600; }
.app-nav a:hover, .app-nav a[aria-current="page"] { background: var(--surface-2); }
@media (max-width: 560px) {
  .brand span { display: none; }
  .app-nav a { padding: 0 var(--space-2); font-size: 0.88rem; }
}
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; background: transparent; color: var(--text); border: 0; border-radius: 50%; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.i-sun { display: none; }
#theme-toggle[aria-pressed="true"] .i-sun { display: block; }
#theme-toggle[aria-pressed="true"] .i-moon { display: none; }

.crumbs ol { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-2); list-style: none; margin: var(--space-2) 0 0; padding: 0; font-size: 0.85rem; color: var(--muted); }
.crumbs li + li::before { content: "›"; margin-right: var(--space-2); }
.crumbs a { color: var(--muted); }

.app-footer { margin-top: var(--space-7); padding: var(--space-5) 0 var(--space-6); border-top: 1px solid var(--border); color: var(--muted); font-size: 0.88rem; }
.app-footer nav { display: flex; flex-wrap: wrap; gap: 0 var(--space-5); margin-bottom: var(--space-2); }
.app-footer a { color: var(--muted); display: inline-block; padding: var(--space-1) 0; }
.app-footer p { margin: var(--space-1) 0; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-5); box-shadow: var(--shadow); }
@media (max-width: 480px) { .card { padding: var(--space-4); } }

/* ---------- form controls ---------- */
.label-row { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.label, .label-row label, .label-row legend { font-size: 0.85rem; font-weight: 700; color: var(--muted); padding: 0; margin: 0; }
.control { border: 0; padding: 0; margin: 0; min-width: 0; }
input[type="text"], select {
  width: 100%; min-height: 48px; padding: 0 var(--space-3); background: var(--bg); color: var(--text);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm); font: inherit;
}
input[type="text"]:focus-visible, select:focus-visible { border-color: var(--focus); outline-offset: 0; }
.input-lg { font-size: 1.3rem; font-weight: 600; letter-spacing: 0.05em; min-height: 56px; }
.field { position: relative; }
.field .icon-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.field input { padding-right: 52px; }

.seg { display: flex; gap: 0; border: 1.5px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg); }
.seg label { flex: 1; margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: grid; place-items: center; min-height: 45px; padding: 0 var(--space-2); text-align: center; font-weight: 600; font-size: 0.93rem; cursor: pointer; color: var(--text); }
.seg input:checked + span { background: var(--text); color: var(--bg); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: -3px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: 50px; padding: 0 var(--space-5);
  border: 0; border-radius: var(--radius-sm); font: inherit; font-weight: 800; text-decoration: none; cursor: pointer;
  background: var(--brand); color: var(--brand-text);
}
.btn:hover { filter: brightness(0.96); }
.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn-quiet { background: var(--surface-2); color: var(--text); font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.chip {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 var(--space-3); background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px; font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
.chip:hover { border-color: var(--text); }

details.more > summary, details.fold > summary { cursor: pointer; list-style: none; }
details.more > summary::-webkit-details-marker, details.fold > summary::-webkit-details-marker { display: none; }
details.more > summary { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 40px; font-weight: 700; font-size: 0.93rem; color: var(--muted); }
details.more > summary::before { content: "+"; display: inline-grid; place-items: center; width: 20px; height: 20px; border: 1.5px solid currentColor; border-radius: 50%; font-size: 0.85rem; line-height: 1; }
details.more[open] > summary::before { content: "–"; }
details.more > summary:hover { color: var(--text); }
details.more > .row { margin-top: var(--space-3); }

/* ---------- accordion (long-form content kept out of the way) ---------- */
.fold { border-bottom: 1px solid var(--border); }
.fold:first-of-type { border-top: 1px solid var(--border); }
.fold > summary { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); min-height: 52px; padding: var(--space-2) 2px; }
.fold > summary h2, .fold > summary h3 { margin: 0; font-size: 1.02rem; font-weight: 700; }
.fold > summary::after { content: ""; flex: none; width: 8px; height: 8px; margin-right: 4px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform 0.2s; }
.fold[open] > summary::after { transform: rotate(-135deg); }
.fold > summary:hover h2, .fold > summary:hover h3 { color: var(--link); }
.fold-body { padding: 0 2px var(--space-5); }
.fold-body > :first-child { margin-top: var(--space-1); }

/* ---------- help anchor: tiny "?" that reveals a short tip on hover, focus or tap ---------- */
.help-wrap { position: relative; display: inline-flex; vertical-align: middle; }
.help {
  display: inline-grid; place-items: center; width: 22px; height: 22px; padding: 0; background: transparent; color: var(--muted);
  border: 1.5px solid var(--border); border-radius: 50%; font: 700 0.75rem/1 system-ui, sans-serif; cursor: help;
}
.help::before { content: ""; position: absolute; inset: -11px; }       /* 44px touch target */
.help:hover, .help[aria-expanded="true"] { color: var(--text); border-color: var(--text); background: var(--surface-2); }
.help-pop {
  position: absolute; z-index: 50; top: calc(100% + 10px); left: 50%; width: max-content; max-width: min(18rem, calc(100vw - 2rem));
  transform: translateX(calc(-50% + var(--shift, 0px)));
  padding: var(--space-3) var(--space-4); background: var(--text); color: var(--bg); border-radius: var(--radius-sm);
  font-size: 0.88rem; font-weight: 500; line-height: 1.5; text-align: left; box-shadow: var(--shadow);
}
.help-pop::before {
  content: ""; position: absolute; top: -5px; left: calc(50% - var(--shift, 0px)); width: 10px; height: 10px; background: inherit;
  transform: translateX(-50%) rotate(45deg);
}
.help-pop b { font-weight: 800; }
.help-pop a { color: inherit; text-decoration: underline; }
.help-pop ol, .help-pop ul { margin: var(--space-1) 0 0; padding-left: 1.1rem; }
.help-pop li { margin: 2px 0; max-width: none; }
.help-pop kbd { background: rgb(255 255 255 / 0.15); border-color: rgb(255 255 255 / 0.3); color: inherit; }
:root[data-theme="dark"] .help-pop kbd { background: rgb(0 0 0 / 0.12); border-color: rgb(0 0 0 / 0.25); }
@media (max-width: 600px) {                                              /* bottom sheet on phones */
  .help-pop {
    position: fixed; left: var(--space-4); right: var(--space-4); bottom: calc(var(--space-4) + env(safe-area-inset-bottom)); top: auto;
    width: auto; max-width: none; transform: none; padding: var(--space-4) var(--space-5); font-size: 0.95rem;
  }
  .help-pop::before { display: none; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 60;
  background: var(--text); color: var(--bg); padding: var(--space-2) var(--space-4); border-radius: 999px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- letter tiles (shared motif) ---------- */
.tile {
  display: inline-grid; place-items: center; width: 34px; height: 38px; text-transform: uppercase;
  background: var(--tile); color: var(--tile-text); border-radius: 6px; box-shadow: 0 2px 0 var(--tile-edge);
  font: 800 1.1rem/1 system-ui, sans-serif;
}
.tile-blank { background: var(--surface-2); box-shadow: 0 2px 0 var(--border); border: 1.5px dashed var(--muted); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}
