/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --felt: #0f3d0f;
    --felt-light: #1a5c1a;
    --text: #e0e0e0;
    --text-muted: #888;
    --accent: #e94560;
    --gold: #ffd700;
    --team-0: #4a9eff;
    --team-1: #4caf50;
    --team-2: #ff5252;
    --card-bg: #faf3e0;
    --card-border: #ccc;
    --red-suit: #d32f2f;
    --black-suit: #222;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
}

.view {
    width: 100%;
    max-width: 1200px;
    padding: 12px 20px;
}

#game-view {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

#game-view.hidden {
    display: none !important;
}

.hidden {
    display: none !important;
}

h1 {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 0.25rem;
    color: var(--gold);
}

.subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* === Rules (lobby) === */
.rules-section {
    max-width: 500px;
    margin: 0 auto 1.5rem;
    background: var(--surface);
    border-radius: 10px;
    padding: 0;
    overflow: hidden;
}

.rules-section summary {
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 600;
    color: var(--gold);
    font-size: 1rem;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.rules-section summary::before {
    content: "\25B6";
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.rules-section[open] summary::before {
    transform: rotate(90deg);
}

.rules-section summary::-webkit-details-marker {
    display: none;
}

.rules-content {
    padding: 0 16px 14px;
    font-size: 0.88rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.rules-content p {
    margin-bottom: 8px;
}

.rules-content ul {
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* === Rules tooltip (game view) === */
.rules-tooltip-wrapper {
    position: relative;
}

.rules-btn {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    font-size: 0.9rem;
    font-weight: 700;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid #444;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rules-btn:hover {
    color: var(--gold);
    border-color: var(--gold);
    transform: none;
}

.rules-tooltip {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--surface);
    border: 1px solid #444;
    border-radius: 10px;
    padding: 14px 16px;
    width: 300px;
    z-index: 50;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.rules-tooltip p {
    margin-bottom: 6px;
    color: var(--gold);
    font-size: 0.9rem;
}

.rules-tooltip ul {
    padding-left: 16px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.rules-tooltip-wrapper:hover .rules-tooltip,
.rules-tooltip-wrapper:focus-within .rules-tooltip {
    display: block;
}

/* === Lobby === */
.lobby-form {
    max-width: 500px;
    margin: 0 auto;
}

.lobby-form input[type="text"],
.lobby-form select {
    width: 100%;
    padding: 12px;
    border: 1px solid #444;
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 1rem;
    outline: none;
}

.lobby-form input[type="text"]:focus {
    border-color: var(--accent);
}

#player-name {
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 1.1rem;
}

.lobby-actions {
    display: flex;
    gap: 1.5rem;
    align-items: stretch;
}

.create-section, .join-section {
    flex: 1;
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.create-section h3, .join-section h3 {
    text-align: center;
    color: var(--gold);
    margin-bottom: 0.25rem;
}

.form-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-row label {
    font-size: 0.9rem;
    white-space: nowrap;
    min-width: 120px;
}

.form-row select {
    flex: 1;
}

.divider {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    font-weight: bold;
    font-size: 0.9rem;
}

button {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--accent);
    color: white;
}

button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--team-1);
}

#room-code {
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 0.2em;
    font-weight: bold;
}

/* === Waiting Room === */
#waiting-view {
    text-align: center;
}

.room-info {
    margin: 1rem 0 0.25rem;
    font-size: 1.1rem;
}

.room-code-display {
    font-size: 2rem;
    font-weight: bold;
    color: var(--gold);
    letter-spacing: 0.15em;
    margin-left: 0.5rem;
}

.game-config-display {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.player-list {
    max-width: 400px;
    margin: 0 auto 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.player-item {
    background: var(--surface);
    padding: 10px 16px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-item .host-badge {
    background: var(--gold);
    color: #000;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
}

.waiting-msg {
    color: var(--text-muted);
    font-style: italic;
}

#btn-start {
    margin-bottom: 1rem;
    padding: 14px 40px;
    font-size: 1.1rem;
}

/* === Theme toggle === */
.header-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    font-size: 1rem;
    line-height: 1;
    background: var(--surface);
    border: 1px solid #444;
    filter: grayscale(1);
    opacity: 0.7;
}

.theme-toggle[aria-pressed="true"] {
    filter: none;
    opacity: 1;
}

.theme-toggle-floating {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 50;
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
}

/* === Game Header === */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 6px;
}

.game-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.room-badge {
    background: var(--surface);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

#turn-indicator {
    font-size: 1rem;
    font-weight: 600;
}

.turn-timer {
    font-size: 0.95rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    padding: 4px 10px;
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    min-width: 50px;
    text-align: center;
}

.turn-timer.low-time {
    color: var(--accent);
    animation: pulse-timer 1s ease-in-out infinite;
}

@keyframes pulse-timer {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.team-scores {
    display: flex;
    gap: 12px;
}

.score-badge {
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
}

/* === Game Body (board + hand side-by-side) === */
.game-body {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* === Board === */
.game-area {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-width: 0;
    height: 100%;
}

.board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: 2px;
    background: var(--felt);
    padding: 6px;
    border-radius: 12px;
    border: 3px solid var(--felt-light);
    --board-size: min(calc(100vh - 90px), calc(100vw - 220px));
    --board-size: min(calc(100dvh - 90px), calc(100vw - 220px));
    width: var(--board-size);
    height: var(--board-size);
    max-width: 800px;
    max-height: 800px;
}

.cell {
    background: var(--card-bg);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.6rem, 2vmin, 1.1rem);
    font-weight: 600;
    cursor: default;
    position: relative;
    transition: all 0.15s;
    border: 2px solid transparent;
    overflow: hidden;
    line-height: 1.1;
}

.cell .card-rank {
    font-size: 1em;
}

.cell .card-suit {
    font-size: 0.9em;
}

.cell.red-suit {
    color: var(--red-suit);
}

.cell.black-suit {
    color: var(--black-suit);
}

.cell.corner {
    background: var(--gold);
    color: #333;
    font-weight: bold;
    font-size: clamp(0.5rem, 1.6vmin, 0.85rem);
}

/* Chips */
.cell.chip-0 { background: var(--team-0); color: white; box-shadow: inset 0 0 6px rgba(0,0,0,0.25); }
.cell.chip-1 { background: var(--team-1); color: white; box-shadow: inset 0 0 6px rgba(0,0,0,0.25); }
.cell.chip-2 { background: var(--team-2); color: white; box-shadow: inset 0 0 6px rgba(0,0,0,0.25); }

/* Last played card highlight */
.cell.last-move {
    border: 3px solid #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.7), 0 0 20px rgba(255, 255, 255, 0.3);
    animation: pulse-last-move 1.5s ease-in-out infinite;
}

@keyframes pulse-last-move {
    0%, 100% { box-shadow: 0 0 10px rgba(255, 255, 255, 0.7), 0 0 20px rgba(255, 255, 255, 0.3); }
    50% { box-shadow: 0 0 16px rgba(255, 255, 255, 1), 0 0 32px rgba(255, 255, 255, 0.5); }
}

/* Sequence highlight */
.cell.in-sequence {
    border: 3px solid var(--gold);
    box-shadow: 0 0 10px var(--gold), 0 0 20px rgba(255, 215, 0, 0.4), inset 0 0 8px rgba(255, 215, 0, 0.3);
}

/* Valid move highlight — uses --hl-r, --hl-g, --hl-b set per team on .board */
.cell.valid-move {
    border: 3px solid rgb(var(--hl-r), var(--hl-g), var(--hl-b));
    background: rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.2) !important;
    box-shadow:
        0 0 12px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.8),
        0 0 24px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.4),
        inset 0 0 8px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.2);
    cursor: pointer;
    animation: pulse-valid 1.2s ease-in-out infinite;
}

@keyframes pulse-valid {
    0%, 100% { box-shadow:
        0 0 12px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.8),
        0 0 24px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.4),
        inset 0 0 8px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.2); }
    50% { box-shadow:
        0 0 18px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 1),
        0 0 36px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.6),
        inset 0 0 12px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.35); }
}

.cell.valid-move:hover {
    transform: scale(1.15);
    z-index: 2;
    background: rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.35) !important;
    box-shadow:
        0 0 20px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 1),
        0 0 40px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.6);
    animation: none;
}

/* The chip a joker has picked up, waiting for its destination */
.cell.shift-source {
    border: 3px dashed var(--gold);
    box-shadow: 0 0 14px var(--gold), inset 0 0 10px rgba(255, 215, 0, 0.35);
    cursor: pointer;
    animation: pulse-shift-source 1.2s ease-in-out infinite;
}

@keyframes pulse-shift-source {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Preview highlight (non-jack, not your turn) */
.cell.preview-move {
    border: 3px solid rgb(var(--hl-r), var(--hl-g), var(--hl-b));
    background: rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.15) !important;
    box-shadow:
        0 0 10px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.7),
        0 0 20px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.3),
        inset 0 0 6px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.2);
    animation: pulse-preview 1.5s ease-in-out infinite;
}

@keyframes pulse-preview {
    0%, 100% { box-shadow:
        0 0 10px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.7),
        0 0 20px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.3),
        inset 0 0 6px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.2); }
    50% { box-shadow:
        0 0 16px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 1),
        0 0 32px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.5),
        inset 0 0 10px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.35); }
}

/* === Hand (right panel) === */
.hand-area {
    width: 160px;
    flex-shrink: 0;
    text-align: center;
    padding-top: 8px;
    max-height: 100%;
    overflow-y: auto;
}

.hand-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.dead-hint {
    font-size: 0.75rem;
    color: var(--accent);
    display: block;
    margin-top: 4px;
}

.hand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.hand-card {
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 8px;
    padding: 10px 8px;
    min-width: 60px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    user-select: none;
}

.hand-card .card-rank {
    font-size: 1.1rem;
    font-weight: bold;
}

.hand-card .card-suit {
    font-size: 1.3rem;
}

/* "JOKER" is five characters where every other rank is one or two */
.hand-card.joker-card .card-rank {
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

.hand-card.red-suit {
    color: var(--red-suit);
}

.hand-card.black-suit {
    color: var(--black-suit);
}

.hand-card:hover {
    transform: translateX(-6px);
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.3);
}

.hand-card.selected {
    border: 3px solid rgb(var(--hl-r), var(--hl-g), var(--hl-b));
    box-shadow: 0 0 14px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.8), 0 0 28px rgba(var(--hl-r), var(--hl-g), var(--hl-b), 0.4);
    transform: translateX(-12px) scale(1.05);
    background: #fff8f0;
}

.hand-card.dead-card {
    opacity: 0.7;
    border-color: #666;
    background: #e8e0d0;
}

.discard-btn {
    margin-top: 2px;
    padding: 2px 8px;
    font-size: 0.65rem;
    font-weight: 600;
    border-radius: 4px;
    background: var(--accent);
    color: white;
    cursor: pointer;
    border: none;
    line-height: 1.3;
}

.hand-card.disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.pass-btn {
    margin-top: 12px;
    padding: 8px 12px;
    width: 100%;
    font-size: 0.8rem;
    font-weight: 700;
    border-radius: 6px;
    background: var(--accent);
    color: white;
    cursor: pointer;
    border: none;
    animation: pulse 1.6s ease-in-out infinite;
}

.pass-btn:hover {
    filter: brightness(1.1);
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.0); }
    50% { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.12); }
}

/* === Game Over Overlay === */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.overlay-content {
    background: var(--surface);
    padding: 3rem;
    border-radius: 16px;
    text-align: center;
    border: 2px solid var(--gold);
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    color: var(--gold);
}

/* Final scoreboard: who was on each team and how they finished */
.final-scoreboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 1.5rem;
    text-align: left;
}

.final-team {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: baseline;
    gap: 12px;
    padding: 8px 14px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid transparent;
}

.final-team.winning-team {
    border-color: var(--gold);
    background: rgba(255, 215, 0, 0.12);
}

.final-team-name {
    font-weight: bold;
}

.final-team-players {
    opacity: 0.9;
}

.final-team-score {
    opacity: 0.75;
    font-size: 0.9rem;
    white-space: nowrap;
}

.overlay-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

#btn-play-again {
    font-size: 1.1rem;
    padding: 12px 32px;
}

#btn-watch-replay {
    font-size: 1.1rem;
    padding: 12px 32px;
}

/* === Replay Bar === */
.replay-bar {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--surface);
    border: 1px solid var(--gold);
    border-radius: 12px;
    padding: 10px 16px;
    z-index: 90;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
    max-width: calc(100vw - 24px);
    flex-wrap: wrap;
    justify-content: center;
}

.replay-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
}

.replay-counter {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--gold);
    font-size: 0.95rem;
}

.replay-move-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
}

.replay-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.replay-btn {
    padding: 8px 12px;
    font-size: 0.9rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid #444;
    min-width: 40px;
}

.replay-btn:hover {
    border-color: var(--gold);
    color: var(--gold);
    transform: none;
    opacity: 1;
}

.replay-btn.replay-play {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    min-width: 84px;
}

.replay-btn.replay-play:hover {
    color: white;
}

.replay-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: #444;
    color: var(--text-muted);
}

.replay-exit {
    padding: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg);
    color: var(--text-muted);
    border: 1px solid #444;
    font-size: 0.9rem;
}

.replay-exit:hover {
    color: var(--accent);
    border-color: var(--accent);
    transform: none;
    opacity: 1;
}

/* === Error Toast === */
.error-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 500;
    z-index: 200;
    animation: toast-in 0.3s;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* === Responsive === */
@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    #game-view {
        height: auto;
        overflow: visible;
    }

    .game-body {
        flex-direction: column;
        align-items: center;
        overflow: visible;
    }

    .game-area {
        height: auto;
    }

    .board {
        --board-size: min(calc(100vw - 40px), calc(65dvh));
        width: var(--board-size);
        height: var(--board-size);
    }

    .hand-area {
        width: 100%;
        padding-top: 0;
        margin-top: 12px;
        max-height: none;
        overflow-y: visible;
    }

    .hand {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .hand-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    .hand-card.selected {
        transform: translateY(-8px) scale(1.05);
        background: #fff8f0;
    }
}

@media (max-width: 600px) {
    .lobby-actions {
        flex-direction: column;
    }

    .divider {
        text-align: center;
        justify-content: center;
        padding: 0.5rem 0;
    }

    .board {
        --board-size: min(calc(100vw - 16px), calc(60dvh));
        width: var(--board-size);
        height: var(--board-size);
        border-radius: 8px;
        padding: 4px;
        gap: 1px;
    }

    .cell {
        border-radius: 2px;
    }

    .hand-card {
        min-width: 48px;
        padding: 8px 6px;
    }

    .game-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ================================================================
   Halloween theme — toggled by data-theme="halloween" on <html>.
   Purely cosmetic and per-viewer: team colours (--team-*) are left
   alone so team names and colours agree for every player.
   ================================================================ */
.spooky-decor {
    display: none;
}

html[data-theme="halloween"] {
    --bg: #120a1c;
    --surface: #24163a;
    --felt: #1b0f2b;
    --felt-light: #ff7518;
    --text: #f2e6d8;
    --text-muted: #a594b8;
    --accent: #ff7518;
    --gold: #ffa31a;
    --card-bg: #efe4cc;
    --card-border: #8a6f4d;
    --red-suit: #b3121f;
    --black-suit: #1a1024;
}

html[data-theme="halloween"] body {
    background:
        radial-gradient(ellipse at 50% 120%, rgba(255, 117, 24, 0.18), transparent 60%),
        radial-gradient(ellipse at 15% 0%, rgba(122, 60, 180, 0.25), transparent 55%),
        var(--bg);
    background-attachment: fixed;
}

html[data-theme="halloween"] h1 {
    font-family: 'Creepster', 'Chiller', 'Papyrus', fantasy;
    letter-spacing: 0.08em;
    text-shadow: 0 0 12px rgba(255, 117, 24, 0.7), 0 3px 0 #4a1a00;
}

html[data-theme="halloween"] #lobby-view h1::before,
html[data-theme="halloween"] #lobby-view h1::after {
    content: "\1F383";
    font-size: 0.8em;
    margin: 0 0.3em;
    text-shadow: none;
}

html[data-theme="halloween"] .subtitle::after {
    content: " \2014  Spooky Edition";
    color: var(--accent);
}

html[data-theme="halloween"] .rules-section,
html[data-theme="halloween"] .create-section,
html[data-theme="halloween"] .join-section,
html[data-theme="halloween"] .overlay-content {
    border: 1px solid rgba(255, 117, 24, 0.25);
    box-shadow: 0 0 18px rgba(122, 60, 180, 0.25);
}

html[data-theme="halloween"] button {
    color: #1a0b00;
}

html[data-theme="halloween"] .theme-toggle,
html[data-theme="halloween"] .rules-btn,
html[data-theme="halloween"] .replay-btn,
html[data-theme="halloween"] .replay-exit {
    color: var(--text);
}

/* Keep the secondary button green-team coloured, with readable text */
html[data-theme="halloween"] .btn-secondary {
    color: white;
}

/* The board: a moonlit graveyard of spiderwebbed cards */
html[data-theme="halloween"] .board {
    box-shadow: 0 0 24px rgba(255, 117, 24, 0.35), inset 0 0 30px rgba(0, 0, 0, 0.6);
}

html[data-theme="halloween"] .cell:not([class*="chip-"]):not(.corner),
html[data-theme="halloween"] .hand-card:not(.selected):not(.dead-card) {
    background:
        radial-gradient(circle at 100% 0%, transparent 0 34%, rgba(60, 40, 30, 0.10) 35% 36%, transparent 37% 52%, rgba(60, 40, 30, 0.10) 53% 54%, transparent 55%),
        linear-gradient(160deg, #f4ead4, #ddcba6);
}

/* Corners become jack-o'-lanterns (the "FREE" label stays for screen readers) */
html[data-theme="halloween"] .cell.corner {
    background: radial-gradient(circle at 50% 40%, #ffb347, #ff7518 55%, #c44d00);
    color: transparent;
}

html[data-theme="halloween"] .cell.corner::before {
    content: "\1F383";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.9rem, 3.2vmin, 1.8rem);
    color: initial;
}

/* Completed sequences glow like candle-lit pumpkins */
html[data-theme="halloween"] .cell.in-sequence {
    box-shadow: 0 0 10px var(--gold), 0 0 22px rgba(255, 117, 24, 0.55), inset 0 0 8px rgba(255, 163, 26, 0.4);
}

html[data-theme="halloween"] .overlay {
    background: rgba(10, 4, 18, 0.85);
}

html[data-theme="halloween"] .overlay-content h2::before {
    content: "\1F987  ";
}

html[data-theme="halloween"] .overlay-content h2::after {
    content: "  \1F987";
}

/* --- Decorations: a moon, flapping bats and a drifting ghost --- */
html[data-theme="halloween"] .spooky-decor {
    display: block;
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

/* Lift the views above the decor layer (overlay/toast/replay bar are already
   fixed-positioned and later in the DOM, so they paint above it too). */
html[data-theme="halloween"] .view {
    position: relative;
    z-index: 1;
}

.spooky-decor .moon {
    position: absolute;
    top: 36px;
    left: 4%;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fffbe6, #f3dfa2 60%, #c9b27a);
    box-shadow: 0 0 40px rgba(255, 240, 190, 0.45), 0 0 90px rgba(255, 240, 190, 0.2);
    opacity: 0.85;
}

.spooky-decor .bat,
.spooky-decor .ghost {
    position: absolute;
    left: -60px;
    font-size: 28px;
    filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.6));
    animation: bat-fly 22s linear infinite;
}

.spooky-decor .bat-1 { top: 12%; animation-delay: 0s; }
.spooky-decor .bat-2 { top: 28%; font-size: 20px; animation-duration: 30s; animation-delay: -12s; }
.spooky-decor .bat-3 { top: 6%;  font-size: 16px; animation-duration: 26s; animation-delay: -5s; }

.spooky-decor .ghost {
    top: auto;
    bottom: 8%;
    font-size: 34px;
    opacity: 0.5;
    animation: ghost-drift 40s ease-in-out infinite;
}

@keyframes bat-fly {
    0%   { transform: translate(0, 0) scaleY(1); }
    10%  { transform: translate(10vw, -20px) scaleY(0.6); }
    20%  { transform: translate(20vw, 10px) scaleY(1); }
    30%  { transform: translate(30vw, -15px) scaleY(0.6); }
    40%  { transform: translate(40vw, 15px) scaleY(1); }
    50%  { transform: translate(50vw, -10px) scaleY(0.6); }
    60%  { transform: translate(60vw, 20px) scaleY(1); }
    70%  { transform: translate(70vw, -20px) scaleY(0.6); }
    80%  { transform: translate(80vw, 5px) scaleY(1); }
    90%  { transform: translate(90vw, -15px) scaleY(0.6); }
    100% { transform: translate(calc(100vw + 120px), 0) scaleY(1); }
}

@keyframes ghost-drift {
    0%, 100% { transform: translate(0, 0); opacity: 0; }
    10%      { opacity: 0.5; }
    50%      { transform: translate(55vw, -30px); opacity: 0.35; }
    90%      { opacity: 0.5; }
    99%      { transform: translate(calc(100vw + 120px), 0); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .spooky-decor .bat,
    .spooky-decor .ghost {
        animation: none;
    }
    .spooky-decor .bat-1 { left: 70%; }
    .spooky-decor .bat-2 { left: 82%; }
    .spooky-decor .bat-3 { left: 88%; }
    .spooky-decor .ghost { left: 8%; }
}

@media (max-width: 600px) {
    .spooky-decor .moon {
        display: none;
    }
}
