:root {
  --bg: #0f172a;
  --panel: #1f2937;
  --panel-soft: rgba(31, 41, 55, .95);
  --border: #374151;
  --text: #f9fafb;
  --muted: #cbd5e1;
  --muted-2: #94a3b8;
  --accent: #60a5fa;
  --accent-2: #bfdbfe;
  --success: #86efac;
  --warning: #fde68a;
  --danger: #fca5a5;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; min-height: 100%; overflow: hidden; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 10%, rgba(59, 130, 246, .16), transparent 30%),
    linear-gradient(145deg, #111827, #0f172a 58%, #111827);
  color: var(--text);
  font: 16px/1.45 Arial, Helvetica, sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; }
button {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 800;
  background: var(--accent);
  color: #0f172a;
  transition: transform .12s ease, filter .12s ease, background .12s ease;
}
button:hover { transform: translateY(-1px); filter: brightness(1.06); }
button.secondary { background: #374151; color: var(--text); }

button.danger { background: #7f1d1d; color: #fee2e2; border: 1px solid #ef4444; }
button.danger:hover { filter: brightness(1.08); }
.cta-button { min-width: 180px; padding: 12px 18px; font-size: 16px; box-shadow: 0 10px 24px rgba(59,130,246,.28); }
.header-run-button { background: linear-gradient(145deg, #86efac, #4ade80); color: #052e16; border: 1px solid #22c55e; box-shadow: 0 8px 20px rgba(34,197,94,.28); }
.header-run-button:hover { filter: brightness(1.04); }
button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.app-shell { max-width: 1500px; height: 100vh; height: 100dvh; margin: 0 auto; padding: 12px 14px 10px; display: flex; flex-direction: column; overflow: hidden; }
.brand-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 12px; padding-right: 104px; }
.brand-lockup { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 58px; height: 58px; display: grid; place-items: center; border-radius: 18px;
  background: linear-gradient(145deg, #2563eb, #60a5fa); box-shadow: 0 10px 24px rgba(37,99,235,.28);
  border: 1px solid rgba(191,219,254,.55); font-weight: 900; font-size: 20px; color: #fff;
}
.brand-copy { min-width: 0; }
.brand-copy h1 { margin: 0; font-size: clamp(22px, 3.2vw, 34px); letter-spacing: -.03em; }
.brand-copy p { margin: 3px 0 0; color: var(--muted-2); font-size: 13px; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.status-chip { padding: 8px 11px; border-radius: 999px; background: rgba(31,41,55,.8); border: 1px solid var(--border); color: var(--muted); font-size: 12px; font-weight: 800; }
.game-card { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 18px; overflow: hidden; background: var(--panel-soft); box-shadow: 0 18px 42px rgba(0,0,0,.3); }
.game-topbar { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: rgba(17,24,39,.92); }
.stage-progress { display: flex; gap: 6px; min-width: 0; }
.stage-pill { flex: 1 1 0; min-width: 0; text-align: center; padding: 7px 8px; border-radius: 8px; background: #111827; border: 1px solid #334155; color: #94a3b8; font-size: 11px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-pill.active { color: #eff6ff; border-color: #60a5fa; background: rgba(37,99,235,.25); }
.stage-pill.complete { color: #dcfce7; border-color: #4ade80; background: rgba(22,101,52,.25); }
.score-cluster { display: flex; gap: 10px; color: var(--muted-2); font-size: 11px; font-weight: 800; white-space: nowrap; }
.score-cluster strong { color: #fff; font-size: 15px; margin-left: 3px; font-variant-numeric: tabular-nums; }
.timer { min-width: 74px; text-align: center; font-weight: 900; color: var(--accent-2); font-variant-numeric: tabular-nums; }
.canvas-wrap { position: relative; flex: 1 1 auto; min-height: 0; width: 100%; background: #070d18; overflow: hidden; display: flex; align-items: center; justify-content: center; }
#gameCanvas { display: block; width: auto; height: auto; max-width: 100%; max-height: 100%; aspect-ratio: 16 / 9; background: #0b1220; touch-action: none; flex: 0 0 auto; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(15,23,42,.75); backdrop-filter: blur(3px); z-index: 5; }
.overlay[hidden] { display: none; }
.overlay-card { width: min(650px, 94%); padding: 22px; border: 1px solid #475569; border-radius: 18px; background: rgba(31,41,55,.985); box-shadow: 0 24px 60px rgba(0,0,0,.45); text-align: center; }
.intro-card { width: min(1120px, 96%); max-height: min(88vh, 760px); overflow: auto; }
.intro-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.95fr); gap: 16px; align-items: start; }
.intro-main { min-width: 0; }
.intro-main > h2, .intro-main > p { text-align: center; }
.intro-main > p { max-width: 100%; }
.intro-actions { justify-content: center; }
.intro-side { display: grid; gap: 14px; align-content: start; }
.result-card { width: min(1120px, 96%); max-height: min(88vh, 760px); overflow: auto; }
.result-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.95fr); gap: 16px; align-items: start; }
.result-main { min-width: 0; }
.result-main .overlay-icon { display: block; margin: 0 auto; }
.result-main > h2, .result-main > p { text-align: center; }
.result-main > p { max-width: 100%; }
.overlay-icon { width: 90px; height: 90px; object-fit: contain; filter: drop-shadow(0 8px 18px rgba(0,0,0,.3)); }
.overlay-card h2 { margin: 8px 0; font-size: clamp(24px, 4vw, 34px); letter-spacing: -.03em; }
.overlay-card p { margin: 8px auto; max-width: 540px; color: var(--muted); }
.educational-note { margin-top: 14px; padding: 11px 13px; border: 1px solid #475569; border-radius: 12px; background: #111827; color: #dbeafe; font-size: 13px; text-align: left; }
.overlay-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 16px; }
.intro-pathogens { display: flex; justify-content: center; align-items: center; gap: 4px; margin-bottom: 2px; }
.intro-pathogens img { width: 70px; height: 70px; object-fit: contain; filter: drop-shadow(0 6px 10px rgba(0,0,0,.25)); }
.question-card { text-align: left; }
.question-stage { color: #93c5fd; text-transform: uppercase; font-size: 12px; letter-spacing: .08em; font-weight: 900; text-align: center; }
.question-pathogen-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 8px 0 12px; }
.question-pathogen-row img { width: 58px; height: 58px; object-fit: contain; }
.question-pathogen-row div { display: grid; }
.question-pathogen-row span { color: var(--muted-2); font-size: 11px; font-weight: 700; }
.question-pathogen-row strong { font-size: 14px; }
.question-card h2 { text-align: center; font-size: clamp(20px, 3vw, 27px); line-height: 1.25; margin: 9px auto 16px; max-width: 580px; }
.question-options { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.question-option { text-align: left; min-height: 54px; background: #111827; color: #e5e7eb; border: 1px solid #475569; padding: 11px 12px; font-weight: 700; }
.question-option:hover { background: #172033; border-color: #60a5fa; }
.question-option.correct { background: rgba(22,101,52,.55); border-color: #4ade80; color: #dcfce7; }
.question-option.incorrect { background: rgba(127,29,29,.55); border-color: #f87171; color: #fee2e2; }
.question-feedback { min-height: 28px; margin-top: 9px; color: var(--muted); text-align: center; font-size: 13px; font-weight: 700; }
.question-feedback.good { color: #bbf7d0; }
.question-feedback.bad { color: #fecaca; }
.question-play-actions { margin-top: 10px; }
.question-play-actions[hidden] { display: none; }
#playStageButton { min-width: 150px; background: #86efac; color: #052e16; }
.result-score { width: fit-content; margin: 12px auto 4px; padding: 9px 14px; background: #111827; border: 1px solid #475569; border-radius: 999px; font-weight: 900; color: #fff; }
.controls-note { padding: 10px 14px; color: var(--muted-2); font-size: 12px; text-align: center; border-top: 1px solid var(--border); background: rgba(17,24,39,.88); }
.mobile-controls { display: none; }
.mobile-pad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); gap: 5px; }
.mobile-pad button { width: 48px; height: 48px; padding: 0; font-size: 20px; border-radius: 14px; background: rgba(31,41,55,.9); color: #fff; border: 1px solid #64748b; box-shadow: 0 6px 16px rgba(0,0,0,.24); touch-action: none; }
.mobile-pad .up { grid-column: 2; grid-row: 1; }
.mobile-pad .left { grid-column: 1; grid-row: 2; }
.mobile-pad .down { grid-column: 2; grid-row: 2; }
.mobile-pad .right { grid-column: 3; grid-row: 2; }
.info-grid { flex: 0 0 auto; display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-top: 8px; }
.info-card { padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px; background: rgba(31,41,55,.78); }
.info-card strong { display: block; margin-bottom: 4px; font-size: 13px; }
.info-card span { color: var(--muted-2); font-size: 12px; }
.footer { flex: 0 0 auto; margin-top: 4px; color: #64748b; font-size: 10px; line-height: 1.2; text-align: center; }

.collection-panel { margin-top: 14px; padding: 11px 13px; border: 1px solid #475569; border-radius: 12px; background: rgba(17,24,39,.92); text-align: left; }
.device-data-panel { padding: 11px 13px; border: 1px solid #475569; border-radius: 12px; background: rgba(17,24,39,.92); text-align: left; }
.device-data-panel strong { display: block; margin-bottom: 4px; font-size: 14px; }
.device-data-panel p { margin: 0 0 9px; color: var(--muted-2); font-size: 12px; }
.device-data-panel button { width: 100%; }
.intro-collection { margin-top: 0; }
.intro-collection .collection-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.intro-collection .collection-card { min-height: 116px; padding: 7px; }
.intro-collection .collection-card img { width: 40px; height: 40px; margin-bottom: 4px; }
.intro-collection .collection-card strong { font-size: 11px; }
.intro-collection .collection-card p { font-size: 10px; line-height: 1.2; }
.intro-collection .collection-header { margin-bottom: 6px; }
.result-collection { margin-top: 0; height: 100%; }
.result-collection .collection-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.result-collection .collection-card { min-height: 116px; padding: 7px; }
.result-collection .collection-card img { width: 40px; height: 40px; margin-bottom: 4px; }
.result-collection .collection-card strong { font-size: 11px; }
.result-collection .collection-card p { font-size: 10px; line-height: 1.2; }
.result-collection .collection-header { margin-bottom: 6px; }
.collection-header { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.collection-header strong { font-size: 14px; }
.collection-header span { color: var(--muted-2); font-size: 12px; }
.collection-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.collection-card { border: 1px solid #475569; border-radius: 12px; background: rgba(31,41,55,.82); padding: 8px; min-height: 142px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.collection-card img { width: 52px; height: 52px; object-fit: contain; margin-bottom: 6px; filter: drop-shadow(0 4px 10px rgba(0,0,0,.22)); }
.collection-card strong { font-size: 12px; margin-bottom: 4px; }
.collection-card p { margin: 0; color: var(--muted-2); font-size: 11px; line-height: 1.25; }
.collection-card.locked { justify-content: center; color: #cbd5e1; background: rgba(15,23,42,.86); }
.collection-card.locked .lock-icon { font-size: 28px; margin-bottom: 6px; }
.collection-card.locked p { color: #94a3b8; }
.collection-card.new-unlock { border-color: #facc15; box-shadow: 0 0 0 2px rgba(250,204,21,.18); }
.recap-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.recap-card { border: 1px solid #475569; border-radius: 12px; background: rgba(17,24,39,.92); padding: 10px; text-align: left; }
.recap-card .recap-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 6px; }
.recap-card strong { font-size: 13px; }
.recap-card p { margin: 0; color: var(--muted-2); font-size: 12px; line-height: 1.3; }
.recap-state { padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 900; white-space: nowrap; }
.recap-state.passed { background: rgba(22,101,52,.45); color: #dcfce7; border: 1px solid #4ade80; }
.recap-state.blocked { background: rgba(127,29,29,.45); color: #fee2e2; border: 1px solid #f87171; }
.recap-state.pending { background: rgba(51,65,85,.7); color: #e2e8f0; border: 1px solid #64748b; }


.game-hud-buttons {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 30;
  display: flex;
  gap: 7px;
  align-items: flex-start;
}
.hud-icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid #64748b;
  background: rgba(15,23,42,.94);
  color: #fff;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  font-size: 19px;
  line-height: 1;
  backdrop-filter: blur(8px);
}
.hud-icon-button.muted { color: #fca5a5; border-color: #f87171; }
.sound-popover {
  position: absolute;
  top: 52px;
  right: 0;
  width: 220px;
  padding: 12px;
  border: 1px solid #475569;
  border-radius: 14px;
  background: rgba(17,24,39,.985);
  box-shadow: 0 16px 36px rgba(0,0,0,.4);
}
.sound-popover[hidden] { display: none; }
.sound-popover strong { display: block; margin-bottom: 7px; }
.sound-popover label,
.audio-settings label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.sound-popover input[type="range"],
.audio-settings input[type="range"] {
  width: 100%;
  accent-color: #60a5fa;
}
button.compact { padding: 7px 10px; font-size: 12px; }
.audio-settings {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #475569;
  border-radius: 12px;
  background: rgba(15,23,42,.72);
  text-align: left;
}
.audio-settings-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 7px;
}
.audio-settings-title span { color: var(--muted-2); font-size: 11px; }
.audio-settings button { margin-top: 7px; }
.pause-card { width: min(500px, 94%); }
.pause-symbol {
  width: 58px; height: 58px; margin: 0 auto 4px; display: grid; place-items: center;
  border-radius: 18px; background: #111827; border: 1px solid #64748b; color: #bfdbfe;
  font-size: 28px; font-weight: 900;
}
.pause-shortcut { margin-top: 8px; color: var(--muted-2); font-size: 11px; text-align: center; }

.glossary-term {
  color: #e0f2fe;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: #93c5fd;
  text-underline-offset: 3px;
  cursor: help;
  font-weight: 700;
}
.glossary-term:hover,
.glossary-term:focus-visible {
  color: #ffffff;
  text-decoration-color: #ffffff;
  outline: none;
}
.tooltip-hint { color: #bfdbfe; font-size: 12px; }
@media (max-width: 900px) {
  .app-shell { padding: 10px; }
  .brand-header { padding-right: 100px; }
  .brand-header { align-items: flex-start; }
  .brand-mark { width: 48px; height: 48px; border-radius: 15px; font-size: 17px; }
  .brand-copy p { display: none; }
  .header-actions .status-chip { display: none; }
  .game-topbar { grid-template-columns: 1fr auto auto; }
  .timer { display: block; min-width: 86px; font-size: 11px; }
  .mobile-controls { position: absolute; left: 12px; bottom: 12px; display: block; z-index: 4; }
  .controls-note { font-size: 11px; padding: 8px 10px; }
}

@media (max-width: 980px) {
  .intro-card, .result-card { width: min(760px, 96%); }
  .intro-layout, .result-layout { grid-template-columns: 1fr; }
  .result-collection { margin-top: 14px; }
  .result-collection .collection-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .intro-collection .collection-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 920px) {
  .collection-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .app-shell { padding: 7px; }
  .brand-header { padding-right: 96px; }
  .hud-icon-button { width: 40px; height: 40px; border-radius: 12px; }
  .sound-popover { top: 47px; width: 205px; }
  .brand-header { margin-bottom: 7px; }
  .brand-copy h1 { font-size: 19px; }
  .header-actions button { padding: 8px 10px; font-size: 12px; }
  .game-topbar { padding: 7px 8px; }
  .stage-pill { font-size: 9px; padding: 6px 4px; }
  .score-cluster { gap: 5px; font-size: 9px; }
  .score-cluster strong { font-size: 12px; }
  .question-options { grid-template-columns: 1fr; }
  .recap-grid { grid-template-columns: 1fr; }
  .collection-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .intro-collection .collection-grid, .result-collection .collection-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .intro-layout, .result-layout { grid-template-columns: 1fr; }
  .intro-pathogens img { width: 54px; height: 54px; }
  .mobile-pad { grid-template-columns: repeat(3,43px); grid-template-rows: repeat(3,43px); gap: 4px; }
  .mobile-pad button { width: 43px; height: 43px; border-radius: 12px; }
  .info-grid, .footer { display: none; }
}
@media (max-height: 820px) {
  .app-shell { padding-top: 7px; padding-bottom: 6px; }
  .brand-header { margin-bottom: 7px; }
  .brand-mark { width: 46px; height: 46px; border-radius: 14px; font-size: 16px; }
  .brand-copy h1 { font-size: 22px; }
  .brand-copy p { display: none; }
  .info-grid { display: none; }
  .footer { display: none; }
  .overlay { padding: 10px; }
  .overlay-card { padding: 14px 16px; }
  .intro-card, .result-card { max-height: min(90vh, 720px); }
  .collection-card { min-height: 126px; }
  .intro-pathogens img { width: 52px; height: 52px; }
  .overlay-card h2 { font-size: clamp(21px, 3vw, 28px); margin: 6px 0; }
  .overlay-card p { margin: 5px auto; }
  .educational-note { margin-top: 8px; padding: 8px 10px; }
  .overlay-actions { margin-top: 10px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .app-shell { max-width: none; padding: 4px 7px; }
  .game-hud-buttons { top: 5px; right: 5px; }
  .hud-icon-button { width: 36px; height: 36px; border-radius: 10px; font-size: 16px; }
  .sound-popover { top: 41px; width: 190px; padding: 9px; }
  .audio-settings { margin-top: 6px; padding: 7px 9px; }
  .audio-settings-title { margin-bottom: 4px; }
  .brand-header, .info-grid, .footer { display: none; }
  .game-card { border-radius: 10px; }
  .game-topbar { padding: 5px 7px; }
  .canvas-wrap { min-height: 0; }
  .controls-note { display: none; }
  .mobile-controls { bottom: 7px; left: 7px; }
  .overlay { padding: 8px; }
  .overlay-card { padding: 9px 12px; max-height: calc(100dvh - 48px); overflow: hidden; }
  .intro-card, .result-card { overflow: auto; }
  .collection-panel { display: none; }
  .device-data-panel { display: none; }
  .recap-grid { margin-top: 10px; gap: 6px; }
  .recap-card { padding: 8px; }
  .intro-card .educational-note { display: none; }
  .intro-card .intro-pathogens img { width: 38px; height: 38px; }
  .intro-card h2 { font-size: 20px; margin: 3px 0; }
  .intro-card p { font-size: 12px; margin: 3px auto; }
  .start-audio-settings { margin-top: 5px; padding: 6px 8px; }
  .pause-card h2 { font-size: 20px; margin: 3px 0; }
  .pause-card p { margin: 2px auto; font-size: 12px; }
  .pause-symbol { width: 42px; height: 42px; border-radius: 12px; font-size: 21px; }
  .question-card h2 { margin: 5px auto 8px; font-size: 18px; }
  .question-options { grid-template-columns: 1fr 1fr; gap: 6px; }
  .question-pathogen-row { margin: 2px 0 5px; }
  .question-pathogen-row img { width: 40px; height: 40px; }
  .question-option { min-height: 39px; padding: 7px 9px; font-size: 12px; }
  .question-feedback { margin-top: 4px; min-height: 20px; }
}

@media (max-height: 440px) and (orientation: landscape) {
  .game-topbar { padding: 4px 6px; }
  .stage-pill { padding: 4px; font-size: 9px; }
  .score-cluster { font-size: 9px; }
  .score-cluster strong { font-size: 12px; }
  .overlay-card { padding: 7px 10px; }
  .question-stage { font-size: 10px; }
  .question-pathogen-row { display: none; }
  .question-card h2 { margin: 4px auto 6px; font-size: 16px; }
  .question-options { gap: 4px; }
  .question-option { min-height: 34px; padding: 5px 8px; font-size: 11px; }
  .question-feedback { min-height: 17px; margin-top: 3px; font-size: 11px; }
  .question-play-actions { margin-top: 4px; }
  #playStageButton { min-width: 120px; padding: 6px 10px; font-size: 12px; }
}

/* Chemisode Games integration */
.games-home-link{display:inline-flex;align-items:center;justify-content:center;min-height:38px;padding:8px 11px;border:1px solid #475569;border-radius:10px;background:#111827;color:#dbeafe;text-decoration:none;font-size:12px;font-weight:800;white-space:nowrap}
.games-home-link:hover,.games-home-link:focus-visible{background:#1e293b;color:#fff;outline:2px solid #93c5fd;outline-offset:2px}
.pause-games-link{min-width:190px}

/* Keep centred overlays inside the actual game area rather than the browser viewport. */
.overlay{overflow:hidden}
.overlay-card{max-height:100%;overflow:auto}
.intro-card,.result-card{max-height:100%}
