/* =================== FOF PAGE =================== */
/* Intro, blurred Matrix backdrop, spies, screen blast and the game panel. */

:root {
    color-scheme: dark;

    --green:        #20ff70;
    --green-soft:   #b9ffd0;
    --green-line:   rgba(32, 255, 112, 0.5);
    --green-glow:   rgba(32, 255, 112, 0.1);
    --bg:           #030605;

    /* Tokens used by tictaktiker.css */
    --orange:       #e8610a;
    --orange-light: #ff8c42;
    --orange-dim:   #9b3f05;
    --black:        #050505;
    --dark:         #101010;
    --dark3:        #242424;
    --mid:          #333333;
    --grey:         #858585;
    --off-white:    #e8e0d5;
    --white:        #f5f0e8;
    --font-mono:    ui-monospace, 'IBM Plex Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
}

body {
    touch-action: manipulation;   /* double tap = start, not zoom */
    color: var(--off-white);
    font-family: var(--font-mono);
}

/* =================== BACKDROP =================== */

/* Low-res canvas upscaled by the browser = soft look without a blur filter.
   Sits behind the spies, so no blend mode is needed. */
#rain {
    position: fixed;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    opacity: 0.4;
    pointer-events: none;
}

.vignette {
    position: fixed;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    background: radial-gradient(ellipse, transparent 16%, rgba(0, 0, 0, 0.53) 100%);
}

/* =================== INTRO =================== */

.intro {
    position: fixed;
    inset: 0;
    z-index: 4;
    display: grid;
    place-items: center;
    pointer-events: none;
    transition: opacity 0.35s;
}

.intro.gone { opacity: 0; }

#intro-copy {
    color: var(--green);
    text-align: center;
    letter-spacing: 0.18em;
    text-shadow: 0 0 10px var(--green), 0 0 30px var(--green);
}

#intro-copy strong {
    display: block;
    font-size: clamp(3rem, 12vw, 8rem);
    line-height: 1;
}

#intro-copy small {
    display: block;
    margin-top: 1rem;
    font-size: clamp(0.65rem, 2vw, 0.95rem);
}

.intro.shake #intro-copy { animation: shake 0.45s ease-out; }

/* =================== SPIES + BLAST =================== */

.spies {
    position: fixed;
    z-index: 1;
    top: 50%;
    left: 50%;
    width: min(78vw, 1050px);
    max-height: 78vh;
    object-fit: contain;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
    transition: opacity 0.9s, transform 1s cubic-bezier(0.16, 0.8, 0.3, 1);
    pointer-events: none;
}

.spies.visible   { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* Clickable while waiting for the double click */
.spies.armed {
    pointer-events: auto;
    cursor: pointer;
    touch-action: manipulation;   /* no double-tap zoom on mobile */
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
}

/* Double click: fall out of the screen (duration = T_DROP in fof.js) */
.spies.dropping {
    transform: translate(-50%, 100vh) rotate(8deg);
    transition: transform 0.9s cubic-bezier(0.55, 0, 0.9, 0.45);
}

/* Double click with 'drop-explode': fall to the bottom edge (--fall-y set by fof.js, duration = T_FALL) */
.spies.falling {
    transform: translate(-50%, calc(-50% + var(--fall-y, 30vh)));
    transition: transform 0.65s cubic-bezier(0.55, 0, 1, 0.45);
}

/* Fragments cover the image during the explosion: hide the original at once */
.spies.exploding { opacity: 0; transition: none; }
.spies.no-anim   { transition: none; }

.blast {
    position: fixed;
    inset: 0;
    z-index: 5;
    opacity: 0;
    pointer-events: none;
    /* --bx / --by: flash centre, set by fof.js (screen centre or the exploding spies) */
    background: radial-gradient(circle at var(--bx, 50%) var(--by, 50%),
        #fff 0, #caffdb 3%, var(--green) 9%, #b5ffc9 14%, transparent 34%);
}

.blast.fire { animation: blast 0.95s ease-out both; }

.fragment-layer {
    position: fixed;
    inset: 0;
    z-index: 6;
    pointer-events: none;
}

/* Tiles are divs with a slice of spies.png as background (set by fof.js) */
.spy-fragment {
    position: fixed;
    display: block;
    opacity: 1;
    background-repeat: no-repeat;
    transition: transform 1.4s cubic-bezier(0.2, 0.65, 0.3, 1), opacity 1.4s cubic-bezier(0.6, 0, 0.9, 0.6);
    will-change: transform, opacity;
}

/* --dx / --dy / --turn are set per fragment by fof.js; opacity eases in late so shards stay visible */
.fragment-layer.burst .spy-fragment {
    opacity: 0;
    transform: translate3d(var(--dx), var(--dy), 0) rotate(var(--turn)) scale(0.35);
}

/* =================== GAME PANEL =================== */

.game-panel {
    position: fixed;
    z-index: 4;
    top: 50%;
    left: 50%;
    display: flex;
    flex-direction: column;
    width: 80vw;
    height: 80vh;
    padding: clamp(1rem, 2.5vw, 2.5rem);
    overflow: hidden;
    background: rgba(0, 0, 0, 0.97);
    border: 1px solid var(--green-line);
    box-shadow: 0 0 45px #000, 0 0 28px var(--green-glow);
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, -48%) scale(0.97);
    transition: opacity 0.8s, transform 0.8s, visibility 0.8s;
}

.game-panel.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.panel-heading {
    flex: 0 0 auto;
    text-align: center;
}

.section-label {
    color: var(--green);
    font-size: 0.75rem;
    letter-spacing: 0.22em;
}

.panel-heading h1 {
    margin: 0.35rem 0;
    font-size: clamp(1.3rem, 3.5vh, 2.4rem);
    letter-spacing: 0.1em;
}

.panel-heading p {
    margin: 0.25rem 0 0.8rem;
    color: var(--grey);
    font-size: clamp(0.65rem, 1.5vh, 0.85rem);
}

/* Board fills the space left between status and controls, always square. */
.game-panel .tt-game  { flex: 1; min-height: 0; width: 100%; }
.game-panel .tt-stage { flex: 1; min-height: 0; container-type: size; padding: 0.5rem 0; }
.game-panel .tt-board { width: min(100cqw, 100cqh); max-width: none; }

/* Pieces, style chosen by PIECE_STYLE in fof.js (class .pieces-<style> on #tictaktiker) */

/* spies: heads cut from spies.png (1493x1053) as CSS sprite.
   size = 1493 / crop * 100%, pos = crop offset / (image - crop) * 100% */
.pieces-spies .tt-piece        { background-image: url('../assets/spies.png'); }
.pieces-spies .tt-p0 .tt-piece { background-size: 403.5%; background-position: 34.73% 8.78%; }  /* white: 390,60 / 370px */
.pieces-spies .tt-p1 .tt-piece { background-size: 398.1%; background-position: 76.92% 0%; }     /* black: 860,0 / 375px */

/* White spy: red glow behind the piece, tells it apart from the black one at a glance */
.pieces-spies .tt-cell.tt-p0 {
    background: radial-gradient(circle, rgba(225, 20, 25, 0.75) 0%, rgba(150, 0, 10, 0.4) 50%, var(--dark) 78%);
}
.pieces-spies .tt-turn.tt-p0 { color: #ff4b4b; }
.pieces-spies .tt-turn.tt-p1 { color: var(--grey); }

/* bombs: own SVGs */
.pieces-bombs .tt-piece        { background-size: contain; background-position: center; }
.pieces-bombs .tt-p0 .tt-piece { background-image: url('../assets/dynamite.svg'); }
.pieces-bombs .tt-p1 .tt-piece { background-image: url('../assets/bomb.svg'); }
.pieces-bombs .tt-turn.tt-p0   { color: #ff4b4b; }
.pieces-bombs .tt-turn.tt-p1   { color: var(--white); }

/* =================== HISCORE =================== */
/* Covers the game panel: name entry after a win, list as pause screen (fof.js HiscoreBoard) */

.hiscore {
    position: absolute;
    inset: 0;
    z-index: 30;                  /* above the game menu (20) */
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.97);   /* opaque enough to hide the game over overlay */
    animation: hs-in 0.4s ease-out both;
}

.hiscore[hidden] { display: none; }
.hiscore.hs-pause { cursor: pointer; }

.hs-box {
    width: min(100%, 560px);
    max-height: 100%;
    overflow: auto;
    text-align: center;
}

.hs-result {
    margin: 0.8rem 0;
    color: var(--orange-light);
    font-size: clamp(0.75rem, 1.8vh, 1rem);
    letter-spacing: 0.08em;
}

.hs-label {
    display: block;
    margin-bottom: 0.4rem;
    color: var(--grey);
    font-size: 0.8rem;
}

#hs-name {
    width: min(100%, 18rem);
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--orange);
    background: var(--dark);
    color: var(--white);
    font: inherit;
    font-size: 1rem;
    letter-spacing: 0.1em;
    text-align: center;
    text-transform: uppercase;
}

#hs-name:focus { outline: 1px solid var(--orange-light); }

.hs-buttons {
    display: flex;
    justify-content: center;
    gap: 0.8rem;
    margin: 0.9rem 0 1.2rem;
}

.hs-buttons button {
    padding: 0.5rem 1rem;
    border: 1px solid var(--orange);
    background: transparent;
    color: var(--orange);
    font: inherit;
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    cursor: pointer;
}

.hs-buttons .hs-save,
.hs-buttons button:hover,
.hs-buttons button:focus-visible { background: var(--orange); color: var(--black); outline: none; }

.hs-table {
    width: 100%;
    margin-top: 0.8rem;
    border-collapse: collapse;
    font-size: clamp(0.72rem, 1.7vh, 0.95rem);
}

.hs-table th {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--green-line);
    color: var(--green);
    font-weight: 400;
    letter-spacing: 0.12em;
}

.hs-table td {
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid var(--mid);
}

.hs-table th:nth-child(2) { text-align: left; }
.hs-table td:nth-child(2) { text-align: left; text-transform: uppercase; }
.hs-table tr:first-child td { color: var(--orange-light); }
.hs-table tr.hs-new td { background: rgba(232, 97, 10, 0.2); color: var(--white); }

.hs-empty,
.hs-hint {
    margin-top: 1rem;
    color: var(--grey);
    font-size: 0.75rem;
}

.hs-entry:not([hidden]) ~ .hs-hint { display: none; }   /* no "click to continue" during entry */

@keyframes hs-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* =================== MULTIPLAYER =================== */
/* Corner: players online, online status, "never" undo icon. Ask box and toast (fof.js MultiplayerClient) */

.mp-corner {
    position: fixed;
    z-index: 10;
    left: 1rem;
    bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--green-line);
    border-radius: 3px;
    background: rgba(3, 6, 5, 0.8);
    color: var(--green-soft);
    font-size: 0.72rem;
    letter-spacing: 0.06em;
}

.mp-corner[hidden] { display: none; }
.mp-dot { color: var(--green); font-size: 0.6rem; }
.mp-status:empty { display: none; }
.mp-status { color: var(--orange-light); }

/* "Never" chosen: crossed-out swap icon, click to allow multiplayer again */
.mp-never {
    padding: 0 0.3rem;
    border: 0;
    background: none;
    color: var(--grey);
    font: inherit;
    font-size: 0.9rem;
    text-decoration: line-through;
    cursor: pointer;
}

.mp-never:hover,
.mp-never:focus-visible { color: var(--green); outline: none; }

.mp-ask,
.mp-toast {
    position: fixed;
    z-index: 40;                 /* above the game panel and hiscore */
    left: 50%;
    top: 1rem;
    transform: translateX(-50%);
    max-width: min(92vw, 460px);
    padding: 0.8rem 1.1rem;
    border: 1px solid var(--orange);
    background: rgba(5, 5, 5, 0.96);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.7);
    text-align: center;
    font-size: 0.85rem;
    animation: mp-in 0.35s ease-out both;
}

.mp-ask[hidden],
.mp-toast[hidden] { display: none; }
.mp-ask p { margin: 0 0 0.7rem; }

.mp-buttons { display: flex; justify-content: center; gap: 0.8rem; }

.mp-buttons button {
    padding: 0.45rem 1.2rem;
    border: 1px solid var(--orange);
    background: transparent;
    color: var(--orange);
    font: inherit;
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    cursor: pointer;
}

.mp-buttons .mp-yes,
.mp-buttons button:hover,
.mp-buttons button:focus-visible { background: var(--orange); color: var(--black); outline: none; }

.mp-toast { border-color: var(--green-line); color: var(--green-soft); }

@keyframes mp-in {
    from { opacity: 0; transform: translate(-50%, -8px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Login dialog reuses the ask box look; logged-in name in the corner (click = log out) */
#mp-name {
    width: min(100%, 16rem);
    margin-bottom: 0.7rem;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--orange);
    background: var(--dark);
    color: var(--white);
    font: inherit;
    letter-spacing: 0.08em;
    text-align: center;
}

.mp-error,
.hs-error { margin: 0 0 0.7rem; color: #ff6b6b; font-size: 0.78rem; }

.mp-me {
    padding: 0 0.2rem;
    border: 0;
    background: none;
    color: var(--white);
    font: inherit;
    cursor: pointer;
}

.mp-me:hover,
.mp-me:focus-visible { color: var(--orange-light); text-decoration: line-through; outline: none; }

/* Online wait bar above the board */
.mp-wait {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.8rem;
    min-height: 1.9rem;
    margin-bottom: 0.3rem;
    color: var(--green-soft);
    font-size: clamp(0.68rem, 1.5vh, 0.85rem);
    letter-spacing: 0.06em;
}

.mp-wait[hidden] { display: none; }
.mp-wait.mp-my-turn { color: var(--orange-light); }
.mp-wait.mp-gone    { color: #ff6b6b; }

.mp-nudge,
.mp-panel-actions button,
.mp-chat-form button {
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--orange);
    background: transparent;
    color: var(--orange);
    font: inherit;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    cursor: pointer;
}

.mp-nudge:hover, .mp-nudge:focus-visible,
.mp-panel-actions button:hover, .mp-panel-actions button:focus-visible,
.mp-chat-form button:hover, .mp-chat-form button:focus-visible { background: var(--orange); color: var(--black); outline: none; }

.mp-nudge:disabled { opacity: 0.4; cursor: default; background: transparent; color: var(--orange); }

.mp-accept-wait { color: var(--grey); font-size: 0.78rem; }

/* Network panel */
.mp-panel {
    position: fixed;
    z-index: 45;
    right: 1rem;
    top: 1rem;
    width: min(92vw, 360px);
    max-height: calc(100vh - 6rem);
    overflow: auto;
    padding: 0.9rem 1rem;
    border: 1px solid var(--green-line);
    background: rgba(3, 6, 5, 0.97);
    box-shadow: 0 0 30px #000;
    font-size: 0.8rem;
}

.mp-panel[hidden] { display: none; }
.mp-panel-head { display: flex; justify-content: space-between; align-items: center; }
.mp-close { border: 0; background: none; color: var(--grey); font: inherit; cursor: pointer; }
.mp-close:hover { color: var(--white); }
.mp-panel-status { margin: 0.7rem 0 0.3rem; }
.mp-panel-names { margin: 0 0 0.7rem; color: var(--grey); }
.mp-panel-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.mp-panel-actions button[hidden] { display: none; }

.mp-chat { margin-top: 0.9rem; border-top: 1px solid var(--mid); padding-top: 0.7rem; }
.mp-chat[hidden] { display: none; }

.mp-chat-log {
    max-height: 12rem;
    overflow-y: auto;
    margin-bottom: 0.5rem;
    line-height: 1.45;
}

.mp-chat-log .mp-me-msg { color: var(--orange-light); }
.mp-chat-log .mp-sys-msg { color: var(--grey); font-style: italic; }
.mp-chat-form { display: flex; gap: 0.4rem; }

.mp-chat-input {
    flex: 1;
    min-width: 0;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--mid);
    background: var(--dark);
    color: var(--white);
    font: inherit;
}

.mp-chat-input:focus { outline: 1px solid var(--orange); }

/* =================== STORAGE NOTICE =================== */

.consent {
    position: fixed;
    z-index: 50;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    width: min(94vw, 620px);
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--green-line);
    background: rgba(3, 6, 5, 0.97);
    box-shadow: 0 0 30px #000;
    font-size: 0.8rem;
    line-height: 1.5;
}

.consent[hidden] { display: none; }
.consent p { margin: 0 0 0.7rem; }
.consent-buttons { display: flex; justify-content: flex-end; gap: 0.7rem; }

.consent-buttons button {
    padding: 0.4rem 1rem;
    border: 1px solid var(--green-line);
    background: transparent;
    color: var(--green-soft);
    font: inherit;
    cursor: pointer;
}

.consent-buttons .consent-ok,
.consent-buttons button:hover,
.consent-buttons button:focus-visible { background: var(--green); color: var(--black); outline: none; }

.sound-toggle {
    position: fixed;
    z-index: 10;
    right: 7.2rem;
    bottom: 1rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--green-line);
    border-radius: 3px;
    background: rgba(3, 6, 5, 0.8);
    color: var(--green-soft);
    font: inherit;
    font-size: 0.72rem;
    cursor: pointer;
}

.sound-toggle.sound-off { color: var(--grey); }
.sound-toggle:hover,
.sound-toggle:focus-visible { outline: 1px solid var(--green); }

.sound-ask { top: auto; bottom: 4.5rem; }        /* bottom, so it never covers the multiplayer question */

/* =================== REPLAY =================== */

.replay {
    position: fixed;
    z-index: 10;
    right: 1rem;
    bottom: 1rem;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--green-line);
    border-radius: 3px;
    background: rgba(3, 6, 5, 0.8);
    color: var(--green-soft);
    font: inherit;
    font-size: 0.72rem;
    cursor: pointer;
    opacity: 0.78;
}

.replay:hover,
.replay:focus-visible {
    opacity: 1;
    outline: 1px solid var(--green);
}

/* =================== ANIMATIONS =================== */

@keyframes blast {
    0%   { opacity: 0; }
    10%  { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes shake {
    0%, 100% { transform: translate(0); }
    20%      { transform: translate(-8px, 3px); }
    45%      { transform: translate(7px, -4px); }
    70%      { transform: translate(-3px, 2px); }
}

@media (max-width: 700px) {
    .game-panel { width: 92vw; padding: 1rem; }   /* keep 80vh: leaves room for Replay */
    .spies      { width: 94vw; }
}

@media (prefers-reduced-motion: reduce) {
    .spy-fragment { transition-duration: 0.15s; }
}
