/* ===========================================================
   數學冒險島 — base.css
   字體、變數、重設、背景、共用動畫
   =========================================================== */

/* ---------- 字體 ---------- */
@font-face {
  font-family: 'Huninn';
  src: url('../assets/fonts/jf-openhuninn-2.0.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Baloo';
  src: url('../assets/fonts/baloo2-latin.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}

/* ---------- 變數 ---------- */
:root {
  --sky-1: #8fdcff;
  --sky-2: #cdefff;
  --sea-1: #2aa9e0;
  --sea-2: #6fd6f7;
  --sand: #ffe6a8;
  --sand-deep: #f4c264;
  --grass: #7fe06a;
  --grass-deep: #3fae4a;
  --wood: #b07a46;
  --wood-deep: #7d5227;
  --ink: #2f3f5e;
  --ink-soft: #5a6c8c;
  --paper: #fffdf6;
  --gold: #ffc93c;
  --gold-deep: #e79b1c;
  --red: #ff6b6b;
  --red-deep: #d9433f;
  --green: #4bc86a;
  --green-deep: #249b48;
  --purple: #9b7cf5;
  --blue: #4aa8ff;
  --blue-deep: #1f76d6;
  --mint: #46d6bb;
  --pink: #ff9ec4;
  --grape: #b07cf5;

  --r-sm: 10px;
  --r: 18px;
  --r-lg: 28px;
  --r-xl: 38px;

  --sh-1: 0 4px 0 rgba(0, 0, 0, .14), 0 8px 18px rgba(20, 40, 80, .16);
  --sh-2: 0 6px 0 rgba(0, 0, 0, .16), 0 14px 26px rgba(20, 40, 80, .22);
  --sh-in: inset 0 -4px 0 rgba(0, 0, 0, .12), inset 0 3px 0 rgba(255, 255, 255, .55);

  --font-cn: 'Huninn', 'Microsoft JhengHei', 'PingFang TC', 'Noto Sans TC', 'Heiti TC', sans-serif;
  --font-num: 'Baloo', 'Huninn', 'Microsoft JhengHei', sans-serif;
  --font: var(--font-cn);

  --hud-h: 74px;
  --maxw: 1220px;
}

body.big-text { font-size: 118%; }

/* ---------- 重設 ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 55%, #eafaff 100%);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
img { display: block; max-width: 100%; -webkit-user-drag: none; }
button { font-family: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
b { font-weight: 800; }

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: rgba(47, 63, 94, .28); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* 數字用 Baloo，比較圓潤可愛 */
.num, .choice-label, .num-tile, .num-box, .eq-num, .eq-op, .eq-sign,
.bond-box, .nl-num, .pill span, .rs-row-val, .big-number, .island-num, .hud-world-name {
  font-family: var(--font-num);
  font-weight: 700;
  letter-spacing: .01em;
}

/* ---------- 版面 ---------- */
#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: var(--hud-h) 1fr;
  z-index: 1;
}

/* ---------- 背景層 ---------- */
.bg-layer { position: absolute; inset: 0; z-index: -1; overflow: hidden; }
.bg-img {
  position: absolute; inset: 0;
  background-size: cover;
  background-position: center bottom;
  background-repeat: no-repeat;
  opacity: .78;
  transition: opacity .5s ease, background-image .4s ease;
}
body.theme-title .bg-img { opacity: 0; }
.bg-sky {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, #7ed2ff 0%, #b9ecff 46%, #fff4cf 100%);
}
.bg-sea {
  position: absolute; left: 0; right: 0; bottom: 0; height: 30%;
  background: linear-gradient(180deg, rgba(58, 186, 235, .85), rgba(20, 130, 190, .95));
}
.bg-wave {
  position: absolute; left: -25%; width: 150%; height: 120px;
  background: radial-gradient(50% 100% at 50% 100%, rgba(255, 255, 255, .55) 0%, rgba(255, 255, 255, 0) 70%);
  border-radius: 50%;
  opacity: .8;
}
.bg-wave.wave-1 { bottom: 22%; animation: wave 11s ease-in-out infinite; }
.bg-wave.wave-2 { bottom: 27%; opacity: .5; animation: wave 15s ease-in-out infinite reverse; }
@keyframes wave {
  0%, 100% { transform: translateX(0) scaleY(1); }
  50% { transform: translateX(-22px) scaleY(1.25); }
}
.bg-sun {
  position: absolute; right: 7%; top: 5%; width: 130px; height: 130px; border-radius: 50%;
  background: radial-gradient(circle at 40% 38%, #fff6c9, #ffd452 60%, #ffb733);
  box-shadow: 0 0 60px 22px rgba(255, 214, 82, .5);
  animation: sunPulse 6s ease-in-out infinite;
}
@keyframes sunPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
body.screen-game .bg-sun, body.screen-map .bg-sun { opacity: .8; }

/* ---------- 共用動畫 ---------- */
@keyframes popIn {
  0% { transform: scale(.7) translateY(14px); opacity: 0; }
  70% { transform: scale(1.04) translateY(-3px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
.pop-in { animation: popIn .42s cubic-bezier(.2, 1.4, .5, 1) both; }

@keyframes floatY { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
@keyframes floatY2 { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-13px) rotate(2deg); } }
@keyframes wiggle { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-9px) rotate(-2deg); }
  35% { transform: translateX(8px) rotate(2deg); }
  55% { transform: translateX(-6px); }
  75% { transform: translateX(5px); }
}
.is-shake { animation: shake .45s ease; }

@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.09); } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes spinSlow { to { transform: rotate(360deg); } }

.is-press { transform: scale(.95) !important; filter: brightness(.95); }
.is-disabled { opacity: .5; pointer-events: none; }
.is-locked { cursor: not-allowed; }
.is-dim { opacity: .35; filter: grayscale(.6); }
.is-hidden { display: none !important; }

/* body 被扣血時整體紅閃一下 */
body.is-hit #app::after {
  content: ''; position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(circle, rgba(255, 90, 90, 0) 40%, rgba(255, 80, 80, .45));
  animation: hitFlash .4s ease-out;
  z-index: 60;
}
@keyframes hitFlash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- 開場載入 ---------- */
.boot {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #5fc9f5, #b7ecff 60%, #ffeec6);
  transition: opacity .6s ease, transform .6s ease;
}
.boot.is-done { opacity: 0; transform: scale(1.06); pointer-events: none; }
.boot-inner { text-align: center; }
.boot-char { width: 120px; margin: 0 auto 14px; animation: floatY 1.6s ease-in-out infinite; }
.boot-title {
  font-size: 42px; font-weight: 800; color: #fff;
  text-shadow: 0 4px 0 #2f8fc4, 0 8px 16px rgba(0, 60, 110, .35);
  letter-spacing: .06em;
}
.boot-bar {
  width: min(420px, 70vw); height: 20px; margin: 22px auto 10px;
  background: rgba(255, 255, 255, .55); border-radius: 20px; overflow: hidden;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, .15);
}
.boot-fill {
  width: 8%; height: 100%;
  background: linear-gradient(90deg, #ffd54f, #ffb02e);
  border-radius: 20px;
  transition: width .4s ease;
  box-shadow: 0 0 12px rgba(255, 200, 60, .8);
}
.boot-text { color: #2b6a91; font-size: 16px; letter-spacing: .08em; }

/* ---------- 特效層 ---------- */
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.fx-star {
  position: absolute;
  transform: translate(-50%, -50%);
  animation: fxFly 1.35s cubic-bezier(.2, .7, .3, 1) forwards;
  will-change: transform, opacity;
}
@keyframes fxFly {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.3) rotate(0deg); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.15) rotate(var(--rot)); }
}
.toast {
  position: fixed; left: 50%; top: 16%; transform: translateX(-50%);
  padding: 14px 26px; border-radius: 999px;
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--sh-2);
  font-size: 20px; font-weight: 700;
  border: 3px solid rgba(255, 255, 255, .9);
  animation: toastIn .35s cubic-bezier(.2, 1.5, .5, 1) both;
  z-index: 95; white-space: nowrap;
}
.toast.tone-sun { color: #b1670a; background: #fff6d8; }
.toast.tone-mint { color: #0d7a63; background: #ddfff6; }
.toast.tone-grape { color: #6b35b8; background: #f2e8ff; }
.toast.is-out { opacity: 0; transform: translateX(-50%) translateY(-16px); transition: all .5s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) scale(.8); } to { opacity: 1; transform: translateX(-50%) scale(1); } }
