/* Immune Ops styles. Light and dark themes via custom properties. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #d5dbe3;
  --text: #17202b;
  --muted: #566273;
  --accent: #0b7a64;
  --accent-ink: #ffffff;
  --accent-soft: #d8f0ea;
  --warn: #a14d00;
  --warn-soft: #fbe9d6;
  --danger: #b4232f;
  --danger-soft: #f8dcdf;
  --good: #1d7a3a;
  --good-soft: #dcf1e2;
  --focus: #1b5fd1;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 14px rgb(0 0 0 / 6%);

  /* Game canvas palette */
  --g-canvas-bg: #f2f5f8;
  --g-grid: #e1e7ee;
  --g-path: #fbe3e1;
  --g-path-edge: #efc3bf;
  --g-text: #17202b;
  --g-muted: #5d6a7a;
  --g-barrier: #b07a4f;
  --g-barrier-breach: #d33c3c;
  --g-core: #3b5b8c;
  --g-cell: #e9a9a2;
  --g-cell-infected: #c0283a;
  --g-bacteria: #4f9a2d;
  --g-virus: #c02686;
  --g-virus-alt: #7a3fd0;
  --g-neutrophil: #2a74c9;
  --g-macrophage: #7b4bb3;
  --g-dendritic: #c2700f;
  --g-bcell: #b38b00;
  --g-ctl: #0a8f8f;
  --g-antibody: #a87f00;
  --g-slot: #9aa7b6;
  --g-slot-active: #0b7a64;
  --g-danger: #c0283a;
  --g-accent: #1d9a55;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1319;
    --surface: #151c25;
    --surface-2: #1c2531;
    --border: #2b3746;
    --text: #e4eaf1;
    --muted: #9aa8b8;
    --accent: #3cc9a6;
    --accent-ink: #062019;
    --accent-soft: #123a31;
    --warn: #f0a252;
    --warn-soft: #3a2611;
    --danger: #f2707a;
    --danger-soft: #3d1a1e;
    --good: #5fd08a;
    --good-soft: #143222;
    --focus: #7fb0ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 18px rgb(0 0 0 / 30%);

    --g-canvas-bg: #0f151c;
    --g-grid: #18212b;
    --g-path: #2a1a20;
    --g-path-edge: #3d222a;
    --g-text: #e4eaf1;
    --g-muted: #8796a8;
    --g-barrier: #c99566;
    --g-barrier-breach: #ff5b5b;
    --g-core: #6f95d6;
    --g-cell: #a8655f;
    --g-cell-infected: #ff4d6a;
    --g-bacteria: #7fd34e;
    --g-virus: #ff5cc0;
    --g-virus-alt: #b48cff;
    --g-neutrophil: #5aa8ff;
    --g-macrophage: #b38cf0;
    --g-dendritic: #ffa94d;
    --g-bcell: #ffd84d;
    --g-ctl: #33d6d6;
    --g-antibody: #ffe27a;
    --g-slot: #4d5c6e;
    --g-slot-active: #3cc9a6;
    --g-danger: #ff4d6a;
    --g-accent: #4fe08a;

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1319;
  --surface: #151c25;
  --surface-2: #1c2531;
  --border: #2b3746;
  --text: #e4eaf1;
  --muted: #9aa8b8;
  --accent: #3cc9a6;
  --accent-ink: #062019;
  --accent-soft: #123a31;
  --warn: #f0a252;
  --warn-soft: #3a2611;
  --danger: #f2707a;
  --danger-soft: #3d1a1e;
  --good: #5fd08a;
  --good-soft: #143222;
  --focus: #7fb0ff;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 18px rgb(0 0 0 / 30%);
  --g-canvas-bg: #0f151c;
  --g-grid: #18212b;
  --g-path: #2a1a20;
  --g-path-edge: #3d222a;
  --g-text: #e4eaf1;
  --g-muted: #8796a8;
  --g-barrier: #c99566;
  --g-barrier-breach: #ff5b5b;
  --g-core: #6f95d6;
  --g-cell: #a8655f;
  --g-cell-infected: #ff4d6a;
  --g-bacteria: #7fd34e;
  --g-virus: #ff5cc0;
  --g-virus-alt: #b48cff;
  --g-neutrophil: #5aa8ff;
  --g-macrophage: #b38cf0;
  --g-dendritic: #ffa94d;
  --g-bcell: #ffd84d;
  --g-ctl: #33d6d6;
  --g-antibody: #ffe27a;
  --g-slot: #4d5c6e;
  --g-slot-active: #3cc9a6;
  --g-danger: #ff4d6a;
  --g-accent: #4fe08a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

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;
  overflow-x: hidden;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 1.6em 0 0.5em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); margin-top: 0.8em; letter-spacing: -0.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 1em 0 0.2em; }
p { margin: 0 0 0.9em; }
a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, canvas:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.wrap.narrow { max-width: 760px; }

.skip {
  position: absolute; left: -999px; top: 8px;
  background: var(--surface); color: var(--text); padding: 8px 12px; border-radius: 6px; z-index: 100;
}
.skip:focus { left: 8px; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.brand-mark { width: 26px; height: 26px; }
.mark-shield { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.mark-y { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; }
.nav { list-style: none; display: flex; gap: 2px; margin: 0; padding: 0; flex-wrap: wrap; }
.nav a {
  display: block; padding: 6px 10px; border-radius: 8px; color: var(--muted);
  text-decoration: none; font-weight: 600; font-size: 0.95rem;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

main { padding-bottom: 48px; }

/* Home */
.hero { padding: 24px 0 8px; max-width: 760px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.78rem; font-weight: 700; color: var(--accent); margin: 0 0 0.4em; }
.lede { font-size: 1.12rem; color: var(--muted); }
.cta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.steps { padding-left: 1.2em; }
.steps li { margin-bottom: 0.5em; }
.mission-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.mission { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.mission strong { display: block; }
.mission-num {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800;
}
.mission-tag { font-size: 0.88rem; color: var(--muted); }
.compare { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.compare-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.compare-col h3 { margin-top: 0; }
.it-line { color: var(--muted); font-style: italic; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 85%, var(--text)); }
.btn-warn { border-color: color-mix(in srgb, var(--warn) 50%, var(--border)); color: var(--warn); }
.btn-ghost { background: transparent; border-color: transparent; padding-left: 0; color: var(--accent); }
.btn-ghost:hover { background: transparent; text-decoration: underline; }

/* Level select */
.level-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.level-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.level-card h2 { margin: 0 0 0.4em; font-size: 1.15rem; }
.level-card p:not(.eyebrow) { color: var(--muted); font-size: 0.95rem; flex: 1; }
.level-card-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.badge { font-size: 0.8rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge-good { background: var(--good-soft); color: var(--good); }

/* Game screen */
.game-top { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-top: 12px; }
.level-title { margin: 0; font-size: 1.4rem; }
.hud { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 2fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; min-width: 0; }
.stat .label { display: block; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }
.stat .value { display: block; font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-wide .value { font-size: 1rem; padding-top: 3px; }
.meter { display: block; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.meter span { display: block; height: 100%; width: 100%; background: var(--good); transition: width 0.2s; }
.meter span.mid { background: var(--warn); }
.meter span.low { background: var(--danger); }

.stage { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--g-canvas-bg); }
#game-canvas { display: block; width: 100%; aspect-ratio: 16 / 9; height: auto; touch-action: manipulation; }

.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 70%, transparent); padding: 16px; overflow: auto;
}
.overlay-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  max-width: 640px; width: 100%; max-height: 100%; overflow: auto; padding: 20px 22px;
}
.overlay-card h2 { margin-top: 0; }
.overlay-card ul { padding-left: 1.2em; }
.overlay-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.objective { background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; }
.compare-note { background: var(--good-soft); border-radius: 8px; padding: 8px 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 12px 0; }
.stats div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.stats dt { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.stats dd { margin: 0; font-weight: 800; font-size: 1.15rem; }

/* On small screens the overlay covers the viewport instead of the small canvas. */
@media (max-width: 720px) {
  .overlay { position: fixed; z-index: 50; align-items: flex-start; }
  body.overlay-open { overflow: hidden; }
  .hud { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-wide { grid-column: 1 / -1; }
}

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 14px; align-items: start; }
@media (max-width: 1000px) { .game-layout { grid-template-columns: 1fr; } }
.game-side { min-width: 0; }
.rotate-tip { display: none; font-size: 0.9rem; color: var(--muted); margin: 0 0 8px; }
@media (max-width: 600px) and (orientation: portrait) { .rotate-tip { display: block; } }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.controls .btn { flex: 1 1 auto; }
.small-heading { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 8px 0; }
.hint { text-transform: none; letter-spacing: 0; font-weight: 500; margin-left: 6px; }
@media (hover: none) { .hint { display: none; } }
.cards { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (max-width: 1000px) { .cards { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.card {
  display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; align-items: center; gap: 2px 10px;
  text-align: left; padding: 8px 12px; border-radius: var(--radius);
  border: 2px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.card:hover { border-color: var(--muted); }
.card[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.card .swatch { grid-row: 1 / span 2; width: 22px; height: 22px; border-radius: 50%; }
.card-text { display: flex; flex-direction: column; min-width: 0; }
.card-name { font-weight: 750; }
.card-it { font-size: 0.82rem; color: var(--muted); }
.card-cost { font-weight: 750; font-variant-numeric: tabular-nums; font-size: 0.92rem; white-space: nowrap; }
.card-lock { grid-column: 2 / -1; font-size: 0.78rem; color: var(--warn); }
.card-lock:empty { display: none; }
.card.is-locked { opacity: 0.6; }
.card.is-poor .card-cost { color: var(--danger); }
.swatch-neutrophil { background: var(--g-neutrophil); }
.swatch-macrophage { background: var(--g-macrophage); }
.swatch-dendritic { background: var(--g-dendritic); }
.swatch-bcell { background: var(--g-bcell); }
.swatch-ctl { background: var(--g-ctl); }

.info { margin-top: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; font-size: 0.95rem; }
.info .small-heading { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 1.05rem; }
.info-it { color: var(--muted); font-weight: 500; }
.info-bio { color: var(--muted); }
.info-extra { color: var(--warn); font-weight: 600; }

.log { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.log li { background: var(--surface); border: 1px solid var(--border); border-left-width: 4px; border-radius: 8px; padding: 6px 10px; font-size: 0.92rem; }
.log-day { font-weight: 750; color: var(--muted); margin-right: 8px; font-variant-numeric: tabular-nums; }
.log-good { border-left-color: var(--good) !important; }
.log-warn { border-left-color: var(--warn) !important; }
.log-danger { border-left-color: var(--danger) !important; }
.log-info { border-left-color: var(--focus) !important; }

/* Field Manual */
.toc ul { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.toc a { display: inline-block; padding: 4px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); text-decoration: none; font-size: 0.92rem; font-weight: 600; }
.manual-group { scroll-margin-top: 72px; }
.manual-group h2 { scroll-margin-top: 72px; }
.manual-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.entry { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px 6px; }
.entry-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; justify-content: space-between; }
.entry-head h3 { margin: 0; }
.tag { font-size: 0.8rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.entry p { font-size: 0.95rem; }

.chart { margin: 12px 0 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart figcaption { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.chart-grid line { stroke: var(--border); stroke-width: 1; }
.chart-ticks text { fill: var(--muted); font-size: 12px; text-anchor: middle; }
.chart-axis { fill: var(--muted); font-size: 13px; font-weight: 700; text-anchor: middle; }
.chart-primary { fill: none; stroke: var(--g-neutrophil); stroke-width: 3; }
.chart-secondary { fill: none; stroke: var(--accent); stroke-width: 3; }
.chart-marker { stroke: var(--muted); stroke-dasharray: 4 4; }
.chart-label { fill: var(--muted); font-size: 12px; }
.chart-note { font-size: 13px; font-weight: 700; }
.chart-note.primary { fill: var(--g-neutrophil); }
.chart-note.secondary { fill: var(--accent); }

/* Quiz */
.question { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 12px 16px; margin: 0 0 14px; }
.question legend { font-weight: 700; padding: 0 4px; }
.q-num { color: var(--accent); }
.option { display: flex; gap: 10px; align-items: flex-start; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.option:hover { background: var(--surface-2); }
.option input { margin-top: 0.35em; accent-color: var(--accent); }
.question.right { border-color: var(--good); }
.question.wrong { border-color: var(--danger); }
.question.right .option.is-answer, .question.wrong .option.is-answer { background: var(--good-soft); font-weight: 650; }
.feedback { margin: 8px 0 0; font-size: 0.94rem; color: var(--muted); }
.quiz-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.quiz-result { margin-top: 18px; background: var(--accent-soft); border-radius: var(--radius); padding: 12px 16px; }
.quiz-result h2 { margin-top: 0; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 0.88rem; padding: 18px 0; }
.site-footer p { margin: 0; }

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