/* ═══════════════════════════════════════════════════════════
   r/place — CSS Design System
   ═══════════════════════════════════════════════════════════ */

:root {
    /* Palette — the 16 canonical r/place colors */
    --c0:  #FFFFFF; /* White */
    --c1:  #E4E4E4; /* Light Grey */
    --c2:  #888888; /* Grey */
    --c3:  #222222; /* Black */
    --c4:  #FFA7D1; /* Pink */
    --c5:  #E50000; /* Red */
    --c6:  #E59500; /* Orange */
    --c7:  #A06A42; /* Brown */
    --c8:  #E5D900; /* Yellow */
    --c9:  #94E044; /* Lime */
    --c10: #02BE01; /* Green */
    --c11: #00D3DD; /* Cyan */
    --c12: #0083C7; /* Blue */
    --c13: #0000EA; /* Dark Blue */
    --c14: #CF6EE4; /* Magenta */
    --c15: #820080; /* Purple */

    /* UI tokens */
    --bg-primary: #0e0e12;
    --bg-secondary: #16161c;
    --bg-elevated: #1e1e28;
    --bg-glass: rgba(22, 22, 28, 0.85);
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-accent: rgba(255, 255, 255, 0.12);
    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #55556a;
    --accent: #6c5ce7;
    --accent-glow: rgba(108, 92, 231, 0.35);
    --success: #00b894;
    --error: #e17055;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
    overscroll-behavior: none;
}

/* ─── Header ────────────────────────────────────────────── */
header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 16px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    border-bottom: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-md);
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}
.header-center::-webkit-scrollbar { display: none; }

/* Logo */
#logo {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    white-space: nowrap;
}
.logo-r {
    color: var(--text-secondary);
}
.logo-place {
    background: linear-gradient(135deg, #e50000, #e59500, #e5d900, #02be01, #0083c7, #cf6ee4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Online badge */
.stat-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}
.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
}
.dot.pulse {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(0, 184, 148, 0.5); }
    50% { opacity: 0.7; box-shadow: 0 0 0 5px rgba(0, 184, 148, 0); }
}

/* ─── Palette ───────────────────────────────────────────── */
#palette {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}

.palette-swatch {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    flex-shrink: 0;
}
.palette-swatch:hover {
    transform: scale(1.15);
    z-index: 1;
}
.palette-swatch.active {
    border-color: var(--text-primary);
    transform: scale(1.2);
    box-shadow: 0 0 12px rgba(255,255,255,0.25);
    z-index: 2;
}

/* ─── Cooldown ring ─────────────────────────────────────── */
#cooldown-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px 4px 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 24px;
    white-space: nowrap;
    transition: var(--transition);
}
#cooldown-container.cooldown-idle {
    border-color: rgba(0, 184, 148, 0.3);
}
#cooldown-container.cooldown-active {
    border-color: rgba(225, 112, 85, 0.4);
}

#cooldown-ring {
    display: block;
}
.ring-bg {
    fill: none;
    stroke: var(--bg-primary);
    stroke-width: 3;
}
.ring-fg {
    fill: none;
    stroke: var(--success);
    stroke-width: 3;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: center;
    transition: stroke 0.3s ease;
}
.cooldown-active .ring-fg {
    stroke: var(--error);
}

#cooldown-text {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--success);
    transition: color 0.3s ease;
}
.cooldown-active #cooldown-text {
    color: var(--error);
}

/* Coordinates */
#coords-display {
    padding: 4px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ─── Canvas viewport ───────────────────────────────────── */
#viewport {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: crosshair;
}

#canvas-wrapper {
    position: absolute;
    width: 100px;
    height: 100px;
    transform-origin: 0 0;
}

#board-canvas, #grid-canvas, #hover-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100px;
    height: 100px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#grid-canvas, #hover-canvas {
    pointer-events: none;
}

/* ─── Zoom controls ─────────────────────────────────────── */
#zoom-controls {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 4px;
    box-shadow: var(--shadow-md);
}
#zoom-controls button {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
#zoom-controls button:hover {
    background: var(--bg-elevated);
}
#zoom-controls button:active {
    transform: scale(0.92);
}

/* ─── Toast ─────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 10px 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    animation: toast-in 0.3s ease, toast-out 0.3s ease 2.5s forwards;
    white-space: nowrap;
}
.toast.error {
    border-color: rgba(225, 112, 85, 0.4);
    color: var(--error);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateY(-8px); }
}

/* ─── Mobile responsive ─────────────────────────────────── */
@media (max-width: 768px) {
    header {
        padding: 6px 10px;
        gap: 6px;
    }

    .header-left {
        gap: 6px;
    }

    #logo {
        font-size: 0.95rem;
    }

    .stat-badge {
        display: none;
    }

    .palette-swatch {
        width: 22px;
        height: 22px;
        border-radius: 4px;
    }

    #palette {
        gap: 3px;
        padding: 3px;
        border-radius: var(--radius-sm);
    }

    #cooldown-container {
        padding: 3px 8px 3px 3px;
    }

    #cooldown-ring {
        width: 30px;
        height: 30px;
    }

    #cooldown-text {
        font-size: 0.6rem;
    }

    #coords-display {
        display: none;
    }

    #zoom-controls {
        bottom: 16px;
        right: 16px;
    }
    #zoom-controls button {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
    }
}

@media (max-width: 420px) {
    #logo {
        display: none;
    }

    .palette-swatch {
        width: 19px;
        height: 19px;
    }
}
