/*
 * loading.css
 * Shared loading-screen styling for SODB Online.
 * Used by both index.html (build-picker/loader page) and the emscripten
 * shell (shell.html -> sodb.html), so the two loading screens look and
 * animate identically.
 *
 * NOTE: relies on a sibling "others/fonts/..." and "others/images/..."
 * folder next to whichever HTML file includes this stylesheet - keep this
 * file copied alongside index.html at the output root the same way it is
 * copied alongside sodb.html in each build folder.
 */

      :root {
        /* -- void / surface -- */
        --void: #010101;
        --void-2: #08090c;
        --black: #000000;
        --surface: rgba(12, 13, 18, 0.55);
        --surface-edge: rgba(255, 178, 64, 0.14);
        --hairline: rgba(255, 255, 255, 0.05);

        /* -- ki / saiyan energy -- */
        --gold: #ffb52e;
        --gold-soft: #ffe3a8;
        --amber: #ff8a3d;
        --ember: #ff5a3c;
        --crimson: #ff3b4a;

        /* -- rare cool counter-accent -- */
        --saiyan: #4fd8ff;

        --cream: #fff6e8;
        --muted: #9aa0b4;

        --font-display: 'Libel Suit', 'Avenir Next', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
        --font-hud: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Roboto Mono', Consolas, monospace;

        --ease: cubic-bezier(0.22, 1, 0.36, 1);
      }

      * { box-sizing: border-box; }

      html, body {
        width: 100%;
        height: 100%;
        height: 100dvh;
      }

      body {
        background-position: center;
        background-size: cover;
        padding: 0;
        margin: 0;
        overscroll-behavior: contain;
        overflow: hidden;
        background-color: var(--void);
        position: fixed;
        inset: 0;
        width: 100vw;
        width: 100dvw;
        height: 100vh;
        height: 100dvh;
      }

      body::after {
        content: "";
        position: fixed;
        inset: 0;
        min-height: 100dvh;
        background:
          radial-gradient(ellipse 62% 46% at 78% 8%, rgba(79, 216, 255, 0.02), transparent 70%),
          radial-gradient(ellipse 68% 56% at 22% 100%, rgba(255, 90, 60, 0.05), transparent 70%),
          radial-gradient(ellipse 60% 50% at 50% 62%, rgba(255, 138, 61, 0.04), transparent 72%),
          linear-gradient(180deg, #000000 0%, #020203 48%, #000000 100%);
        z-index: -1;
        pointer-events: none;
      }

      .backbuffer {
        position: absolute;
        top: 0px;
        left: 0px;
        margin: 0px;
        border: 0;
        width: 100% !important;
        height: 100% !important;
        overflow: hidden;
        display: block;
        opacity: 0.0;
        transition: opacity 0.5s;
        touch-action: none;
        -webkit-user-select: none;
        user-select: none;
        image-rendering: optimizeSpeed;
        image-rendering: -moz-crisp-edges;
        image-rendering: -o-crisp-edges;
        image-rendering: -webkit-optimize-contrast;
        image-rendering: optimize-contrast;
        image-rendering: crisp-edges;
        -ms-interpolation-mode: nearest-neighbor;
      }

      .backbuffer.fade { opacity: 1; }

      @font-face {
        font-family: libel-suit-rg;
        src: url('others/fonts/libel-suit-rg.ttf');
        font-display: swap;
      }

      .loading-screen {
        position: absolute;
        inset: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: clamp(14px, 4vh, 30px);
        padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
        text-align: center;
        transition: opacity 0.9s ease, visibility 0.9s ease;
        overflow: hidden;
        box-sizing: border-box;
      }

      .loading-screen--done {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
      }

      .loading-screen > * {
        position: relative;
        z-index: 1;
      }

      .embers {
        position: absolute;
        inset: 0;
        z-index: 0;
        pointer-events: none;
        overflow: hidden;
      }

      .embers span {
        position: absolute;
        bottom: -5%;
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: var(--gold);
        box-shadow: 0 0 10px 2px rgba(255, 138, 61, 0.6);
        opacity: 0;
        animation: rise 9s ease-in infinite;
        filter: blur(0.2px);
      }

      .embers span.spark {
        background: var(--saiyan);
        box-shadow: 0 0 10px 2px rgba(79, 216, 255, 0.55);
      }

      .embers span:nth-child(1) { left: 8%;  animation-delay: 0s;    animation-duration: 8.5s; }
      .embers span:nth-child(2) { left: 20%; animation-delay: 1.4s;  animation-duration: 7.5s; width: 3px; height: 3px; }
      .embers span:nth-child(3) { left: 33%; animation-delay: 3.1s;  animation-duration: 9.5s; }
      .embers span:nth-child(4) { left: 47%; animation-delay: 0.8s;  animation-duration: 8s;   width: 5px; height: 5px; }
      .embers span:nth-child(5) { left: 60%; animation-delay: 3.8s;  animation-duration: 8.8s; }
      .embers span:nth-child(6) { left: 73%; animation-delay: 2.2s;  animation-duration: 7.8s; width: 3px; height: 3px; }
      .embers span:nth-child(7) { left: 86%; animation-delay: 4.6s;  animation-duration: 9.2s; }
      .embers span:nth-child(8) { left: 15%; animation-delay: 5.4s;  animation-duration: 8.4s; }
      .embers span:nth-child(9) { left: 92%; animation-delay: 1.9s;  animation-duration: 7.6s; }

      @keyframes rise {
        0% { transform: translateY(0) scale(0.6); opacity: 0; }
        14% { opacity: 0.9; }
        50% { transform: translateY(-52vh) scale(1); }
        86% { opacity: 0.35; }
        100% { transform: translateY(-108vh) scale(0.85); opacity: 0; }
      }

      .ball-wrap {
        position: relative;
        width: clamp(84px, 24vmin, 156px);
        aspect-ratio: 1 / 1;
        display: flex;
        align-items: center;
        justify-content: center;
        animation: power-pulse 2.6s ease-in-out infinite;
      }

      .ball-wrap::before {
        content: "";
        position: absolute;
        inset: -34px;
        border-radius: 50%;
        background:
          radial-gradient(circle, rgba(255, 138, 61, 0.10), transparent 60%),
          radial-gradient(circle, rgba(255, 59, 74, 0.04), transparent 72%);
        filter: blur(14px);
        z-index: -1;
      }

      .aura {
        position: absolute;
        inset: -8px;
        border-radius: 50%;
        background: conic-gradient(
          from 0deg,
          transparent 0deg,
          rgba(255, 181, 46, 0.85) 40deg,
          rgba(255, 138, 61, 0.35) 90deg,
          transparent 150deg,
          transparent 360deg
        );
        mask: radial-gradient(closest-side, transparent 84%, #000 87%, #000 96%, transparent 100%);
        -webkit-mask: radial-gradient(closest-side, transparent 84%, #000 87%, #000 96%, transparent 100%);
        animation: spin 3.4s linear infinite;
        filter: blur(0.5px) drop-shadow(0 0 6px rgba(255, 138, 61, 0.28));
      }

      .dragonball {
        position: relative;
        width: clamp(52px, 15vmin, 96px);
        aspect-ratio: 1 / 1;
        border-radius: 50%;
        background: radial-gradient(circle at 33% 26%, #fff6de 0%, #ffcf72 20%, #ff9a3d 52%, #d9560f 88%);
        box-shadow:
          inset -14px -16px 26px rgba(0, 0, 0, 0.38),
          inset 10px 12px 18px rgba(255, 255, 255, 0.45),
          0 0 16px rgba(255, 165, 40, 0.32),
          0 0 30px rgba(255, 59, 74, 0.12);
        animation: bob 2.6s ease-in-out infinite;
      }

      .star {
        position: absolute;
        width: clamp(8px, 2vmin, 13px);
        height: clamp(8px, 2vmin, 13px);
        background: radial-gradient(circle at 35% 30%, #ffb3ad, var(--crimson) 70%);
        clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
        filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35)) drop-shadow(0 0 5px rgba(255, 59, 74, 0.5));
      }
      .star--1 { top: 29%; left: 29%; }
      .star--2 { top: 29%; left: 58%; }
      .star--3 { top: 56%; left: 29%; }
      .star--4 { top: 56%; left: 58%; }

      @keyframes spin {
        to { transform: rotate(360deg); }
      }

      @keyframes bob {
        0%, 100% { transform: translateY(0); }
        50% { transform: translateY(-6px); }
      }

      @keyframes power-pulse {
        0%, 100% { transform: scale(1); }
        50% { transform: scale(1.03); }
      }

      .wordmark {
        margin: 0;
        pointer-events: none;
        font-family: var(--font-display);
        font-weight: 800;
        font-size: clamp(26px, 8vmin, 50px);
        line-height: 1;
        letter-spacing: 0.5px;
        max-width: 90vw;
        font-style: italic;
        background: linear-gradient(180deg, var(--cream) 0%, var(--gold) 42%, var(--amber) 78%, var(--ember) 100%);
        -webkit-background-clip: text;
        background-clip: text;
        color: var(--gold);
        filter: drop-shadow(0 2px 10px rgba(255, 138, 61, 0.35));
      }

      .wordmark span {
        display: block;
        margin-top: 8px;
        font-family: var(--font-hud);
        font-weight: 600;
        font-size: clamp(9px, 2.4vmin, 13px);
        letter-spacing: clamp(3px, 1vmin, 6px);
        font-style: normal;
        background: none;
        -webkit-text-fill-color: currentColor;
        color: var(--muted);
      }

      .status {
        min-height: 1.2em;
        min-width: 1px;
        outline: none;
        font-family: var(--font-hud);
        font-weight: 600;
        font-size: 11px;
        letter-spacing: 0.16em;
        text-transform: uppercase;
        color: var(--gold-soft);
        caret-color: transparent;
        opacity: 0.85;
        pointer-events: none;
        user-select: none;
        -webkit-user-select: none;
      }

      .hud-frame {
        position: relative;
        width: min(320px, 90vw);
        opacity: 0;
        max-height: 0;
        overflow: hidden;
        transition: opacity 0.4s var(--ease), max-height 0.4s var(--ease);
      }

      .hud-frame.hud-frame--visible {
        opacity: 1;
        max-height: 76px;
      }

      .hud-label {
        display: flex;
        justify-content: space-between;
        font-family: var(--font-hud);
        font-size: 10px;
        font-weight: 600;
        letter-spacing: 0.14em;
        color: var(--muted);
        margin-bottom: 8px;
        padding: 0 2px;
      }

      .hud-label span:last-child { color: var(--saiyan); }

      .progress {
        display: flex;
        align-items: center;
        gap: 12px;
        width: 100%;
        padding: 12px 14px;
        background: var(--surface);
        border: 1px solid var(--surface-edge);
        border-radius: 14px;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
      }

      .progress__track {
        position: relative;
        flex: 1;
        height: 10px;
        background: rgba(0, 0, 0, 0.4);
        border-radius: 999px;
        box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.55);
        overflow: hidden;
      }

      .progress__fill {
        position: relative;
        height: 100%;
        width: 0%;
        border-radius: 999px;
        background: linear-gradient(90deg, var(--ember), var(--amber) 55%, var(--gold));
        background-size: 180% 100%;
        transition: width 0.3s var(--ease);
        animation: charge 2.2s ease-in-out infinite;
        box-shadow: 0 0 12px rgba(255, 138, 61, 0.55);
      }

      .progress__fill::after {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: inherit;
        background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 55%);
      }

      @keyframes charge {
        0%, 100% { background-position: 0% 0; }
        50% { background-position: 100% 0; }
      }

      .progress__pct {
        display: flex;
        align-items: center;
        gap: 5px;
        min-width: 5ch;
        font-family: var(--font-hud);
        font-weight: 700;
        font-size: 13px;
        letter-spacing: 0.03em;
        color: var(--gold-soft);
      }

      .bolt {
        width: 9px;
        height: 13px;
        fill: var(--gold);
        filter: drop-shadow(0 0 3px rgba(255, 181, 46, 0.6));
      }

      @media (prefers-reduced-motion: reduce) {
        .aura,
        .ball-wrap,
        .dragonball,
        .progress__fill,
        .embers span {
          animation: none;
        }
        .embers { display: none; }
      }

      @media (max-width: 480px) {
        .hud-frame { width: 90vw; }
      }

      /* Very narrow screens (small phones in portrait) */
      @media (max-width: 340px) {
        .loading-screen { gap: 12px; padding: 12px; }
      }

      /* Short height (phone in landscape / on-screen keyboard open) */
      @media (max-height: 480px) {
        .loading-screen { gap: 10px; }
        .ball-wrap { width: clamp(56px, 16vh, 96px); }
        .dragonball { width: clamp(36px, 10vh, 60px); }
        .wordmark { font-size: clamp(20px, 6vh, 34px); }
        .wordmark span { margin-top: 4px; }
        .hud-frame.hud-frame--visible { max-height: 60px; }
      }

      /* Large screens / desktop - limit excessive content stretching */
      @media (min-width: 1600px) {
        .wordmark { font-size: 56px; }
      }
