:root {
  color-scheme: dark;
  --ink: #14222c;
  --cream: #fff8e8;
  --paper: #fffdf7;
  --muted: #6e6870;
  --teal: #1c8c83;
  --teal-dark: #0d5c59;
  --burgundy: #9b3851;
  --burgundy-dark: #63243a;
  --gold: #f1bd4a;
  --gold-light: #ffe9a3;
  font-family: ui-rounded, "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; min-width: 1000px; min-height: 650px; overflow: hidden; }
body { margin: 0; background: #10222b; }
button { color: inherit; font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 4px solid var(--gold); outline-offset: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.library {
  position: relative;
  width: 100%;
  height: 100%;
  isolation: isolate;
  overflow: hidden;
  color: var(--ink);
  background: #18313a url("art/library-backdrop-01.webp") center / cover no-repeat;
}
.library::before { position: absolute; z-index: -1; inset: 0; content: ""; background: linear-gradient(90deg, rgba(8,23,30,.28), transparent 35%, transparent 78%, rgba(8,23,30,.23)), linear-gradient(rgba(5,17,23,.08), rgba(5,17,23,.38)); }
.world-glow { position: absolute; z-index: -1; left: 43%; bottom: 6%; width: 53%; height: 40%; border-radius: 50%; background: radial-gradient(ellipse, rgba(255,213,111,.24), transparent 68%); filter: blur(10px); pointer-events: none; }

.game-hud { position: absolute; z-index: 10; left: 24px; right: 24px; top: 18px; height: 66px; display: grid; grid-template-columns: 220px 1fr auto; align-items: center; gap: 20px; }
.chapter-card,.magic-meter,.scoreboard { border: 1px solid rgba(255,234,183,.35); background: rgba(19,38,46,.88); box-shadow: 0 7px 24px rgba(0,0,0,.24); backdrop-filter: blur(12px); color: var(--cream); }
.chapter-card { height: 66px; display: flex; flex-direction: column; justify-content: center; padding: 10px 17px; border-radius: 18px; }
.chapter-card span,.magic-meter span,.scoreboard span { color: #c8bfae; font-size: 10px; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.chapter-card strong { margin-top: 3px; font-size: 16px; }
.magic-meter { justify-self: center; width: min(380px,100%); padding: 10px 16px; border-radius: 18px; }
.magic-meter > div:first-child { display: flex; align-items: baseline; justify-content: space-between; }.magic-meter strong { color: var(--gold-light); font-size: 12px; }
.meter-track { position: relative; height: 11px; margin-top: 7px; border-radius: 999px; background: #091a21; box-shadow: inset 0 1px 4px rgba(0,0,0,.7); }
.meter-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg,#34b8a5,var(--gold)); box-shadow: 0 0 18px var(--gold); transition: width 280ms ease-out; }
.meter-track b { position: absolute; right: -3px; top: -9px; color: var(--gold); text-shadow: 0 0 12px var(--gold); }
.scoreboard { height: 66px; display: flex; align-items: stretch; padding: 7px; border-radius: 18px; }
.scoreboard > div { min-width: 72px; display: grid; place-content: center; padding: 0 11px; text-align: center; }.scoreboard > div + div { border-left: 1px solid rgba(255,255,255,.14); }
.scoreboard strong { margin-top: 2px; color: white; font-size: 22px; line-height: 1; }.scoreboard .difficulty { min-width: 100px; }.scoreboard .difficulty strong { color: var(--gold); font-size: 17px; }

.mascot-panel { position: absolute; z-index: 3; left: 25px; top: 108px; bottom: 25px; width: 235px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.mascot-bubble { position: absolute; z-index: 4; top: 3px; left: 15px; right: 3px; padding: 14px 17px; border: 2px solid #d9b968; border-radius: 20px 20px 20px 5px; background: var(--cream); box-shadow: 0 7px 0 rgba(69,42,27,.27); font-size: 13px; font-weight: 900; line-height: 1.35; }
.mascot { position: relative; z-index: 2; width: 205px; height: 250px; object-fit: contain; filter: drop-shadow(0 15px 12px rgba(0,0,0,.36)); transform-origin: 50% 90%; transition: transform 160ms ease-out, filter 160ms ease-out; }
.library.is-celebrating .mascot { animation: owl-cheer 620ms cubic-bezier(.2,.8,.2,1); filter: drop-shadow(0 0 18px rgba(255,222,123,.8)); }
.library.is-missing .mascot { animation: owl-wobble 280ms ease-out; }
.spellbook-wrap { position: relative; z-index: 3; width: 190px; height: 92px; margin-top: -38px; }.spellbook-wrap img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 9px 7px rgba(0,0,0,.35)); }
.lit-books { width: 185px; display: flex; justify-content: center; gap: 8px; margin-top: 7px; }
.lit-books i { width: 17px; height: 42px; border: 2px solid rgba(255,236,174,.45); border-radius: 3px 6px 3px 3px; background: #5a2637; box-shadow: 3px 0 #193f45; transition: 180ms ease-out; }.lit-books i.is-lit { border-color: var(--gold); background: var(--teal); box-shadow: 0 0 13px var(--gold); transform: translateY(-5px); }

.game-table { position: absolute; z-index: 3; left: 275px; right: 25px; top: 104px; bottom: 25px; display: grid; grid-template-rows: auto 32px minmax(240px,1fr) auto 26px 66px; align-content: start; padding: 22px 32px 20px; overflow: hidden; border: 1px solid rgba(114,72,48,.35); border-radius: 28px; background: rgba(255,249,232,.965); box-shadow: 0 10px 0 rgba(48,27,24,.25), 0 30px 60px rgba(0,0,0,.28); }
.game-table::after { position: absolute; right: -24px; top: -30px; width: 150px; height: 150px; content: ""; opacity: .2; transform: rotate(12deg); background: url("art/glowing-cards.png") center / contain no-repeat; pointer-events: none; }
.mission { text-align: center; }.eyebrow { margin: 0 0 5px; color: var(--burgundy); font-size: 11px; font-weight: 1000; letter-spacing: .14em; text-transform: uppercase; }.mission h1 { margin: 0; font-size: clamp(27px,3vw,41px); line-height: 1; letter-spacing: -.045em; }.mission > p:last-child { margin: 7px 0 0; color: var(--muted); font-size: 14px; }
.relation-sign { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); font-size: 11px; font-weight: 900; letter-spacing: .08em; }.relation-sign span { padding: 4px 9px; border-radius: 999px; }.same-sign { color: var(--teal-dark); background: #d7f2eb; }.opposite-sign { color: var(--burgundy-dark); background: #f5dce2; }.relation-sign i { font-style: normal; }

.match-board { position: relative; min-height: 0; display: grid; grid-template-columns: minmax(220px,1fr) 88px minmax(260px,1.08fr); align-items: center; gap: 13px; padding: 10px 25px 8px; overflow: visible; }
.connection-layer { position: absolute; z-index: 4; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }.connection-layer path { fill: none; stroke: var(--gold); stroke-width: 7; stroke-linecap: round; filter: drop-shadow(0 0 6px rgba(218,151,24,.65)); }.connection-layer #dragLine { opacity: .8; stroke: var(--teal); stroke-width: 5; stroke-dasharray: 10 8; }
.word-column { position: relative; z-index: 5; display: flex; flex-direction: column; justify-content: center; gap: 14px; min-height: 100%; }.source-column { align-items: flex-end; }.choice-column { align-items: flex-start; }
.word-card { position: relative; min-width: 205px; min-height: 70px; display: grid; place-items: center; padding: 14px 25px; border: 2px solid #d2c5a9; border-radius: 18px; color: var(--ink); background: linear-gradient(145deg,#fffef8,#f8efd9); box-shadow: 0 7px 0 #c9b994, 0 14px 26px rgba(61,43,31,.11); font-family: Georgia, "Times New Roman", serif; font-size: clamp(23px,2.25vw,34px); font-weight: 800; letter-spacing: -.02em; cursor: grab; user-select: none; touch-action: none; transition: transform 140ms ease-out, border-color 140ms ease-out, box-shadow 140ms ease-out, opacity 140ms ease-out; }
.word-card::before,.word-card::after { position: absolute; top: 50%; width: 11px; height: 11px; content: ""; transform: translateY(-50%) rotate(45deg); border-radius: 2px; background: var(--gold); box-shadow: 0 0 10px var(--gold); }.source-column .word-card::after { right: -7px; }.source-column .word-card::before { display: none; }.choice-column .word-card::before { left: -7px; }.choice-column .word-card::after { display: none; }
.word-card:hover { transform: translateY(-3px) rotate(-.4deg); border-color: #b9903c; box-shadow: 0 10px 0 #c9b994, 0 17px 28px rgba(61,43,31,.14); }.word-card:active,.word-card.is-selected { cursor: grabbing; transform: translateY(3px) scale(.985); border-color: var(--teal); box-shadow: 0 3px 0 #a9c7bd, 0 0 0 6px rgba(28,140,131,.13); }.word-card.is-matched { border-color: var(--gold); background: #fff5c9; box-shadow: 0 6px 0 #d6af4d, 0 0 27px rgba(241,189,74,.65); cursor: default; }.word-card.is-dim { opacity: .36; filter: grayscale(.45); }
.portal { display: grid; place-items: center; color: var(--gold); }.portal span { z-index: 2; display: grid; place-items: center; width: 49px; height: 49px; border: 2px solid #bb8e31; border-radius: 50%; background: #fff2bf; box-shadow: 0 0 25px rgba(241,189,74,.55); font-size: 22px; }.portal i { position: absolute; width: 72px; height: 72px; border: 2px dashed rgba(155,56,81,.38); border-radius: 50%; animation: portal-spin 10s linear infinite; }
.evidence-card { align-self: center; justify-self: center; max-width: 760px; padding: 10px 18px; border: 1px solid #d6bd76; border-radius: 14px; color: #624d20; background: #fff4c8; font-size: 14px; font-weight: 800; text-align: center; animation: evidence-pop 260ms ease-out; }
.feedback { min-height: 26px; margin: 0; display: grid; place-items: center; color: var(--burgundy); font-size: 13px; font-weight: 900; text-align: center; }.feedback.is-success { color: var(--teal-dark); }
.action-area { min-height: 62px; display: flex; align-items: center; justify-content: center; gap: 12px; }
.choice-row { width: min(680px,100%); display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }.choice-row.three { grid-template-columns: repeat(3,minmax(0,1fr)); }
.action,.primary { min-height: 56px; padding: 10px 17px; border: 2px solid #d2c5ae; border-radius: 16px; background: white; box-shadow: 0 5px 0 #d4c7ae; font-weight: 950; transition: 140ms ease-out; }.action small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }.action:hover { transform: translateY(-2px); border-color: var(--teal); box-shadow: 0 7px 0 #b8d5cc; }.action:active { transform: translateY(3px); box-shadow: 0 2px 0 #b8d5cc; }
.primary { min-width: 230px; border-color: var(--teal-dark); color: white; background: var(--teal); box-shadow: 0 6px 0 var(--teal-dark); font-size: 15px; }.primary:hover { transform: translateY(-2px); box-shadow: 0 8px 0 var(--teal-dark); }.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--teal-dark); }.primary.burgundy { border-color: var(--burgundy-dark); background: var(--burgundy); box-shadow: 0 6px 0 var(--burgundy-dark); }

.spark-burst { position: absolute; z-index: 30; left: 58%; top: 52%; pointer-events: none; }.spark-burst i { position: absolute; width: 13px; height: 13px; opacity: 0; transform: rotate(45deg); border-radius: 3px; background: var(--gold); }.library.is-celebrating .spark-burst i { animation: spark 700ms ease-out both; }.spark-burst i:nth-child(1){--x:-130px;--y:-120px}.spark-burst i:nth-child(2){--x:125px;--y:-105px;animation-delay:40ms}.spark-burst i:nth-child(3){--x:165px;--y:15px;animation-delay:80ms}.spark-burst i:nth-child(4){--x:-170px;--y:25px;animation-delay:120ms}.spark-burst i:nth-child(5){--x:80px;--y:112px;animation-delay:160ms}.spark-burst i:nth-child(6){--x:-76px;--y:120px;animation-delay:200ms}.spark-burst i:nth-child(7){--x:5px;--y:-145px;animation-delay:240ms}.spark-burst i:nth-child(8){--x:18px;--y:138px;animation-delay:280ms}
.toast { position: absolute; z-index: 40; left: 58%; bottom: 35px; max-width: 70%; padding: 11px 18px; opacity: 0; transform: translate(-50%,12px); border-radius: 999px; color: white; background: #142c37; box-shadow: 0 8px 22px rgba(0,0,0,.25); pointer-events: none; font-size: 13px; font-weight: 900; transition: 150ms ease-out; }.toast.is-showing { opacity: 1; transform: translate(-50%,0); }

@keyframes portal-spin { to { transform: rotate(360deg); } }
@keyframes evidence-pop { from { opacity: 0; transform: translateY(8px) scale(.96); } }
@keyframes spark { 0% { opacity: 0; transform: translate(0,0) rotate(45deg) scale(.2); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--x),var(--y)) rotate(190deg) scale(1.25); } }
@keyframes owl-cheer { 0%,100% { transform: none; } 35% { transform: translateY(-18px) rotate(-5deg) scale(1.08); } 65% { transform: translateY(-7px) rotate(4deg) scale(1.04); } }
@keyframes owl-wobble { 25% { transform: translateX(-7px) rotate(-3deg); } 70% { transform: translateX(7px) rotate(3deg); } }
@keyframes board-shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@media (max-height: 730px) { .game-hud { top: 12px; height: 58px; }.chapter-card,.scoreboard { height: 58px; }.mascot-panel,.game-table { top: 84px; bottom: 16px; }.mascot { width: 170px; height: 205px; }.game-table { padding-top: 16px; padding-bottom: 13px; }.word-card { min-height: 58px; }.match-board { padding-top: 3px; padding-bottom: 3px; } }
@media (prefers-reduced-motion: reduce) { *,*::before,*::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
