/*
 * Tiles - Collaborative Painting Board
 * Stario light theme with warm yellows
 */

:root {
    --bg: #fafaf9;
    --fg: #1c1917;
    --surface: #ffffff;
    --surface-hover: #fef3c7;
    --border: #e7e5e4;
    --border-strong: #d6d3d1;
    --accent: #f59e0b;
    --accent-light: #fbbf24;
    --accent-glow: rgba(245, 158, 11, 0.25);
    --accent-soft: #fef3c7;
    --muted: #78716c;
    --radius: 10px;
    --cell-size: clamp(36px, 6vw, 48px);
    --gap: 4px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--fg);
    min-height: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem 0.75rem;
    background-image: radial-gradient(circle, #d6d3d1 1px, transparent 1px);
    background-size: 24px 24px;
}

.container {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

/* Color swatch (player indicator) */
.swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    vertical-align: middle;
}

.users-list .swatch {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Info Panel (combined stats + players) */
.info-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    min-width: 240px;
}

.info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.info-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.info-stats {
    font-size: 0.9rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.info-stats .count {
    color: var(--accent);
    font-weight: 700;
    font-size: 1.1rem;
}

.info-label--complete {
    color: var(--accent);
}

.info-stats--complete {
    color: var(--accent);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Game Board */
.board-wrap {
    position: relative;
}

.board {
    background: var(--surface);
    border: 4px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    padding: calc(var(--gap) * 2);
    display: flex;
    flex-direction: column;
    gap: var(--gap);

    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.05),
        0 4px 24px rgba(0, 0, 0, 0.08),
        0 0 0 1px var(--border);

    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Celebration effect when all cells are filled */
.board.complete {
    border-color: transparent;
    background:
        linear-gradient(var(--surface), var(--surface)) padding-box,
        linear-gradient(90deg, #ef4444, #f97316, #eab308, #22c55e, #3b82f6, #8b5cf6, #ec4899, #ef4444) border-box;
    background-size: 100% 100%, 200% 100%;
    animation: rainbow 2s linear infinite;
}

.board.celebrating {
    position: relative;
    overflow: hidden;
    box-shadow:
        0 0 0 1px rgba(245, 158, 11, 0.35),
        0 8px 32px rgba(245, 158, 11, 0.22),
        0 0 48px rgba(251, 191, 36, 0.18);
}

.board.celebrating .cell {
    cursor: default;
    pointer-events: none;
}

.board.celebrating .cell.painted {
    animation: celebratePulse 0.75s ease-in-out infinite alternate;
}

.board.celebrating .cell:hover {
    transform: none;
    filter: none;
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.1),
        inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

.board-sparkles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 2;
}

.sparkle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: radial-gradient(circle, #fff 0%, #fbbf24 45%, transparent 70%);
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.9);
    animation: sparkleFloat 1.4s ease-in-out infinite;
    opacity: 0;
}

.sparkle:nth-child(3n) {
    width: 4px;
    height: 4px;
}

.sparkle:nth-child(3n + 1) {
    width: 8px;
    height: 8px;
}

.row {
    display: flex;
    gap: var(--gap);
}

/* Individual Cells */
.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;

    user-select: none;

    transition:
        background-color 0.15s ease,
        border-color 0.15s ease,
        transform 0.1s ease,
        box-shadow 0.15s ease;
}

.cell:hover {
    background: var(--accent-soft);
    border-color: var(--accent-light);
    transform: scale(1.05);
    box-shadow: 0 0 12px var(--accent-glow);
}

.cell:active {
    transform: scale(0.95);
}

/* Painted State - color applied via inline style */
.cell.painted {
    border-color: rgba(0, 0, 0, 0.15);
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.1),
        inset 0 1px 2px rgba(255, 255, 255, 0.3);
    animation: pop 0.2s ease-out;
}

.cell.painted:hover {
    transform: scale(1.05);
    filter: brightness(1.05);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.12),
        inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

/* Users List (inside info panel) */
.users-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    justify-content: flex-end;
}

.users-list .swatch {
    width: 20px;
    height: 20px;
    border-radius: 5px;
}

.users-list li {
    animation: slideIn 0.2s ease-out;
}

.empty {
    color: var(--muted);
    font-size: 0.75rem;
    font-style: italic;
}

/* Error Page */
.error h1 {
    background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.error p {
    color: var(--muted);
    margin-top: 0.5rem;
}

.back-link a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.15s ease;
}

.back-link a:hover {
    color: #d97706;
    text-decoration: underline;
}

/* Animations */
@keyframes pop {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes rainbow {
    to {
        background-position: 100% 100%, -200% 0;
    }
}

@keyframes celebratePulse {
    from {
        transform: scale(1);
        filter: brightness(1);
    }

    to {
        transform: scale(1.06);
        filter: brightness(1.12) saturate(1.15);
    }
}

@keyframes sparkleFloat {
    0% {
        opacity: 0;
        transform: translateY(6px) scale(0.4);
    }

    35% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: translateY(-18px) scale(1.1);
    }
}

/* Responsive */
@media (max-width: 640px) {
    .info-panel {
        min-width: unset;
        width: 100%;
        max-width: 400px;
    }

    .info-row {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

@media (max-width: 400px) {
    body {
        padding: 1rem 0.5rem;
    }

    .board {
        padding: var(--gap);
    }

    .info-panel {
        padding: 0.5rem 0.75rem;
    }
}