/* Loci — design system.
 *
 * One dark theme, deliberately: the app is used in short high-attention bursts,
 * and a single stable theme keeps the imagery consistent. Layout is mobile-first
 * because this is a PWA meant to be opened on a phone for five minutes.
 */

:root {
  /* surfaces */
  --bg: #080b11;
  --bg-2: #0d121b;
  --surface: #121a26;
  --surface-2: #172130;
  --surface-3: #1e2a3b;
  --line: #24334a;
  --line-soft: #1a2534;

  /* text */
  --ink: #e9eef7;
  --ink-2: #b3c0d4;
  --ink-3: #7b8ba3;
  --ink-4: #55647c;

  /* module accents */
  --violet: #9b6bff;
  --gold: #f5b544;
  --rose: #ff5d8f;
  --azure: #4aa3ff;
  --ember: #ff6b35;
  --jade: #2ec4a6;
  --crimson: #e5484d;
  --lime: #9ede4a;

  --accent: var(--violet);

  /* type scale */
  --fs-xs: 11px;
  --fs-sm: 12.5px;
  --fs-md: 14.5px;
  --fs-lg: 17px;
  --fs-xl: 22px;
  --fs-2xl: 30px;
  --fs-3xl: 42px;

  /* spacing */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 26px;
  --r-full: 999px;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 6px 24px rgba(0, 0, 0, 0.45);
  --shadow-3: 0 18px 60px rgba(0, 0, 0, 0.6);

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --nav-h: 60px;
  --maxw: 1080px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(1100px 520px at 12% -8%, rgba(155, 107, 255, 0.16), transparent 62%),
    radial-gradient(900px 480px at 88% 4%, rgba(74, 163, 255, 0.11), transparent 60%);
  background-attachment: fixed;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.22; font-weight: 680; letter-spacing: -0.015em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p { margin: 0 0 var(--s3); }
a { color: var(--azure); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--azure); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------------------------------------------ layout */

.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 700; letter-spacing: -0.02em; }
.brand svg { width: 26px; height: 26px; }
.brand small { color: var(--ink-3); font-weight: 500; font-size: var(--fs-xs); letter-spacing: 0.06em; text-transform: uppercase; }

.topbarSpacer { flex: 1; }

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--s4) var(--s4) calc(var(--nav-h) + var(--s6));
}

@media (min-width: 760px) {
  .container { padding: var(--s5) var(--s5) var(--s7); }
}

.view { display: none; }
.view.active { display: block; animation: fade 0.22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------------- bottom nav */

.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  gap: 2px;
  height: var(--nav-h);
  padding: 6px max(6px, env(safe-area-inset-left)) max(6px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg-2) 94%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line-soft);
  overflow-x: auto;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }

.navBtn {
  flex: 1 0 auto;
  min-width: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  border-radius: var(--r-md);
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: color 0.15s, background 0.15s;
}
.navBtn .navIcon { font-size: 17px; line-height: 1; }
.navBtn:hover { color: var(--ink-2); background: rgba(255, 255, 255, 0.04); }
.navBtn.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.navBtn .navDot {
  position: absolute;
  margin: -18px 0 0 16px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--jade);
}

/* ------------------------------------------------------------------- cards */

.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: var(--s4);
  box-shadow: var(--shadow-1);
}
.card + .card { margin-top: var(--s3); }
.card.pad-lg { padding: var(--s5); }

.cardGrid { display: grid; gap: var(--s3); grid-template-columns: 1fr; }
@media (min-width: 560px) { .cardGrid.two { grid-template-columns: 1fr 1fr; } }
@media (min-width: 860px) { .cardGrid.three { grid-template-columns: repeat(3, 1fr); } }

.moduleCard {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  border-color: color-mix(in srgb, var(--m) 26%, var(--line-soft));
  background: linear-gradient(150deg, color-mix(in srgb, var(--m) 13%, var(--surface)), var(--bg-2) 72%);
  transition: transform 0.14s, border-color 0.14s, box-shadow 0.14s;
}
.moduleCard:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--m) 52%, var(--line)); box-shadow: var(--shadow-2); }
.moduleCard:active { transform: translateY(0); }
.moduleCard h3 { color: var(--m); }
.moduleCard .modArt { position: absolute; right: -18px; bottom: -16px; opacity: 0.16; pointer-events: none; }

.row { display: flex; align-items: center; gap: var(--s3); }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.stack.tight { gap: var(--s2); }
.center { text-align: center; }

.muted { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------- typography */

.eyebrow {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-4);
  font-weight: 700;
}
.lead { font-size: var(--fs-lg); color: var(--ink-2); line-height: 1.5; }
.stat { font-size: var(--fs-3xl); font-weight: 720; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat.sm { font-size: var(--fs-xl); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 650;
  background: var(--surface-3);
  color: var(--ink-2);
  border: 1px solid var(--line);
}
.pill.good { background: color-mix(in srgb, var(--jade) 18%, transparent); color: var(--jade); border-color: color-mix(in srgb, var(--jade) 36%, transparent); }
.pill.warn { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); border-color: color-mix(in srgb, var(--gold) 36%, transparent); }
.pill.bad  { background: color-mix(in srgb, var(--crimson) 18%, transparent); color: var(--crimson); border-color: color-mix(in srgb, var(--crimson) 36%, transparent); }
.pill.info { background: color-mix(in srgb, var(--azure) 18%, transparent); color: var(--azure); border-color: color-mix(in srgb, var(--azure) 36%, transparent); }

kbd {
  font-family: var(--mono);
  font-size: var(--fs-xs);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--ink-2);
}

/* ----------------------------------------------------------------- buttons */

button.primary, button.ghost, button.danger, button.subtle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: 10px 16px;
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: 640;
  cursor: pointer;
  border: 1px solid transparent;
  transition: filter 0.14s, background 0.14s, border-color 0.14s, transform 0.08s;
  white-space: nowrap;
}
button.primary { background: var(--accent); color: #07090e; border-color: color-mix(in srgb, var(--accent) 70%, #fff); }
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); }
button.ghost:hover { background: var(--surface-3); color: var(--ink); }
button.danger { background: color-mix(in srgb, var(--crimson) 22%, transparent); color: var(--crimson); border-color: color-mix(in srgb, var(--crimson) 42%, transparent); }
button.subtle { background: transparent; color: var(--ink-3); padding: 8px 10px; }
button.subtle:hover { color: var(--ink); background: rgba(255, 255, 255, 0.05); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.lg { padding: 14px 22px; font-size: var(--fs-lg); border-radius: var(--r-lg); }
button.block { width: 100%; }
button.icon { padding: 9px 11px; }

.btnRow { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ---------------------------------------------------------------- segmented */

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 100%;
}
.segmented::-webkit-scrollbar { display: none; }
.seg {
  border: 0;
  background: transparent;
  color: var(--ink-3);
  padding: 6px 12px;
  border-radius: 9px;
  font-size: var(--fs-sm);
  font-weight: 620;
  cursor: pointer;
  white-space: nowrap;
}
.seg:hover { color: var(--ink); }
.seg.active { background: var(--surface-3); color: var(--ink); box-shadow: var(--shadow-1); }

/* ------------------------------------------------------------------ inputs */

input.text, textarea.text, select.text {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--ink);
  font-size: var(--fs-lg);
  font-family: inherit;
}
input.text:focus, textarea.text:focus, select.text:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input.text.big { font-size: var(--fs-xl); text-align: center; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }
textarea.text { min-height: 90px; resize: vertical; line-height: 1.55; }
label.field { display: block; margin-bottom: var(--s3); }
label.field > span { display: block; font-size: var(--fs-sm); color: var(--ink-3); margin-bottom: 5px; font-weight: 600; }

/* ------------------------------------------------------------------ meters */

.meter { height: 7px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; }
.meterFill { height: 100%; background: var(--accent); border-radius: var(--r-full); transition: width 0.35s ease; }

/* ------------------------------------------------------------------- art */

.art { display: block; }
.art.room { width: 100%; height: auto; border-radius: var(--r-md); }
.art.face { border-radius: var(--r-md); }
.art.anchor { opacity: 0.95; }

.locusGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: var(--s2);
}
.locusTile {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-2), var(--bg-2));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s1);
  cursor: pointer;
  transition: border-color 0.14s, transform 0.1s;
}
.locusTile:hover { border-color: var(--accent); transform: translateY(-1px); }
.locusTile.empty { border-style: dashed; opacity: 0.55; }
.locusTile.correct { border-color: var(--jade); box-shadow: 0 0 0 2px color-mix(in srgb, var(--jade) 40%, transparent); }
.locusTile.wrong { border-color: var(--crimson); box-shadow: 0 0 0 2px color-mix(in srgb, var(--crimson) 40%, transparent); }
.locusTile .num {
  position: absolute; top: 4px; left: 6px;
  font-size: var(--fs-xs); font-weight: 700; color: var(--ink-4);
  font-family: var(--mono);
}
.locusTile .cap {
  position: absolute; bottom: 3px; left: 0; right: 0;
  text-align: center; font-size: 9.5px; color: var(--ink-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px;
}

.itemChip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-full); padding: 4px 11px;
  font-size: var(--fs-sm); font-weight: 600;
}
.itemChip.pick { cursor: pointer; }
.itemChip.pick:hover { border-color: var(--accent); background: var(--surface-3); }
.itemChip.used { opacity: 0.3; pointer-events: none; }

/* --------------------------------------------------------------- stimulus */

.stage {
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  padding: var(--s4);
  border-radius: var(--r-lg);
  background: radial-gradient(circle at 50% 40%, var(--surface-2), var(--bg-2) 74%);
  border: 1px solid var(--line-soft);
}

.flashItem { font-size: clamp(38px, 13vw, 72px); font-weight: 750; letter-spacing: 0.04em; }
.flashItem.sm { font-size: clamp(24px, 7vw, 40px); }

.digitString {
  font-family: var(--mono);
  font-size: clamp(26px, 8.5vw, 48px);
  font-weight: 700;
  letter-spacing: 0.14em;
  word-break: break-all;
  text-align: center;
}

.corsiGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s3);
  width: min(340px, 84vw);
}
.corsiBlock {
  aspect-ratio: 1;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.12s, transform 0.1s, border-color 0.12s;
}
.corsiBlock.lit { background: var(--azure); border-color: var(--azure); transform: scale(1.05); }
.corsiBlock.picked { background: color-mix(in srgb, var(--azure) 34%, transparent); border-color: var(--azure); }
.corsiBlock:disabled { cursor: default; }
.corsiBlock.hit { background: var(--jade); border-color: var(--jade); }
.corsiBlock.miss { background: var(--crimson); border-color: var(--crimson); }

.picGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: var(--s2);
  width: 100%;
}
.picTile {
  aspect-ratio: 1;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, var(--surface-2), var(--bg-2));
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.1s;
}
.picTile:hover { border-color: var(--azure); transform: translateY(-1px); }
.picTile.correct { border-color: var(--jade); }
.picTile.wrong { border-color: var(--crimson); }

.faceGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: var(--s3); }
.faceCard {
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-2), var(--bg-2));
  padding: var(--s2);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.13s, transform 0.1s;
}
.faceCard:hover { border-color: var(--rose); transform: translateY(-2px); }
.faceCard.correct { border-color: var(--jade); }
.faceCard.wrong { border-color: var(--crimson); }
.faceCard .name { font-weight: 680; font-size: var(--fs-md); margin-top: 4px; }

/* ------------------------------------------------------------------ charts */

.chart { width: 100%; height: auto; overflow: visible; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .gridline { stroke: var(--line-soft); stroke-width: 1; stroke-dasharray: 3 5; }
.chart .line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: 0.13; }
.chart .dot { stroke: var(--bg); stroke-width: 2; }
.chart text { fill: var(--ink-4); font-size: 9px; font-family: var(--sans); }
.chart .chartLabel { fill: var(--ink-3); font-size: 10px; font-weight: 600; }

.legend { display: flex; gap: var(--s3); flex-wrap: wrap; font-size: var(--fs-sm); color: var(--ink-3); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

/* ------------------------------------------------------------------ toasts */

.toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 14px);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  align-items: center;
  pointer-events: none;
  width: min(440px, 92vw);
}
.toast {
  padding: 11px 16px;
  border-radius: var(--r-md);
  background: var(--surface-3);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  animation: toastIn 0.22s ease;
  width: 100%;
  text-align: center;
}
.toast.good { border-color: color-mix(in srgb, var(--jade) 50%, transparent); color: var(--jade); }
.toast.bad { border-color: color-mix(in srgb, var(--crimson) 50%, transparent); color: var(--crimson); }
.toast.leaving { opacity: 0; transform: translateY(8px); transition: opacity 0.3s, transform 0.3s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------- modal */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
  opacity: 0;
  transition: opacity 0.2s;
}
.overlay.shown { opacity: 1; }
.modal {
  width: min(560px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: var(--s5);
  box-shadow: var(--shadow-3);
  transform: translateY(10px) scale(0.98);
  transition: transform 0.22s ease;
}
.overlay.shown .modal { transform: none; }
.modalTitle { margin-bottom: var(--s3); }
.modalActions { display: flex; gap: var(--s2); justify-content: flex-end; margin-top: var(--s4); flex-wrap: wrap; }

/* ------------------------------------------------------------------ tables */

table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.data th, table.data td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); }
table.data th { color: var(--ink-4); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
table.data tr:last-child td { border-bottom: 0; }

/* --------------------------------------------------------------- evidence */

.claim {
  border-left: 3px solid var(--line);
  padding: var(--s3) var(--s4);
  background: var(--surface);
  border-radius: 0 var(--r-md) var(--r-md) 0;
}
.claim.works { border-left-color: var(--jade); }
.claim.mixed { border-left-color: var(--gold); }
.claim.debunked { border-left-color: var(--crimson); }
.claim h4 { margin-bottom: 5px; }
.claim cite { display: block; margin-top: 7px; color: var(--ink-4); font-size: var(--fs-xs); font-style: normal; font-family: var(--mono); }

details.ref {
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: var(--s2) var(--s3);
  background: var(--bg-2);
}
details.ref summary { cursor: pointer; font-weight: 620; font-size: var(--fs-sm); color: var(--ink-2); }
details.ref summary:hover { color: var(--ink); }
details.ref .refBody { padding-top: var(--s3); font-size: var(--fs-sm); color: var(--ink-2); }

/* --------------------------------------------------------------- counters */

.timerRing { transform: rotate(-90deg); }
.timerRing circle { fill: none; stroke-width: 5; stroke-linecap: round; }
.timerRing .track { stroke: var(--line-soft); }
.timerRing .prog { stroke: var(--accent); transition: stroke-dashoffset 0.1s linear; }

.countdown { font-family: var(--mono); font-size: var(--fs-2xl); font-weight: 700; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
