/* ============================================================
   PEPBUG LAB — The Punnett Square Game
   Aesthetic: modern science lab / specimen slides
   Fonts: Rubik (display + body) + IBM Plex Mono (data + genotypes)
   Palette: deep indigo ink, electric violet, cyan, magenta, lime
   ============================================================ */

:root {
  --ink:          #1E1B4B;
  --violet:       #6D4AFF;
  --violet-soft:  #E8E3FF;
  --cyan:         #19C3D6;
  --magenta:      #FF4F9A;
  --lime:         #C6F135;
  --paper:        #F1F2FF;
  --white:        #FFFFFF;
  --good:         #E7F9A9;
  --bad:          #FFD6E7;
  --font-display: 'Rubik', system-ui, sans-serif;
  --font-body:    'Rubik', system-ui, sans-serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, monospace;
  --hard:         4px 4px 0 var(--ink);
  --hard-sm:      3px 3px 0 var(--ink);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--ink);
  background-color: var(--paper);
  min-height: 100dvh;
}

/* molecular hex grid */
.bg-dots {
  position: fixed; inset: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='100' viewBox='0 0 56 100'%3E%3Cpath d='M28 66L0 50V16L28 0l28 16v34zM28 100L0 84V50M28 100l28-16V50' fill='none' stroke='%23d3d6f6' stroke-width='2'/%3E%3C/svg%3E");
  background-size: 56px 100px;
}

#game { position: relative; max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }

.screen { display: none; }
.screen--active { display: block; }

[hidden] { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font: 700 1.15rem var(--font-display); text-decoration: none;
  color: var(--ink); background: var(--cyan);
  border: 3px solid var(--ink); border-radius: 14px; padding: .7rem 1.8rem; cursor: pointer;
  box-shadow: var(--hard);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn:focus-visible, .choice:focus-visible, .cell:focus-visible, .link-btn:focus-visible { outline: 3px solid var(--magenta); outline-offset: 3px; }
.btn--primary { background: var(--violet); color: #fff; }
.btn--small { font-size: 1rem; padding: .5rem 1.2rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: var(--hard); }

.link-btn {
  display: block; margin: 28px auto 0; background: none; border: 0; cursor: pointer;
  font: 700 .85rem var(--font-mono); color: var(--ink); text-decoration: underline; text-underline-offset: 3px;
}

/* ---------- Start / End ---------- */
.start, .end {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  text-align: center; padding: 24px 0;
}
.sticker {
  font: 700 .75rem var(--font-mono); letter-spacing: .14em; text-transform: uppercase;
  background: var(--lime); color: var(--ink); border: 3px solid var(--ink); border-radius: 8px;
  padding: 3px 12px; transform: rotate(-2deg); box-shadow: 3px 3px 0 var(--ink);
}
.logo-icon { font-size: 3.2rem; line-height: 1; }
.game-title {
  font-family: var(--font-display); font-weight: 800; text-transform: uppercase;
  font-size: clamp(2.6rem, 10vw, 4.4rem); line-height: .95; letter-spacing: -.01em;
  color: var(--ink);
}
.title-accent {
  color: var(--violet); font-size: 1.25em; display: inline-block; transform: rotate(-2deg);
  text-shadow: 3px 3px 0 var(--ink);
}
.tagline { font: 700 .95rem var(--font-mono); line-height: 1.6; max-width: 340px; }
.start-bugs { display: flex; gap: 10px; justify-content: center; }
.start-bugs .bug-box { width: 76px; }
.start .btn, .end .btn { min-width: 230px; }

.end-title { font-family: var(--font-display); font-weight: 800; font-size: 2.4rem; text-transform: uppercase; line-height: 1.05; }
.end-score { font: 700 4rem var(--font-mono); color: var(--violet); line-height: 1; text-shadow: 3px 3px 0 var(--ink); }
.end-score small { font-size: 1rem; color: var(--ink); text-shadow: none; }
.end-detail { font: 700 .95rem var(--font-mono); max-width: 340px; }

.save-box { background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 16px 18px; width: 100%; max-width: 360px; box-shadow: 6px 6px 0 var(--violet); }
.save-box label { display: block; font: 700 .8rem var(--font-mono); letter-spacing: .08em; text-transform: uppercase; margin-bottom: 8px; }
.save-row { display: flex; gap: 10px; }
/* the Save button keeps its natural size (the end-screen rule above would stretch it and squeeze the name box) */
.end .save-row .btn { min-width: 0; flex: none; }
.save-row input {
  flex: 1; min-width: 0; font: 700 1.05rem var(--font-mono); padding: 8px 12px; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 12px; background: var(--paper);
}
.save-row input:focus { outline: none; background: #fff; box-shadow: 3px 3px 0 var(--cyan); }
.save-msg { min-height: 1.3em; margin-top: 8px; font: 700 .8rem var(--font-mono); }

/* ---------- Leaderboard ---------- */
.board { list-style: none; width: 100%; max-width: 360px; counter-reset: rank; text-align: left; border: 3px solid var(--ink); border-radius: 14px; overflow: hidden; background: #fff; }
.board li {
  counter-increment: rank; display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; font: 700 .95rem var(--font-mono);
}
.board li:nth-child(even) { background: var(--violet-soft); }
.board li::before { content: counter(rank); width: 1.6rem; color: var(--magenta); }
.board li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li .pts { color: var(--violet); }
.board li.me { background: var(--lime); }
.board .empty::before { content: none; }

/* ---------- HUD (instrument panel) ---------- */
.hud {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  background: var(--ink); color: #fff; border-radius: 16px; padding: 12px 16px;
  box-shadow: 4px 4px 0 var(--violet);
}
.hud-label { display: block; font: 700 .65rem var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--cyan); }
.hud-title { font: 800 1.3rem var(--font-display); color: #fff; }
.hud-stats { display: flex; gap: 20px; }
.stat { text-align: center; }
.stat-val { font: 700 1.3rem var(--font-mono); color: var(--lime); }
.stage-tip { text-align: center; font: 700 .85rem var(--font-mono); margin: 16px 0 6px; }
.stage-tip::before { content: '// '; color: var(--magenta); }

/* ---------- Round panel ---------- */
.panel {
  background: #fff; border: 3px solid var(--ink); border-radius: 20px; padding: 20px 18px;
  margin-top: 12px; box-shadow: 6px 6px 0 var(--violet);
}
.prompt { font-size: 1.15rem; font-weight: 700; text-align: center; line-height: 1.45; margin-bottom: 14px; }
.geno {
  display: inline-block; font: 700 1.1em var(--font-mono); color: #fff; background: var(--violet);
  border: 2px solid var(--ink); border-radius: 8px; padding: 0 .5rem; letter-spacing: .1em; line-height: 1.4;
}
.geno.rec { background: var(--magenta); }

.key {
  display: flex; flex-wrap: wrap; gap: 8px 22px; justify-content: center;
  background: var(--violet-soft); border-radius: 12px; padding: 8px 12px; margin-bottom: 16px;
  font-weight: 600; font-size: .9rem;
}
.key span { display: inline-flex; align-items: center; gap: 6px; }
.key b { font: 700 1.2rem var(--font-mono); }
.key em { font-style: normal; font-weight: 500; opacity: .75; }
.key .bug-box { width: 34px; flex: none; }

/* Pepbugs */
.bug { display: block; width: 100%; height: auto; }
.bug-box { width: 100px; }

/* petri dishes */
.choice .bug-box, .pup .bug-box, .start-bugs .bug-box {
  padding: 8px; border: 3px solid var(--ink); border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0, #e3f9fc 55%, #b9eef5 100%);
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.75), 2px 2px 0 var(--ink);
}

/* Answer choices */
.choices { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.choice {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font: 700 1.05rem var(--font-body); color: var(--ink); text-align: center;
  background: #fff; border: 3px solid var(--ink); border-radius: 14px;
  padding: 14px 10px; min-height: 64px; cursor: pointer;
  box-shadow: var(--hard-sm);
  transition: transform .12s ease, box-shadow .12s ease, background .12s;
}
.choice:hover:not([disabled]) { transform: translate(-2px, -2px); box-shadow: 5px 5px 0 var(--ink); background: var(--violet-soft); }
.choice:active:not([disabled]) { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.choice[disabled] { cursor: default; }
.choice.correct { background: var(--lime); }
.choice.wrong { background: var(--bad); }
.choice .bug-box { width: 100px; }
.choice .big { font: 700 1.6rem var(--font-mono); letter-spacing: .06em; }
.choice .pair { display: flex; align-items: center; gap: 4px; }
.choice .pair .bug-box { width: 58px; padding: 5px; }
.choice .times { font: 700 1.1rem var(--font-mono); color: var(--magenta); }
.choices.pct { grid-template-columns: repeat(5, 1fr); gap: 8px; }
.choices.pct .choice { padding: 12px 2px; }
.choices.pct .big { font-size: 1.1rem; letter-spacing: 0; }
.choices.three { grid-template-columns: 1fr; }

/* Punnett square (the slide) */
.sq {
  display: grid; grid-template-columns: auto 1fr 1fr; grid-template-rows: auto 1fr 1fr;
  gap: 8px; max-width: 340px; margin: 6px auto 16px;
}
.allele {
  display: grid; place-items: center; width: 48px; height: 44px; margin: 0 auto;
  font: 700 1.6rem var(--font-mono); color: #fff; background: var(--violet);
  border: 3px solid var(--ink); border-radius: 10px; box-shadow: 2px 2px 0 var(--ink);
}
.allele.rec { background: var(--magenta); }
.sq .corner { width: 48px; }
.cell {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 92px; font: 700 1.9rem var(--font-mono); letter-spacing: .08em;
  color: var(--ink); background: var(--paper); border: 3px dashed rgba(30,27,75,.45);
  border-radius: 12px; cursor: pointer; transition: transform .12s ease;
}
button.cell:hover { transform: scale(1.04); }
.cell.filled { border: 3px solid var(--ink); background: #fff; box-shadow: var(--hard-sm); }
.cell.wrong { border: 3px solid var(--ink); background: var(--bad); }
.cell.right { border: 3px solid var(--ink); background: var(--lime); }
.cell.static { cursor: default; border: 3px solid var(--ink); background: #fff; box-shadow: var(--hard-sm); }
.cell.static.right { background: var(--lime); }
.cell .bug-box { width: 40px; }

.actions { display: flex; justify-content: center; margin-top: 4px; }
.msg { text-align: center; font: 700 .85rem var(--font-mono); color: #c2185b; min-height: 1.4em; margin-bottom: 8px; }

/* Feedback */
#feedback { margin-top: 18px; }
.fb {
  border: 3px solid var(--ink); background: var(--good); border-radius: 16px; padding: 14px 18px;
  box-shadow: var(--hard); animation: pop .25s ease-out;
}
.fb.no { background: var(--bad); }
.fb strong { font: 800 1.3rem var(--font-display); display: block; margin-bottom: 4px; }
.fb p { font-weight: 500; line-height: 1.5; }
.fb p + p { margin-top: 6px; }
.fb-next { display: flex; justify-content: center; margin-top: 18px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

/* Litter */
.litter { display: flex; gap: 10px; justify-content: center; margin: 12px 0 4px; }
.pup { text-align: center; width: 22%; max-width: 84px; font: 700 .95rem var(--font-mono); letter-spacing: .06em; animation: pop .4s ease-out both; }
.pup .bug-box { width: 100%; margin-bottom: 4px; }
.pup:nth-child(2) { animation-delay: .25s; }
.pup:nth-child(3) { animation-delay: .5s; }
.pup:nth-child(4) { animation-delay: .75s; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(30,27,75,.6); overflow-y: auto; }
.modal-box {
  position: relative; background: #fff; border: 3px solid var(--ink); border-radius: 20px;
  box-shadow: 8px 8px 0 var(--violet);
  padding: 24px 22px; width: 100%; max-width: 440px; max-height: 90dvh; overflow-y: auto;
  animation: pop .25s ease-out;
}
.modal-box h2 { font: 800 1.7rem var(--font-display); margin-bottom: 12px; text-align: center; }
.modal-close {
  position: absolute; top: 10px; right: 12px; width: 38px; height: 38px; border-radius: 10px;
  border: 3px solid var(--ink); background: var(--lime); font: 700 1rem var(--font-mono); cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
}
.glossary dt { font: 700 .95rem var(--font-mono); color: var(--violet); margin-top: 12px; text-transform: uppercase; letter-spacing: .06em; }
.glossary dd { font-weight: 500; line-height: 1.45; }
.glossary b { font-family: var(--font-mono); }
.scores-best { text-align: center; font: 700 .85rem var(--font-mono); margin-bottom: 10px; }
.modal-box .board { margin: 0 auto; }

@media (min-width: 600px) { .choices.three { grid-template-columns: repeat(3, 1fr); } }

@media (max-width: 480px) {
  .hud { padding: 10px 12px; }
  .hud-stats { gap: 12px; width: 100%; justify-content: space-between; }
  .cell { min-height: 80px; font-size: 1.6rem; }
  .choice .bug-box { width: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
