:root {
  --night: #0b1f1a;
  --glass: rgba(10, 32, 27, .88);
  --edge: rgba(240, 192, 90, .55);
  --gold: #f0c05a;
  --gold-d: #b98a2e;
  --rune: #5ee6c8;
  --ruby: #e04b5f;
  --ink: #f3ebd0;
  --muted: #b3c4b6;
  --serif: "Palatino Linotype", "Book Antiqua", Palatino, "Noto Serif", Georgia, serif;
  --sans: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

/* night forest behind the fight screens: two rows of pine silhouettes */
body {
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='150' viewBox='0 0 300 150'><g fill='%23071812'><polygon points='20,150 60,30 100,150'/><polygon points='90,150 140,0 190,150'/><polygon points='180,150 215,45 250,150'/><polygon points='240,150 275,60 310,150'/></g></svg>") repeat-x left bottom / 300px 150px fixed,
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='110' viewBox='0 0 220 110'><g fill='%230a2119'><polygon points='0,110 35,20 70,110'/><polygon points='60,110 100,0 140,110'/><polygon points='130,110 170,35 210,110'/></g></svg>") repeat-x -70px bottom / 220px 110px fixed,
    radial-gradient(ellipse at 50% -10%, rgba(94, 230, 200, .2), transparent 55%),
    radial-gradient(circle at 15% 30%, rgba(240, 192, 90, .08), transparent 40%),
    var(--night);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 18px max(120px, env(safe-area-inset-bottom));
}

.hidden { display: none !important; }
.loading { text-align: center; margin-top: 30vh; color: var(--muted); }

/* ---------- adventure map ---------- */

body.world-mode { overflow: hidden; position: fixed; inset: 0; width: 100%; background: var(--night); }
body.world-mode #app { max-width: none; padding: 0; height: 100%; }
.world { position: fixed; inset: 0; }
.world canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.w-hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}
.w-title, .w-hud .gems {
  background: var(--glass);
  border: 1.5px solid var(--edge);
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .4);
  backdrop-filter: blur(6px);
}
.w-title {
  margin: 0;
  padding: 8px 18px;
  font: 700 1.3rem/1.2 var(--serif);
  color: var(--gold);
  user-select: none;
  pointer-events: auto;
}
.w-hud .gems { padding: 8px 16px; }

.w-hint, .w-loading {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 18px;
  max-width: calc(100% - 32px);
  text-align: center;
  background: var(--glass);
  border: 1.5px solid var(--edge);
  border-radius: 16px;
  color: var(--ink);
  font-size: .98rem;
  pointer-events: none;
}
.w-hint { bottom: max(26px, env(safe-area-inset-bottom)); }
.w-loading { top: 45%; }

.w-enter {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(440px, calc(100% - 28px));
  padding: 16px 18px 10px;
  background: var(--glass);
  border: 1.5px solid var(--edge);
  border-radius: 20px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 235, 170, .2);
  backdrop-filter: blur(8px);
  animation: rise .22s ease-out;
}
.e-title { font: 700 1.45rem/1.2 var(--serif); color: var(--gold); }
.e-sub { color: var(--muted); font-size: .95rem; margin-top: 2px; }
.e-meta { display: flex; justify-content: space-between; align-items: baseline; margin: 8px 0 2px; font-size: .95rem; color: var(--muted); }

/* ---------- shared ---------- */

h1 { margin: 0; font: 700 1.6rem/1.2 var(--serif); color: var(--gold); text-shadow: 0 2px 10px rgba(0, 0, 0, .5); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 4px 20px; }
.gems { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; color: var(--ink); }
.hearts { display: flex; gap: 6px; }
.ico { width: 28px; height: 25px; display: block; }
.ico.gem { width: 24px; height: 24px; }

.stars { color: var(--gold); letter-spacing: 2px; font-size: 1.1rem; }
.stars i { font-style: normal; color: #5b6b61; }

.panel {
  position: relative;
  background: var(--glass);
  color: var(--ink);
  border: 1.5px solid var(--edge);
  border-radius: 20px;
  padding: 18px 20px;
  margin: 4px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 235, 170, .2);
}

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, .07);
  border: 1.5px solid rgba(240, 192, 90, .5);
  border-radius: 14px;
  padding: 12px 18px;
  min-height: 56px;
  margin: 6px 4px;
  cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .08s;
}
.btn:hover { background: rgba(240, 192, 90, .14); border-color: var(--gold); }
.btn:active { transform: scale(.98); }
.btn.ghost { background: rgba(255, 255, 255, .05); }
.btn.small { min-height: 48px; padding: 8px 16px; }
.btn.go {
  display: block;
  width: calc(100% - 8px);
  color: #2a1a05;
  font-weight: 800;
  background: linear-gradient(#f7d27a, #e0a63a);
  border-color: #ffe9a8;
  box-shadow: 0 6px 20px rgba(240, 192, 90, .3), inset 0 1px 0 rgba(255, 255, 255, .5);
}
.btn.go:hover { background: linear-gradient(#ffdc8c, #ebb04a); }
.btn:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--rune); outline-offset: 3px; }

/* ---------- fight ---------- */

.battle { display: flex; align-items: flex-end; gap: 14px; margin: 0 4px 20px; }
.hero-img { width: 72px; height: 90px; object-fit: contain; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .5)); }
.mon { font-size: 54px; line-height: 1; filter: drop-shadow(0 0 14px rgba(224, 75, 95, .6)); }
.hp {
  flex: 1;
  align-self: center;
  height: 16px;
  background: rgba(0, 0, 0, .5);
  border: 1.5px solid var(--edge);
  border-radius: 999px;
  overflow: hidden;
}
.hp i { display: block; height: 100%; background: linear-gradient(90deg, #ff8a98, var(--ruby)); border-radius: 999px; transition: width .35s ease-out; }

.q .topic { font-size: .92rem; color: var(--rune); margin-bottom: 6px; }
.q h2 { margin: 0; font: 700 1.5rem/1.35 var(--serif); }

.answer { margin: 22px 0 8px; }
.opt { display: block; width: calc(100% - 8px); text-align: left; font-size: 1.1rem; }
.opt.correct { background: rgba(94, 230, 200, .2); border-color: var(--rune); box-shadow: 0 0 18px rgba(94, 230, 200, .35); }
.opt.wrong { background: rgba(224, 75, 95, .22); border-color: var(--ruby); }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 1.15rem; }
.chip.sel { background: rgba(94, 230, 200, .22); border-color: var(--rune); }
.chip.correct { background: rgba(94, 230, 200, .2); border-color: var(--rune); box-shadow: 0 0 18px rgba(94, 230, 200, .35); }
.chip.wrong { background: rgba(224, 75, 95, .22); border-color: var(--ruby); }

.inp {
  display: block;
  width: calc(100% - 8px);
  margin: 6px 4px 10px;
  padding: 12px 16px;
  font: inherit;
  font-size: 1.4rem;
  color: var(--ink);
  background: rgba(0, 0, 0, .35);
  border: 1.5px solid var(--edge);
  border-radius: 14px;
}
.inp:disabled { opacity: .85; }

.built {
  min-height: 72px;
  margin: 6px 4px 14px;
  padding: 8px;
  background: rgba(0, 0, 0, .3);
  border: 1.5px dashed var(--edge);
  border-radius: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.built .hint { padding: 0 10px; color: var(--muted); }
.built .dot { font-size: 1.6rem; font-weight: 800; color: var(--gold); }
.built.ok { border-color: var(--rune); background: rgba(94, 230, 200, .12); }
.built.bad { border-color: var(--ruby); background: rgba(224, 75, 95, .12); }

.locked .btn, .locked .inp { pointer-events: none; }
.locked .opt:not(.correct):not(.wrong) { opacity: .5; }

.fb { margin-top: 18px; animation: rise .22s ease-out; }
.fb.good { border-color: var(--rune); }
.fb.bad { border-color: var(--ruby); }
.fb strong { font: 700 1.35rem/1.3 var(--serif); }
.fb.good strong { color: var(--rune); }
.fb.bad strong { color: #ff8a98; }
.fb p { margin: 8px 0; }
.fb .why { font-size: 1rem; color: var(--muted); }

/* ---------- result and parent view ---------- */

.result { text-align: center; margin-top: 12px; }
.result .big { font-size: 64px; line-height: 1.1; }
.result h2 { margin: 6px 0 10px; font: 700 1.6rem/1.3 var(--serif); color: var(--gold); }
.big-stars { font-size: 2.3rem; }
.row { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin-top: 10px; }

.parent h2 { margin: 18px 0 6px; font: 700 1.15rem/1.3 var(--serif); color: var(--gold); }
.parent ul { margin: 6px 0; padding-left: 20px; }
.parent li { margin: 4px 0; }

/* the only motion: things react to what the child does */
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
.fb { animation-name: rise-plain; }
@keyframes rise-plain { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes hit {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px) rotate(-8deg); }
  75% { transform: translateX(8px) rotate(8deg); }
}
.hit, .shake { animation: hit .35s; }
@media (prefers-reduced-motion: reduce) {
  .hit, .shake, .fb, .w-enter { animation: none; }
  .hp i { transition: none; }
}

/* ---------- dialog ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 14, 11, .74);
  backdrop-filter: blur(3px);
  animation: fade .15s ease-out;
}
.modal-card { width: min(420px, 100%); text-align: center; animation: pop .18s ease-out; }
.modal-text { margin: 4px 0 14px; font: 700 1.3rem/1.4 var(--serif); color: var(--ink); }
.modal .row { flex-direction: column; align-items: stretch; margin-top: 0; }
.modal .btn { width: calc(100% - 8px); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .modal, .modal-card { animation: none; } }
