/* ============================================================
   Math Quest — calm, sensory-friendly UI
   Soft pastels, rounded cards, big readable type, no flashing.
   ============================================================ */

:root {
  --ink: #34304a;
  --ink-soft: #6b6685;
  --cream: #fff8ef;
  --card: rgba(255, 252, 246, 0.94);
  --mint: #8fd6b4;
  --sky: #bfe3f2;
  --peach: #ffd6a8;
  --rose: #ffb4ba;
  --lav: #cdb9f0;
  --gold: #f5c451;
  --good: #57b894;
  --soft-shadow: 0 10px 30px rgba(80, 70, 110, 0.18);
  --radius: 18px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  overflow: hidden;
  background: #cfeaf3;
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#game-root { position: fixed; inset: 0; }
#game-root canvas { display: block; }

.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  font-size: 1.05rem;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .15s ease;
  box-shadow: 0 5px 0 rgba(0,0,0,0.08);
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(1px); box-shadow: 0 2px 0 rgba(0,0,0,0.1); }
.btn-primary { background: linear-gradient(180deg, #7ed9b0, #57b894); color: #14392c; }
.btn-soft { background: #ece6f7; color: var(--ink-soft); box-shadow: 0 4px 0 rgba(0,0,0,0.06); }
.btn-big { padding: 16px 40px; font-size: 1.3rem; margin-top: 8px; }
.btn-small { padding: 8px 18px; font-size: .85rem; }

.key-badge {
  display: inline-block;
  background: #fff;
  border: 2px solid #e3dcef;
  border-bottom-width: 3px;
  border-radius: 8px;
  padding: 1px 8px;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 0.85em;
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}

/* ============ HUD ============ */
#hud { position: fixed; inset: 0; pointer-events: none; }

#hud-top {
  position: absolute; top: 16px; left: 16px;
  display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap;
}
.hud-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 16px;
  box-shadow: var(--soft-shadow);
  font-weight: 800;
  display: flex; align-items: center; gap: 8px;
}
#hearts { gap: 4px; font-size: 1.5rem; }
.heart { filter: drop-shadow(0 2px 1px rgba(0,0,0,0.12)); }
.heart-full { color: #ff7b89; }
.heart-empty { color: #e6dfe9; }

.hud-counter { font-size: 1.2rem; }
.hud-icon { font-size: 1.3rem; line-height: 1; }
.crystal-icon { color: #6cc6e8; }
.key-icon { color: var(--gold); }
.star-icon { color: var(--gold); }
.rupee-icon { color: #57b894; }
.hud-sub { font-size: .8rem; color: var(--ink-soft); font-weight: 700; }

.hud-level { flex-direction: column; align-items: stretch; gap: 6px; min-width: 150px; }
.level-row { display: flex; align-items: center; gap: 8px; }
.xp-track { height: 9px; background: #ece6f7; border-radius: 999px; overflow: hidden; }
.xp-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold), #ffe08a); border-radius: 999px; transition: width .5s ease; }

#objective-card {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--card); border-radius: var(--radius);
  padding: 9px 20px; box-shadow: var(--soft-shadow);
  display: flex; align-items: center; gap: 12px; max-width: 70vw;
}
.objective-label {
  background: var(--lav); color: #3c2f63; font-weight: 800;
  font-size: .72rem; letter-spacing: 1px; padding: 3px 9px; border-radius: 999px;
}
#objective-text { font-weight: 700; font-size: 1.02rem; }

#minimap {
  position: absolute; top: 16px; right: 16px;
  width: 180px; height: 180px;
  background: rgba(255,252,246,0.9);
  border-radius: 20px;
  box-shadow: var(--soft-shadow);
  border: 4px solid rgba(255,255,255,0.7);
}

#interact-prompt {
  position: absolute; bottom: 92px; left: 50%; transform: translateX(-50%);
  background: var(--card); border-radius: 999px;
  padding: 10px 22px; box-shadow: var(--soft-shadow);
  font-weight: 800; font-size: 1.1rem;
  display: flex; align-items: center; gap: 10px;
  animation: bob 1.6s ease-in-out infinite;
}
@keyframes bob { 0%,100%{ transform: translateX(-50%) translateY(0);} 50%{ transform: translateX(-50%) translateY(-5px);} }

/* ---- boss battle UI ---- */
#boss-ui {
  position: absolute; bottom: 130px; left: 50%; transform: translateX(-50%);
  width: min(520px, 86vw); text-align: center;
}
#boss-name {
  font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.25rem;
  color: #fff; text-shadow: 0 2px 8px rgba(120,30,60,0.7); margin-bottom: 6px;
  letter-spacing: 1px;
}
#boss-hp-track {
  height: 18px; background: rgba(40,20,40,0.55); border-radius: 999px;
  border: 3px solid rgba(255,255,255,0.5); overflow: hidden; box-shadow: var(--soft-shadow);
}
#boss-hp-fill {
  height: 100%; width: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #ff6a8a, #ff9a4a);
  transition: width .4s ease;
}
#battle-banner {
  position: absolute; top: 96px; left: 50%; transform: translateX(-50%);
  background: rgba(52,30,60,0.82); color: #ffe9b0;
  font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.25rem;
  padding: 10px 26px; border-radius: 999px; box-shadow: var(--soft-shadow);
  border: 3px solid rgba(255,220,150,0.4); white-space: nowrap;
  animation: bannerPop .35s ease;
}
@keyframes bannerPop { from { transform: translateX(-50%) scale(.85); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

#controls-hint {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(255,252,246,0.8); border-radius: 999px;
  padding: 7px 18px; font-size: .82rem; color: var(--ink-soft); font-weight: 700;
  box-shadow: var(--soft-shadow);
}

/* ============ Dialog ============ */
#dialog {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  width: min(680px, 92vw); z-index: 30;
}
.dialog-inner {
  background: var(--card); border-radius: 22px;
  padding: 20px 26px; box-shadow: var(--soft-shadow);
  border: 4px solid rgba(255,255,255,0.8);
}
.dialog-speaker {
  font-family: 'Baloo 2'; font-weight: 800; color: var(--good);
  font-size: 1.15rem; margin-bottom: 4px;
}
.dialog-text { font-size: 1.2rem; line-height: 1.5; font-weight: 700; white-space: pre-wrap; }
.dialog-continue { margin-top: 12px; text-align: right; color: var(--ink-soft); font-size: .9rem; font-weight: 700; }

/* ============ Math modal ============ */
#math-modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(52, 48, 74, 0.42);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.math-card {
  background: var(--cream); border-radius: 26px;
  padding: 30px 34px; width: min(560px, 92vw);
  box-shadow: 0 24px 60px rgba(40,30,70,0.35);
  border: 5px solid #fff;
  text-align: center;
  animation: pop .22s ease;
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.math-topic {
  display: inline-block; background: var(--sky); color: #1f5066;
  font-weight: 800; font-size: .8rem; letter-spacing: .5px;
  padding: 4px 14px; border-radius: 999px; margin-bottom: 12px;
}
.math-title { font-family: 'Baloo 2'; font-weight: 800; font-size: 1.5rem; color: var(--ink); }
.math-prompt {
  font-size: 1.7rem; font-weight: 800; margin: 16px 0 20px;
  white-space: pre-wrap; line-height: 1.4; color: #2c2842;
  font-family: 'Baloo 2';
}
#math-input {
  font-family: 'Baloo 2'; font-weight: 700; font-size: 1.6rem; text-align: center;
  width: 220px; padding: 12px 16px; border-radius: 16px;
  border: 3px solid #e0d8ef; background: #fff; color: var(--ink);
  outline: none; transition: border .15s;
}
#math-input:focus { border-color: var(--mint); }

#math-choices { display: grid; gap: 10px; margin-top: 6px; }
.choice-btn {
  font-family: 'Baloo 2'; font-weight: 700; font-size: 1.25rem;
  padding: 14px; border-radius: 16px; border: 3px solid #e0d8ef;
  background: #fff; color: var(--ink); cursor: pointer; transition: all .12s;
}
.choice-btn:hover { border-color: var(--mint); transform: translateY(-2px); }
.choice-btn.sel { border-color: var(--good); background: #ecfbf3; }

.math-feedback { min-height: 28px; margin: 14px 0 6px; font-weight: 800; font-size: 1.15rem; }
.math-feedback.good { color: var(--good); }
.math-feedback.try { color: #e58a3a; }

.math-actions { display: flex; gap: 12px; justify-content: center; margin-top: 6px; }
.math-hint {
  margin-top: 16px; background: #fff5e2; border-radius: 14px;
  padding: 14px 18px; font-weight: 700; color: #7a5a1e; line-height: 1.45;
  border: 2px dashed #f0d28a;
}

/* ============ Toast ============ */
#toast {
  position: fixed; top: 96px; left: 50%; transform: translateX(-50%);
  background: var(--card); border-radius: 18px;
  padding: 14px 26px; box-shadow: var(--soft-shadow);
  font-family: 'Baloo 2'; font-weight: 800; font-size: 1.2rem; z-index: 35;
  border: 3px solid #fff;
  animation: toastIn .3s ease;
}
@keyframes toastIn { from { transform: translateX(-50%) translateY(-14px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }

/* ============ Start / Win / Loading ============ */
#start-screen, #win-screen {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 120% at 50% 0%, #d9f0f8 0%, #cbe6f0 40%, #bcd9ec 100%);
}
.start-inner, .win-inner {
  text-align: center; max-width: 620px; padding: 40px;
  background: var(--card); border-radius: 30px;
  box-shadow: 0 30px 70px rgba(40,30,70,0.25);
  border: 6px solid #fff;
}
.start-inner h1, .win-inner h1 {
  font-family: 'Baloo 2'; font-weight: 800; font-size: 3.2rem; margin: 0;
  color: var(--good); letter-spacing: 1px;
}
.start-inner h2 { font-family: 'Baloo 2'; font-weight: 700; font-size: 1.5rem; margin: 0 0 14px; color: var(--lav); }
.start-blurb, .win-blurb { font-size: 1.1rem; line-height: 1.55; font-weight: 700; color: var(--ink-soft); }
.start-controls {
  display: grid; gap: 8px; margin: 22px auto; max-width: 380px;
  text-align: left; font-weight: 700; color: var(--ink);
}
.start-controls > div { background: #f4f0fb; border-radius: 12px; padding: 8px 14px; }
.start-note { margin-top: 16px; color: var(--ink-soft); font-weight: 700; }
#reset-save-btn { margin-top: 12px; display: block; margin-left: auto; margin-right: auto; }
.win-spark { font-size: 2rem; color: var(--gold); letter-spacing: 8px; margin-bottom: 10px; }
#win-stats { font-weight: 800; font-size: 1.2rem; color: var(--ink); }

#loading {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  background: #cfeaf3;
}
.loading-inner { font-family: 'Baloo 2'; font-weight: 700; font-size: 1.4rem; color: var(--ink-soft); }

@media (max-width: 640px) {
  #minimap { width: 120px; height: 120px; }
  #objective-card { max-width: 60vw; font-size: .9rem; }
  .math-prompt { font-size: 1.4rem; }
  #controls-hint { font-size: .7rem; }
}
