:root {
  --ink: #172238;
  --paper: #fffaf0;
  --cream: #fff3d9;
  --yellow: #ffd166;
  --coral: #ef6a67;
  --teal: #167d83;
  --green: #4c9a68;
  --purple: #7557a6;
  --shadow: 0 18px 60px rgba(20, 29, 55, .24);
  --radius: 24px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { font-family: ui-rounded, "Nunito", "Avenir Next", system-ui, sans-serif; color: var(--ink); background: #b9e4e1; }
button { font: inherit; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 4px solid #163c91; outline-offset: 3px; }
#app, #scene { position: fixed; inset: 0; width: 100%; height: 100%; }
#scene { touch-action: none; display: block; }
#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(circle at 50% 45%, transparent 45%, rgba(16,27,51,.25) 120%); }
#topbar { position: fixed; z-index: 10; left: 0; right: 130px; top: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: max(14px, env(safe-area-inset-top)) 0 0 max(16px, env(safe-area-inset-left)); pointer-events: none; }
#top-actions { position: fixed; z-index: 12; right: max(16px, env(safe-area-inset-right)); top: max(14px, env(safe-area-inset-top)); display: flex; gap: 8px; }
#topbar > * { pointer-events: auto; }
.icon-button { width: 48px; height: 48px; flex: 0 0 48px; border: 2px solid rgba(255,255,255,.7); border-radius: 50%; background: rgba(255,250,240,.9); color: var(--ink); box-shadow: 0 5px 20px rgba(20,30,50,.14); font-size: 24px; font-weight: 800; cursor: pointer; }
.icon-button:hover { transform: translateY(-2px); background: #fff; }
#journey { display: flex; align-items: center; gap: 5px; max-width: min(620px, 62vw); padding: 8px 12px; border-radius: 99px; background: rgba(255,250,240,.88); box-shadow: 0 5px 20px rgba(20,30,50,.12); backdrop-filter: blur(8px); }
.journey-dot { position: relative; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: #ded9cf; color: #625f5a; cursor: pointer; font-weight: 900; font-size: 13px; }
.journey-dot.unlocked { background: #fff; border: 2px solid var(--teal); color: var(--teal); }
.journey-dot.active { background: var(--teal); color: white; transform: scale(1.14); }
.journey-dot:disabled { cursor: default; opacity: .55; }
.journey-line { height: 3px; width: clamp(4px, 1.4vw, 17px); border-radius: 4px; background: #d7d2c8; }
.journey-line.done { background: var(--teal); }
.card { position: absolute; z-index: 5; left: max(22px, env(safe-area-inset-left)); top: 50%; transform: translateY(-50%); width: min(430px, calc(100vw - 44px)); max-height: calc(100dvh - 128px); overflow: auto; padding: 28px; border: 2px solid rgba(255,255,255,.72); border-radius: var(--radius); background: rgba(255,250,240,.94); box-shadow: var(--shadow); backdrop-filter: blur(12px); scrollbar-width: thin; scrollbar-gutter: stable; }
.kicker { margin: 0 0 8px; color: var(--teal); font-size: 12px; line-height: 1.2; letter-spacing: .14em; font-weight: 950; }
h1 { margin: 0 0 14px; font-size: clamp(29px, 3.3vw, 44px); line-height: 1.03; letter-spacing: -.035em; }
p { font-size: 17px; line-height: 1.52; }
#chapter-copy { margin: 0 0 18px; }
.hint { margin: 14px 0 0; color: #5d6470; font-size: 12px; line-height: 1.35; }
.primary, .secondary, .choice, .lab-steps button { border: 0; cursor: pointer; font-weight: 850; }
.primary { min-height: 52px; padding: 13px 22px; border-radius: 16px; color: #fff; background: var(--teal); box-shadow: 0 5px 0 #0d5257; font-size: 18px; }
.primary:hover { background: #11686d; transform: translateY(-1px); }
.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #0d5257; }
.secondary { min-height: 46px; padding: 10px 17px; border-radius: 14px; color: var(--ink); background: #eee7da; border: 2px solid #d8cfc0; }
.secondary:hover { background: #e2d9c9; }
.choice-row { display: flex; gap: 8px; margin-bottom: 16px; }
.choice { flex: 1; min-height: 49px; padding: 8px 5px; border-radius: 14px; background: #eee8dd; color: #464950; font-size: 15px; }
.choice.selected { background: #fff0bd; box-shadow: inset 0 0 0 3px #d69e22; color: #4b3500; }
.lab-panel { width: min(630px, calc(100vw - 44px)); top: 84px; bottom: 16px; transform: none; max-height: none; padding: 18px 20px; }
.lab-heading { display: flex; align-items: start; justify-content: space-between; gap: 15px; }
.lab-heading h1 { font-size: clamp(23px, 2.7vw, 30px); margin-bottom: 7px; }
.coverage { position: relative; flex: 0 0 118px; height: 30px; overflow: hidden; border-radius: 99px; background: #ded8cc; }
.coverage span { position: absolute; inset: 0 auto 0 0; width: 0; background: #80c9a0; transition: width .5s; }
.coverage strong { position: relative; display: grid; place-items: center; height: 100%; font-size: 11px; }
.lab-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 0; margin: 4px 0 9px; list-style: none; }
.lab-steps button { width: 100%; min-height: 42px; padding: 6px 3px; border-radius: 11px; background: #e9e2d7; color: #706b64; font-size: 13px; }
.lab-steps b { display: block; font-size: 13px; }
.lab-steps li.active button { background: var(--ink); color: white; }
.lab-steps li.done button { background: #d8eddf; color: #236038; }
.lab-instruction { margin: 0 0 12px; font-size: 15px; line-height: 1.42; }
#lab-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
#lab-tools:empty { display: none; }
.read-tray { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; max-height: 76px; overflow: auto; padding: 2px; }
.read-tray:empty { display: none; }
.read-chip { --base: #eee; position: relative; padding: 8px 10px; border: 2px solid #d3cabc; border-radius: 10px; background: white; cursor: grab; font: 800 12px/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .06em; user-select: none; touch-action: none; box-shadow: 0 3px 0 #d3cabc; }
.read-chip:hover { border-color: var(--teal); transform: translateY(-2px); }
.read-chip.used { opacity: .32; cursor: default; text-decoration: line-through; }
.read-chip.dragging { opacity: .7; cursor: grabbing; z-index: 20; transform: rotate(-3deg) scale(1.06); }
.read-chip.reject { animation: shake .35s; border-color: var(--coral); }
.read-chip.match { animation: match .4s; border-color: var(--green); }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-8px)} 75%{transform:translateX(8px)} }
@keyframes match { 50%{transform:scale(1.14); background:#dcf4df} }
.assembly-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; font-size: 13px; }
.contig { display: flex; flex-wrap: wrap; gap: 3px; min-height: 40px; margin: 9px 0 12px; padding: 8px; border-radius: 12px; background: #1d2b43; }
.base { display: inline-grid; place-items: center; width: 20px; height: 25px; border-radius: 5px; color: #172238; font: 900 13px/1 ui-monospace, monospace; }
.base.a { background: #ffd166; } .base.t { background: #ef8d86; } .base.g { background: #80c9a0; } .base.c { background: #80bce8; }
.base.unknown { color: #c8c5bd; background: #455069; }
.base.gene { box-shadow: 0 0 0 2px #fff3a0, 0 0 12px #fff3a0; }
.base.mutated { background: #c89be8; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { transform: translateY(-3px); } }
.drop-zone { display: grid; place-items: center; min-height: 58px; padding: 10px; border: 3px dashed #b7aa95; border-radius: 15px; color: #675f55; text-align: center; font-size: 14px; background: #f5eddd; }
.drop-zone.over { border-color: var(--teal); background: #dcf2ed; transform: scale(1.01); }
.assembly-actions, .gene-actions { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.gene-panel { border-color: #ffe7a0; font-size: 14px; padding: 19px 21px; }
.gene-panel h1 { font-size: 27px; margin-bottom: 6px; }
.gene-panel p { font-size: 13px; line-height: 1.35; }
.gene-panel .gene-sequence { margin: 6px 0; padding: 7px; }
.gene-panel .codon-row { margin: 6px 0 9px; }
.gene-panel .protein-card { padding: 9px 11px; font-size: 13px; }
.gene-panel .gene-actions { margin-top: 8px; }
.gene-sequence { display: flex; flex-wrap: wrap; gap: 2px; margin: 10px 0; padding: 10px; border-radius: 12px; background: #202c44; }
.codon-row { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0 14px; }
.codon { padding: 5px; border-radius: 8px; background: #e9e2f3; text-align: center; font: 800 11px/1.25 ui-monospace, monospace; }
.codon b { display: block; color: var(--purple); font-size: 10px; }
.protein-card { padding: 14px 16px; border-radius: 15px; background: #e0f0e7; border: 2px solid #b9d9c5; }
.protein-card strong { color: #245e3a; }
.trait-copy { margin-bottom: 10px; font-size: 15px; }
.mutation-copy { min-height: 24px; color: #604079; font-size: 15px; }
.finale-card { text-align: center; padding-bottom: 34px; }
.finale-card .primary { position: relative; z-index: 26; }
.finale-card .finale-stats { margin: 14px 0; }
.finale-stats { display: grid; gap: 8px; margin: 20px 0; }
.finale-stats span { padding: 8px; border-radius: 12px; background: #e8f2eb; }
.finale-stats b { color: var(--teal); font-size: 22px; }
#toast { position: fixed; z-index: 30; left: 50%; bottom: max(96px, calc(env(safe-area-inset-bottom) + 84px)); transform: translate(-50%, 20px); max-width: min(520px, 90vw); padding: 12px 20px; border-radius: 99px; color: white; background: #172238; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; text-align: center; font-size: 15px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.lab-mode { left: auto; right: 20px; top: auto; bottom: 100px; transform: translate(0, 20px); max-width: min(420px, calc(100vw - 690px)); text-align: left; }
#toast.lab-mode.show { transform: translate(0, 0); }
#pointer-label { position: fixed; z-index: 8; display: none; padding: 7px 11px; border-radius: 9px; background: #172238; color: white; pointer-events: none; font-size: 13px; }
#zoom-controls { position: fixed; z-index: 9; right: max(18px, env(safe-area-inset-right)); top: 50%; display: grid; gap: 8px; transform: translateY(-50%); }
#zoom-controls button { width: 46px; height: 46px; border: 2px solid white; border-radius: 13px; background: rgba(255,250,240,.9); font-size: 27px; font-weight: 700; cursor: pointer; }
.panel { position: fixed; z-index: 50; left: 50%; top: 50%; transform: translate(-50%,-50%); padding: 24px 30px; border-radius: 20px; background: var(--paper); box-shadow: var(--shadow); font-size: 18px; }
.dialog { position: fixed; z-index: 40; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(13,21,39,.58); }
.dialog[hidden] { display: none; }
.dialog-inner { position: relative; width: min(560px, 94vw); max-height: 88vh; overflow: auto; padding: 30px; border-radius: 24px; background: var(--paper); box-shadow: var(--shadow); }
.dialog-close { position: absolute; right: 15px; top: 15px; }
.dialog h2 { margin: 0 40px 16px 0; font-size: 30px; }
.dialog dt { margin-top: 12px; font-weight: 900; }
.dialog dd { margin: 2px 0 0; line-height: 1.4; }
.confetti { position: fixed; z-index: 25; top: -20px; width: 11px; height: 18px; pointer-events: none; animation: fall var(--fall) linear forwards; }
@keyframes fall { to { transform: translate(var(--drift), 110vh) rotate(900deg); opacity: .1; } }
@media (min-width: 721px) and (max-width: 1050px) {
  .card { width: min(370px, calc(100vw - 36px)); padding: 22px; }
  .card p { font-size: 15px; }
  .lab-panel { width: min(520px, calc(100vw - 36px)); }
}
@media (max-width: 720px) {
  #journey { max-width: 55vw; padding: 6px 8px; gap: 3px; }
  .journey-dot { width: 25px; height: 25px; font-size: 11px; }
  .journey-line { width: 3px; }
  .card { left: 12px; top: auto; bottom: 10px; transform: none; width: calc(100vw - 24px); max-height: 60dvh; padding: 19px; border-radius: 20px; }
  .card:not(.lab-panel) { max-width: 440px; }
  .lab-panel { left: 12px; right: 12px; bottom: 10px; top: 76px; width: auto; max-height: none; padding: 15px; }
  #topbar { right: 132px; }
  #journey { overflow-x: auto; scrollbar-width: none; }
  .journey-dot { flex: 0 0 25px; }
  .journey-line { flex: 0 0 3px; }
  .lab-heading h1 { font-size: 23px; }
  .coverage { flex-basis: 100px; }
  .lab-steps button { font-size: 0; } .lab-steps b { font-size: 11px; }
  #zoom-controls { top: 84px; bottom: auto; right: 12px; }
  .lab-panel ~ #zoom-controls { display: none; }
  #toast.lab-mode { left: 12px; right: 12px; top: 66px; bottom: auto; max-width: none; font-size: 13px; text-align: center; }
  #toast:not(.lab-mode) { bottom: max(24px, env(safe-area-inset-bottom)); }
  h1 { font-size: 31px; }
  p { font-size: 16px; }
  .read-chip { font-size: 10px; padding: 8px; }
  .base { width: 16px; height: 22px; font-size: 11px; }
}
@media (max-width: 430px) {
  #home-button { display: none; }
  #journey { max-width: 72vw; }
  .choice { font-size: 13px; }
  .coverage strong { font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}