/* Personal Arcade: join/admin pages. Self-hosted only (no external fonts/CDNs). */
@font-face {
    font-family: "Chargen";
    src: url("/fonts/6809-Chargen.woff2") format("woff2");
    font-display: swap;
}

:root {
    --bg: #0d0d12;
    --panel: rgba(20, 20, 28, 0.94);
    --line: rgba(255, 255, 255, 0.14);
    --text: #f2f2f5;
    --muted: #9a9aa8;
    --accent: #ffcc00;
    --danger: #ff4d5e;
    --btn-a: #e5484d;
    --btn-b: #f5c400;
    --btn-x: #3e7bfa;
    --btn-y: #30a46c;
    --ctl: rgba(255, 255, 255, 0.10);
    --ctl-line: rgba(255, 255, 255, 0.35);
    --ctl-down: rgba(255, 255, 255, 0.45);
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

body { overflow: hidden; }

[hidden] { display: none !important; }

button, input {
    font: inherit;
    color: inherit;
}

button {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 0.6em 1em;
    cursor: pointer;
    touch-action: manipulation;
}

button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 700; }
button.danger { border-color: var(--danger); color: var(--danger); }
button.small { padding: 0.35em 0.7em; font-size: 0.9em; }

input {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.6em 0.8em;
}

/* ---------- code / login screen ---------- */

.code-screen {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.2rem;
    padding: 16px;
    text-align: center;
}

.logo {
    font-family: "Chargen", monospace;
    font-size: clamp(2.2rem, 9vw, 4rem);
    letter-spacing: 0.15em;
    color: var(--accent);
    margin: 0;
}

.code-screen form {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    width: min(320px, 100%);
}

.code-screen label { color: var(--muted); font-size: 0.9rem; }

#code {
    font-family: "Chargen", monospace;
    font-size: 2.4rem;
    text-align: center;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    padding: 0.4em 0 0.4em 0.4em;
}

.status { min-height: 1.4em; color: var(--muted); margin: 0; max-width: 32ch; }
.status.error { color: var(--danger); }

/* ---------- play screen ---------- */

.play-screen {
    position: fixed;
    inset: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.stage {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.stage video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.stage.idle video { opacity: 0; }

.corner {
    position: absolute;
    display: flex;
    gap: 6px;
    z-index: 5;
}

.corner.top-left { top: calc(6px + var(--safe-t)); left: calc(6px + var(--safe-l)); }

.chip {
    border-radius: 999px;
    padding: 0.3em 0.8em;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid var(--line);
    font-size: 0.9rem;
}

.chip.sound {
    position: absolute;
    top: calc(6px + var(--safe-t));
    left: 50%;
    transform: translateX(-50%);
    z-index: 6;
}

/* sheets (slot picker, game picker, admin menu) */
.sheet {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(440px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 16px;
    z-index: 10;
    touch-action: pan-y;
    user-select: text;
}

.sheet.wide { width: min(640px, calc(100vw - 32px)); }
.sheet h2 { margin: 0 0 12px; font-size: 1.15rem; }
.sheet h3 { margin: 16px 0 8px; font-size: 0.95rem; color: var(--muted); font-weight: 600; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sheet-head h2 { margin: 0; }
.sheet > .primary { width: 100%; margin-top: 14px; font-size: 1.1rem; }

.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 12px 4px;
    border-radius: 12px;
}

.slot .p { font-family: "Chargen", monospace; font-size: 1.4rem; }
.slot .who { font-size: 0.8rem; color: var(--muted); }
.slot.mine { border-color: var(--accent); background: rgba(255, 204, 0, 0.15); }
.slot.mine .who { color: var(--accent); }
.slot.taken { opacity: 0.35; cursor: not-allowed; }

/* admin */
#game-filter { width: 100%; margin: 12px 0; }
.games { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.games .empty { color: var(--muted); padding: 8px 0; }
.game { width: 100%; display: flex; justify-content: space-between; gap: 12px; text-align: left; }
.game .s { color: var(--muted); font-size: 0.85rem; }

.code-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; justify-content: space-between; }
.label { color: var(--muted); font-size: 0.85rem; }
.code-big { font-family: "Chargen", monospace; font-size: 2.6rem; letter-spacing: 0.25em; color: var(--accent); }
.muted { color: var(--muted); }
.link { display: flex; gap: 6px; flex: 1 1 220px; }
.link input { flex: 1; min-width: 0; font-size: 0.85rem; }

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.players li { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.stats {
    position: absolute;
    top: calc(6px + var(--safe-t));
    right: calc(6px + var(--safe-r));
    margin: 0;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    font: 11px/1.35 ui-monospace, Menlo, monospace;
    white-space: pre;
    pointer-events: none;
    z-index: 7;
}

.toast {
    position: absolute;
    left: 50%;
    bottom: calc(18vh + var(--safe-b));
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid var(--line);
    padding: 8px 14px;
    border-radius: 999px;
    z-index: 20;
    pointer-events: none;
}

/* ---------- admin launcher ---------- */

.launcher {
    position: absolute;
    inset: 0;
    z-index: 9;
    overflow-y: auto;
    background: var(--bg);
    padding: calc(8px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
    touch-action: pan-y;
    user-select: none;
}

.launcher-head {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 6px 0 10px;
}

.brand {
    font-family: "Chargen", monospace;
    color: var(--accent);
    font-size: 1.6rem;
    letter-spacing: 0.15em;
    margin-right: auto;
}

.now-playing {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    background: rgba(255, 204, 0, 0.10);
    border: 1px solid rgba(255, 204, 0, 0.35);
    border-radius: 12px;
    padding: 6px 6px 6px 12px;
    font-size: 0.95rem;
}

.now-playing b { color: var(--accent); }

.launcher-tools {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.launcher-tools input[type="search"] { flex: 1; min-width: 0; }

.toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    color: var(--muted);
}

.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 10px;
    scrollbar-width: none;
}

.tab {
    border-radius: 999px;
    padding: 0.35em 1em;
    white-space: nowrap;
    color: var(--muted);
}

.tab[aria-pressed="true"] { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 700; }

.grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
}

.grid .empty { grid-column: 1 / -1; color: var(--muted); padding: 24px 0; max-width: 60ch; }

.tile {
    width: 100%;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.04);
    text-align: left;
    display: flex;
    flex-direction: column;
}

.tile:hover, .tile:focus-visible { border-color: var(--accent); }
.tile.current { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 204, 0, 0.35); }

.tile .art {
    position: relative;
    aspect-ratio: 3 / 4;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tile .art img { width: 100%; height: 100%; object-fit: contain; }

.tile .art.none {
    font-family: "Chargen", monospace;
    font-size: 3rem;
    color: rgba(255, 255, 255, 0.25);
    background: linear-gradient(160deg, #1d1d27, #0d0d12);
}

.tile .players {
    position: absolute;
    top: 6px;
    right: 6px;
    background: var(--accent);
    color: #111;
    font-weight: 800;
    font-size: 0.8rem;
    padding: 2px 7px;
    border-radius: 999px;
}

.tile .meta { padding: 8px 10px 10px; }
.tile .t { font-weight: 650; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .s { color: var(--muted); font-size: 0.8rem; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* session panel above the launcher */
#menu { z-index: 12; }
.session-art { float: right; width: 96px; max-height: 128px; object-fit: contain; margin: 0 0 8px 12px; border-radius: 8px; }

@media (max-width: 420px) {
    .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* join: what's playing */
.join-game { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.join-game img { width: 64px; max-height: 86px; object-fit: contain; border-radius: 6px; }
.join-title { font-weight: 700; font-size: 1.1rem; }



/* ---------- touch controller ----------
   All sizes derive from --u (1vmin at size M), so S/M/L scale everything. */

.pad {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 4;
    --u: 1vmin;
    --ctl-bg: rgba(0, 0, 0, 0.30);
    --ctl-edge: rgba(255, 255, 255, 0.55);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 6px rgba(0, 0, 0, 0.6);
}
.pad.size-s { --u: 0.85vmin; }
.pad.size-l { --u: 1.15vmin; }

.pad .btn, .pad .dpad, .pad .stick, .pad .float-zone, .pad button, .pad .pad-settings {
    pointer-events: auto;
    touch-action: none;
}

.pad .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ctl-bg);
    border: 2px solid var(--ctl-edge);
    color: #fff;
    font-weight: 800;
    font-size: calc(4 * var(--u));
    text-shadow: var(--shadow);
    user-select: none;
    -webkit-user-select: none;
}
.pad .btn.down { background: rgba(255, 255, 255, 0.5); transform: scale(0.94); }

.cluster {
    position: absolute;
    bottom: calc(5vh + var(--safe-b));
    display: flex;
    align-items: flex-end;
    gap: calc(3 * var(--u));
}
.cluster.left { left: calc(4vw + var(--safe-l)); }
.cluster.right { right: calc(4vw + var(--safe-r)); flex-direction: row-reverse; }

/* fixed cross D-pad */
.dpad { position: relative; width: calc(40 * var(--u)); height: calc(40 * var(--u)); }
.dpad-cross { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.dpad-cross path { fill: var(--ctl-bg); stroke: var(--ctl-edge); stroke-width: 2; vector-effect: non-scaling-stroke; }
.dpad .arrow {
    position: absolute; width: 0; height: 0;
    border: calc(2.6 * var(--u)) solid transparent;
    opacity: 0.75;
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.9));
}
.dpad .arrow.up { left: 50%; top: 8%; transform: translateX(-50%); border-bottom-color: #fff; border-top-width: 0; }
.dpad .arrow.down { left: 50%; bottom: 8%; transform: translateX(-50%); border-top-color: #fff; border-bottom-width: 0; }
.dpad .arrow.left { top: 50%; left: 8%; transform: translateY(-50%); border-right-color: #fff; border-left-width: 0; }
.dpad .arrow.right { top: 50%; right: 8%; transform: translateY(-50%); border-left-color: #fff; border-right-width: 0; }
.dpad[data-dirs~="up"] .arrow.up, .dpad[data-dirs~="down"] .arrow.down,
.dpad[data-dirs~="left"] .arrow.left, .dpad[data-dirs~="right"] .arrow.right { opacity: 1; border-color: transparent; }
.dpad[data-dirs~="up"] .arrow.up { border-bottom-color: var(--accent); }
.dpad[data-dirs~="down"] .arrow.down { border-top-color: var(--accent); }
.dpad[data-dirs~="left"] .arrow.left { border-right-color: var(--accent); }
.dpad[data-dirs~="right"] .arrow.right { border-left-color: var(--accent); }

/* floating stick: touch anywhere on the left side */
.float-zone {
    position: absolute;
    left: 0;
    top: 22%;
    bottom: 0;
    width: 46%;
}
.float-ghost, .float-stick {
    position: absolute;
    width: calc(30 * var(--u));
    height: calc(30 * var(--u));
    margin: calc(-15 * var(--u)) 0 0 calc(-15 * var(--u));
    border-radius: 50%;
    border: 2px solid var(--ctl-edge);
    background: radial-gradient(circle, rgba(0, 0, 0, 0.15) 0 40%, rgba(0, 0, 0, 0.35) 100%);
    pointer-events: none;
}
/* resting hint where the thumb usually goes */
.float-ghost { left: calc(19 * var(--u) + 4vw + var(--safe-l)); bottom: calc(5vh + var(--safe-b)); top: auto; margin-top: 0; margin-bottom: calc(0 * var(--u)); opacity: 0.55; }
.float-zone.touched .float-ghost { opacity: 0; }
.float-ghost-knob, .float-knob {
    position: absolute;
    left: 50%; top: 50%;
    width: calc(13 * var(--u)); height: calc(13 * var(--u));
    margin: calc(-6.5 * var(--u)) 0 0 calc(-6.5 * var(--u));
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.55);
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.6);
}
.float-stick { display: none; }
.float-stick.active { display: block; }
.float-stick[data-dirs]:not([data-dirs=""]) .float-knob { background: var(--accent); }

/* face buttons: diamond (X top, Y left, A right, B bottom), colored like a classic pad */
.face { position: relative; width: calc(44 * var(--u)); height: calc(44 * var(--u)); }
.facebtn { position: absolute; width: calc(16 * var(--u)); height: calc(16 * var(--u)); border-radius: 50%; }
.facebtn.top { left: 50%; top: 0; transform: translateX(-50%); }
.facebtn.bottom { left: 50%; bottom: 0; transform: translateX(-50%); }
.facebtn.left { top: 50%; left: 0; transform: translateY(-50%); }
.facebtn.right { top: 50%; right: 0; transform: translateY(-50%); }
.facebtn.top.down, .facebtn.bottom.down { transform: translateX(-50%) scale(0.94); }
.facebtn.left.down, .facebtn.right.down { transform: translateY(-50%) scale(0.94); }
.key-x { border-color: var(--btn-x) !important; background: rgba(62, 123, 250, 0.32) !important; }
.key-a { border-color: var(--btn-a) !important; background: rgba(229, 72, 77, 0.32) !important; }
.key-b { border-color: var(--btn-b) !important; background: rgba(245, 196, 0, 0.30) !important; }
.key-y { border-color: var(--btn-y) !important; background: rgba(48, 164, 108, 0.32) !important; }
.facebtn.down { filter: brightness(1.8); }

/* shoulders along the top edges */
.shoulders {
    position: absolute;
    top: calc(4vh + var(--safe-t));
    left: calc(4vw + var(--safe-l));
    right: calc(4vw + var(--safe-r));
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}
.shoulder-group { display: flex; gap: calc(2 * var(--u)); margin-top: calc(8 * var(--u)); }
.shoulder { width: calc(17 * var(--u)); height: calc(9 * var(--u)); border-radius: calc(3 * var(--u)); font-size: calc(3.4 * var(--u)); }

/* coin / start / admin hotkey */
.center {
    position: absolute;
    left: 50%;
    bottom: calc(3vh + var(--safe-b));
    transform: translateX(-50%);
    display: flex;
    gap: calc(2.5 * var(--u));
    align-items: center;
}
.center .pill { height: calc(8 * var(--u)); padding: 0 calc(3.5 * var(--u)); border-radius: 999px; font-size: calc(3 * var(--u)); }
.pad .pill-btn {
    height: calc(8 * var(--u)); min-width: calc(10 * var(--u)); border-radius: 999px;
    background: rgba(0, 0, 0, 0.55); border: 1px solid var(--accent); color: var(--accent);
    font-size: calc(3.4 * var(--u)); padding: 0 calc(2 * var(--u));
}

/* analog sticks (full layout or profile.sticks) */
.stick-wrap { display: flex; flex-direction: column; align-items: center; gap: calc(1.5 * var(--u)); }
.stick { position: relative; width: calc(26 * var(--u)); height: calc(26 * var(--u)); border-radius: 50%; background: var(--ctl-bg); border: 2px solid var(--ctl-edge); }
.stick .knob {
    position: absolute; left: 50%; top: 50%;
    width: calc(11 * var(--u)); height: calc(11 * var(--u));
    margin: calc(-5.5 * var(--u)) 0 0 calc(-5.5 * var(--u));
    border-radius: 50%; background: rgba(255, 255, 255, 0.5); pointer-events: none;
}
.small-btn { width: calc(10 * var(--u)); height: calc(6 * var(--u)); border-radius: calc(2 * var(--u)); font-size: calc(2.6 * var(--u)); }
.pad.full .dpad { width: calc(32 * var(--u)); height: calc(32 * var(--u)); }
.pad.full .face { width: calc(36 * var(--u)); height: calc(36 * var(--u)); }
.pad.full .facebtn { width: calc(13 * var(--u)); height: calc(13 * var(--u)); }
.pad.full .float-zone { width: 30%; }

/* per-player settings */
.pad-settings {
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: min(420px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px 16px 16px;
    z-index: 15;
    touch-action: auto;
}
.set-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.set-head h2 { margin: 0; font-size: 1.1rem; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.set-title { color: var(--muted); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg-btn { border: 0; border-radius: 0; padding: 0.45em 0.9em; background: transparent; }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: #111; font-weight: 700; }

/* whole page locked while playing (no scroll / zoom gestures) */
html.playing, html.playing body { touch-action: none; overflow: hidden; overscroll-behavior: none; }
html.playing .launcher, html.playing .sheet, html.playing .pad-settings { touch-action: pan-y; }

/* "turn your phone sideways" */
.rotate-hint { display: none; }
@media (orientation: portrait) {
    html.playing body:not(.portrait-ok) .rotate-hint {
        display: flex; position: fixed; inset: 0; z-index: 30;
        flex-direction: column; align-items: center; justify-content: center; gap: 16px;
        background: var(--bg); text-align: center; padding: 24px;
    }
    .rotate-phone {
        width: 60px; height: 100px; border: 4px solid var(--accent); border-radius: 12px;
        animation: rotate-phone 2s ease-in-out infinite;
    }
    @keyframes rotate-phone { 0%, 20% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }

    /* portrait layout: video on top, controls under it */
    .stage { bottom: auto; height: 46dvh; top: var(--safe-t); }
    .pad { --u: 1.05vw; }
    .pad.size-s { --u: 0.9vw; }
    .pad.size-l { --u: 1.2vw; }
    .shoulders { top: calc(47dvh + var(--safe-t)); }
    .shoulder-group { margin-top: 0; }
    .cluster { bottom: calc(14vh + var(--safe-b)); }
    .float-zone { top: 50%; width: 50%; }
    /* sound button: bottom edge of the video, clear of the corner buttons */
    .chip.sound { top: calc(46dvh - 44px + var(--safe-t)); }
}

/* iPhone tip */
.a2hs { color: var(--muted); font-size: 0.9rem; max-width: 34ch; margin: 0; }
.a2hs b { color: var(--text); }
button.link { border: 0; background: none; color: var(--accent); padding: 0 0.3em; text-decoration: underline; }
