/* ✦ Haeglo — whimsical fantasy theme ✦ */
:root {
  --bg-deep: #1a1333;
  --bg-mid: #2a1f4d;
  --bg-card: rgba(255, 255, 255, 0.07);
  --bg-card-hover: rgba(255, 255, 255, 0.12);
  --border: rgba(186, 156, 255, 0.25);
  --text: #f3eeff;
  --text-muted: #b9a8d9;
  --lilac: #b388ff;
  --teal: #5eead4;
  --gold: #fcd34d;
  --rose: #f9a8d4;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at 20% 0%, #3b2a6b 0%, var(--bg-mid) 40%, var(--bg-deep) 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.center-text { text-align: center; }

/* ───── sparkle field ───── */
#sparkle-field { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.sparkle {
  position: absolute; border-radius: 50%;
  background: white; opacity: 0;
  animation: twinkle linear infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: 0; transform: scale(0.4); }
  50% { opacity: 0.9; transform: scale(1); }
}

/* ───── top bar ───── */
#topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 22px;
  background: rgba(26, 19, 51, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.logo {
  font-size: 1.5rem; font-weight: 800; cursor: pointer;
  background: linear-gradient(90deg, var(--lilac), var(--teal));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#main-nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
#main-nav button {
  background: none; border: none; color: var(--text-muted);
  font-size: 0.95rem; padding: 8px 12px; border-radius: 10px; cursor: pointer;
  transition: all 0.2s;
}
#main-nav button:hover { color: var(--text); background: var(--bg-card-hover); }
#main-nav button.active { color: var(--text); background: rgba(179, 136, 255, 0.2); }
.wallet {
  font-weight: 700; color: var(--gold); font-size: 1.05rem;
  background: rgba(252, 211, 77, 0.1); border: 1px solid rgba(252, 211, 77, 0.3);
  padding: 6px 14px; border-radius: 999px;
}

/* ───── layout ───── */
#app { position: relative; z-index: 1; max-width: 1020px; margin: 0 auto; padding: 28px 18px 80px; }
.page { display: none; animation: fadeUp 0.35s ease; }
.page.active { display: block; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.page-title { text-align: center; margin-bottom: 20px; font-size: 1.9rem; }

.welcome-hero { text-align: center; padding: 36px 0 22px; }
.welcome-hero h1 {
  font-size: 2.8rem;
  background: linear-gradient(90deg, var(--rose), var(--lilac), var(--teal));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 40px rgba(179, 136, 255, 0.4);
}
.welcome-hero.small { padding: 14px 0 8px; }
.welcome-hero.small h1 { font-size: 2rem; }
.tagline { color: var(--text-muted); margin-top: 8px; font-size: 1.1rem; }

/* ───── cards ───── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  margin-top: 18px;
}
.card.click { cursor: pointer; transition: transform 0.2s, background 0.2s; }
.card.click:hover { transform: translateY(-4px); background: var(--bg-card-hover); }
.card h3 { margin-bottom: 6px; }
.card p { color: var(--text-muted); font-size: 0.92rem; }
.card-icon { font-size: 2.2rem; margin-bottom: 10px; }
.home-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-top: 10px; }
.home-cards .card { margin-top: 0; }

/* ───── buttons ───── */
.btn {
  font-size: 0.95rem; font-weight: 600; color: var(--text);
  background: var(--bg-card-hover); border: 1px solid var(--border);
  padding: 10px 20px; border-radius: 12px; cursor: pointer;
  transition: all 0.2s;
}
.btn:hover { background: rgba(179, 136, 255, 0.25); transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(135deg, var(--lilac), #8b5cf6);
  border: none; color: white;
  box-shadow: 0 4px 18px rgba(139, 92, 246, 0.45);
}
.btn.primary:hover { filter: brightness(1.12); }
.btn.ghost { background: transparent; }
.btn.tab { padding: 7px 14px; border-radius: 999px; font-size: 0.88rem; }
.btn.tab.active { background: linear-gradient(135deg, var(--lilac), #8b5cf6); border-color: transparent; color: white; }
.btn.small { padding: 6px 12px; font-size: 0.85rem; }

.row { display: flex; gap: 10px; margin-top: 16px; align-items: center; }
.row.center { justify-content: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

/* ───── adoption ───── */
.pet-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 18px; margin-top: 12px; }
.pet-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 14px; text-align: center; cursor: pointer; transition: all 0.25s;
}
.pet-card:hover { transform: translateY(-6px) scale(1.02); background: var(--bg-card-hover); box-shadow: 0 0 30px rgba(179, 136, 255, 0.3); }
.pet-card svg { width: 110px; height: 110px; }
.pet-card h3 { margin-top: 10px; }
.pet-card p { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; }

.adopt-form {
  max-width: 440px; margin: 20px auto; text-align: center;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow);
}
#adopt-preview svg { width: 160px; height: 160px; }
.adopt-form input {
  width: 100%; margin-top: 16px; padding: 12px 16px; font-size: 1rem;
  background: rgba(0, 0, 0, 0.25); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; outline: none;
}
.adopt-form input:focus { border-color: var(--lilac); }
.color-picker { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.color-dot {
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: transform 0.15s;
}
.color-dot:hover { transform: scale(1.15); }
.color-dot.active { border-color: white; box-shadow: 0 0 12px rgba(255, 255, 255, 0.6); }

/* ───── pet page ───── */
.pet-stage { text-align: center; padding: 10px 0; }
#pet-display svg { width: 200px; height: 200px; filter: drop-shadow(0 0 24px rgba(179, 136, 255, 0.45)); animation: float 3.4s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
.pet-mood { font-size: 1.05rem; margin-top: 6px; color: var(--teal); min-height: 1.4em; }

.stats-panel { max-width: 520px; margin: 14px auto; display: grid; gap: 12px; }
.stat label { font-size: 0.9rem; color: var(--text-muted); display: block; margin-bottom: 4px; }
.bar { height: 14px; background: rgba(0, 0, 0, 0.3); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; width: 0; }
.fill.hunger { background: linear-gradient(90deg, #f87171, #fb923c); }
.fill.happy { background: linear-gradient(90deg, var(--rose), var(--lilac)); }
.fill.energy { background: linear-gradient(90deg, var(--gold), #fbbf24); }
.fill.xp { background: linear-gradient(90deg, var(--teal), #38bdf8); }

/* ───── world ───── */
.world-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.realm {
  border-radius: var(--radius); padding: 24px 18px; cursor: pointer;
  border: 1px solid var(--border); text-align: center;
  transition: transform 0.22s, box-shadow 0.22s; position: relative; overflow: hidden;
}
.realm:hover { transform: translateY(-5px); box-shadow: 0 0 34px rgba(179, 136, 255, 0.35); }
.realm .realm-icon { font-size: 2.6rem; }
.realm h3 { margin-top: 8px; }
.realm p { font-size: 0.85rem; color: rgba(255, 255, 255, 0.75); margin-top: 6px; }
.realm .cooldown { position: absolute; inset: 0; background: rgba(10, 6, 25, 0.78); display: flex; align-items: center; justify-content: center; font-size: 1rem; border-radius: var(--radius); }

/* ───── items / shop ───── */
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-top: 18px; }
.item-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 12px; text-align: center; transition: background 0.2s;
}
.item-card:hover { background: var(--bg-card-hover); }
.item-card .item-icon { font-size: 2rem; }
.item-card h4 { margin-top: 8px; font-size: 0.95rem; }
.item-card .desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; min-height: 2.2em; }
.item-card .price { color: var(--gold); font-weight: 700; margin-top: 6px; }
.item-card .qty { color: var(--teal); font-size: 0.85rem; margin-top: 2px; }
.item-card .row { justify-content: center; margin-top: 10px; }

/* ───── games ───── */
.game-hud { font-size: 1.05rem; font-weight: 700; color: var(--gold); }
#game-board { margin-top: 18px; display: flex; justify-content: center; }

.memory-grid { display: grid; grid-template-columns: repeat(4, 86px); gap: 10px; }
.mem-card {
  width: 86px; height: 86px; cursor: pointer; perspective: 600px; background: none; border: none; padding: 0;
}
.mem-inner { position: relative; width: 100%; height: 100%; transition: transform 0.4s; transform-style: preserve-3d; }
.mem-card.flipped .mem-inner, .mem-card.matched .mem-inner { transform: rotateY(180deg); }
.mem-face {
  position: absolute; inset: 0; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; font-size: 2rem;
  backface-visibility: hidden; border: 1px solid var(--border);
}
.mem-back { background: linear-gradient(135deg, #4c2e8a, #2a1f4d); }
.mem-back::after { content: "✦"; color: var(--lilac); font-size: 1.6rem; }
.mem-front { background: rgba(94, 234, 212, 0.12); transform: rotateY(180deg); }
.mem-card.matched .mem-front { background: rgba(94, 234, 212, 0.3); box-shadow: 0 0 16px rgba(94, 234, 212, 0.5); }

.wheel-wrap { text-align: center; }
#wheel-canvas { border-radius: 50%; box-shadow: 0 0 40px rgba(179, 136, 255, 0.35); }
.wheel-pointer { font-size: 2rem; margin-bottom: -10px; }

#catch-canvas { background: linear-gradient(180deg, #131029, #2a1f4d); border-radius: var(--radius); border: 1px solid var(--border); cursor: none; max-width: 100%; }

/* ───── house ───── */
/* ───── house room (2D interior) ───── */
.house-room {
  position: relative; max-width: 720px; margin: 0 auto 24px;
  aspect-ratio: 3 / 2; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); box-shadow: var(--shadow);
  touch-action: none;
}
.house-room.drop-ready { outline: 2px dashed var(--teal); outline-offset: -6px; }
.room-art { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.decor-layer { position: absolute; inset: 0; }

.decor-item {
  position: absolute; transform: translate(-50%, -50%);
  font-size: 2.6rem; line-height: 1; cursor: grab; user-select: none;
  touch-action: none; z-index: 1;
}
.decor-glyph {
  display: block; line-height: 1;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.45));
  transition: filter 0.15s;
}
.decor-item:hover { z-index: 6; }
.decor-item:hover .decor-glyph { filter: drop-shadow(0 0 10px rgba(179, 136, 255, 0.8)); }
.decor-item.dragging { cursor: grabbing; z-index: 7; }
.decor-item.dragging .decor-glyph { filter: drop-shadow(0 0 14px rgba(94, 234, 212, 0.9)); }

.decor-remove, .decor-resize {
  position: absolute; width: 22px; height: 22px; border-radius: 50%;
  border: none; line-height: 1; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.decor-remove {
  top: -11px; right: -11px;
  background: var(--rose); color: #2a1f4d;
  font-size: 0.85rem; font-weight: 700;
}
.decor-resize {
  bottom: -11px; right: -11px;
  background: var(--teal); color: #08332b;
  font-size: 0.8rem; font-weight: 700; cursor: nwse-resize;
  touch-action: none;
}
.decor-item:hover .decor-remove,
.decor-item:hover .decor-resize { display: flex; }

.shelf-item {
  padding: 10px 14px; border-radius: 12px; background: var(--bg-card); border: 1px solid var(--border);
  cursor: pointer; font-size: 1.4rem; transition: all 0.15s;
}
.shelf-item:hover { background: var(--bg-card-hover); }
.shelf-item.selected { border-color: var(--teal); box-shadow: 0 0 14px rgba(94, 234, 212, 0.5); }

/* ───── battle ───── */
#battle-board { max-width: 640px; margin: 0 auto; }
.battle-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 10px 6px; }
.enemy-row { flex-direction: row; }
.player-row { flex-direction: row; }
.c-sprite { position: relative; }
.c-sprite svg { width: 150px; height: 150px; filter: drop-shadow(0 0 18px rgba(179, 136, 255, 0.4)); }
.enemy-row .c-sprite svg { width: 130px; height: 130px; }
.combat-info { flex: 1; max-width: 320px; }
.c-name { font-weight: 700; margin-bottom: 6px; }
.c-level { color: var(--gold); font-size: 0.85rem; margin-left: 4px; }
.hp-bar { height: 16px; }
.fill.hp { background: linear-gradient(90deg, #4ade80, #22d3ee); }
.fill.hp.low { background: linear-gradient(90deg, #ef4444, #f97316); }
.hp-num { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

#battle-log {
  background: rgba(0, 0, 0, 0.3); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 16px; margin: 14px 0; height: 110px; overflow-y: auto;
  font-size: 0.92rem; line-height: 1.55;
}
.move-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.move-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; border-width: 2px; }
.move-meta { font-size: 0.78rem; color: var(--text-muted); font-weight: 400; }

.shake { animation: shake 0.45s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px) rotate(-3deg); }
  40% { transform: translateX(8px) rotate(2deg); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}
.hit-flash svg { filter: drop-shadow(0 0 18px rgba(248, 113, 113, 0.9)) brightness(1.6) !important; }
.heal-flash svg { filter: drop-shadow(0 0 22px rgba(74, 222, 128, 0.9)) brightness(1.3) !important; }

.float-dmg {
  position: absolute; top: 10%; left: 50%; transform: translateX(-50%);
  font-weight: 800; font-size: 1.5rem; color: #f87171; pointer-events: none;
  animation: floatUp 0.9s ease forwards; text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
.float-dmg.crit { color: var(--gold); font-size: 1.9rem; }
@keyframes floatUp { to { transform: translateX(-50%) translateY(-44px); opacity: 0; } }

/* ───── arena ───── */
.trainer-card { text-align: center; }
.trainer-head { display: flex; align-items: center; gap: 12px; text-align: left; }
.trainer-icon { font-size: 2rem; }
.trainer-sprite svg { width: 100px; height: 100px; margin: 8px auto; }
.trainer-card .btn { margin-top: 10px; width: 100%; }

/* ───── toasts & modal ───── */
#toast-zone { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: rgba(26, 19, 51, 0.95); border: 1px solid var(--lilac);
  padding: 12px 22px; border-radius: 999px; box-shadow: var(--shadow);
  animation: toastIn 0.3s ease; font-size: 0.95rem;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.toast.fade { opacity: 0; transition: opacity 0.4s; }

#modal-zone:not(:empty) {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(10, 6, 25, 0.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg-mid); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 30px; max-width: 420px; width: 90%; text-align: center; box-shadow: var(--shadow);
  animation: fadeUp 0.3s ease;
}
.modal h2 { margin-bottom: 10px; }
.modal .big-icon { font-size: 3rem; margin-bottom: 8px; }

@media (max-width: 600px) {
  .memory-grid { grid-template-columns: repeat(4, 70px); }
  .mem-card { width: 70px; height: 70px; }
  .decor-item { font-size: 2rem; }
}
