/* AP Chemistry Games — one stylesheet for every page.
   Colors come from a molecular model kit: nitrogen blue, oxygen red, chlorine green, sulfur yellow. */

:root {
  --paper: #eef3f8;
  --grid: #dde6f0;
  --card: #ffffff;
  --ink: #1c2a4a;
  --ink-2: #52607d;
  --line: #c9d4e2;
  --nitrogen: #2f6fd6;
  --nitrogen-dark: #1f4fa3;
  --oxygen: #d9473f;
  --chlorine: #2e9e5b;
  --sulfur: #f2c230;
  --lone-pair: #a58be0;
  --radius: 18px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 #c9d4e2, 0 8px 24px -16px rgba(28, 42, 74, 0.35);
  --font: 'Lexend', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
}
button, input { font: inherit; color: inherit; }
a { color: var(--nitrogen-dark); }
:focus-visible { outline: 3px solid var(--nitrogen); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.chem sub, .chem sup, sup { font-size: 0.7em; line-height: 0; }

/* ---------- top bar ---------- */
.topbar {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; }
.brand svg { width: 38px; height: 38px; }
.who { display: flex; align-items: center; gap: 10px; font-size: 0.95rem; color: var(--ink-2); }
.who strong { color: var(--ink); font-weight: 600; white-space: nowrap; }
.link-button { background: none; border: 0; padding: 4px 2px; color: var(--nitrogen-dark); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 0.95rem; }

/* ---------- buttons ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 12px 26px;
  border: 0; border-radius: 999px;
  background: var(--nitrogen); color: #fff;
  font-weight: 600; font-size: 1.05rem; text-decoration: none; cursor: pointer;
  box-shadow: 0 3px 0 var(--nitrogen-dark);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.button:hover { background: #2a63c2; }
.button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--nitrogen-dark); }
.button:disabled { opacity: 0.55; cursor: progress; }
.button.secondary { background: var(--card); color: var(--ink); box-shadow: 0 3px 0 var(--line); border: 1.5px solid var(--line); }
.button.secondary:hover { background: #f6f8fb; }

/* ---------- menu ---------- */
.menu { max-width: 1080px; margin: 0 auto; padding: 8px 20px 64px; }
.menu h1 { font-size: clamp(2rem, 5vw, 3rem); line-height: 1.1; letter-spacing: -0.03em; margin: 16px 0 28px; }
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.unit {
  display: grid; grid-template-columns: 72px 1fr; align-items: center; gap: 18px;
  padding: 18px 20px; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow); text-align: left; cursor: pointer;
}
.unit:hover { border-color: var(--unit-color); }
.unit .meta { display: block; font-size: 0.9rem; color: var(--ink-2); }
.unit .name { display: block; font-size: 1.15rem; font-weight: 600; line-height: 1.25; margin: 2px 0; }
.atom {
  width: 72px; height: 72px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 1.6rem;
  background: radial-gradient(circle at 34% 30%, color-mix(in srgb, var(--unit-color) 35%, #fff) 0%, var(--unit-color) 55%, color-mix(in srgb, var(--unit-color) 70%, #000) 100%);
  box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.18);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.unit-head { display: flex; align-items: center; gap: 18px; margin: 12px 0 24px; }
.unit-head h1 { margin: 0; }
.unit-head .atom { flex: none; }
.back { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; }
.games { display: grid; gap: 14px; }
.game {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 20px 22px; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow);
}
.game h2 { margin: 0 0 4px; font-size: 1.25rem; }
.game p { margin: 0; color: var(--ink-2); max-width: 60ch; }
.empty { color: var(--ink-2); }

/* ---------- nickname dialog ---------- */
dialog {
  width: min(440px, calc(100vw - 32px));
  border: 0; border-radius: var(--radius); padding: 28px;
  box-shadow: 0 30px 80px -20px rgba(28, 42, 74, 0.5);
}
dialog::backdrop { background: rgba(28, 42, 74, 0.45); }
dialog h2 { margin: 0 0 6px; font-size: 1.5rem; }
dialog p { margin: 0 0 18px; color: var(--ink-2); }
.field { display: grid; gap: 6px; margin-bottom: 18px; }
.field input {
  min-height: 52px; padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: #fff; font-size: 1.1rem;
}
.field input:focus { border-color: var(--nitrogen); outline: none; box-shadow: 0 0 0 3px rgba(47, 111, 214, 0.2); }
.error { color: var(--oxygen); font-weight: 500; min-height: 1.5em; margin: 0 0 8px; }

/* ---------- game page ---------- */
.play { max-width: 860px; margin: 0 auto; padding: 0 16px 64px; }
.play-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 4px; }
.play-bar .title { font-weight: 600; text-align: center; flex: 1; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 5.5ch; text-align: right; }

/* The streak chain: 16 atoms joined by bonds. It fills as the run goes. */
.chain { display: flex; align-items: center; justify-content: center; padding: 6px 0 22px; }
.chain .bead {
  flex: none; width: clamp(14px, 3.6vw, 26px); aspect-ratio: 1; border-radius: 50%;
  background: #fff; border: 2px solid var(--line);
  transition: background 0.25s ease, border-color 0.25s ease, transform 0.25s ease;
}
.chain .bond { flex: 1; max-width: 22px; min-width: 3px; height: 4px; background: var(--line); }
.chain .bead.done {
  border-color: #c79a14;
  background: radial-gradient(circle at 35% 30%, #fff3c2 0%, var(--sulfur) 55%, #c79a14 100%);
}
.chain .bond.done { background: #c79a14; }
.chain .bead.current { border-color: var(--nitrogen); border-width: 3px; transform: scale(1.18); }
.chain .bead.missed { border-color: #9d2a24; background: radial-gradient(circle at 35% 30%, #ffc9c5 0%, var(--oxygen) 55%, #9d2a24 100%); }

.panel {
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: clamp(20px, 4vw, 36px);
}
.start h1 { font-size: clamp(1.9rem, 5vw, 2.6rem); line-height: 1.1; letter-spacing: -0.03em; margin: 0 0 10px; }
.start .lead { font-size: 1.15rem; margin: 0 0 22px; max-width: 52ch; }
.best { display: flex; gap: 28px; flex-wrap: wrap; margin: 0 0 24px; padding: 14px 18px; border-radius: var(--radius-sm); background: #f4f7fb; }
.best div { display: grid; }
.best span { font-size: 0.9rem; color: var(--ink-2); }
.best strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.start-row { display: flex; flex-wrap: wrap; align-items: center; gap: 20px; }

.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 52px; height: 30px; border-radius: 999px; background: var(--line); position: relative; transition: background 0.15s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.15s; }
.switch input:checked + .track { background: var(--chlorine); }
.switch input:checked + .track::after { transform: translateX(22px); }
.switch input:focus-visible + .track { outline: 3px solid var(--nitrogen); outline-offset: 3px; }

.q-count { color: var(--ink-2); font-size: 0.95rem; margin: 0 0 6px; }
.prompt { font-size: clamp(1.25rem, 3.2vw, 1.6rem); line-height: 1.3; font-weight: 600; margin: 0 0 18px; letter-spacing: -0.01em; }
.visual { display: flex; justify-content: center; margin: 0 0 20px; padding: 10px; border-radius: var(--radius-sm); background: #f7f9fc; border: 1px dashed var(--line); }
.visual svg { width: min(300px, 80vw); height: auto; }
.visual svg.lewis { width: min(260px, 75vw); }

fieldset.part { border: 0; padding: 0; margin: 0 0 20px; }
fieldset.part legend { font-weight: 600; font-size: 1rem; margin-bottom: 10px; padding: 0; }
.options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.options.pictures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.option {
  position: relative; min-height: 58px; padding: 12px 16px;
  border: 2px solid var(--line); border-radius: var(--radius-sm); background: #fff;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 1.15rem; font-weight: 500; cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
}
.option:hover { border-color: #93a6c4; }
.option[aria-checked='true'] { border-color: var(--nitrogen); background: #eaf1fd; box-shadow: inset 0 0 0 1px var(--nitrogen); }
.option.picture { padding: 6px; }
.option.picture svg { width: 100%; max-width: 210px; height: auto; }
.option .tick {
  position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 6px;
  border: 2px solid var(--line); background: #fff; display: grid; place-items: center; font-size: 14px; color: #fff;
}
.option[aria-checked='true'] .tick { background: var(--nitrogen); border-color: var(--nitrogen); }
.text-answer input {
  width: 100%; min-height: 54px; padding: 10px 14px; font-size: 1.15rem;
  border: 2px solid var(--line); border-radius: var(--radius-sm);
}
.text-answer input:focus { border-color: var(--nitrogen); outline: none; box-shadow: 0 0 0 3px rgba(47, 111, 214, 0.2); }
.number-row { display: flex; align-items: center; gap: 10px; }
.number-row input { max-width: 220px; }
.unit-label { font-weight: 600; font-size: 1.1rem; }
.opt-name small { font-weight: 400; color: var(--ink-2); }
.opt-sub { display: block; font-size: 0.85rem; }
.option.picture svg.polymer { max-width: 220px; }
.visual svg.graph { width: min(420px, 88vw); }
.hint { display: block; color: var(--ink-2); font-size: 0.9rem; margin-top: 6px; }
.actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 6px; }
.flash { font-weight: 600; color: var(--chlorine); }
.panel.correct { border-color: var(--chlorine); box-shadow: 0 0 0 3px rgba(46, 158, 91, 0.25), var(--shadow); }

/* ---------- end screen ---------- */
.end { text-align: center; }
.end .score { font-size: clamp(4rem, 14vw, 7rem); font-weight: 700; line-height: 1; letter-spacing: -0.05em; margin: 4px 0 4px; font-variant-numeric: tabular-nums; }
.end .score small { font-size: 0.4em; color: var(--ink-2); letter-spacing: 0; }
.end .verdict { font-size: 1.3rem; font-weight: 600; margin: 0 0 18px; }
.end .stats { display: flex; justify-content: center; gap: 28px; flex-wrap: wrap; margin: 0 0 24px; }
.end .stats div { display: grid; }
.end .stats span { font-size: 0.9rem; color: var(--ink-2); }
.end .stats strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.new-best { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--sulfur); color: var(--ink); font-size: 0.8rem; font-weight: 600; }
.mascot { width: min(220px, 55vw); height: auto; margin: 0 auto 6px; display: block; }
.code-card { display: inline-grid; gap: 4px; margin: 0 auto 24px; padding: 16px 28px; border-radius: var(--radius-sm); border: 2px dashed var(--chlorine); background: #effaf3; }
.code-card .code { font-size: 2rem; font-weight: 700; letter-spacing: 0.18em; font-variant-numeric: tabular-nums; }
.code-card span { color: var(--ink-2); font-size: 0.95rem; }
.review { text-align: left; margin: 0 0 24px; padding: 20px; border-radius: var(--radius-sm); background: #fbf5f4; border: 1.5px solid #efc9c6; }
.review h2 { font-size: 1.1rem; margin: 0 0 10px; }
.review .prompt { font-size: 1.15rem; }
.review .visual { background: #fff; }
.compare { display: grid; gap: 10px; margin: 0 0 14px; }
.compare-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.compare-row h3 { grid-column: 1 / -1; margin: 0; font-size: 0.95rem; }
.answer-box { padding: 10px 12px; border-radius: var(--radius-sm); background: #fff; border: 2px solid var(--line); }
.answer-box > span { display: block; font-size: 0.85rem; color: var(--ink-2); margin-bottom: 2px; }
.answer-box.wrong { border-color: var(--oxygen); }
.answer-box.right { border-color: var(--chlorine); }
.answer-box svg { width: 100%; max-width: 170px; height: auto; display: block; margin: 0 auto; }
.reason { margin: 0; line-height: 1.6; }
.end-actions { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

.status { text-align: center; color: var(--ink-2); padding: 40px 0; }
.verify { max-width: 520px; margin: 0 auto; padding: 0 16px 64px; }
.verify h1 { font-size: 2rem; letter-spacing: -0.02em; margin: 12px 0 8px; }
.verify select { width: 100%; min-height: 52px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: #fff; font: inherit; }
.result { margin-top: 18px; padding: 16px; border-radius: var(--radius-sm); font-weight: 600; }
.result.yes { background: #effaf3; border: 2px solid var(--chlorine); }
.result.no { background: #fbf5f4; border: 2px solid var(--oxygen); }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .topbar { padding: 14px 16px; }
  .brand { font-size: 1rem; gap: 8px; }
  .brand svg { width: 30px; height: 30px; }
  .who-label { display: none; }
  .play-bar .title { font-size: 0.95rem; }
  .options { grid-template-columns: 1fr; }
  .options.pictures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .game { flex-direction: column; align-items: stretch; }
  .compare-row { grid-template-columns: 1fr; }
  .unit { grid-template-columns: 56px 1fr; }
  .atom { width: 56px; height: 56px; font-size: 1.3rem; }
}

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