/* ===== Tokens ===== */
:root {
    --bg0: #150c2a;
    --bg1: #24123f;
    --bg2: #3a1d63;
    --ink: #140c22;
    --yellow: #FFD23F;
    --yellow-d: #d79a12;
    --coral: #FF4D6D;
    --coral-d: #b81f43;
    --cyan: #2EC4F1;
    --cyan-d: #107fa6;
    /* team colours (P1 / P2): red / blue; `solo-swap` (set on <html> for CPU matches, see render/artUtils.js) makes the human (P1, left) blue and the CPU red */
    --t1: var(--coral); --t1-d: var(--coral-d); --t1-tc: #fff; --t1-rgb: 255, 77, 109;
    --t2: var(--cyan); --t2-d: var(--cyan-d); --t2-tc: var(--ink); --t2-rgb: 46, 196, 241;
    --purple: #9B5CFF;
    --purple-d: #5d2fb5;
    --green: #5BE37D;
    --green-d: #218a3d;
    --red: #ff3b3b;
    --text: #fff7e8;
    --text-dim: #b9acd6;
    --panel: rgba(36, 18, 63, 0.86);
    --panel-2: rgba(21, 12, 42, 0.78);
    --font-display: 'Russo One', 'Rubik', Impact, sans-serif;
    --font-ui: 'Rubik', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
    --ease-out: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0; padding: 0; width: 100%; height: 100%;
    overflow: hidden;
    background: radial-gradient(120% 120% at 50% 0%, var(--bg1), var(--bg0) 70%);
    color: var(--text);
    font-family: var(--font-ui);
    font-weight: 600;
    -webkit-user-select: none; user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    overscroll-behavior: none;
    -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
canvas { display: block; }

/* ===== Stage (max 2:1, letterboxed) ===== */
#stage {
    position: fixed;
    left: 50%; top: 50%;
    width: min(100vw, 200vh);
    height: 100vh;
    height: 100dvh;
    width: min(100vw, 200dvh);
    transform: translate(-50%, -50%);
    overflow: hidden;
    container-type: size;
    container-name: stage;
    background: linear-gradient(180deg, var(--bg1) 0%, var(--bg0) 100%);
    font-size: clamp(12px, 2.4cqmin, 28px);
    box-shadow: 0 0 0 100vmax var(--bg0);
}
#screens, #overlays { position: absolute; inset: 0; }
#overlays { pointer-events: none; z-index: 50; }
#overlays > * { pointer-events: auto; }

:root.solo-swap {
    --t1: var(--cyan); --t1-d: var(--cyan-d); --t1-tc: var(--ink); --t1-rgb: 46, 196, 241;
    --t2: var(--coral); --t2-d: var(--coral-d); --t2-tc: #fff; --t2-rgb: 255, 77, 109;
}

/* ===== Animated background ===== */
#bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none;
    background:
        radial-gradient(60% 50% at 20% 100%, rgba(var(--t1-rgb), .16), transparent 70%),
        radial-gradient(60% 50% at 80% 100%, rgba(var(--t2-rgb), .16), transparent 70%),
        linear-gradient(180deg, #1c0e36, #150c2a 70%);
}
.bg-stars { position: absolute; inset: 0;
    background-image:
        radial-gradient(1.5px 1.5px at 12% 18%, #fff8, transparent),
        radial-gradient(1.5px 1.5px at 33% 8%, #fff6, transparent),
        radial-gradient(2px 2px at 58% 22%, #ffd23f88, transparent),
        radial-gradient(1.5px 1.5px at 76% 12%, #fff7, transparent),
        radial-gradient(1.5px 1.5px at 90% 30%, #fff5, transparent),
        radial-gradient(1.5px 1.5px at 22% 40%, #fff4, transparent),
        radial-gradient(1.5px 1.5px at 66% 46%, #fff4, transparent);
    animation: twinkle 4s ease-in-out infinite alternate;
}
.bg-gear { position: absolute; opacity: .09; background: url('gear.svg') center / contain no-repeat; }
.bg-gear.g1 { width: 70cqmin; height: 70cqmin; left: -18cqmin; bottom: -26cqmin; animation: spin 90s linear infinite; }
.bg-gear.g2 { width: 50cqmin; height: 50cqmin; right: -12cqmin; top: -16cqmin; animation: spin 70s linear infinite reverse; }
.bg-gear.g3 { width: 30cqmin; height: 30cqmin; right: 18%; bottom: -10cqmin; animation: spin 50s linear infinite; opacity: .07; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes twinkle { from { opacity: .55; } to { opacity: 1; } }

/* ===== Screens ===== */
.screen {
    position: absolute; inset: 0;
    display: none;
    opacity: 0;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: block; opacity: 1; }
.screen.enter { animation: scrIn .32s var(--ease-out) both; }
.screen.leave { display: block; animation: scrOut .22s ease-in both; pointer-events: none; }
@keyframes scrIn { from { opacity: 0; transform: translateY(2.5cqh) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes scrOut { from { opacity: 1; } to { opacity: 0; transform: scale(1.02); } }

/* ===== Buttons ===== */
.btn {
    --c: var(--yellow); --cd: var(--yellow-d); --tc: var(--ink);
    position: relative;
    display: inline-flex; align-items: center; justify-content: center; gap: .4em;
    min-height: 44px; min-width: 44px;
    padding: .55em 1.1em;
    border: .2em solid var(--ink);
    border-radius: .9em;
    background: linear-gradient(180deg, color-mix(in srgb, var(--c) 82%, #fff) 0%, var(--c) 38%, var(--cd) 100%);
    color: var(--tc);
    font-family: var(--font-display);
    font-size: 1em;
    letter-spacing: .03em;
    text-transform: uppercase;
    line-height: 1.05;
    cursor: pointer;
    box-shadow: 0 .32em 0 var(--ink), 0 .55em .8em rgba(0, 0, 0, .45), inset 0 .12em 0 rgba(255, 255, 255, .45);
    transition: transform .12s var(--ease-spring), box-shadow .12s, filter .15s;
    transform: translateY(0);
    white-space: nowrap;
    touch-action: none;
}
.btn > span { display: block; max-width: 100%; }
.btn:hover:not(:disabled) { transform: translateY(-.1em) scale(1.03); filter: brightness(1.08); }
.btn.pressed, .btn:active:not(:disabled) {
    transform: translateY(.28em) scale(.96);
    box-shadow: 0 .04em 0 var(--ink), 0 .15em .3em rgba(0, 0, 0, .4), inset 0 .1em 0 rgba(255, 255, 255, .3);
    filter: brightness(.95);
    transition-duration: .05s;
}
.btn:disabled, .btn.disabled { filter: grayscale(.85) brightness(.7); cursor: not-allowed; }
.btn:focus-visible { outline: .22em solid #fff; outline-offset: .15em; }
.btn.coral { --c: var(--coral); --cd: var(--coral-d); --tc: #fff; }
.btn.cyan { --c: var(--cyan); --cd: var(--cyan-d); --tc: var(--ink); }
.btn.purple { --c: var(--purple); --cd: var(--purple-d); --tc: #fff; }
.btn.green { --c: var(--green); --cd: var(--green-d); --tc: var(--ink); }
.btn.ghost { --c: #4a2d7c; --cd: #2e1a55; --tc: var(--text); }
.btn.big { font-size: 1.5em; padding: .6em 1.2em; }
.btn.round { border-radius: 50%; padding: 0; width: 2.9em; height: 2.9em; }
.btn svg { width: 1.3em; height: 1.3em; flex: none; }
.btn.kbd-focus { outline: .22em solid #fff; outline-offset: .12em; animation: pulseRing 1s ease-in-out infinite; }
@keyframes pulseRing { 50% { outline-offset: .3em; } }

/* Generic spring pop for freshly shown elements */
.pop-in { animation: popIn .42s var(--ease-spring) both; }
@keyframes popIn { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
.shake { animation: shake .38s ease-in-out; }
@keyframes shake { 15% { transform: translateX(-6px) rotate(-1.5deg); } 35% { transform: translateX(6px) rotate(1.5deg); } 55% { transform: translateX(-4px); } 75% { transform: translateX(3px); } }

/* ===== Titles / labels ===== */
.display { font-family: var(--font-display); text-transform: uppercase; letter-spacing: .03em; }
.screen-title {
    font-family: var(--font-display); text-transform: uppercase;
    font-size: clamp(22px, 3.2em, 56px);
    color: var(--yellow);
    -webkit-text-stroke: .08em var(--ink); paint-order: stroke fill;
    text-shadow: 0 .09em 0 var(--ink), 0 .18em .3em rgba(0, 0, 0, .5);
    transform: rotate(-1.5deg);
    margin: 0; text-align: center;
}
.tilt-l { transform: rotate(-2.5deg); }
.tilt-r { transform: rotate(2.5deg); }
.stroke { -webkit-text-stroke: .08em var(--ink); paint-order: stroke fill; text-shadow: 0 .1em 0 var(--ink); }
.fit { white-space: nowrap; overflow: hidden; }

/* ===== Popups ===== */
.modal-back {
    position: absolute; inset: 0; z-index: 60;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10, 5, 24, .72);
    backdrop-filter: blur(3px);
    animation: fadeIn .2s ease-out both;
    padding: 2.5cqmin;
}
.modal-back.closing { animation: fadeOut .18s ease-in both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; } }
.modal {
    position: relative;
    width: min(94%, 34em); max-height: 96%;
    overflow: visible;   /* never clip the close button / shadows; bodies scroll themselves (.modal-body) */
    display: flex; flex-direction: column; gap: .7em;
    padding: 1.1em 1.2em 1.2em;
    background: linear-gradient(180deg, #3a1d63, #24123f);
    border: .22em solid var(--ink);
    border-radius: 1.3em;
    box-shadow: 0 .4em 0 var(--ink), 0 1.2em 2.5em rgba(0, 0, 0, .6), inset 0 .15em 0 rgba(255, 255, 255, .15);
    animation: popIn .38s var(--ease-spring) both;
}
.modal h2 { margin: 0; text-align: center; }
.modal .x {
    position: absolute; top: -.6em; right: -.6em; z-index: 3;
    width: 2.6em; height: 2.6em; min-width: 44px; min-height: 44px; font-size: .85em;
}
.modal-body { overflow-x: hidden; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
/* modal bodies with buttons: room inside the scroller for hover pop (scale) + drop shadows, so hovering never
   creates a scrollbar and shadows are not clipped at the scroll edge; the negative margin keeps the layout unchanged */
.modal-body.room { padding: .45em .9em 1em; margin: -.45em -.9em -.45em; }
/* styled thin scrollbar (only drawn when the content truly overflows) */
.modal-body, .lb-list, .legal-body, .cr-scroll { scrollbar-width: thin; scrollbar-color: var(--purple) rgba(12, 6, 26, .55); }
.modal-body::-webkit-scrollbar, .lb-list::-webkit-scrollbar { width: .55em; height: .55em; }
.modal-body::-webkit-scrollbar-track, .lb-list::-webkit-scrollbar-track { background: rgba(12, 6, 26, .55); border-radius: 1em; }
.modal-body::-webkit-scrollbar-thumb, .lb-list::-webkit-scrollbar-thumb { background: linear-gradient(90deg, var(--purple), var(--purple-d)); border: .1em solid var(--ink); border-radius: 1em; }
.modal-body::-webkit-scrollbar-thumb:hover, .lb-list::-webkit-scrollbar-thumb:hover { background: var(--yellow-d); }
.modal-body::-webkit-scrollbar-corner, .lb-list::-webkit-scrollbar-corner { background: transparent; }

/* ===== Toggle / chips ===== */
.seg { display: flex; gap: .4em; }
.seg .btn { flex: 1; font-size: .85em; padding: .5em .4em; }
.seg .btn.on { --c: var(--yellow); --cd: var(--yellow-d); --tc: var(--ink); }
.seg .btn:not(.on) { --c: #4a2d7c; --cd: #2e1a55; --tc: var(--text); box-shadow: 0 .2em 0 var(--ink), inset 0 .1em 0 rgba(255, 255, 255, .2); }

/* toggle buttons: the off state draws a slash over the icon (never a check mark / "on" look) */
.btn.toggle .ico { position: relative; }
.btn.toggle:not(.on) .ico { opacity: .8; }
.btn.toggle:not(.on) .ico::after { content: ''; position: absolute; left: -.08em; right: -.08em; top: 50%; height: .2em; margin-top: -.1em; border-radius: .2em; background: currentColor; box-shadow: 0 0 0 .07em #2e1a55; transform: rotate(-42deg); }

/* ===== Toast ===== */
#toasts { position: absolute; left: 0; right: 0; top: 12%; z-index: 90; pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: .5em; }
.toast { padding: .5em 1em; background: var(--ink); border: .15em solid var(--yellow); border-radius: 1em; color: var(--yellow); font-family: var(--font-display); animation: toastIn 1.8s ease both; }
@keyframes toastIn { 0% { transform: translateY(-1em) scale(.8); opacity: 0; } 12% { transform: none; opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-.5em); } }

/* ===== Loading ===== */
.loading-wrap { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.6em; padding: 0 8%; }
.loading-title { font-family: var(--font-display); font-size: clamp(30px, 6.2em, 100px); text-align: center; color: var(--yellow);
    -webkit-text-stroke: .07em var(--ink); paint-order: stroke fill; text-shadow: 0 .08em 0 var(--ink), 0 .2em .5em #000a;
    transform: rotate(-2deg); animation: bob 1.8s ease-in-out infinite; line-height: 1; }
@keyframes bob { 50% { transform: rotate(-2deg) translateY(-.15em) scale(1.02); } }
.loading-bar { position: relative; width: min(70%, 28em); height: 1.5em; border: .2em solid var(--ink); border-radius: 1em; background: #0c0618; overflow: visible;
    box-shadow: 0 .25em 0 var(--ink); }
.loading-fill { height: 100%; width: 0%; border-radius: .8em; background: repeating-linear-gradient(-45deg, var(--yellow) 0 .7em, #ffb703 .7em 1.4em); background-size: 200% 100%; animation: stripes 1s linear infinite; transition: width .2s linear; }
@keyframes stripes { to { background-position: 2em 0; } }
.loading-gear { position: absolute; top: 50%; left: 0; width: 2.6em; height: 2.6em; margin: -1.3em 0 0 -1.3em; border-radius: 50%;
    background: url('gear.svg') center / contain no-repeat; filter: brightness(1.8) drop-shadow(0 0 2px #140c22); animation: spin 1.2s linear infinite; }
.loading-tip { color: var(--text-dim); font-size: 1em; text-align: center; min-height: 1.4em; }
