:root {
  color-scheme: dark;
  --ink: #f5f0ff;
  --muted: #c3b8d4;
  --violet: #a977ff;
  --violet-dark: #6d3ec1;
  --gold: #f2c66d;
  --red: #ff6b7b;
  --green: #87e6b0;
  --panel: rgba(27, 18, 43, .82);
  --line: rgba(222, 199, 255, .28);
  --bg: #0d0815;
  --accent: #a977ff;
  --accent-soft: rgba(169, 119, 255, .28);
  --accent-deep: #6d3ec1;
  --secondary: #f2c66d;
  --secondary-soft: rgba(242, 198, 109, .18);
  --surface-a: rgba(43, 28, 64, .86);
  --surface-b: rgba(19, 13, 29, .92);
}

body[data-book="upper"] { --accent: #7dc8ff; --accent-soft: rgba(125, 200, 255, .28); --accent-deep: #2267a7; --secondary: #ffd36b; --secondary-soft: rgba(255, 211, 107, .18); --surface-a: rgba(24, 49, 75, .9); --surface-b: rgba(12, 18, 33, .94); }
body[data-book="lower"] { --accent: #a977ff; --accent-soft: rgba(169, 119, 255, .28); --accent-deep: #6d3ec1; --secondary: #f2c66d; --secondary-soft: rgba(242, 198, 109, .18); --surface-a: rgba(43, 28, 64, .88); --surface-b: rgba(19, 13, 29, .94); }
body[data-book="grade8-upper"] { --accent: #4fd0bb; --accent-soft: rgba(79, 208, 187, .25); --accent-deep: #1d7d72; --secondary: #ffcf7a; --secondary-soft: rgba(255, 207, 122, .17); --surface-a: rgba(18, 62, 62, .88); --surface-b: rgba(9, 24, 29, .94); }
body[data-book="grade8-lower"] { --accent: #ff9f7a; --accent-soft: rgba(255, 159, 122, .24); --accent-deep: #a95737; --secondary: #9fe6ff; --secondary-soft: rgba(159, 230, 255, .17); --surface-a: rgba(74, 37, 30, .88); --surface-b: rgba(28, 15, 17, .94); }
body[data-book="grade9-upper"] { --accent: #99d86f; --accent-soft: rgba(153, 216, 111, .24); --accent-deep: #477b35; --secondary: #d9c36a; --secondary-soft: rgba(217, 195, 106, .17); --surface-a: rgba(35, 61, 35, .9); --surface-b: rgba(15, 24, 18, .94); }
body[data-book="grade9-lower"] { --accent: #f08bd8; --accent-soft: rgba(240, 139, 216, .25); --accent-deep: #9a4a88; --secondary: #7ddcff; --secondary-soft: rgba(125, 220, 255, .18); --surface-a: rgba(61, 31, 62, .9); --surface-b: rgba(22, 14, 30, .95); }

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); overflow-x: hidden; }
body {
  margin: 0; min-height: 100vh; color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    linear-gradient(115deg, rgba(255,255,255,.025) 0 1px, transparent 1px 72px),
    linear-gradient(155deg, var(--surface-a) 0%, #09060f 70%);
  overflow-x: hidden;
  transition: background .45s ease, color .25s ease;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background:
    radial-gradient(circle at 18% 12%, var(--accent-soft), transparent 34%),
    radial-gradient(circle at 85% 36%, var(--secondary-soft), transparent 32%),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: auto, auto, 74px 74px, 74px 74px;
  animation: atmosphere 16s ease-in-out infinite alternate;
}
button, textarea { font: inherit; }
button { color: inherit; }
.mist { position: fixed; border-radius: 50%; filter: blur(70px); pointer-events: none; opacity: .22; animation: drift 11s ease-in-out infinite alternate; }
.mist-one { width: 380px; height: 220px; background: var(--accent); left: -180px; top: 40%; }
.mist-two { width: 300px; height: 180px; background: var(--secondary); right: -120px; top: 12%; animation-delay: -4s; }

.topbar {
  position: sticky; top: 0; z-index: 20; height: 76px; display: flex; align-items: center;
  justify-content: space-between; padding: 0 max(24px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid var(--line); background: rgba(10,6,17,.76); backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 11px; border: 0; background: none; cursor: pointer; text-align: left; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid color-mix(in srgb, var(--accent) 52%, transparent); border-radius: 50%; color: var(--secondary); font-size: 23px; box-shadow: inset 0 0 18px var(--accent-soft), 0 0 22px rgba(0,0,0,.18); animation: sigil 4s ease-in-out infinite; }
.brand b { display: block; font-family: Georgia, "Songti SC", serif; font-size: 18px; letter-spacing: .08em; }
.brand small { display: block; color: var(--muted); letter-spacing: .18em; font-size: 8px; margin-top: 3px; }
.source-badge { color: var(--muted); font-size: 12px; letter-spacing: .06em; }
#sourceCount { color: var(--secondary); }
.ghost-button, .back-link { border: 0; background: none; color: var(--muted); cursor: pointer; }
.ghost-button { border: 1px solid var(--line); border-radius: 999px; padding: 9px 15px; }
.ghost-button:hover, .back-link:hover { color: white; border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar .hall-back { padding: 7px 12px; font-size: 13px; box-shadow: 0 3px 0 #4a2a08; }

main { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 52px 0 80px; }
.screen { display: none; }
.screen.active { display: block; animation: appear .42s cubic-bezier(.2,.8,.2,1) both; }
.hero { display: grid; grid-template-columns: 1.35fr .65fr; align-items: center; min-height: 390px; border-bottom: 1px solid var(--line); }
.eyebrow { color: var(--secondary); font-size: 10px; letter-spacing: .24em; font-weight: 800; text-transform: uppercase; }
.hero h1 { margin: 15px 0 22px; font-family: Georgia, "Songti SC", serif; font-size: clamp(40px, 5.8vw, 72px); line-height: 1.12; font-weight: 500; }
.hero h1 em { color: var(--accent); font-style: normal; text-shadow: 0 0 34px var(--accent-soft); }
.hero-copy > p:not(.eyebrow) { max-width: 640px; color: var(--muted); font-size: 16px; line-height: 1.9; }
.hero-stats { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
.hero-stats span { padding: 10px 14px; background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 8px; color: var(--muted); font-size: 12px; animation: riseIn .42s ease both; }
.hero-stats b { color: white; font-size: 16px; margin-right: 4px; }
.cauldron-art { position: relative; width: 280px; height: 280px; justify-self: end; display: grid; place-items: center; }
.pot { width: 210px; height: 125px; margin-top: 55px; border-radius: 16px 16px 90px 90px; border: 2px solid color-mix(in srgb, var(--accent) 70%, white); background: radial-gradient(circle at 50% 0%, var(--accent) 0 4%, #302043 35%, #160f23 74%); box-shadow: 0 28px 70px var(--accent-soft), inset 0 -10px 30px #09060f; display: grid; place-items: center; animation: brew 4.8s ease-in-out infinite; }
.pot::before { content: ""; position: absolute; top: 75px; width: 236px; height: 24px; border-radius: 50%; background: linear-gradient(90deg, #191023, color-mix(in srgb, var(--accent) 34%, #191023), #191023); border: 3px solid color-mix(in srgb, var(--accent) 68%, white); box-shadow: inset 0 6px 10px #050309, 0 0 25px var(--accent-soft); animation: shimmer 5.2s linear infinite; }
.pot span { color: var(--secondary); font-size: 34px; z-index: 1; animation: sigil 3.8s ease-in-out infinite; }
.steam { position: absolute; top: 16px; font-size: 80px; color: var(--accent-soft); transform: rotate(-8deg); animation: steam 4.5s ease-in-out infinite; }
.flame { position: absolute; bottom: 18px; color: var(--accent); font-size: 42px; filter: drop-shadow(0 0 15px var(--accent)); animation: flame 1.6s ease-in-out infinite; }
.bubble { position: absolute; border: 1px solid color-mix(in srgb, var(--accent) 65%, white); background: var(--accent-soft); border-radius: 50%; animation: float 3s ease-in-out infinite; }
.b1 { width: 15px; height: 15px; top: 60px; left: 55px; }.b2 { width: 9px; height: 9px; top: 28px; right: 65px; animation-delay: -.7s; }.b3 { width: 21px; height: 21px; top: 85px; right: 38px; animation-delay: -1.3s; }

.section-heading { display: flex; justify-content: space-between; align-items: end; margin: 48px 0 22px; gap: 20px; }
.section-heading h2, .setup-head h2 { margin: 5px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 32px; font-weight: 500; }
.section-heading > p { color: var(--muted); max-width: 450px; line-height: 1.7; font-size: 13px; text-align: right; }
.level-heading { margin-top: 18px; }
.book-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.book-card { min-height: 210px; padding: 28px; text-align: left; border: 1px solid rgba(222,199,255,.18); border-radius: 8px; cursor: pointer; background:
  linear-gradient(115deg, rgba(255,255,255,.045) 0 1px, transparent 1px 34px),
  radial-gradient(circle at 90% 15%, var(--secondary-soft), transparent 34%),
  linear-gradient(145deg, var(--surface-a), var(--surface-b)); transition: .28s ease; position: relative; overflow: hidden; animation: riseIn .48s cubic-bezier(.2,.8,.2,1) both; animation-delay: var(--delay); }
.book-card::before { content: "☾"; position: absolute; right: 24px; top: 18px; color: var(--secondary-soft); font-size: 54px; transition: .28s ease; }
.book-card::after { content: ""; position: absolute; left: 28px; right: 28px; bottom: 24px; height: 1px; background: linear-gradient(90deg, var(--accent), transparent); }
.book-card:hover { transform: translateY(-6px); border-color: color-mix(in srgb, var(--accent) 70%, transparent); box-shadow: 0 24px 48px rgba(0,0,0,.28), 0 0 36px var(--accent-soft); }
.book-card:hover::before { transform: translateY(4px) rotate(12deg); color: var(--secondary); }
.book-card span { color: var(--secondary); font-size: 10px; letter-spacing: .18em; text-transform: uppercase; }
.book-card b { display: block; margin: 20px 0 42px; font-family: Georgia, "Songti SC", serif; font-size: clamp(30px, 5vw, 46px); font-weight: 500; }
.book-card small { color: var(--muted); line-height: 1.7; }
.level-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.level-card { min-height: 150px; padding: 20px; text-align: left; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background:
  linear-gradient(135deg, rgba(255,255,255,.04), transparent 42%),
  linear-gradient(145deg, color-mix(in srgb, var(--surface-a) 82%, transparent), color-mix(in srgb, var(--surface-b) 92%, transparent)); transition: .25s ease; position: relative; overflow: hidden; animation: riseIn .42s cubic-bezier(.2,.8,.2,1) both; animation-delay: var(--delay); }
.level-card::after { content: "✦"; position: absolute; right: 14px; top: 11px; color: var(--secondary-soft); font-size: 28px; transition: .28s ease; }
.level-card:hover { transform: translateY(-4px); border-color: color-mix(in srgb, var(--accent) 62%, transparent); box-shadow: 0 18px 35px rgba(0,0,0,.25), 0 0 28px var(--accent-soft); }
.level-card:hover::after { color: var(--secondary); transform: rotate(18deg) scale(1.1); }
.level-card span { color: var(--secondary); font-size: 10px; letter-spacing: .18em; }
.level-card b { display: block; margin: 12px 0 16px; font-family: Georgia, serif; font-size: 23px; font-weight: 500; }
.level-card small { color: var(--muted); }

.back-link { margin-bottom: 24px; padding: 8px 0; }
.setup-shell { border: 1px solid var(--line); background:
  linear-gradient(145deg, rgba(255,255,255,.035), transparent 36%),
  color-mix(in srgb, var(--surface-b) 82%, transparent); border-radius: 8px; padding: clamp(24px, 5vw, 54px); min-height: 610px; box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 24px 70px rgba(0,0,0,.25); }
.setup-head { text-align: center; margin-bottom: 40px; }
.setup-head > p:last-child { color: var(--muted); }
.setup-step { display: none; }
.setup-step.active { display: block; animation: appear .35s cubic-bezier(.2,.8,.2,1); }
.punishment-grid { display: grid; grid-template-columns: 1fr 52px 1fr; align-items: center; gap: 18px; }
.player-panel { display: block; min-height: 245px; padding: 26px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.025); transition: border-color .25s ease, box-shadow .25s ease, transform .25s ease; }
.player-panel:focus-within { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 58%, transparent); box-shadow: 0 16px 36px rgba(0,0,0,.2); }
.player-panel b { display: block; margin: 14px 0 16px; font-size: 18px; }
.player-tag { font-size: 10px; letter-spacing: .14em; }
.player-one .player-tag { color: #c39bff; }.player-two .player-tag { color: var(--gold); }
textarea { width: 100%; height: 130px; resize: vertical; border: 1px solid var(--line); border-radius: 8px; padding: 14px; color: white; background: rgba(4,2,8,.35); outline: none; line-height: 1.6; }
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.versus { font-family: Georgia, serif; color: var(--muted); text-align: center; font-size: 18px; }
.brew-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 22px 0; padding: 16px 18px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.02); }
.brew-row b, .brew-row small { display: block; }.brew-row small { color: var(--muted); margin-top: 5px; }
.segmented { display: flex; padding: 4px; border-radius: 8px; background: #0b0711; }
.brew-choice { border: 0; background: transparent; color: var(--muted); padding: 9px 14px; border-radius: 7px; cursor: pointer; }
.brew-choice.active { color: white; background: var(--accent-deep); box-shadow: 0 0 18px var(--accent-soft); }
.primary-button, .secondary-button { border-radius: 9px; padding: 13px 22px; cursor: pointer; font-weight: 700; letter-spacing: .03em; }
.primary-button { display: block; margin: 28px auto 0; border: 1px solid color-mix(in srgb, var(--accent) 70%, white); background: linear-gradient(135deg, var(--accent), var(--accent-deep)); box-shadow: 0 8px 25px var(--accent-soft); position: relative; overflow: hidden; }
.primary-button::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 0 30%, rgba(255,255,255,.24) 45%, transparent 60%); transform: translateX(-130%); }
.primary-button:hover::after { animation: sweep .8s ease; }
.primary-button:hover { filter: brightness(1.12); transform: translateY(-1px); }
.secondary-button { border: 1px solid var(--line); background: rgba(255,255,255,.04); }

.secret-banner { display: flex; align-items: center; gap: 16px; max-width: 760px; margin: 0 auto 24px; padding: 17px 20px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.025); }
.secret-banner > span { flex: none; padding: 8px 12px; border-radius: 8px; background: var(--violet-dark); font-weight: 800; }
.secret-banner b, .secret-banner small { display: block; }.secret-banner small { margin-top: 4px; color: var(--muted); }
.card-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.compact { max-width: 760px; margin: 0 auto; }
.word-card { position: relative; aspect-ratio: 1 / 1; min-height: 92px; border: 1px solid rgba(197,164,235,.22); border-radius: 8px; cursor: pointer; background:
  linear-gradient(135deg, color-mix(in srgb, var(--accent) 16%, transparent), transparent 38%),
  linear-gradient(145deg, #2c1d42, #171022); box-shadow: 0 7px 15px rgba(0,0,0,.22); transform-style: preserve-3d; transition: .3s ease; overflow: hidden; animation: cardDeal .38s cubic-bezier(.2,.8,.2,1) both; animation-delay: var(--delay); }
.word-card::before { content: "☾"; display: grid; place-items: center; position: absolute; inset: 10px; border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent); border-radius: 50%; color: color-mix(in srgb, var(--secondary) 72%, transparent); font-size: clamp(18px, 2vw, 28px); transition: .28s ease; }
.word-card::after { content: attr(data-number); position: absolute; left: 9px; top: 7px; color: var(--muted); font-size: 9px; letter-spacing: .12em; }
.word-card:hover:not(:disabled) { transform: translateY(-4px) rotate(.5deg); border-color: var(--accent); box-shadow: 0 14px 26px rgba(61,32,95,.45), 0 0 24px var(--accent-soft); }
.word-card:hover:not(:disabled)::before { color: var(--secondary); transform: scale(1.06); }
.word-card:disabled { cursor: default; }
.word-card.resolved { background: rgba(20,14,28,.5); box-shadow: none; transform: rotateY(180deg); animation: none; }
.word-card.resolved::before { content: attr(data-word); inset: 0; border: 0; border-radius: 0; transform: rotateY(180deg); padding: 8px; font-size: clamp(9px, 1.4vw, 15px); color: white; font-weight: 700; overflow-wrap: anywhere; text-align: center; }
.word-card.resolved.correct-p1 { border-color: color-mix(in srgb, var(--accent) 70%, transparent); background: var(--accent-soft); }
.word-card.resolved.correct-p2 { border-color: rgba(242,198,109,.7); background: rgba(140,101,34,.25); }
.word-card.resolved.wrong { border-color: rgba(255,107,123,.5); background: rgba(115,29,45,.18); }
.pass-step { text-align: center; padding: 65px 20px; }
.pass-orb { width: 90px; height: 90px; display: grid; place-items: center; margin: 0 auto 26px; border-radius: 50%; border: 1px solid var(--accent); color: var(--secondary); font-size: 48px; box-shadow: inset 0 0 35px var(--accent-soft), 0 0 45px var(--accent-soft); animation: sigil 4s ease-in-out infinite; }
.pass-step h2 { font-family: Georgia, "Songti SC", serif; font-weight: 500; font-size: 32px; }
.pass-step > p:not(.eyebrow) { color: var(--muted); }

.game-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-bottom: 18px; }
.game-head .back-link { margin: 0; justify-self: start; }
.game-title { text-align: center; }.game-title span, .game-title b { display: block; }.game-title span { color: var(--secondary); font-size: 10px; letter-spacing: .18em; }.game-title b { margin-top: 5px; font-family: Georgia, "Songti SC", serif; font-size: 24px; }
.progress-wrap { justify-self: end; color: var(--muted); font-size: 11px; }
.progress-wrap i { display: block; width: 120px; height: 4px; background: rgba(255,255,255,.08); margin-top: 7px; border-radius: 4px; overflow: hidden; }
.progress-wrap i b { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--accent), var(--secondary)); transition: width .3s; }
.scoreboard { display: grid; grid-template-columns: 1fr 80px 1fr; align-items: center; max-width: 680px; margin: 0 auto 24px; }
.score { display: flex; align-items: baseline; gap: 10px; padding: 15px 20px; border: 1px solid var(--line); background: var(--panel); }
.score:first-child { border-radius: 12px 0 0 12px; }.score:last-child { border-radius: 0 12px 12px 0; justify-content: flex-end; }
.score span { color: var(--muted); font-size: 11px; }.score b { font-size: 26px; }.score small { color: var(--muted); font-size: 9px; }
.turn-orb { z-index: 2; width: 70px; height: 70px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; align-content: center; border: 1px solid var(--accent); background: #171021; box-shadow: 0 0 30px var(--accent-soft); animation: sigil 4.4s ease-in-out infinite; }
.turn-orb span { font: 26px Georgia, serif; }.turn-orb small { color: var(--secondary); font-size: 7px; letter-spacing: .18em; }
.game-grid { max-width: 790px; margin: 0 auto; gap: 14px; }
.game-grid .word-card { min-height: 112px; }
.game-hint { text-align: center; color: var(--muted); font-size: 11px; margin-top: 22px; }

.modal { display: none; position: fixed; inset: 0; z-index: 50; padding: 20px; place-items: center; background: rgba(5,3,9,.78); backdrop-filter: blur(10px); }
.modal.open { display: grid; animation: fadeIn .22s ease; }
.modal-card { width: min(520px, 100%); border: 1px solid color-mix(in srgb, var(--accent) 36%, transparent); border-radius: 8px; padding: 34px; background: linear-gradient(150deg, color-mix(in srgb, var(--surface-a) 70%, #120c1c), #120c1c); box-shadow: 0 35px 90px rgba(0,0,0,.55), 0 0 38px var(--accent-soft); position: relative; animation: modalPop .28s cubic-bezier(.2,.8,.2,1) both; }
.question-top { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; letter-spacing: .17em; }
.question-top button { border: 1px solid var(--line); border-radius: 50%; background: rgba(255,255,255,.03); width: 34px; height: 34px; cursor: pointer; }
.question-card h2 { font-family: "PingFang SC", "Microsoft YaHei", Georgia, serif; font-size: clamp(28px, 5.4vw, 44px); font-weight: 500; margin: 12px 0 28px; overflow-wrap: anywhere; line-height: 1.25; }
.answers { display: grid; gap: 10px; }
.answer { display: flex; gap: 12px; align-items: center; text-align: left; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.025); cursor: pointer; line-height: 1.5; transition: .2s ease; }
.answer:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateX(3px); }
.answer i { display: grid; place-items: center; flex: none; width: 27px; height: 27px; border-radius: 50%; border: 1px solid rgba(255,255,255,.15); color: var(--secondary); font-style: normal; font-size: 11px; }
.answer-note { text-align: center; color: var(--muted); font-size: 10px; margin: 18px 0 0; }
.result-card { text-align: center; }
.result-icon { display: grid; place-items: center; width: 76px; height: 76px; margin: 0 auto 22px; border-radius: 50%; color: var(--green); border: 1px solid currentColor; font-size: 35px; box-shadow: inset 0 0 24px rgba(135,230,176,.12), 0 0 22px currentColor; animation: sigil 3.3s ease-in-out infinite; }
.result-icon.bad { color: var(--red); }
.result-card h2 { margin: 8px 0 12px; font: 34px Georgia, "Songti SC", serif; }
.result-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.7; }
.punishment-reveal { display: none; margin-top: 20px; padding: 16px; border: 1px solid rgba(255,107,123,.3); border-radius: 8px; background: rgba(255,107,123,.07); color: #ffd8dd; line-height: 1.6; }
.punishment-reveal.show { display: block; }
.finish-actions { display: flex; justify-content: center; gap: 10px; margin-top: 22px; }.finish-actions .primary-button { margin: 0; }
.trophy { color: var(--gold); }
.rules-card { width: min(620px, 100%); }
.rules-card h2 { font: 36px Georgia, "Songti SC", serif; margin: 10px 0 25px; }
.rules-card ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 14px; counter-reset: rules; }
.rules-card li { counter-increment: rules; display: grid; grid-template-columns: 34px 105px 1fr; align-items: start; gap: 10px; }
.rules-card li::before { content: counter(rules); width: 27px; height: 27px; display: grid; place-items: center; border: 1px solid var(--violet); border-radius: 50%; color: var(--gold); font-size: 11px; }
.rules-card li span { color: var(--muted); line-height: 1.6; }
.rules-note { margin-top: 24px; padding: 14px; background: var(--secondary-soft); border-left: 2px solid var(--secondary); color: var(--muted); line-height: 1.6; font-size: 12px; }
.modal-close { position: absolute; top: 15px; right: 17px; border: 0; background: none; color: var(--muted); font-size: 28px; cursor: pointer; }

@keyframes appear { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes riseIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes cardDeal { from { opacity: 0; transform: translateY(14px) rotateX(18deg) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes modalPop { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes float { 50% { transform: translateY(-16px); opacity: .35; } }
@keyframes drift { to { transform: translate3d(28px, -18px, 0) scale(1.06); } }
@keyframes atmosphere { to { transform: translateY(-12px); opacity: .86; } }
@keyframes sigil { 50% { transform: scale(1.045); filter: brightness(1.18); } }
@keyframes brew { 50% { transform: translateY(-4px) rotate(.4deg); } }
@keyframes steam { 50% { transform: translateY(-12px) rotate(4deg); opacity: .54; } }
@keyframes flame { 50% { transform: translateY(-3px) scale(1.08); filter: drop-shadow(0 0 22px var(--accent)); } }
@keyframes shimmer { to { background-position: 236px 0; } }
@keyframes sweep { to { transform: translateX(130%); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }
}

@media (max-width: 820px) {
  .source-badge { display: none; }
  .topbar-actions { margin-left: auto; }
  main { width: min(100% - 24px, 680px); padding-top: 30px; }
  .hero { grid-template-columns: 1fr; padding-bottom: 30px; }.cauldron-art { display: none; }
  .book-grid { grid-template-columns: 1fr; }
  .level-grid { grid-template-columns: repeat(2, 1fr); }
  .section-heading { align-items: start; flex-direction: column; }.section-heading > p { text-align: left; }
  .punishment-grid { grid-template-columns: 1fr; }.versus { margin: -8px 0; }.player-panel { min-height: 0; }
  .brew-row { align-items: flex-start; flex-direction: column; }
  .game-head { grid-template-columns: 1fr 1fr; }.game-title { grid-column: 1 / -1; grid-row: 1; margin-bottom: 18px; }.game-head .back-link { grid-row: 2; }.progress-wrap { grid-row: 2; }
  .game-grid .word-card { min-height: 78px; }.card-grid { gap: 7px; }
}
@media (max-width: 480px) {
  .topbar { padding: 0 14px; }.ghost-button { padding: 8px 10px; }.brand b { font-size: 15px; }
  .hero h1 { font-size: 37px; }.level-grid { grid-template-columns: 1fr 1fr; gap: 9px; }.level-card { min-height: 128px; padding: 15px; }
  .setup-shell { padding: 20px 12px; }.compact { gap: 6px; }.compact .word-card { min-height: 54px; }
  .scoreboard { grid-template-columns: 1fr 60px 1fr; }.score { padding: 10px; display: block; }.score:last-child { text-align: right; }.score b { margin: 0 5px; }
  .turn-orb { width: 58px; height: 58px; }.game-grid { gap: 6px; }.game-grid .word-card { min-height: 62px; }
  .modal-card { padding: 26px 20px; }.rules-card li { grid-template-columns: 30px 1fr; }.rules-card li span { grid-column: 2; }
}

/* Readability within the game's own dark theme. */
button:focus-visible, a:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 4px;
}
textarea { font-size: 16px; }
textarea::placeholder { color: #bdb1cf; opacity: 1; }
.primary-button {
  color: #fff;
  background: linear-gradient(135deg, #6840a8, #482777);
}
.brew-choice.active { color: #fff; background: #59358c; }
.topbar .hall-back { margin-bottom: 0; }
.eyebrow, .book-card span, .level-card span, .player-tag,
.question-top, .answer-note, .game-hint, .score span, .score small {
  font-size: 12px;
}
.book-card small, .level-card small { font-size: 14px; }
.word-card::after { font-size: 12px; color: #d8cce8; }
.word-card.resolved::before { font-size: clamp(12px, 1.4vw, 16px); }
.answer { font-size: 18px; color: var(--ink); background: #21162f; }
.answer:hover { background: #38244d; }
.modal { overflow-y: auto; z-index: 100; }
.modal-card { max-height: calc(100dvh - 40px); overflow-y: auto; }
/* Keep the shared reset control consistent with the game's dark surfaces. */
body[data-pet-companion="off"] :is(.pr-btn, .pr-dialog) { color: #f5f0ff; background: #21162f; border: 1px solid #67507e; }
body[data-pet-companion="off"] .pr-dialog p { color: #c3b8d4; }
body[data-pet-companion="off"] .pr-dialog .pr-error { color: #ffacb8; }
body[data-pet-companion="off"] .pr-dialog .pr-cancel { color: #f5f0ff; background: #3a2850; }
@media (max-width: 480px) {
  .topbar { height: auto; min-height: 76px; padding: 12px; gap: 12px; flex-wrap: wrap; }
  .brand { padding: 0; }
  .topbar-actions { flex-wrap: wrap; gap: 8px; }
  .hero h1 { font-size: clamp(30px, 8.6vw, 37px); line-height: 1.3; }
  .game-grid .word-card { min-height: 48px; }
  .word-card.resolved::after { content: none; }
  .finish-actions { flex-wrap: wrap; }
}

/* Curriculum selection shares the potion game's dark surfaces. */
.curriculum-nav { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 25px; }
.curriculum-nav a { color: var(--muted); padding: 12px 16px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; font-size: 14px; }
.curriculum-nav a[aria-current="page"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.curriculum-nav a:hover { color: white; border-color: var(--accent); }
.book-card:disabled { cursor: default; background: #171220; box-shadow: none; }
.book-card:disabled:hover { transform: none; border-color: var(--line); }
.book-card:disabled b { color: var(--muted); }
.pending-notice { padding: 36px 24px; border: 1px dashed var(--line); border-radius: 12px; background: var(--panel); }
.pending-notice > span { font-size: 32px; color: var(--gold); }
.pending-notice p { color: var(--muted); line-height: 1.8; }
.pending-notice a { display: inline-block; padding: 12px 0; color: var(--gold); }
.vocab-inventory { margin-top: 28px; padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.vocab-inventory summary { cursor: pointer; color: var(--gold); line-height: 1.8; }
.vocab-inventory h3 { margin-top: 28px; color: var(--accent); }
.vocab-inventory dl { margin: 0; }
.vocab-inventory dl > div { display: grid; grid-template-columns: 1fr 1.2fr; gap: 18px; padding: 12px 0; border-bottom: 1px solid var(--line); line-height: 1.6; }
.vocab-inventory dt { font-weight: 650; overflow-wrap: anywhere; }
.vocab-inventory dd { margin: 0; color: var(--muted); }
@media (max-width: 480px) {
  .curriculum-nav { gap: 6px; }
  .curriculum-nav a { font-size: 12px; padding: 11px 9px; }
  .vocab-inventory { padding: 14px; font-size: 14px; }
}

/* High-school phrases must wrap within narrow answer cards. */
.answer span { min-width: 0; overflow-wrap: anywhere; }
