:root {
  --ink: #172c33; --muted: #62747a; --paper: #f5f2e9; --white: #fffdf8;
  --rule: #ccd4cf; --teal: #157d78; --teal-dark: #105f5c; --teal-soft: #dcefea;
  --orange: #e26c3f; --red: #b94838; --red-soft: #f6dfd8;
  --shadow: 0 22px 60px rgba(23, 44, 51, .11);
}
* { box-sizing: border-box; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: Arial, Helvetica, sans-serif; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.site-header { height: 76px; padding: 0 max(24px, calc((100vw - 1180px) / 2)); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--rule); background: rgba(245,242,233,.92); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(14px); }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; background: var(--teal); color: white; font: 700 19px "Source Serif 4", serif; }
.brand > span:last-child { display: flex; flex-direction: column; line-height: 1.05; }
.brand strong { font-size: 14px; letter-spacing: -.01em; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; }
nav { display: flex; align-items: center; gap: 8px; }
.nav-link { padding: 10px 12px; border: 0; background: transparent; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600; cursor: pointer; }
.nav-link:hover { color: var(--teal); }
.auth-link { border: 1px solid #9fc9c2; border-radius: 7px; color: var(--teal-dark); }
main { width: min(1180px, calc(100% - 48px)); margin: 0 auto; }
.intro { padding: 48px 0 32px; }
.eyebrow { margin: 0 0 14px; color: var(--teal); font: 500 11px DM Mono, monospace; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font: 700 clamp(48px, 7vw, 82px)/.95 "Source Serif 4", serif; letter-spacing: -.055em; }
h1 em { color: var(--teal); font-weight: 700; }
.lede { max-width: 440px; margin-bottom: 6px; color: var(--muted); font-size: 16px; line-height: 1.7; }
.game-shell { overflow: hidden; margin-bottom: 84px; border: 1px solid var(--rule); border-radius: 18px; background: var(--white); box-shadow: var(--shadow); }
.game-toolbar { min-height: 82px; padding: 16px 26px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--rule); background: #fdfbf5; }
.toolbar-controls { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.mode-picker { display: flex; align-items: center; gap: 7px; margin: 0; padding: 0; border: 0; }
.mode-picker legend { float: left; margin-right: 12px; color: var(--muted); font: 500 10px DM Mono, monospace; letter-spacing: .1em; text-transform: uppercase; }
.mode-picker label { cursor: pointer; }
.mode-picker label:has(input:disabled) { cursor: not-allowed; }
.mode-picker input { position: absolute; opacity: 0; pointer-events: none; }
.mode-picker span { display: block; min-width: 62px; padding: 9px 13px; border: 1px solid transparent; border-radius: 99px; color: var(--muted); text-align: center; font-size: 12px; font-weight: 700; white-space: nowrap; }
.mode-picker input:checked + span { border-color: #9fc9c2; background: var(--teal-soft); color: var(--teal-dark); }
.mode-picker input:focus-visible + span { outline: 3px solid rgba(21,125,120,.25); }
.mode-picker input:disabled + span { opacity: .42; }
.session-picker span { min-width: 112px; }
.session-note { margin: -5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.timer { display: flex; align-items: baseline; gap: 12px; }
.timer span { color: var(--muted); font: 500 10px DM Mono, monospace; letter-spacing: .1em; text-transform: uppercase; }
.timer strong { min-width: 76px; font: 500 18px DM Mono, monospace; font-variant-numeric: tabular-nums; }
.instruction { margin: 28px 26px 20px; color: var(--muted); text-align: center; font-size: 13px; }
.puzzle-stage { min-height: 480px; position: relative; }
.start-screen { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 36px 24px; border-top: 1px solid var(--rule); background: var(--white); text-align: center; }
.start-screen p { max-width: 390px; margin: 0; color: var(--ink); font-size: 16px; font-weight: 700; line-height: 1.5; }
.start-screen small { color: var(--muted); font-size: 11px; }
.molecule-grid { display: grid; grid-template-columns: repeat(5, 1fr); padding: 0 22px; }
.molecule-card { min-width: 0; position: relative; margin: 0; padding: 12px 10px 15px; border-right: 1px solid var(--rule); text-align: center; }
.molecule-card:last-child { border-right: 0; }
.molecule-number { position: absolute; left: 13px; top: 10px; z-index: 1; color: #97a4a7; font: 500 10px DM Mono, monospace; }
.molecule-card img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; mix-blend-mode: multiply; }
.molecule-card small { color: var(--muted); font: 500 10px DM Mono, monospace; letter-spacing: .08em; text-transform: uppercase; }
.atom-key { display: flex; justify-content: center; flex-wrap: wrap; gap: 9px 17px; padding: 16px 20px 22px; color: var(--muted); font-size: 9px; }
.atom-key span { display: inline-flex; align-items: center; gap: 5px; }
.atom { width: 9px; height: 9px; border: 1px solid rgba(23,44,51,.28); border-radius: 50%; box-shadow: inset -2px -2px 2px rgba(0,0,0,.18); }
.atom.carbon { background: #525b5e; }.atom.hydrogen { background: #f1f3ef; }.atom.nitrogen { background: #305bbe; }.atom.oxygen { background: #d23430; }.atom.sulfur { background: #e1b120; }
.answer-area { padding: 26px 24px 34px; border-top: 1px solid var(--rule); background: #f9f7f0; text-align: center; }
.letter-grid { width: min(510px, 100%); margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.letter-grid input { width: 100%; min-width: 0; aspect-ratio: 1; max-height: 84px; border: 1px solid #aebbb6; border-radius: 10px; background: var(--white); color: var(--ink); text-align: center; text-transform: uppercase; font: 700 clamp(26px, 5vw, 40px) DM Mono, monospace; caret-color: var(--teal); outline: none; transition: border .15s, box-shadow .15s, background .15s; }
.letter-grid input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(21,125,120,.14); }
.letter-grid input.is-correct { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); opacity: 1; }
.letter-grid input.is-wrong { border-color: var(--red); background: var(--red-soft); color: var(--red); opacity: 1; }
.form-error { min-height: 18px; margin: 10px 0 2px; color: var(--red); font-size: 12px; }
.check-button { min-width: 190px; padding: 14px 20px; border: 0; border-radius: 8px; background: var(--teal); color: white; font-weight: 700; cursor: pointer; box-shadow: 0 7px 18px rgba(21,125,120,.18); }
.check-button span { margin-left: 24px; }
.check-button:hover { background: var(--teal-dark); }
.result-panel { padding: 30px clamp(24px, 5vw, 64px) 38px; border-top: 1px solid var(--rule); }
.result-panel.is-wrong { background: #fffaf7; }
.result-heading { display: flex; align-items: center; gap: 16px; }
.result-icon { display: grid; place-items: center; width: 46px; height: 46px; flex: 0 0 auto; border-radius: 50%; background: var(--teal-soft); color: var(--teal); font-size: 22px; font-weight: 800; }
.is-wrong .result-icon { background: var(--red-soft); color: var(--red); }
.result-heading p { margin: 0 0 3px; color: var(--teal); font: 500 10px DM Mono, monospace; letter-spacing: .1em; text-transform: uppercase; }
.is-wrong .result-heading p { color: var(--red); }
.result-heading h2 { margin: 0; font: 700 28px "Source Serif 4", serif; }
.result-panel > p { margin: 20px 0; color: var(--muted); line-height: 1.6; }
.answer-reveal { display: inline-flex; align-items: center; gap: 22px; margin-bottom: 26px; padding: 12px 16px; border: 1px solid var(--rule); border-radius: 8px; background: var(--white); }
.answer-reveal span { color: var(--muted); font: 500 10px DM Mono, monospace; letter-spacing: .09em; text-transform: uppercase; }
.answer-reveal strong { font: 500 18px DM Mono, monospace; letter-spacing: .16em; }
.result-actions { display: flex; align-items: center; gap: 18px; }
.text-button { border: 0; border-bottom: 1px solid currentColor; background: none; color: var(--teal-dark); font-size: 12px; font-weight: 700; cursor: pointer; }
.reference-dialog { width: min(760px, calc(100% - 30px)); max-height: calc(100vh - 40px); padding: 28px; border: 0; border-radius: 16px; background: var(--white); color: var(--ink); box-shadow: 0 30px 100px rgba(0,0,0,.25); }
.reference-dialog::backdrop { background: rgba(14,35,41,.62); backdrop-filter: blur(4px); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; }
.dialog-heading h2 { margin-bottom: 10px; font: 700 34px "Source Serif 4", serif; }
.dialog-heading button { width: 36px; height: 36px; border: 1px solid var(--rule); border-radius: 50%; background: transparent; color: var(--ink); font-size: 22px; cursor: pointer; }
.reference-dialog > p { color: var(--muted); font-size: 13px; }
.reference-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.reference-item { display: grid; grid-template-columns: 31px 1fr; align-items: center; gap: 8px; padding: 9px; border: 1px solid #e0e4e0; border-radius: 7px; }
.reference-item strong { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 5px; background: var(--teal-soft); color: var(--teal-dark); font: 700 14px DM Mono, monospace; }
.reference-item span { font-size: 11px; font-weight: 600; }
.reference-item small { display: block; margin-top: 2px; color: var(--muted); font: 400 9px DM Mono, monospace; }
.help-dialog { width: min(640px, calc(100% - 30px)); }
.help-steps { margin: 10px 0 28px; padding-left: 24px; color: var(--ink); font-size: 14px; line-height: 1.65; }
.help-steps li + li { margin-top: 6px; }
.help-details { display: grid; gap: 0; margin: 0; border-top: 1px solid var(--rule); }
.help-details div { display: grid; grid-template-columns: 145px 1fr; gap: 18px; padding: 15px 0; border-bottom: 1px solid var(--rule); }
.help-details dt { font-size: 12px; font-weight: 700; }
.help-details dd { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
footer { display: flex; justify-content: space-between; gap: 20px; padding: 24px max(24px, calc((100vw - 1180px) / 2)); border-top: 1px solid var(--rule); color: var(--muted); font-size: 11px; }
footer a { color: var(--teal-dark); }
[hidden] { display: none !important; }
@media (max-width: 760px) {
  .site-header { height: auto; min-height: 70px; padding: 12px 18px; }
  nav a:not(.auth-link) { display: none; }
  .auth-link { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  main { width: min(100% - 24px, 600px); }
  .intro { padding: 36px 6px 24px; }
  h1 { font-size: clamp(43px, 15vw, 64px); }
  .game-toolbar { align-items: flex-end; padding: 14px 16px; }
  .toolbar-controls { width: calc(100% - 88px); }
  .mode-picker { flex-wrap: wrap; }
  .mode-picker legend { width: 100%; margin: 0 0 6px; }
  .mode-picker span { min-width: 51px; padding: 8px 9px; }
  .timer { flex-direction: column; gap: 4px; align-items: flex-end; }
  .molecule-grid { padding: 0 5px; }
  .puzzle-stage { min-height: 400px; }
  .molecule-card { padding: 8px 2px 12px; }
  .molecule-card small { font-size: 8px; }
  .molecule-number { left: 5px; top: 5px; font-size: 8px; }
  .answer-area { padding: 22px 12px 28px; }
  .letter-grid { gap: 6px; }
  .result-actions { align-items: flex-start; flex-direction: column; }
  .reference-grid { grid-template-columns: repeat(2, 1fr); }
  .help-details div { grid-template-columns: 1fr; gap: 5px; }
  footer { flex-direction: column; }
}
@media (max-width: 500px) {
  .game-toolbar { align-items: stretch; flex-direction: column; gap: 14px; }
  .toolbar-controls { width: 100%; }
  .timer { align-items: baseline; flex-direction: row; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--rule); }
  .session-picker label { flex: 1; }
  .session-picker span { min-width: 0; }
  .reference-dialog { padding: 22px 18px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
