/* FluxMerge — full portal revamp (accent #9A5CFF).
   Dice are solid value-coloured tiles (cold → hot ramp) so board state reads
   at a glance; the Next Block preview is sized for both orientations.
   Background matches the wrapper's .board gradient for a seamless iframe. */
:root {
    --accent: #9A5CFF;
    --accent-ink: #1C0E38;
    --green: #2BD67B;
    --red: #FF4D5E;
    --amber: #FFB23D;
    --text-primary: #F4F5F7;
    --text-muted: #9097A3;
    --text-faint: #7E8595;
    --panel-grad: linear-gradient(180deg, #181B23, #131519);
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.15);
    --font-disp: 'Bricolage Grotesque', 'Space Grotesk', sans-serif;
    --font-body: 'Inter', system-ui, sans-serif;
    --font-mono: 'Space Mono', monospace;

    /* dice value colours — cold (low) → hot (high) */
    --dice-1: #6FB7FF;
    --dice-2: #4FD6C4;
    --dice-3: #2BD67B;
    --dice-4: #FFD84D;
    --dice-5: #FF8A3D;
    --dice-6: #FF4D5E;
}

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-user-select: none; }

body {
    background:
        radial-gradient(80% 90% at 50% 18%, rgba(154, 92, 255, 0.13), rgba(0, 0, 0, 0) 70%),
        linear-gradient(180deg, #15171F, #101218);
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---------- header (standalone only) ---------- */
header { text-align: center; padding: 1.4rem 1rem 0.4rem; }
.logo {
    font-family: var(--font-disp);
    font-size: 2.6rem; font-weight: 800; letter-spacing: -0.02em;
    color: var(--text-primary); display: inline-block;
}
.logo-dot { color: var(--accent); }
.tagline {
    font-family: var(--font-mono);
    font-size: 0.72rem; color: var(--text-faint);
    letter-spacing: 0.22em; text-transform: uppercase; margin-top: 0.15rem;
}

/* ---------- layout ---------- */
.game-container {
    max-width: 1020px; width: 100%; margin: 0 auto; padding: 1rem;
    display: flex; justify-content: center; align-items: flex-start;
    gap: 1.25rem; flex-grow: 1;
}
.side-panel { display: flex; flex-direction: column; gap: 1rem; width: 200px; flex-shrink: 0; }

.panel-card {
    background: var(--panel-grad);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 1.1rem 1.2rem;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 14px 32px rgba(0, 0, 0, 0.38);
    text-align: center;
}
.panel-card h2 {
    font-family: var(--font-mono);
    font-size: 0.66rem; color: var(--text-faint);
    letter-spacing: 0.2em; text-transform: uppercase; margin-bottom: 0.55rem;
}
.panel-card h2.stat-gap { margin-top: 1.05rem; }
.stat-value { font-family: var(--font-mono); font-size: 1.8rem; font-weight: 700; color: var(--text-primary); }
.stat-value.stat-sub { font-size: 1.2rem; color: var(--accent); }

.progress-bar-container {
    width: 100%; height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px; margin-top: 0.7rem; overflow: hidden;
}
.progress-bar {
    width: 0%; height: 100%;
    background: linear-gradient(90deg, var(--accent), #54A9FF);
    border-radius: 3px; transition: width 0.1s linear;
}

/* ---------- board ---------- */
.board-wrapper {
    position: relative;
    border-radius: 18px;
    background: linear-gradient(180deg, #14161E, #0F1116);
    border: 1px solid rgba(154, 92, 255, 0.24);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), inset 0 0 60px rgba(154, 92, 255, 0.05), 0 22px 48px rgba(0, 0, 0, 0.45);
    padding: 10px;
    width: min(440px, 94vw);
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
}
.grid-board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 7px;
    width: 100%; height: 100%;
}
.cell {
    position: relative;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

/* placement affordances */
.cell.placement-possible {
    border-color: rgba(154, 92, 255, 0.45);
    border-style: dashed;
    background: rgba(154, 92, 255, 0.06);
}
.cell.ghost-hover {
    background: rgba(154, 92, 255, 0.14);
    border-color: var(--accent);
    border-style: solid;
    box-shadow: inset 0 0 14px rgba(154, 92, 255, 0.2);
}
.cell.ghost-invalid {
    background: rgba(255, 77, 94, 0.12);
    border-color: rgba(255, 77, 94, 0.65);
}

/* ---------- dice tiles ---------- */
.dice {
    width: 100%; height: 100%;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-mono);
    font-size: clamp(1.2rem, 4.6vw, 1.9rem);
    font-weight: 700;
    color: rgba(12, 16, 24, 0.9);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.18), 0 3px 8px rgba(0, 0, 0, 0.35);
}
.dice-1 { background: var(--dice-1); }
.dice-2 { background: var(--dice-2); }
.dice-3 { background: var(--dice-3); }
.dice-4 { background: var(--dice-4); }
.dice-5 { background: var(--dice-5); }
.dice-6 { background: var(--dice-6); box-shadow: inset 0 2px 0 rgba(255,255,255,0.35), inset 0 -3px 0 rgba(0,0,0,0.18), 0 0 16px rgba(255, 77, 94, 0.45); }

.dice-flux {
    background: linear-gradient(135deg, #9A5CFF, #54A9FF, #2BD67B, #FFB23D, #9A5CFF);
    background-size: 300% 300%;
    animation: fluxShift 3s linear infinite;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3), 0 0 18px rgba(154, 92, 255, 0.55);
}
@keyframes fluxShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ghost preview of a pending placement */
.ghost-dice-preview { opacity: 0.45; box-shadow: none; }

/* merge animations */
.cell.merge-out .dice { animation: mergeOut 0.38s ease forwards; }
@keyframes mergeOut {
    to { transform: scale(0.1); opacity: 0; }
}
.cell.merge-in .dice { animation: mergeIn 0.38s cubic-bezier(0.175, 0.885, 0.32, 1.4); }
@keyframes mergeIn {
    0% { transform: scale(0.6); }
    55% { transform: scale(1.18); }
    100% { transform: scale(1); }
}
.cell.blast-shockwave {
    background: rgba(154, 92, 255, 0.22);
    border-color: var(--accent);
    box-shadow: inset 0 0 22px rgba(154, 92, 255, 0.45);
}

/* ---------- next-block preview ---------- */
.preview-area {
    min-height: 128px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.28);
    border: 1px dashed rgba(255, 255, 255, 0.12);
    border-radius: 13px;
    margin-bottom: 0.65rem;
    cursor: grab;
    transition: border-color 0.15s, background 0.15s;
    padding: 10px;
}
.preview-area:active { cursor: grabbing; }
.preview-area:hover { border-color: rgba(154, 92, 255, 0.5); }

.preview-block-container { display: flex; gap: 6px; }
.preview-block-container.block-vertical { flex-direction: column; }
.preview-block-container .dice {
    width: 48px; height: 48px;
    font-size: 1.35rem;
    flex: none;
}
.preview-block-container.active-select .dice {
    outline: 2px solid var(--amber);
    outline-offset: 2px;
    animation: selectPulse 1.1s ease-in-out infinite;
}
@keyframes selectPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}
.preview-hint {
    font-size: 0.72rem; color: var(--text-faint);
    line-height: 1.4; margin-bottom: 0.7rem;
}

/* floating drag clone */
.drag-element {
    position: fixed;
    pointer-events: none;
    z-index: 100;
    display: flex; gap: 6px;
    filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.5));
}
.drag-element.block-vertical { flex-direction: column; }
.drag-element .dice { width: 54px; height: 54px; font-size: 1.5rem; flex: none; }

/* ---------- buttons ---------- */
.btn-primary {
    background: var(--accent);
    border: none; color: #fff;
    font-family: var(--font-body); font-size: 0.95rem; font-weight: 700;
    padding: 0.7rem 2.1rem; border-radius: 12px; cursor: pointer;
    box-shadow: 0 6px 22px rgba(154, 92, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transition: transform 0.16s, filter 0.16s;
}
.btn-primary:hover { transform: translateY(-2px); filter: brightness(1.1); }
.btn-primary:active { transform: translateY(0); }

.btn-action {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
    color: #C7CCD5;
    font-family: var(--font-body); font-size: 0.82rem; font-weight: 600;
    padding: 0.65rem 1rem; border-radius: 11px; cursor: pointer;
    transition: all 0.18s ease;
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.btn-action + .btn-action { margin-top: 0.6rem; }
.btn-action:hover { background: rgba(255, 255, 255, 0.08); color: #EDEFF2; border-color: var(--line-strong); }
.btn-action-warn:hover { border-color: rgba(255, 138, 61, 0.5); color: var(--amber); }
.action-icon { font-size: 0.95rem; }

/* ---------- overlays ---------- */
.overlay-screen {
    position: absolute; inset: 0;
    background: rgba(11, 13, 17, 0.82);
    backdrop-filter: blur(9px); -webkit-backdrop-filter: blur(9px);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    z-index: 10; opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 1.4rem; text-align: center; border-radius: 17px;
    overflow-y: auto;
}
.overlay-screen.active { opacity: 1; pointer-events: auto; }

.eyebrow {
    font-family: var(--font-mono); font-size: 10px;
    letter-spacing: 0.22em; text-transform: uppercase;
    color: var(--accent); margin-bottom: 9px;
}
.eyebrow-danger { color: var(--red); }
.overlay-title {
    font-family: var(--font-disp);
    font-size: 2.1rem; font-weight: 800; letter-spacing: -0.02em;
    color: var(--text-primary); margin-bottom: 0.7rem; line-height: 1.05;
}
.overlay-copy {
    color: var(--text-muted); margin-bottom: 1rem;
    max-width: 300px; line-height: 1.5; font-size: 0.88rem;
}
.overlay-copy strong { color: var(--accent); }

.legend {
    display: flex; flex-direction: column; gap: 7px;
    margin: 0 auto 1.1rem; text-align: left;
}
.lg { display: flex; align-items: center; gap: 9px; font-size: 0.8rem; color: var(--text-muted); }
.lg b { color: var(--text-primary); }
.sw { width: 11px; height: 11px; border-radius: 3.5px; flex: none; box-shadow: 0 0 8px rgba(255, 255, 255, 0.15); }
.sw-flux {
    background: linear-gradient(135deg, #9A5CFF, #54A9FF, #2BD67B);
    box-shadow: 0 0 8px rgba(154, 92, 255, 0.6);
}

.overlay-stats {
    margin-bottom: 1.1rem; font-size: 0.92rem; color: var(--text-muted);
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px; padding: 0.85rem 1.6rem;
    display: flex; flex-direction: column; gap: 0.4rem;
}
.overlay-stats span {
    color: var(--text-primary); font-weight: 700;
    font-family: var(--font-mono); margin-left: 0.4rem;
}

/* ---------- toggle ---------- */
.settings-wrap { width: 100%; max-width: 200px; margin: 0 auto 1.2rem; }
.settings-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; color: var(--text-muted); }
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 22px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; inset: 0;
    background-color: #23262F; transition: 0.3s;
    border-radius: 22px; border: 1px solid rgba(255, 255, 255, 0.07);
}
.slider:before {
    position: absolute; content: "";
    height: 14px; width: 14px; left: 3px; bottom: 3px;
    background-color: #8B92A0; transition: 0.3s; border-radius: 50%;
}
input:checked + .slider { background-color: rgba(154, 92, 255, 0.25); border-color: rgba(154, 92, 255, 0.55); }
input:checked + .slider:before { transform: translateX(22px); background-color: var(--accent); }

/* ---------- help + footer ---------- */
.instructions-panel {
    max-width: 1020px; margin: 1.25rem auto; padding: 0 1rem;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem; width: 100%;
}
.instruction-group {
    background: var(--panel-grad);
    border: 1px solid var(--line);
    border-radius: 14px; padding: 1.1rem 1.25rem;
}
.instruction-group h3 {
    font-family: var(--font-mono); font-size: 0.66rem;
    letter-spacing: 0.2em; color: var(--accent);
    margin-bottom: 0.7rem; text-transform: uppercase;
}
.key-list { list-style: none; font-size: 0.82rem; color: var(--text-muted); }
.key-list li {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 0.38rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    line-height: 1.4;
}
.key-list li:last-child { border: none; }
.key-list span:last-child { color: var(--text-primary); font-weight: 500; text-align: right; }

footer {
    text-align: center; padding: 1.25rem;
    color: var(--text-faint); font-size: 0.78rem;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    margin-top: auto;
}
footer a { color: var(--accent); text-decoration: none; }

/* ---------- responsive ----------
   Phones get a single-screen layout: slim score strip, board, and a bottom
   dock holding the Next block — dragging never requires scrolling. */
@media (max-width: 860px) {
    html, body { height: 100%; }
    body { display: flex; flex-direction: column; overflow: hidden; }
    header { padding: 0.5rem 1rem 0.1rem; }
    .logo { font-size: 1.4rem; }
    .tagline, .instructions-panel, footer { display: none; }

    .game-container {
        flex: 1; min-height: 0;
        flex-direction: column; flex-wrap: nowrap; align-items: center;
        gap: 0.55rem; padding: 0.55rem; overflow: hidden;
    }

    /* score + combo as one slim strip */
    #left-side-panel {
        order: 0; width: 100%; min-width: 0;
        display: flex; flex-direction: row; gap: 0.55rem;
    }
    #left-side-panel .panel-card {
        flex: 1; min-width: 0; padding: 0.5rem 0.75rem;
        display: flex; align-items: center; gap: 0.6rem;
    }
    #left-side-panel h2 { margin: 0; white-space: nowrap; }
    #card-score .stat-gap { margin-top: 0; }
    .stat-value { font-size: 1.05rem; }
    .stat-value.stat-sub { font-size: 0.95rem; }
    .progress-bar-container { flex: 1; min-width: 36px; }

    /* board shrinks to whatever height the strip + dock leave over */
    .board-wrapper {
        order: 1;
        width: min(94vw, calc(100dvh - 205px));
        margin: 0 auto;
    }
    .embedded .board-wrapper { width: min(94vw, calc(100dvh - 160px)); }

    /* bottom dock: next block + rotate + actions, always on screen */
    #right-side-panel {
        order: 2; width: 100%;
        display: flex; flex-direction: row; gap: 0.55rem; align-items: stretch;
    }
    #card-preview {
        flex: 2.2; min-width: 0;
        display: flex; align-items: center; gap: 0.55rem; padding: 0.45rem 0.6rem;
    }
    #card-preview h2, .preview-hint { display: none; }
    /* vertical NEXT tag so the dock reads like a player control */
    #card-preview::before {
        content: 'NEXT';
        font-family: 'Space Mono', monospace;
        font-size: 0.55rem; letter-spacing: 0.22em; color: var(--text-faint);
        writing-mode: vertical-rl; transform: rotate(180deg);
        flex-shrink: 0;
    }
    .preview-area {
        min-height: 0; flex: 1; margin: 0; padding: 0.4rem;
        display: flex; align-items: center; justify-content: center;
    }
    .preview-block-container .dice { width: 44px; height: 44px; font-size: 1.2rem; }
    .preview-block-container.block-vertical .dice { width: 34px; height: 34px; font-size: 1rem; }
    /* icon-only round buttons in the dock (font-size:0 hides text nodes) */
    #card-preview .btn-action, #card-actions .btn-action {
        width: 46px; height: 46px; min-width: 46px; margin: 0; padding: 0;
        border-radius: 13px; font-size: 0;
        display: grid; place-items: center; align-self: center;
    }
    #card-preview .btn-action .action-icon, #card-actions .btn-action .action-icon { font-size: 1.15rem; }
    #card-actions {
        flex: none; min-width: 0;
        display: flex; flex-direction: row; align-items: center; gap: 0.5rem; padding: 0.45rem 0.6rem;
    }
    #card-actions h2 { display: none; }
}

@media (max-height: 720px) and (min-width: 861px) {
    header { padding: 0.7rem 1rem 0.2rem; }
    .logo { font-size: 1.8rem; }
    .tagline { display: none; }
}

/* Embedded in the Skorven game player (iframe): hide standalone chrome */
.embedded header,
.embedded footer,
.embedded .instructions-panel { display: none !important; }
.embedded .game-container { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.embedded body { background-attachment: scroll; }
