:root {
  --night: #2a1d4f;
  --night-deep: #1d1633;
  --ink: #221a38;
  --muted: #5a5375;
  --card: #fffaf0;
  --parchment: #f6ecd2;
  --go: #6a3fd1;
  --go-dark: #4b2a9e;
  --friends: #e0464e;
  --line: #221a38;
  --gold: #ffd23f;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column; min-height: 100%;
  background: radial-gradient(circle at 50% 0%, #4a3488, var(--night) 55%, var(--night-deep));
  color: var(--ink);
  font-family: Fredoka, ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--ink); text-underline-offset: 3px; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }

/* Every game: a way back to the others, and who's signed in. */
.bar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.12); color: #e9e2ff; font-size: 15px;
  position: relative; z-index: 5;
}
.bar a { color: var(--gold); }
.bar .home { color: #d6ccf5; text-decoration: none; }
.bar .home:hover { color: #fff; }
.bar .account { color: #d6ccf5; text-align: right; }
.bar .account strong { color: #fff; }

main { flex: 1; display: flex; position: relative; }
.screen {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); text-align: center;
}
.screen[hidden] { display: none; }
#home { color: #fff; }

h1 {
  font-size: clamp(48px, 13vw, 96px); line-height: 1; margin: 0; font-weight: 700;
  color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink);
}
h1 span { color: var(--gold); }
h2 { font-size: clamp(26px, 6vw, 36px); margin: 0; font-weight: 700; }
.lead { font-size: 20px; margin: 0; color: #e0d8fa; max-width: 34em; }
.hello { font-size: 26px; margin: 0; font-weight: 600; }
.credits { margin: 8px 0 0; font-size: 13px; color: #b9addf; }
.credits a { color: #d6ccf5; }
.error { color: #ffb3b3; font-size: 18px; min-height: 1.4em; margin: 0; font-weight: 600; }

.ages { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.ages legend { font-size: 20px; padding: 0 0 8px; }
.age-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.age {
  border: 3px solid var(--line); border-radius: 18px; background: var(--card); color: var(--ink);
  padding: 8px 16px; min-width: 104px; cursor: pointer; box-shadow: 0 4px 0 var(--line);
  display: flex; flex-direction: column; align-items: center; line-height: 1.15;
}
.age strong { font-size: 28px; }
.age small { font-size: 15px; color: var(--muted); }
.age[aria-checked="true"] { background: var(--gold); box-shadow: 0 0 0 4px #fff, 0 4px 0 var(--line); transform: scale(1.05); }

.buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.big {
  border: 3px solid var(--line); border-radius: 22px; background: var(--card); color: var(--ink);
  font-size: 24px; font-weight: 600; padding: 14px 26px; min-height: 64px; cursor: pointer;
  box-shadow: 0 5px 0 var(--line); transition: transform 0.08s;
}
.big:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.big.go { background: var(--go); color: #fff; }
.big.friends { background: var(--friends); color: #fff; }
.big:disabled { opacity: 0.45; cursor: default; transform: none; }
.small {
  border: 2px solid var(--muted); border-radius: 14px; background: transparent;
  color: var(--muted); font-size: 17px; padding: 8px 18px; cursor: pointer;
}

.name, .join { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 20px; }
.join .row { display: flex; gap: 10px; }
input {
  border: 3px solid var(--line); border-radius: 18px; background: #fff; color: var(--ink);
  font-size: 26px; padding: 10px 16px; width: min(320px, 80vw); text-align: center;
}
#code { width: 150px; letter-spacing: 6px; }

/* The game: the classroom fills the screen, with big friendly overlays. */
.screen.game { padding: 0; position: relative; overflow: hidden; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  width: min(520px, calc(100% - 200px)); pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.banner {
  margin: 0; background: var(--card); border: 3px solid var(--line); border-radius: 20px;
  padding: 8px 16px; font-size: clamp(17px, 4.2vw, 24px); font-weight: 600; box-shadow: 0 4px 0 var(--line);
}
.players { margin: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.players span {
  background: rgba(255, 255, 255, 0.9); border: 2px solid var(--line); border-radius: 12px;
  padding: 2px 10px; font-size: 15px;
}
.players .away { opacity: 0.55; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); vertical-align: -1px; margin-right: 4px; }
.score, .chip {
  position: absolute; top: 10px; margin: 0; background: var(--card); border: 3px solid var(--line);
  border-radius: 18px; padding: 6px 14px; font-size: 22px; font-weight: 700; box-shadow: 0 4px 0 var(--line);
}
.score { left: 12px; }
.chip { right: 12px; font-size: 17px; cursor: pointer; }
.chip[hidden] { display: none; }
.bubble {
  position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%);
  margin: 0; background: var(--card); border: 4px solid var(--line); border-radius: 30px;
  padding: 12px 26px; font-size: clamp(22px, 6vw, 34px); font-weight: 700; pointer-events: none;
  animation: pop 0.3s ease-out; width: max-content; max-width: calc(100% - 32px);
}
@keyframes pop { from { transform: translate(-50%, -50%) scale(0.4); } }
.round {
  width: 52px; height: 52px; border-radius: 50%; border: 3px solid var(--line); background: var(--card);
  font-size: 24px; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.sound { position: absolute; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom)); }
.quit { position: absolute; left: 12px; bottom: calc(14px + env(safe-area-inset-bottom)); }
.question[hidden], .learn[hidden], .bubble[hidden], .brew[hidden], .made[hidden], #spell[hidden], .hint[hidden] { display: none; }

@media (max-width: 560px) {
  .hud { top: 64px; width: calc(100% - 24px); }
}

/* Brewing. */
.brew {
  position: absolute; inset: 0; z-index: 10; background: rgba(29, 22, 51, 0.72);
  display: flex; align-items: center; justify-content: center; padding: 12px; overflow-y: auto;
}
.brew-card {
  position: relative; width: min(640px, 100%); margin: auto; background: var(--parchment);
  border: 4px solid var(--line); border-radius: 30px; box-shadow: 0 8px 0 var(--line);
  padding: 18px 16px 0; display: flex; flex-direction: column; align-items: center; gap: 12px; overflow: hidden;
}
.close { position: absolute; top: 10px; right: 10px; font-size: 20px; width: 44px; height: 44px; }
#potionName { padding: 0 44px; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; color: var(--potion, #7ed957); }
.recipe { list-style: none; display: flex; gap: 10px; margin: 0; padding: 0; }
.recipe li {
  width: 56px; height: 56px; border-radius: 16px; border: 3px solid var(--line); background: #fff;
  display: grid; place-items: center; font-size: 32px; position: relative;
}
.recipe li img { width: 38px; height: 38px; }
.recipe li.now { box-shadow: 0 0 0 4px var(--gold); transform: scale(1.1); }
.recipe li.done::after {
  content: "✔"; position: absolute; right: -8px; bottom: -8px; font-size: 16px; color: #fff;
  background: #2fae63; border: 2px solid var(--line); border-radius: 50%; width: 26px; height: 26px; display: grid; place-items: center;
}
#spell { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }
.picture-row { display: flex; align-items: center; gap: 12px; }
.picture-row .hear { margin-left: -4px; }
.picture {
  margin: 0; width: clamp(120px, 34vw, 170px); height: clamp(120px, 34vw, 170px); border-radius: 50%;
  border: 4px solid var(--line); background: radial-gradient(circle, #fff, #fbe9b7);
  display: grid; place-items: center; font-size: clamp(70px, 20vw, 104px); line-height: 1;
}
.picture img { width: 66%; height: 66%; pointer-events: none; }
.picture.pop { animation: picPop 0.35s ease-out; }
@keyframes picPop { from { transform: scale(0.3) rotate(-20deg); } }
.slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 0; }
.slot {
  width: clamp(34px, 9vw, 52px); height: clamp(44px, 11vw, 62px); border: 3px solid var(--line); border-radius: 12px;
  background: #fff; display: grid; place-items: center; font-size: clamp(26px, 7vw, 40px); font-weight: 700; text-transform: lowercase;
}
.slot.filled { background: #d9f7d0; color: var(--ink); animation: picPop 0.2s ease-out; }
.slot.next { box-shadow: 0 0 0 3px var(--gold); }
.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 560px; }
.tiles.keyboard { gap: 5px; width: 100%; }
.tiles .krow { display: flex; justify-content: center; gap: 5px; width: 100%; }
.keyboard .krow .tile { flex: 0 0 auto; }
.tile {
  width: clamp(44px, 12vw, 60px); height: clamp(48px, 13vw, 62px); border: 3px solid var(--line); border-radius: 14px;
  background: var(--gold); font-size: clamp(26px, 7vw, 36px); font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 0 var(--line); text-transform: lowercase; padding: 0;
}
.keyboard .tile { width: min(48px, calc((100% - 45px) / 10)); height: clamp(42px, 11vw, 54px); font-size: clamp(20px, 5.4vw, 28px); background: #fff; }
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.tile.used { visibility: hidden; }
.tile.wrong { animation: shake 0.4s; background: #ffb3b3; }
.tile.glow { animation: glow 0.8s ease-in-out infinite alternate; }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-4px); } }
@keyframes glow { to { box-shadow: 0 0 0 5px #fff, 0 0 18px 8px var(--gold); } }
.hint { border-color: var(--ink); color: var(--ink); }

/* The cauldron at the bottom of the card, that the ingredients drop into. */
.pot {
  width: 190px; height: 70px; margin-top: 4px; background: #2f2b40; border: 4px solid var(--line); border-bottom: 0;
  border-radius: 95px 95px 0 0 / 40px 40px 0 0; position: relative; overflow: hidden;
}
.pot-liquid {
  position: absolute; left: 10px; right: 10px; top: 8px; height: 26px; border-radius: 50%;
  background: var(--liquid, #8a8aa0); transition: background 0.8s; border: 3px solid rgba(0, 0, 0, 0.3);
}
.splash { animation: splash 0.6s ease-out; }
@keyframes splash { 40% { transform: scaleY(1.6) translateY(-6px); } }

.made { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 6px 0; }
.made-text { margin: 0; font-size: 24px; font-weight: 600; }
.bottle {
  width: 90px; height: 120px; position: relative; animation: picPop 0.5s ease-out;
}
.bottle::before {
  content: ""; position: absolute; left: 31px; top: 0; width: 28px; height: 34px; background: #fff;
  border: 4px solid var(--line); border-bottom: 0; border-radius: 6px 6px 0 0;
}
.bottle span {
  position: absolute; left: 0; bottom: 0; width: 90px; height: 90px; border-radius: 50%;
  border: 4px solid var(--line); background: radial-gradient(circle at 35% 35%, #fff 0 10%, var(--potion, #7ed957) 12%);
}

/* The spells button: under the potions count, or beside 🏠 on a phone. */
.spells-chip { left: 12px; right: auto; top: 62px; font-size: 22px; }
@media (max-width: 560px) {
  .spells-chip { top: auto; left: 74px; bottom: calc(14px + env(safe-area-inset-bottom)); }
}

/* Reading a spell book. */
.book-card { background: #f3e3c0; padding-bottom: 20px; }
#bookTitle, #spellbookTitle { padding: 0 44px; }
.pages { list-style: none; display: flex; gap: 8px; margin: 0; padding: 0; }
.pages li { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--line); background: #fff; }
.pages li.done { background: #2fae63; }
.pages li.now { background: var(--gold); transform: scale(1.2); }
.question, .learn { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.question.turn { animation: turn 0.35s ease-out; }
@keyframes turn { from { transform: perspective(600px) rotateY(-50deg); opacity: 0.3; } }
.means {
  margin: 0; font-size: clamp(22px, 5.6vw, 30px); font-weight: 600; line-height: 1.25;
  background: #fffaf0; border: 3px solid var(--line); border-radius: 20px; padding: 14px 18px; max-width: 480px;
}
.options { display: flex; flex-direction: column; gap: 10px; width: min(380px, 100%); }
.option { display: flex; align-items: center; gap: 8px; }
.choice { flex: 1; font-size: clamp(22px, 6vw, 28px); padding: 10px 16px; min-height: 56px; }
.choice.right { background: #2fae63; color: #fff; }
.choice.wrong { background: #ffb3b3; animation: shake 0.4s; }
.choice:disabled { cursor: default; }
.choice.wrong:disabled { opacity: 0.55; }
.hear-word { width: 44px; height: 44px; font-size: 20px; flex: none; }
.found { margin: 0; font-size: 22px; font-weight: 600; }
.spell-name {
  margin: 0; font-size: clamp(40px, 11vw, 60px); font-weight: 700; color: #b07cff;
  -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
}
.spell-does { margin: 0; font-size: 20px; color: var(--muted); }

/* My spells. */
.cast { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 20px; }
.cast .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#castInput { width: min(240px, 60vw); }
#castMsg { color: #c92a2a; }
.spell-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; width: min(480px, 100%); }
.spell-list li {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center;
  background: #fffaf0; border: 3px solid var(--line); border-radius: 16px; padding: 8px 12px; text-align: left;
}
.spell-list .hear-word { grid-row: span 2; }
.spell-list strong { font-size: 22px; }
.spell-list span { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .bubble, .picture.pop, .slot.filled, .bottle, .tile.glow, .question.turn, .choice.wrong { animation: none; }
}
