/* ============================================================ */
/* SECTION 1: Layer Declaration Order                            */
/* ============================================================ */
@import url('https://cdn.jsdelivr.net/npm/modern-normalize/modern-normalize.css') layer(reset);
@import url('https://unpkg.com/open-props/normalize.min.css') layer(reset);

@layer reset, base, tokens, components, layout, utilities;

@layer tokens {
/* ============================================================ */
/* TOKENS: Gallery Canvas Design System                          */
/* ============================================================ */
:root, [data-theme="dark"] {
    /* --- Core Palette: Gallery Canvas --- */
    --bg-dark: #1a1612;          /* dark aged wood */
    --bg-muted: #252019;         /* warm charcoal */
    --bg-card: #252019;          /* card base - warm dark */
    --bg-body: #0f0d0a;          /* deepest dark - like a museum at night */
    --acc-primary: #2dd4bf;      /* teal for interactive states */
    --acc-gold: #c9a84c;         /* gallery brass/gold for frames & decor */
    --acc-gold-dim: #8b6914;     /* darker gold for borders */
    --acc-secondary: #e07b39;    /* warm amber for pending/action states */
    --acc-success: #4ade80;
    --acc-warning: #fbbf24;
    --txt-main: #e8dcc8;         /* warm parchment white */
    --txt-muted: #a89880;        /* warm grey-brown */
    --text-color: var(--txt-main);

    /* --- Semantic State Colors --- */
    --color-success: #22c55e;
    --color-success-dim: rgba(34, 197, 94, 0.15);
    --color-danger: #ef4444;
    --color-danger-dim: rgba(239, 68, 68, 0.15);
    --color-warning: #fbbf24;
    --color-warning-dim: rgba(251, 191, 36, 0.1);
    --color-muted: #6b5d4f;

    /* --- Effects: Gallery Frame --- */
    --glass-bg: rgba(30, 25, 18, 0.92);
    --glass-bg-blur: rgba(201, 168, 76, 0.04);
    --glass-border: rgba(201, 168, 76, 0.3);   /* gold border */
    --glass-blur: blur(10px);
    --frame-border: 2px solid var(--acc-gold);
    --frame-shadow: 0 0 0 4px var(--bg-dark), 0 0 0 6px var(--acc-gold-dim), 0 8px 32px rgba(0,0,0,0.7);

    /* --- Surface Layers --- */
    --surface-1: rgba(201, 168, 76, 0.03);
    --surface-2: rgba(201, 168, 76, 0.06);
    --surface-3: rgba(201, 168, 76, 0.09);
    --surface-4: rgba(201, 168, 76, 0.14);

    /* --- Border Radius Scale --- */
    --radius-xs: 2px;     /* frames should be less rounded */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --radius-xl: 14px;
    --radius-full: 9999px;

    /* --- Z-Index Scale --- */
    --z-base: 1;
    --z-raised: 10;
    --z-nav: 100;
    --z-overlay: 500;
    --z-modal: 1000;
    --z-cursor: 9999;

    /* --- Shadows --- */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.8);
    --shadow-glow: 0 0 20px rgba(201, 168, 76, 0.2);
    --shadow-glow-primary: 0 0 25px rgba(45, 212, 191, 0.25);
    --shadow-glow-success: 0 0 15px rgba(34, 197, 94, 0.3);
    --shadow-glow-danger: 0 0 15px rgba(239, 68, 68, 0.3);

    /* --- Transitions --- */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);

    /* --- Typography --- */
    --f-heading: 'Outfit', sans-serif;
    --f-body: 'Inter', sans-serif;

    /* --- Game Options (set by JS) --- */
    --preview-blur: 3px;
    --preview-size: 50px;
}
} /* end tokens layer */

@layer base {
/* --- Global Reset & Base Styles --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    /* NOTE: NO overflow:hidden on html - breaks Firefox */
}

body {
    height: 100%;
    overflow-x: hidden;
}

body {
    /* Warm stone/canvas gallery wall texture with dynamic gradient */
    background-color: var(--bg-body);
    background-image:
        url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' preserveAspectRatio='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E"),
        radial-gradient(circle at 15% 50%, rgba(224, 123, 57, 0.08), transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(45, 212, 191, 0.06), transparent 50%),
        radial-gradient(ellipse at 50% 0%, #2a2218 0%, #0f0d0a 80%);
    background-size: cover, 150% 150%, 150% 150%, cover;
    background-attachment: fixed;
    animation: ambientPan 25s ease-in-out infinite alternate;
    color: var(--txt-main);
    font-family: var(--f-body);
    line-height: 1.6;
}

@keyframes ambientPan {
    0% { background-position: center, 0% 0%, 100% 0%, center; }
    50% { background-position: center, 50% 100%, 50% 100%, center; }
    100% { background-position: center, 100% 0%, 0% 0%, center; }
}

/* --- App Shell CSS Grid --- */
#app.app-container {
    display: grid;
    grid-template-columns: 1fr 300px;
    grid-template-rows: auto 1fr;
    grid-template-areas: 
        "nav nav"
        "main chat";
    height: 100vh;
    height: 100dvh; /* modern fallback */
    max-height: 100vh;
    overflow: hidden;
}

@media (max-width: 800px) {
    .app-container {
        grid-template-columns: 1fr;
        grid-template-areas: 
            "nav"
            "main";
    }
    .chat-sidebar {
        display: none !important; /* Will need a toggle for mobile later */
    }
}

.main-content-area {
    grid-area: main;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    padding-bottom: 2rem;
    /* Ensure scrollbar stays inside this column */
    scrollbar-width: thin;
    scrollbar-color: var(--acc-primary) transparent;
}

.chat-sidebar-wrapper {
    grid-area: chat;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    border-left: 1px solid var(--glass-border);
}

.chat-sidebar {
    display: flex;
    flex-direction: column;
    background: rgba(15, 13, 10, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: inset 20px 0 50px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    padding: 1rem;
    min-height: 0;
    min-width: 0;
    flex: 1;
}

.chat-sidebar.game-chat {
    background: rgba(45, 27, 46, 0.6); /* Slightly different tint for game chat */
}


.view {
    min-height: 100%;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Typography Helpers --- */
h1,
h2,
h3 {
    font-family: var(--f-heading);
    letter-spacing: -0.02em;
}

.glitch-text {
    font-size: 3.5rem;
    font-weight: 600;
    /* Warm gold-to-teal gallery gradient */
    background: linear-gradient(135deg, var(--acc-gold) 0%, #e8d5a3 50%, var(--acc-primary) 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 2px 8px rgba(201, 168, 76, 0.3));
    letter-spacing: -0.03em;
}

.subtitle {
    color: var(--txt-muted);
    font-size: 1rem;
    font-weight: 300;
    margin-bottom: 2.5rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 0.85rem;
}

/* --- Gallery Section Headers --- */
.lobby-section h2,
.leaderboard-section h2 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--acc-gold);
    margin-bottom: 1.2rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--acc-gold-dim);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
} /* end base layer */

@layer components {
/* --- Components: Buttons --- */
.btn {
    padding: 0.8rem 1.8rem;
    border: none;
    border-radius: 12px;
    font-family: var(--f-heading);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:hover {
    transform: translateY(-2px) scale(1.02);
}

.btn:active {
    transform: translateY(0);
}

.btn.primary {
    background: linear-gradient(135deg, var(--acc-gold-dim), var(--acc-gold));
    color: #0f0d0a;
    font-weight: 700;
    border: 1px solid var(--acc-gold);
    letter-spacing: 0.02em;
}

.btn.primary.glow:hover {
    box-shadow: 0 0 25px var(--acc-primary);
}

.btn.secondary {
    background: var(--bg-muted);
    color: var(--txt-main);
    border: 1px solid var(--glass-border);
}

.btn.glass {
    background: rgba(30, 25, 18, 0.8);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    color: var(--txt-main);
}

.btn.ghost {
    background: transparent;
    color: var(--txt-muted);
}

.btn.ghost:hover {
    color: white;
    background: rgba(255, 255, 255, 0.05);
}

.btn-admin {
    background: var(--color-danger) !important;
    border: 1px solid #ef4444 !important;
    color: #ffffff !important;
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
    border-radius: 6px;
    font-weight: 700;
    letter-spacing: 0.05em;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-admin:hover {
    background: #dc2626 !important;
    box-shadow: var(--shadow-glow-danger);
    transform: translateY(-1px);
}

.btn.small {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    border-radius: 8px;
}

.btn-icon {
    background: transparent;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: rotate(45deg);
}

} /* end components layer */

@layer layout {
/* --- Top Navigation: Gallery Header Bar --- */
.top-nav {
    grid-area: nav;
    position: relative;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: var(--z-nav);
    border-bottom: 1px solid var(--acc-gold-dim);
    background: #1a1510;
    /* Subtle inner highlight at top */
    box-shadow: inset 0 1px 0 rgba(201, 168, 76, 0.1);
}

.top-nav-left {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.user-profile {
    display: flex;
    align-items: center;
    white-space: nowrap;
    flex-shrink: 0;
    padding: 0.2rem 0.5rem;
}

.username-input {
    width: 90px;
    padding: 0.2rem;
}

.group-selector {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.group-dropdown {
    max-width: 140px;
    padding: 0.2rem 0.5rem;
}

.version-tag {
    font-size: 0.7rem;
    font-family: var(--f-heading);
    color: var(--acc-gold);
    background: rgba(201, 168, 76, 0.08);
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    border: 1px solid var(--acc-gold-dim);
    letter-spacing: 0.08em;
}

/* --- Layout: Lobby Actions --- */
.actions {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 2.5rem;
}

/* --- Lobby: Section containers --- */
.lobby-section,
.leaderboard-section {
    width: 100%;
    max-width: 820px;
    margin-bottom: 2.5rem;
}

/* --- Lobby: Pending Turns Grid --- */
.turns-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.2rem;
    width: 100%;
    max-width: 820px;
    margin-top: 0.5rem;
}
} /* end layout layer */

@layer components {
/* --- Components: Gallery Frame Card --- */
.glass {
    /* Warm dark panel with gold border — gallery frame aesthetic */
    background: #1e1a14;
    border: 1px solid var(--acc-gold-dim);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

/* Only apply expensive backdrop-filter on key UI elements, not every card */
.glass.blur-safe,
.toolbar {
    background: rgba(30, 25, 18, 0.85);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
}

/* GPU-promote animated/hoverable cards to their own layer */
.turn-card {
    will-change: transform;
    contain: layout style;
    isolation: isolate;
}

/* --- Canvas Area --- */
.canvas-wrapper {
    margin: 1.5rem auto;
    position: relative;
    width: 90vw;
    max-width: 800px;
    height: 70vh;
    max-height: 500px;
    overflow: hidden;
    cursor: crosshair;
}

#drawing-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    background-color: #ffffff;
    cursor: none; /* Hide default cursor to use custom brush outline */
}

/* --- Brush Outline Cursor --- */
.brush-cursor {
    position: fixed;
    top: 0;
    left: 0;
    border: 2px solid rgba(0, 0, 0, 0.4);
    border-radius: 50%;
    pointer-events: none;
    z-index: var(--z-cursor);
    transform: translate3d(0, 0, 0) translate(-50%, -50%);
    will-change: transform;
    display: none; /* Shown via JS when hovering canvas */
    box-shadow: 0 0 2px rgba(255, 255, 255, 0.8), inset 0 0 2px rgba(255, 255, 255, 0.8);
}

/* --- Toolbar UI --- */
.toolbar {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 960px;
}

.tool-group {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}
.tool-section-group {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.btn-tool {
    background: transparent;
    border: 1px solid transparent;
    font-size: 1.2rem;
    padding: 0.3rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-tool:hover {
    background: var(--glass-bg);
}

.btn-tool.active {
    background: var(--acc-primary);
    border-color: rgba(255, 255, 255, 0.2);
}

/* --- Color Palette --- */
.color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-width: 200px; /* Forces 5x3 grid approx */
}

.swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s, border-color 0.1s;
    box-sizing: border-box;
}

.swatch:hover {
    transform: scale(1.15);
}

.swatch.active {
    border-color: #ffffff !important;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
    transform: scale(1.1);
}

.swatch.custom-swatch {
    border: 1px dashed rgba(255, 255, 255, 0.6) !important;
    padding: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background-size: cover;
}

.swatch.custom-swatch:hover {
    border-style: solid;
    border-color: white;
}

/* Hide Pickr's default button inside our swatch */
.swatch.custom-swatch .pickr {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
}
.swatch.custom-swatch .pcr-button {
    width: 100% !important;
    height: 100% !important;
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
}
.swatch.custom-swatch .pcr-button::before,
.swatch.custom-swatch .pcr-button::after {
    display: none !important;
}

/* Position Pickr App to the left of the palette */
.pcr-app.nano {
    margin-left: -50px; /* Offset to push it left of the trigger */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6) !important;
    border: 1px solid var(--glass-border) !important;
    background: var(--bg-card) !important;
    backdrop-filter: blur(15px);
}

.pcr-app.nano .pcr-selection .pcr-picker {
    border: 2px solid white !important;
}

.spray-flow-control {
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.tool-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

/* --- Utilities --- */
.empty-msg {
    color: var(--txt-muted);
    font-style: italic;
    opacity: 0.7;
    text-align: center;
}

/* --- Guessing Room --- */
.guessing-header {
    text-align: center;
    margin-bottom: 2rem;
}

.drawing-display-wrapper {
    width: 90vw;
    max-width: 800px;
    height: 70vh;
    max-height: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 2rem;
    padding: 1rem;
}

.drawing-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.guess-input-container {
    display: flex;
    gap: 0.75rem;
    width: 100%;
    max-width: 700px;
    margin: 0 auto 2rem auto;
    align-items: stretch;
    justify-content: center;
}

.guess-input-container .btn {
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

#btn-give-up {
    color: var(--color-danger);
    border: 1px solid var(--color-danger-dim);
    background: rgba(239, 68, 68, 0.05);
    font-size: 0.9rem;
    opacity: 0.8;
}

#btn-give-up:hover {
    background: rgba(239, 68, 68, 0.1);
    opacity: 1;
    border-color: var(--color-danger);
}

.input-main {
    flex: 1;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    color: white;
    font-size: 1.1rem;
}

.input-main:focus {
    box-shadow: 0 0 15px rgba(129, 140, 248, 0.4);
}



/* GPU-promote animated/hoverable cards to their own layer */
.turn-card {
    will-change: transform;
    contain: layout style;
    isolation: isolate;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform var(--transition-bounce), box-shadow var(--transition-base);
    position: relative;
    overflow: hidden;
    /* Gallery frame: dark warm canvas + double border */
    background: #1e1a14;
    border: 1px solid var(--acc-gold-dim);
    border-radius: var(--radius-sm);
    /* Double-border frame effect via box-shadow */
    box-shadow: inset 0 0 0 1px rgba(201, 168, 76, 0.08), var(--shadow-md);
    cursor: pointer;
}

.turn-card:hover {
    transform: translateY(-3px);
    border-color: var(--acc-gold);
    /* Gallery spotlight hover glow */
    box-shadow:
        inset 0 0 0 1px rgba(201, 168, 76, 0.15),
        0 0 20px rgba(201, 168, 76, 0.12),
        0 12px 32px rgba(0, 0, 0, 0.6);
}

/* Shimmer reveal on hover */
.turn-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(201, 168, 76, 0.06), transparent);
    transition: 0.6s ease;
    pointer-events: none;
}

.turn-card:hover::after {
    left: 100%;
}

.turn-info h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
    color: var(--txt-main);
}

.turn-info p {
    color: var(--txt-muted);
    font-size: 0.8rem;
}


@media (max-width: 640px) {
    .glitch-text {
        font-size: 2.5rem;
    }

    .toolbar {
        flex-direction: column;
        gap: 1rem;
    }

    .guess-input-container {
        flex-direction: column;
    }

    .turn-card {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
}

/* History Grid Layout */
.pending-turns,
.game-history {
    width: 100%;
    max-width: 1000px;
}

.history-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    margin-top: 1rem;
    min-height: 400px;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    width: 100%;
    flex: 1;
}

.history-detail-view {
    width: 350px;
    padding: 1.5rem;
    flex-shrink: 0;
    position: sticky;
    top: 2rem;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 800px) {
    .history-layout { flex-direction: column; }
    .history-detail-view { width: 100%; position: static; }
}

.history-card-sm {
    padding: 0.5rem !important;
    display: flex;
    flex-direction: column !important;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
}

.history-card-sm:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
}

.history-card-sm .history-thumb {
    width: 100% !important;
    height: 100px !important;
    margin-bottom: 0.5rem;
}

/* Modifiers for JS injecting blur and size dynamically inline, or classes */
.turn-card img.history-thumb {
    width: var(--preview-size, 50px) !important;
    height: var(--preview-size, 50px) !important;
}

.turn-card img.history-thumb.blurred {
    filter: blur(var(--preview-blur, 3px)) !important;
}

.history-card-sm .turn-info {
    width: 100%;
    text-align: center;
}

.history-card-sm h3 {
    font-size: 0.9rem;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-card-sm p {
    display: none;
}

/* --- Dictionary Management --- */
.dict-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.dict-info {
    display: flex;
    flex-direction: column;
}

.dict-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.dict-meta {
    font-size: 0.75rem;
    color: var(--txt-muted);
}

.btn-delete-dict {
    color: var(--acc-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.btn-delete-dict:hover {
    color: var(--color-danger);
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    backdrop-filter: blur(5px);
}
.modal-overlay.hidden {
    display: none !important;
}
.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

/* --- User Identity & Game History --- */

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    border-radius: 20px;
    background: var(--surface-2);
    border: 1px solid var(--glass-border);
    transition: all 0.2s ease;
}
.user-profile:hover {
    background: var(--surface-3);
}

.username-input {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-family: var(--f-body);
    font-size: 0.9rem;
    font-weight: 500;
    width: 150px;
    outline: none;
    padding: 0.25rem;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}
.username-input:focus {
    border-bottom: 1px solid var(--acc-primary);
}

.edit-icon {
    font-size: 0.8rem;
    opacity: 0.6;
    cursor: pointer;
}

.drawn-by-tag {
    font-size: 0.85rem;
    opacity: 0.8;
    margin-top: -0.5rem;
    margin-bottom: 1rem;
    color: var(--txt-main);
}

.guess-log-container {
    max-width: 600px;
    margin: 1rem auto;
    padding: 1rem;
    text-align: left;
    max-height: 200px;
    overflow-y: auto;
}
.guess-log {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.guess-log li {
    font-size: 0.9rem;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
}
.guess-user {
    font-weight: 600;
    color: var(--acc-primary);
}
.guess-text {
    opacity: 0.9;
}
.guess-time {
    font-size: 0.75rem;
    opacity: 0.5;
}

.view-guesses {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 250px;
    overflow-y: auto;
}
.view-guesses li {
    font-size: 0.85rem;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    display: flex;
    justify-content: flex-start;
    gap: 0.5rem;
    align-items: center;
}
.guess-item.correct {
    border-left: 3px solid var(--color-success);
    background: var(--color-success-dim);
}
.guess-item.wrong {
    border-left: 3px solid var(--color-danger);
}
.guess-item.gave-up {
    border-left: 3px solid var(--color-muted);
    opacity: 0.7;
}

/* --- Group Selector & Nav Layout --- */

.top-nav-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.group-selector {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
    margin-top: 0.25rem;
}

.group-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 0.2rem;
}

.group-actions .btn-icon {
    font-size: 1rem;
    padding: 0.2rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.group-actions .btn-icon:hover {
    opacity: 1;
}

.group-dropdown {
    appearance: none;
    -webkit-appearance: none;
    background: var(--surface-2);
    border: 1px solid var(--glass-border);
    color: var(--txt-main);
    font-family: var(--f-body);
    font-size: 0.85rem;
    padding: 0.4rem 2rem 0.4rem 0.75rem;
    border-radius: 20px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
}
.group-dropdown:hover,
.group-dropdown:focus {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: var(--acc-primary);
}
.group-dropdown option {
    background: var(--bg-dark);
    color: var(--txt-main);
}

/* --- Lobby Sections --- */

.lobby-section,
.leaderboard-section {
    width: 100%;
    max-width: 820px;
    margin-bottom: 2.5rem;
}

.leaderboard-container {
    /* Gallery: engraved brass plaque */
    background: #18140e;
    border-radius: var(--radius-md);
    border: 2px solid var(--acc-gold-dim);
    padding: 0;
    overflow: hidden;
    box-shadow:
        inset 0 0 30px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(201, 168, 76, 0.08);
}

.leaderboard-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    text-align: left;
    font-size: 0.875rem;
}

.leaderboard-table th {
    padding: 0.75rem 0.875rem;
    color: var(--acc-gold);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    border-bottom: 1px solid var(--acc-gold-dim);
    font-family: var(--f-heading);
    background: rgba(201, 168, 76, 0.05);
    font-weight: 600;
}

.leaderboard-table td {
    padding: 0.75rem 0.875rem;
    border-bottom: 1px solid rgba(201, 168, 76, 0.06);
    color: var(--txt-main);
    transition: background 0.2s;
}

.leaderboard-table tr:last-child td {
    border-bottom: none;
}

.leaderboard-table tr:hover td {
    background: rgba(201, 168, 76, 0.04);
}

.leaderboard-table .rank-1 { color: #fbbf24; font-weight: bold; }
.leaderboard-table .rank-2 { color: #94a3b8; }
.leaderboard-table .rank-3 { color: #cd7c3a; }
/* --- Leaderboard End --- */

.leaderboard-table .rank-col { width: 36px; text-align: center; }
.leaderboard-table .player-cell { font-weight: 500; color: var(--txt-main); }
.leaderboard-table th.stat-col, .leaderboard-table td.stat-col { text-align: center; font-variant-numeric: tabular-nums; }
.leaderboard-table .avg-col { font-weight: 700; text-align: right; color: var(--acc-gold); }

/* --- Completion Badge --- */

.completion-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    background: rgba(129, 140, 248, 0.15);
    color: var(--acc-primary);
    font-weight: 500;
    white-space: nowrap;
}

.waiting-names {
    font-size: 0.75rem;
    color: var(--txt-muted);
    margin-top: 0.25rem;
    font-style: italic;
}

@media (max-width: 640px) {
    .top-nav-left { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
}

/* --- Toolbar Overrides --- */

.palette-container {
    flex-shrink: 0;
}

.color-palette {
    width: 175px; /* Fixed width to force 5x3 grid cleanly */
}

#brush-cursor {
    /* Optimization for translate3d */
    will-change: transform;
    left: 0 !important;
    top: 0 !important;
}

/* --- Voting Widget --- */
.vote-widget {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    position: relative;
}

.vote-widget.vote-locked {
    opacity: 0.7;
    pointer-events: none;
}

.vote-widget.vote-locked .vote-thumb.selected {
    opacity: 1;
}

.vote-thumb {
    background: none;
    border: 1px solid transparent;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.25rem 0.3rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    position: relative;
    line-height: 1;
}

.vote-thumb:hover {
    background: var(--glass-bg);
    transform: scale(1.15);
}

.vote-thumb.selected {
    border-color: rgba(255, 255, 255, 0.3);
    transform: scale(1.2);
}

.vote-thumb.selected.thumb-up {
    background: rgba(34, 197, 94, 0.25);
    border-color: var(--color-success);
}

.vote-thumb.selected.thumb-down {
    background: rgba(239, 68, 68, 0.25);
    border-color: var(--color-danger);
}

.vote-slider-popout {
    display: none;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.5rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    backdrop-filter: blur(12px);
    animation: voteSlideIn 0.2s ease-out;
}

.vote-slider-popout.visible {
    display: inline-flex;
}

.vote-slider-popout input[type="range"] {
    width: 80px;
    accent-color: var(--acc-primary);
}

.vote-slider-popout .vote-number-label {
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 1.5em;
    text-align: center;
    color: rgba(255, 255, 255, 0.9);
}

@keyframes voteSlideIn {
    from { opacity: 0; transform: translateX(-5px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Vote score summary on cards */
.vote-summary {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.8rem;
    opacity: 0.8;
    margin-top: 0.3rem;
}

.vote-summary .vote-stat {
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

.vote-summary .vote-stat.positive {
    color: var(--color-success);
}

.vote-summary .vote-stat.negative {
    color: var(--color-danger);
}

/* Prompt vote widget placement */
.prompt-vote-area {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 0.75rem;
    vertical-align: middle;
}

/* Drawing vote next to submit */
.canvas-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Guessing vote next to guess button */
.guess-vote-area {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

} /* end components layer */

@layer layout {
/* --- Chat & Comments --- */

.split-view {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    align-items: stretch;
}

@media (max-width: 1000px) {
    .chat-sidebar {
        max-width: 100%;
    }
}

.split-view-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center; /* Center main content (canvas/leaderboard) */
}

/* Removed old inline styling override to avoid conflicts */
.chat-sidebar-inner {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-right: 0.5rem;
    min-height: 0;
}

.chat-message {
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    position: relative;
    word-break: break-word;
}

.chat-message.is-reply {
    margin-left: 1rem;
    border-left: 2px solid var(--acc-primary);
    border-radius: 0 8px 8px 0;
}

.chat-message-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.8rem;
    opacity: 0.8;
}

.chat-user {
    font-weight: 600;
    color: var(--acc-secondary);
}

.chat-time {
    font-size: 0.7rem;
    opacity: 0.5;
}

.chat-text {
    line-height: 1.4;
}

.mention {
    color: var(--color-warning);
    font-weight: bold;
    background: var(--color-warning-dim);
    padding: 0 0.2rem;
    border-radius: var(--radius-xs);
}

.spoiler-blurred .chat-text,
.spoiler-blurred .chat-image-attachment {
    filter: blur(8px);
    cursor: pointer;
    user-select: none;
    transition: filter 0.2s;
    opacity: 0.8;
}

.spoiler-blurred .chat-text::after {
    content: 'Spoiler (Click to view)';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.8rem;
    color: white;
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    pointer-events: none;
}

.spoiler-revealed .chat-text,
.spoiler-revealed .chat-image-attachment {
    filter: none;
    cursor: text;
    user-select: auto;
}

.chat-image-attachment {
    max-width: 100%;
    max-height: 200px;
    border-radius: 6px;
    margin-top: 0.5rem;
    object-fit: cover;
    border: 1px solid var(--glass-border);
}

.chat-game-preview {
    display: flex;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.5rem;
    border-radius: 6px;
    margin-top: 0.5rem;
    cursor: pointer;
    align-items: center;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}

.chat-game-preview:hover {
    border-color: var(--acc-primary);
}

.chat-game-thumb {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    object-fit: cover;
}

.chat-game-info {
    font-size: 0.75rem;
    opacity: 0.7;
}

.chat-input-area {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-input-row {
    display: flex;
    gap: 0.5rem;
}

.chat-input-row .input-main {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}

.chat-input-area .btn {
    padding: 0.5rem 0.75rem;
}

.btn-icon-small {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: white;
    font-size: 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    width: 40px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-small:hover {
    background: rgba(255, 255, 255, 0.15);
}

.chat-options-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    opacity: 0.8;
}

.reply-target-indicator {
    font-size: 0.75rem;
    color: var(--acc-primary);
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0.5rem;
    background: rgba(129, 140, 248, 0.1);
    border-radius: 4px;
    margin-bottom: 0.25rem;
}

.btn-cancel-reply {
    cursor: pointer;
    opacity: 0.7;
}
.btn-cancel-reply:hover {
    opacity: 1;
}

.chat-actions {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.chat-message:hover .chat-actions {
    opacity: 1;
}

.chat-action-btn {
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    color: white;
    border-radius: 4px;
    font-size: 0.7rem;
    padding: 0.1rem 0.3rem;
    cursor: pointer;
}

.chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

} /* end layout layer */

@layer utilities {
.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.95);
}

/* --- Notifications & Extras --- */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--color-danger);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: var(--shadow-glow-danger);
}

.image-preview-wrapper {
    position: relative;
    max-width: 100px;
    margin-top: 0.25rem;
}

.image-preview-wrapper img {
    width: 100%;
    border-radius: 6px;
    border: 1px solid var(--glass-border);
}

.btn-remove-image {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--color-danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Game Modal Overlay --- */
.game-modal-overlay {
    grid-area: main;
    position: relative;
    width: 100%;
    height: 100%;
    background: rgba(10, 8, 15, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 9000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 1rem;
    box-sizing: border-box;
}

.game-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.game-modal-content {
    background: rgba(20, 18, 25, 0.95);
    border: 1px solid var(--acc-gold-dim);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 900px;
    height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    padding: 2rem;
    box-sizing: border-box;
}

.game-modal-close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.game-modal-close:hover {
    color: var(--acc-secondary);
}

.modal-split-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    margin-top: 1rem;
}

.modal-split-main {
    flex: 2;
    min-width: 0;
}

.modal-split-sidebar {
    flex: 1;
    min-width: 0;
}

/* --- Internal Modal Elements --- */
.history-detail-view,
#guessing-room {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.modal-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.modal-header .view-word {
    font-size: 2.5rem;
    margin-top: 0;
    margin-bottom: 0.25rem;
}

.modal-header h2 {
    font-size: 1.8rem;
    margin-bottom: 0.25rem;
}

.modal-header .drawn-by-tag {
    margin: 0;
    font-size: 1.1rem;
    color: var(--acc-gold);
    opacity: 0.8;
}

.modal-image-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    width: 100%;
}

.modal-image-frame {
    padding: 0.75rem;
    border-radius: 16px;
    background: rgba(0,0,0,0.4);
    max-width: 100%;
    max-height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-image {
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: 40vh;
    object-fit: contain;
    border-radius: 8px;
}

.view-guesses-container {
    margin-top: 1.5rem;
    text-align: left;
    padding: 1.5rem;
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
}

.view-guesses-container h3 {
    margin-top: 0;
    font-size: 1.1rem;
    color: var(--acc-gold);
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

.guess-log-container {
    width: 100%;
    max-width: 600px;
    margin-top: 1.5rem;
    max-height: 150px;
    overflow-y: auto;
    padding: 1rem;
}

.guess-log-container h3 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    opacity: 0.8;
}

.guess-input-container {
    margin-top: 1.5rem;
    width: 100%;
    max-width: 600px;
    align-self: center;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.guess-input-container .input-main {
    flex: 1;
}

.guess-vote-area {
    align-self: center;
    margin-top: 1rem;
}
} /* end utilities layer */


/* Admin Management Tables */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 0.85rem;
}

.admin-table th, .admin-table td {
    text-align: left;
    padding: 0.75rem;
    border-bottom: 1px solid var(--glass-border);
}

.admin-table th {
    color: var(--acc-secondary);
    font-weight: bold;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
}

.admin-table tr:hover {
    background: rgba(255,255,255,0.03);
}

.btn.danger {
    background: var(--color-danger);
    color: white !important;
}

.btn.danger:hover {
    background: #dc2626;
    box-shadow: 0 0 10px rgba(220, 38, 38, 0.4);
}

/* ================================================
   Cropper.js - Circular Crop Box Override
   ================================================ */

/* Make the crop view box circular */
.cropper-view-box,
.cropper-face {
    border-radius: 50%;
}

/* Soften the crop outline */
.cropper-view-box {
    outline: 2px solid var(--acc-primary, #f59e0b);
    outline-color: rgba(245, 158, 11, 0.75);
}

/* Hide corner/edge drag handles (box is locked anyway) */
.cropper-point,
.cropper-line {
    display: none !important;
}
