/* ============================================================
   SPELLBINDER
   Global styles — canvas host, overlays, dashboard, utilities
   ============================================================ */

:root {
    --gold:       #F1B440;
    --gold-glow:  #FFD700;
    --gold-dim:   rgba(241, 180, 64, 0.25);
    --mint:       #8EC9A2;
    --sky:        #5BB8D6;
    --cloud:      #F5F4EE;
    --coral:      #E8845A;
    --deep-bg:    #130A32;
    --panel-bg:   rgba(19, 10, 50, 0.92);

    --font-display: 'Cinzel Decorative', Georgia, serif;
    --font-label:   'Cinzel', Georgia, serif;
    --font-body:    'Crimson Text', Georgia, serif;
}

/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: linear-gradient(180deg, #E0F2FE 0%, #EFF6FF 45%, #F8FAFC 100%);
    color: #1E293B;
    font-family: 'Nunito', var(--font-body);
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

/* ── Canvas container ───────────────────────────────────────── */
#game-container {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

/* ── Overlay root (DOM overlays rendered by JS) ─────────────── */
#overlay-root {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10;
}

#overlay-root > * {
    pointer-events: auto;
}

/* ── Typography defaults ────────────────────────────────────── */
h1, h2, h3 { font-family: var(--font-display); }
p           { font-family: var(--font-body); margin: 0; }

/* ── Button defaults ────────────────────────────────────────── */
button {
    font-family: var(--font-label);
    cursor: pointer;
    outline: none;
    transition: transform 0.12s ease, filter 0.12s ease;
}

button:focus-visible {
    outline: 2px solid var(--gold-dim);
    outline-offset: 3px;
}

button:hover { transform: scale(1.04); }
button:active { transform: scale(0.97); }

/* ── Input fields ───────────────────────────────────────────── */
input[type="text"],
input[type="password"],
textarea {
    font-family: var(--font-body);
    background: rgba(20, 10, 45, 0.9);
    border: 1px solid var(--gold-dim);
    border-radius: 6px;
    color: var(--cloud);
    outline: none;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
    border-color: rgba(241, 180, 64, 0.65);
    box-shadow: 0 0 8px rgba(241, 180, 64, 0.2);
}

/* ── Dashboard overlay ──────────────────────────────────────── */
#dashboard-overlay {
    font-family: 'Nunito', Arial, sans-serif;
    background: rgba(219, 234, 254, 0.97);
    color: #1E293B;
}

/* ── Virtual keyboard (mobile) ──────────────────────────────── */
#vkb button:active {
    background: rgba(241, 180, 64, 0.2) !important;
    transform: scale(0.95);
}

/* ── Scrollbar styling ──────────────────────────────────────── */
::-webkit-scrollbar          { width: 6px; }
::-webkit-scrollbar-track    { background: rgba(10, 6, 28, 0.5); }
::-webkit-scrollbar-thumb    { background: rgba(241, 180, 64, 0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(241, 180, 64, 0.55); }

/* ── Selection ──────────────────────────────────────────────── */
::selection { background: rgba(241, 180, 64, 0.3); color: var(--cloud); }

/* ── Animations ─────────────────────────────────────────────── */
@keyframes glow-pulse {
    0%, 100% { text-shadow: 0 0 8px rgba(245, 240, 232, 0.35); }
    50%       { text-shadow: 0 0 22px rgba(241, 180, 64, 0.55); }
}

@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Utility ─────────────────────────────────────────────────── */
.gold      { color: var(--gold); }
.mint      { color: var(--mint); }
.coral     { color: var(--coral); }
.cloud     { color: var(--cloud); }
.cinzel    { font-family: var(--font-label); }
.cinzel-d  { font-family: var(--font-display); }

/* ── Boot / loading screen (web shell — Tier 1 storybook first impression) ── */
#spellbinder-loader {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow: hidden;
    background:
        radial-gradient(ellipse 90% 55% at 50% 108%, rgba(255, 214, 140, 0.85) 0%, rgba(255, 214, 140, 0) 60%),
        linear-gradient(180deg, #6fb3d8 0%, #a8d8ea 42%, #fdeed3 78%, #ffe3ae 100%);
    transition: opacity 0.7s ease;
}

#spellbinder-loader.is-done {
    opacity: 0;
    pointer-events: none;
}

.loader-inner {
    position: relative;
    padding: 0 24px;
    max-width: 640px;
    animation: fade-in-up 0.9s ease both;
}

.loader-eyebrow {
    font-family: var(--font-label);
    font-size: 13px;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: #4a6a8a;
    margin: 0 0 10px;
}

.loader-title {
    font-family: 'Fredoka', var(--font-display);
    font-weight: 700;
    font-size: clamp(44px, 10vw, 88px);
    line-height: 1.05;
    margin: 0;
    color: #1D4ED8;
    text-shadow:
        0 2px 0 #ffffff,
        0 4px 14px rgba(29, 78, 216, 0.18);
}

.loader-tagline {
    font-family: 'Nunito', var(--font-body);
    font-size: clamp(18px, 4vw, 26px);
    font-weight: 600;
    color: #475569;
    margin: 10px 0 0;
}

/* Wand progress shimmer — indeterminate while Phaser boots */
.loader-wand {
    position: relative;
    width: min(320px, 70vw);
    height: 10px;
    margin: 34px auto 18px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.55);
    box-shadow: inset 0 1px 3px rgba(90, 74, 47, 0.25);
    overflow: hidden;
}

.loader-wand-spark {
    position: absolute;
    top: 0; bottom: 0;
    width: 40%;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(241, 180, 64,0) 0%, #F1B440 45%, #ffe9a8 55%, rgba(241, 180, 64,0) 100%);
    animation: wand-shimmer 1.6s ease-in-out infinite;
}

@keyframes wand-shimmer {
    0%   { left: -40%; }
    100% { left: 100%; }
}

.loader-status {
    font-family: 'Nunito', var(--font-label);
    font-size: 14px;
    letter-spacing: 1px;
    color: #64748B;
    margin: 0;
}

/* Twinkling stars */
.loader-stars span {
    position: absolute;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #fffbe8;
    box-shadow: 0 0 8px 2px rgba(255, 251, 232, 0.9);
    animation: star-twinkle 2.8s ease-in-out infinite;
}

.loader-stars span:nth-child(1)  { top: 12%; left: 18%; animation-delay: 0s; }
.loader-stars span:nth-child(2)  { top: 22%; left: 78%; animation-delay: 0.4s; width: 8px; height: 8px; }
.loader-stars span:nth-child(3)  { top: 38%; left: 8%;  animation-delay: 1.1s; }
.loader-stars span:nth-child(4)  { top: 8%;  left: 55%; animation-delay: 1.7s; width: 5px; height: 5px; }
.loader-stars span:nth-child(5)  { top: 55%; left: 88%; animation-delay: 0.9s; }
.loader-stars span:nth-child(6)  { top: 68%; left: 12%; animation-delay: 2.1s; width: 8px; height: 8px; }
.loader-stars span:nth-child(7)  { top: 30%; left: 38%; animation-delay: 1.4s; width: 5px; height: 5px; }
.loader-stars span:nth-child(8)  { top: 48%; left: 64%; animation-delay: 2.5s; }
.loader-stars span:nth-child(9)  { top: 75%; left: 70%; animation-delay: 0.2s; width: 5px; height: 5px; }
.loader-stars span:nth-child(10) { top: 16%; left: 32%; animation-delay: 1.9s; }

@keyframes star-twinkle {
    0%, 100% { opacity: 0.25; transform: scale(0.8); }
    50%      { opacity: 1;    transform: scale(1.15); }
}

@media (prefers-reduced-motion: reduce) {
    .loader-stars span,
    .loader-wand-spark { animation: none; }
    .loader-inner { animation: none; }
}

/* ── Mobile / PWA safe area ─────────────────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    body { padding-bottom: env(safe-area-inset-bottom); }
}
