/* Empress Express — base page (A): full-screen canvas, #ui root for D, loading card, A's fallback touch pads,
   stats overlay and the minimal fallback UI. D's css/ui.css styles everything inside #ui. */
:root {
    --lacquer: #14100f;
    --red: #9e1b1f;
    --gold: #e8b547;
    --cream: #f6ecd8;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--lacquer);
    color: var(--cream);
    font-family: 'Baloo 2', system-ui, sans-serif;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

#game {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    display: block;
    outline: none;
    touch-action: none;
}

#ui {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}
/* only for the bare fallback UI: D's UI (.ee-ui) sets pointer-events per layer, and its frame/confetti/HUD layers must let taps through */
#ui:not(.ee-ui) > * { pointer-events: auto; }

/* ---- loading ------------------------------------------------------------------------------------------------- */
#loading {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    background: radial-gradient(ellipse at 50% 40%, #3a1414 0%, var(--lacquer) 70%);
    transition: opacity 0.5s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
.ld-card { text-align: center; width: min(320px, 84vw); }
.ld-seal {
    width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 14px;
    display: grid; place-items: center; font-size: 42px; font-weight: 700;
    background: var(--red); color: var(--gold); border: 3px solid var(--gold);
    box-shadow: 0 6px 24px rgba(158, 27, 31, 0.5);
    font-family: 'Ma Shan Zheng', 'KaiTi', serif;
}
.ld-title { font-family: 'Lilita One', 'Arial Black', sans-serif; font-size: 32px; letter-spacing: 0.5px; color: var(--cream); }
.ld-zh { color: var(--gold); font-size: 18px; margin-bottom: 18px; opacity: 0.9; }
.ld-track { height: 8px; border-radius: 8px; background: rgba(246, 236, 216, 0.12); overflow: hidden; border: 1px solid rgba(232, 181, 71, 0.35); }
.ld-track i { display: block; height: 100%; width: 4%; background: linear-gradient(90deg, var(--red), var(--gold)); transition: width 0.25s ease; }
.ld-text { margin-top: 10px; font-size: 15px; opacity: 0.75; }
.nojs { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; }

/* ---- stats overlay (?stats=1) -------------------------------------------------------------------------------- */
.a-stats {
    position: fixed; left: 6px; bottom: 6px; z-index: 200; pointer-events: none;
    font: 11px/1.3 ui-monospace, Consolas, monospace; color: #fff;
    background: rgba(0, 0, 0, 0.55); padding: 3px 7px; border-radius: 6px; max-width: calc(100vw - 12px);
}

/* ---- A's fallback touch pads (only when D's UI provides none) ------------------------------------------------ */
.a-touch { position: fixed; inset: auto 0 0 0; height: 46vh; z-index: 20; pointer-events: none; touch-action: none; }
.a-touch[hidden] { display: none; }
.a-touch button {
    pointer-events: auto; touch-action: none; border: 3px solid rgba(232, 181, 71, 0.7); color: var(--cream);
    background: rgba(20, 16, 15, 0.45); border-radius: 22px; font: 700 22px 'Lilita One', sans-serif;
    -webkit-user-select: none; user-select: none;
}
.a-touch button.on { background: rgba(158, 27, 31, 0.75); transform: scale(0.96); }
.a-steer { position: absolute; left: calc(14px + var(--safe-l)); bottom: calc(18px + var(--safe-b)); display: flex; gap: 12px; }
.a-steer button { width: 88px; height: 112px; font-size: 34px; }
.a-pedals { position: absolute; right: calc(14px + var(--safe-r)); bottom: calc(18px + var(--safe-b)); display: grid; grid-template-columns: 84px 96px; grid-template-rows: 64px 112px; gap: 10px; }
.a-pedals .drift { grid-column: 1 / 3; font-size: 18px; }
.a-pedals .brake { font-size: 26px; }
.a-pedals .gas { background: rgba(158, 27, 31, 0.55); }

/* ---- A's fallback UI (only when js/ui/index.js is missing) --------------------------------------------------- */
.a-ui {
    position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; background: rgba(20, 16, 15, 0.55); padding: 16px;
}
.a-ui[hidden] { display: none; }
.a-ui h1, .a-ui h2 { font-family: 'Lilita One', sans-serif; color: var(--gold); margin: 0 0 8px; text-align: center; }
.a-ui h1 { font-size: 40px; }
.a-maps { display: grid; gap: 8px; width: min(360px, 100%); }
.a-ui button {
    font: 700 18px 'Baloo 2', sans-serif; padding: 10px 18px; border-radius: 12px; border: 2px solid var(--gold);
    background: var(--red); color: var(--cream); cursor: pointer; min-height: 44px;
}
.a-hud {
    position: fixed; top: calc(8px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%);
    font: 700 18px 'Baloo 2', sans-serif; background: rgba(20, 16, 15, 0.6); padding: 4px 14px; border-radius: 12px;
    border: 1px solid rgba(232, 181, 71, 0.5); white-space: nowrap; pointer-events: none;
}
.a-hud[hidden] { display: none; }
.a-msg {
    position: fixed; left: 50%; top: 32%; transform: translate(-50%, -50%) scale(0.8); opacity: 0;
    font: 64px 'Lilita One', sans-serif; color: var(--gold); text-shadow: 0 4px 0 var(--red), 0 8px 24px rgba(0, 0, 0, 0.5);
    transition: opacity 0.18s, transform 0.18s; pointer-events: none; white-space: nowrap;
}
.a-msg.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
@media (max-width: 480px) {
    .a-msg { font-size: 44px; }
    .a-hud { font-size: 15px; }
}
