/* DrawIt Perfect - Modern Shape Drawing Challenge */

:root {
    /* Deep space theme with neon accents */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a25;
    --bg-card: #16161f;
    
    --accent-primary: #00f5d4;
    --accent-secondary: #7b2cbf;
    --accent-tertiary: #ff6b6b;
    
    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #55556a;
    
    --perfect-color: #00f5d4;
    --medium-color: #f5d400;
    --poor-color: #ff4757;
    
    --border-color: rgba(255, 255, 255, 0.08);
    --glow-primary: 0 0 30px rgba(0, 245, 212, 0.3);
    --glow-secondary: 0 0 20px rgba(123, 44, 191, 0.3);
    
    --font-main: 'Outfit', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --sidebar-width: 280px;
    --border-radius: 16px;
    --border-radius-sm: 10px;
}

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

html, body {
    min-height: 100%;
    min-width: 800px;
    overflow: auto;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

/* Background pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(ellipse at 20% 80%, rgba(123, 44, 191, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(0, 245, 212, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(255, 107, 107, 0.05) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

/* Grid pattern overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: 0;
}

.app-container {
    display: flex;
    min-height: 100vh;
    height: 100vh;
    min-width: 800px;
    position: relative;
    z-index: 1;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 12px 12px;
    gap: 10px;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.logo-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-text {
    display: flex;
    flex-direction: column;
}

.logo-icon {
    font-size: 38px;
    color: var(--accent-primary);
    text-shadow: var(--glow-primary);
    animation: pulse 2s ease-in-out infinite;
    margin-top: -2px;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.logo h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin: 0;
    line-height: 1.2;
}

.logo .accent {
    color: var(--accent-primary);
}

.powered-by {
    font-size: 9px;
    color: var(--text-muted);
    opacity: 0.6;
    letter-spacing: 0.3px;
}

/* Desktop: show bottom button, hide header button */
.header-clear {
    display: none !important;
}

.bottom-clear {
    display: flex;
    margin-top: auto;
}

/* Shape Selector */
.shape-selector h2 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.shapes-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.shape-btn {
    aspect-ratio: 1;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.shape-btn svg {
    width: 36px;
    height: 36px;
    transition: transform 0.2s ease;
}

.shape-btn span {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.shape-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.shape-btn:hover svg {
    transform: scale(1.1);
}

.shape-btn.active {
    background: linear-gradient(135deg, rgba(0, 245, 212, 0.15), rgba(123, 44, 191, 0.1));
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    box-shadow: var(--glow-primary);
}

/* Collapsible Shape Selector (Group Mode) */
.shape-selector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.shape-selector-header h2 {
    margin-bottom: 0;
}

.shape-selector-collapsed {
    display: none;
    flex-direction: column;
    align-items: center;
    margin-bottom: 8px;
}

.collapsed-shape-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.collapsed-shape-icon {
    aspect-ratio: 1;
    background: var(--bg-card);
    border: 2px solid var(--accent-primary);
    border-radius: var(--border-radius-sm);
    padding: 6px;
    color: var(--accent-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: linear-gradient(135deg, rgba(0, 245, 212, 0.15), rgba(123, 44, 191, 0.1));
    box-shadow: var(--glow-primary);
    cursor: pointer;
    /* Match the size of shape buttons in the grid (2 columns with 6px gap) */
    width: calc((100% - 6px) / 2);
}

.collapsed-shape-icon:hover {
    transform: scale(1.05);
}

.collapsed-shape-icon svg {
    width: 36px;
    height: 36px;
    transition: transform 0.2s ease;
}

.shape-toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    padding: 4px 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px;
}

.shape-toggle-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
}


/* When shape selector is collapsed */
.shape-selector.collapsed .shapes-grid {
    display: none;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.shape-selector.collapsed .shape-selector-collapsed {
    display: flex;
    animation: fadeInCollapsed 0.4s ease;
}

.shape-selector.collapsed .shape-toggle-btn {
    transform: rotate(90deg);
}

.shape-selector.collapsed {
    margin-bottom: 4px;
}

/* Reduce spacing after collapsed shape selector */
.shape-selector.collapsed + .how-to-play-section,
.shape-selector.collapsed + .group-section,
.shape-selector.collapsed ~ .group-info-section {
    margin-top: 0;
    padding-top: 4px;
}

/* When shape selector is expanded */
.shape-selector:not(.collapsed) .shape-selector-collapsed {
    display: none;
}

.shape-selector:not(.collapsed) .shapes-grid {
    animation: fadeInExpanded 0.4s ease;
}

/* Make header clickable in group mode */
.shape-selector.collapsible .shape-selector-header {
    cursor: pointer;
    padding: 8px 10px;
    margin: -8px -10px 10px -10px;
    border-radius: var(--border-radius-sm);
    transition: background 0.2s ease;
}

.shape-selector.collapsible .shape-selector-header:hover {
    background: var(--bg-tertiary);
}

.shape-selector.collapsible.collapsed .shape-selector-header {
    margin-bottom: 0;
    padding: 8px 10px;
}

/* Animation for shape transition */
@keyframes fadeInCollapsed {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes fadeInExpanded {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}


/* Instructions */
.instructions {
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    padding: 10px;
}

.instructions h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.instructions ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.instructions li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-secondary);
}

.instructions .step {
    width: 18px;
    height: 18px;
    background: var(--accent-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

/* Clear Button */
.clear-btn {
    margin-top: auto;
    background: transparent;
    border: 2px solid var(--accent-tertiary);
    color: var(--accent-tertiary);
    padding: 10px 16px;
    border-radius: var(--border-radius-sm);
    font-family: var(--font-main);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s ease;
}

.clear-btn:hover {
    background: var(--accent-tertiary);
    color: white;
    box-shadow: 0 0 20px rgba(255, 107, 107, 0.3);
}

.btn-icon {
    font-size: 18px;
}

/* ===== MAIN DRAWING AREA ===== */
.drawing-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 16px;
    min-width: 500px;
    min-height: 500px;
}

.canvas-container {
    flex: 1;
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    overflow: hidden;
    min-height: 400px;
}

#drawingCanvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
}

/* Score Display */
.score-display {
    position: absolute;
    top: 30px;
    right: 30px;
    background: rgba(10, 10, 15, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px 30px;
    text-align: center;
    min-width: 160px;
    transition: all 0.3s ease;
    z-index: 10;
}

.score-display.calculating {
    border-color: var(--accent-primary);
    box-shadow: var(--glow-primary);
}

.score-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.score-value {
    font-family: var(--font-mono);
    font-size: 42px;
    font-weight: 600;
    line-height: 1;
    color: var(--text-primary);
    transition: color 0.3s ease;
    display: inline;
}

.score-value.perfect {
    color: var(--perfect-color);
    text-shadow: 0 0 30px rgba(0, 245, 212, 0.5);
}

.score-value.good {
    color: var(--medium-color);
    text-shadow: 0 0 30px rgba(245, 212, 0, 0.5);
}

.score-value.poor {
    color: var(--poor-color);
    text-shadow: 0 0 30px rgba(255, 71, 87, 0.5);
}

.score-percent {
    font-size: 16px;
    color: var(--text-secondary);
    display: inline;
    vertical-align: bottom;
    margin-left: 2px;
    margin-left: 2px;
}

/* Start Hint */
.start-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.start-hint.hidden {
    opacity: 0;
}

.hint-content {
    text-align: center;
    background: rgba(10, 10, 15, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 40px 60px;
}

.hint-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 16px;
    opacity: 0.6;
    animation: bob 2s ease-in-out infinite;
}

@keyframes bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.hint-content p {
    color: var(--text-secondary);
    font-size: 16px;
}

.hint-shape {
    margin-top: 12px;
    font-size: 14px !important;
}

.hint-shape strong {
    color: var(--accent-primary);
}

/* Status Bar */
.status-bar {
    display: flex;
    align-items: center;
    gap: 30px;
    padding: 14px 24px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.status-value {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text-primary);
}

.legend {
    margin-left: auto;
    gap: 20px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.legend-color.perfect {
    background: var(--perfect-color);
    box-shadow: 0 0 8px rgba(0, 245, 212, 0.5);
}

.legend-color.medium {
    background: var(--medium-color);
    box-shadow: 0 0 8px rgba(245, 212, 0, 0.5);
}

.legend-color.poor {
    background: var(--poor-color);
    box-shadow: 0 0 8px rgba(255, 71, 87, 0.5);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    html, body {
        min-width: auto;
        min-height: auto;
        height: 100%;
        overflow: hidden;
    }
    
    .app-container {
        flex-direction: column;
        min-width: auto;
        min-height: 0;
        height: 100vh;
        max-height: 100vh;
        overflow: hidden;
    }
    
    .sidebar {
        width: 100%;
        min-width: auto;
        max-width: none;
        min-height: auto;
        max-height: 45vh;
        padding: 10px 12px;
        gap: 8px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        flex-shrink: 0;
        overflow-y: auto;
    }
    
    .logo {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }
    
    .logo-left {
        gap: 8px;
    }
    
    .logo h1 {
        font-size: 18px;
    }
    
    .logo-icon {
        font-size: 28px;
        margin-top: -1px;
    }
    
    .powered-by {
        display: block;
        font-size: 7px;
        margin-top: -1px;
    }
    
    .shape-selector h2 {
        display: none;
    }
    
    .shapes-grid {
        grid-template-columns: repeat(8, 1fr);
        gap: 4px;
    }
    
    .shape-btn {
        aspect-ratio: 1;
        padding: 4px;
        gap: 0;
    }
    
    .shape-btn svg {
        width: 32px;
        height: 32px;
    }
    
    .shape-btn span {
        display: none;
    }
    
    .instructions {
        display: none;
    }
    
    /* Hide How to Play in small view */
    .how-to-play-section {
        display: none;
    }
    
    /* Hide canvas clear button in small view (it's in header) */
    .canvas-clear {
        display: none !important;
    }
    
    /* Small screen: show header button, hide bottom button */
    .header-clear {
        display: flex !important;
        padding: 8px 14px;
        font-size: 12px;
    }
    
    .header-clear .btn-icon {
        font-size: 14px;
    }
    
    .header-clear .clear-text {
        display: inline;
    }
    
    .bottom-clear {
        display: none !important;
    }
    
    .drawing-area {
        min-height: 0;
        min-width: auto;
        padding: 8px;
        gap: 6px;
        flex: 1;
        overflow: hidden;
    }
    
    .canvas-container {
        flex: 1;
        min-height: 0;
    }
    
    .status-bar {
        flex-shrink: 0;
    }
    
    .score-display {
        top: 10px;
        right: 10px;
        padding: 10px 14px;
        min-width: 100px;
    }
    
    .score-value {
        font-size: 32px;
    }
    
    .best-score-label {
        font-size: 9px;
    }
    
    .best-score-value {
        font-size: 16px;
    }
    
    .status-bar {
        flex-wrap: nowrap;
        gap: 16px;
        padding: 10px 16px;
    }
    
    .legend {
        width: auto;
        margin-left: auto;
        gap: 12px;
    }
    
    .legend-item {
        font-size: 10px;
    }
    
    .status-label {
        font-size: 10px;
    }
    
    .status-value {
        font-size: 12px;
    }
    
    .hint-content {
        padding: 20px 24px;
        max-width: 280px;
    }
    
    .hint-icon {
        font-size: 32px;
        margin-bottom: 10px;
    }
    
    .hint-content p {
        font-size: 14px;
        line-height: 1.4;
    }
    
    .hint-shape {
        margin-top: 8px;
        font-size: 12px !important;
    }
}

@media (max-width: 600px) {
    .shapes-grid {
        grid-template-columns: repeat(8, 1fr);
        gap: 3px;
    }
    
    .shape-btn {
        padding: 3px;
        border-radius: 6px;
    }
    
    .shape-btn svg {
        width: 28px;
        height: 28px;
    }
    
    .shape-btn span {
        display: none;
    }
    
    .header-clear .clear-text {
        display: none;
    }
    
    .header-clear {
        padding: 8px;
    }
    
    .legend-item span:not(.legend-color) {
        display: none;
    }
    
    .legend {
        gap: 8px;
    }
    
    .logo h1 {
        font-size: 16px;
    }
    
    .logo-icon {
        font-size: 26px;
    }
    
    .powered-by {
        font-size: 6px;
    }
    
    .hint-content {
        padding: 16px 20px;
        max-width: 240px;
    }
    
    .hint-icon {
        font-size: 28px;
        margin-bottom: 8px;
    }
    
    .hint-content p {
        font-size: 13px;
    }
    
    .hint-shape {
        font-size: 11px !important;
    }
}

/* Very small screens - inline score display at top */
@media (max-width: 500px) {
    .logo-icon {
        font-size: 26px;
    }
    
    .logo h1 {
        font-size: 16px;
    }
    
    .powered-by {
        font-size: 6px;
    }
    
    .canvas-container {
        display: flex;
        flex-direction: column;
    }
    
    .score-display {
        position: relative !important;
        top: 0 !important;
        right: 0 !important;
        width: 100%;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-start;
        gap: 0;
        padding: 6px 10px;
        min-width: auto;
        border-radius: 0;
        background: rgba(15, 15, 20, 0.95);
        border: none;
        border-bottom: 1px solid var(--border-color);
        order: -1;
        flex-shrink: 0;
        text-align: left;
    }
    
    /* Left side elements - PERFECTION label and score */
    .score-label {
        display: inline;
        margin-bottom: 0;
        font-size: 11px;
        letter-spacing: 1px;
        margin-right: 6px;
    }
    
    .score-value {
        font-size: 32px;
        font-weight: 700;
        display: inline;
    }
    
    .score-percent {
        font-size: 14px;
        color: var(--text-secondary);
        margin-left: 1px;
        display: inline;
        vertical-align: baseline;
    }
    
    /* Right side: BEST - smaller than PERFECTION, vertically centered */
    .best-score {
        margin: 0 !important;
        margin-top: 0 !important;
        margin-left: auto !important;
        padding: 0 !important;
        padding-top: 0 !important;
        border: none !important;
        border-top: none !important;
        gap: 3px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        white-space: nowrap;
        flex-shrink: 0;
        height: 100%;
    }
    
    .best-score .best-label {
        font-size: 9px;
        letter-spacing: 1px;
        color: var(--text-muted);
    }
    
    .best-score .best-value {
        font-size: 18px;
        color: var(--accent-primary);
    }
    
    .best-score .best-percent {
        font-size: 11px;
        color: var(--text-muted);
        margin-left: 1px;
    }
    
    #drawingCanvas {
        flex: 1;
    }
}

/* ===== BEST SCORE ===== */
.best-score {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 4px;
}

.best-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.best-value {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 600;
    color: var(--accent-primary);
}

.best-percent {
    font-size: 12px;
    color: var(--text-muted);
}

.best-score.new-record .best-value {
    animation: bestPulse 0.6s ease-out;
    color: var(--perfect-color);
    text-shadow: 0 0 20px rgba(0, 245, 212, 0.8);
}

@keyframes bestPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* ===== CELEBRATION OVERLAY ===== */
.celebration-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 100;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.celebration-overlay.active {
    opacity: 1;
}

.celebration-shapes {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.celebration-shape {
    position: absolute;
    opacity: 0;
    animation: celebrateFall 2.5s ease-out forwards;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

@keyframes celebrateFall {
    0% {
        opacity: 1;
        transform: translateY(-50px) rotate(0deg) scale(0);
    }
    20% {
        opacity: 1;
        transform: translateY(0) rotate(90deg) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(360deg) scale(0.5);
    }
}

.new-best-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 32px;
    font-weight: 800;
    color: var(--accent-primary);
    text-shadow: 0 0 30px rgba(0, 245, 212, 0.8);
    white-space: nowrap;
    opacity: 0;
}

.celebration-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5), 0 0 30px rgba(0, 245, 212, 0.5);
    white-space: nowrap;
    animation: celebrationMessagePop 4s ease-out forwards;
    z-index: 10;
    padding: 16px 32px;
    background: linear-gradient(135deg, rgba(0, 245, 212, 0.2), rgba(123, 44, 191, 0.2));
    border-radius: 16px;
    border: 2px solid rgba(0, 245, 212, 0.4);
    backdrop-filter: blur(10px);
}

@keyframes celebrationMessagePop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    10% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.1);
    }
    15% {
        transform: translate(-50%, -50%) scale(1);
    }
    85% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

.celebration-overlay.active .new-best-text {
    animation: newBestPop 1.5s ease-out forwards;
}

@keyframes newBestPop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0) rotate(-10deg);
    }
    30% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2) rotate(5deg);
    }
    50% {
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }
    70% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.1) rotate(-2deg);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8) rotate(0deg);
    }
}

/* Emoji celebration - no color override needed */

/* ===== COUNTDOWN TIMER ===== */
.countdown-timer {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    z-index: 50;
}

.countdown-timer.active {
    display: flex;
}

.countdown-value {
    font-family: var(--font-mono);
    font-size: 64px;
    font-weight: 700;
    color: #ff4757;
    line-height: 1;
    text-shadow: 0 0 20px rgba(255, 71, 87, 0.6), 0 0 40px rgba(255, 71, 87, 0.4);
    animation: countdownBounce 0.5s ease-in-out infinite;
}

.countdown-text {
    font-size: 16px;
    font-weight: 700;
    color: #ff4757;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(255, 71, 87, 0.5);
    animation: countdownShake 0.3s ease-in-out infinite;
}

@keyframes countdownBounce {
    0%, 100% { 
        transform: scale(1);
    }
    50% { 
        transform: scale(1.15);
    }
}

@keyframes countdownShake {
    0%, 100% { 
        transform: translateX(0);
    }
    25% { 
        transform: translateX(-3px);
    }
    75% { 
        transform: translateX(3px);
    }
}

/* ===== ANIMATIONS ===== */
@keyframes scorePopIn {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.score-display.show-result .score-value {
    animation: scorePopIn 0.4s ease-out;
}

/* Drawing active state */
.canvas-container.drawing {
    box-shadow: inset 0 0 0 2px var(--accent-primary);
}

/* ===== HOW TO PLAY SECTION ===== */
.how-to-play-section {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 10px;
}

.how-to-play-section h3 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin: 0 0 8px 0;
}

/* ===== GROUP SECTION ===== */
.group-section {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.group-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.group-section-header h3 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin: 0;
}

/* ===== GROUP INFO SECTION (when in group) ===== */
.group-info-section {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: padding-top 0.4s ease, margin-top 0.4s ease;
}

/* Adjust spacing when shape selector is collapsed */
.sidebar .shape-selector.collapsed + *,
.sidebar .shape-selector.collapsed ~ .group-info-section {
    margin-top: 0;
}

.sidebar .shape-selector.collapsed ~ .group-info-section {
    padding-top: 4px;
}

.group-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 0;
}

.group-name-row .group-connection-status {
    margin-left: auto;
}

.group-name-row .group-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.group-name-row .group-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-primary);
}

/* ===== GROUP CONTROLS ===== */
.group-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.group-buttons {
    display: flex;
    gap: 8px;
}

.group-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.group-btn:hover {
    background: var(--bg-card);
    border-color: var(--accent-primary);
}

.group-btn .btn-icon {
    font-size: 14px;
}

.group-btn.create-btn:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px rgba(0, 245, 212, 0.2);
}

.group-btn.join-btn:hover {
    border-color: var(--accent-secondary);
    box-shadow: 0 0 15px rgba(123, 44, 191, 0.2);
}

.group-btn.quit-btn {
    width: 100%;
    background: rgba(255, 71, 87, 0.1);
    border-color: rgba(255, 71, 87, 0.3);
}

.group-btn.quit-btn:hover {
    background: rgba(255, 71, 87, 0.2);
    border-color: var(--poor-color);
}

/* ===== CONNECTION STATUS ===== */
.connection-status {
    font-size: 10px;
    color: var(--perfect-color);
    animation: connectionPulse 5s ease-in-out infinite;
    text-shadow: 0 0 8px rgba(0, 245, 212, 0.8);
    display: inline-block;
}

.connection-status.disconnected {
    color: var(--poor-color);
    animation: none;
    text-shadow: 0 0 8px rgba(255, 71, 87, 0.8);
}

.group-connection-status {
    margin-left: auto;
}

/* More visible connection pulse animation */
@keyframes connectionPulse {
    0%, 100% { 
        opacity: 1;
        transform: scale(1);
    }
    50% { 
        opacity: 0.4;
        transform: scale(1.2);
    }
}

/* Members section styling */
.members-section {
    background: var(--bg-card);
    margin-top: 0;
}

.members-section .collapsible-header h4 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin: 0;
}

.group-members {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.member-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 12px;
}

.member-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-secondary); /* Default, overridden by inline style */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.member-name {
    flex: 1;
    color: var(--text-primary);
}

.member-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.member-badge.owner {
    background: rgba(0, 245, 212, 0.2);
    color: var(--accent-primary);
}

.member-badge.you {
    background: rgba(123, 44, 191, 0.2);
    color: var(--accent-secondary);
}

.member-status.exited {
    color: var(--text-muted);
    font-size: 10px;
    font-style: italic;
}

/* ===== RANKING PANEL ===== */
.ranking-panel {
    width: 280px;
    min-width: 280px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 16px;
    overflow: hidden;
}

.ranking-panel.hidden {
    display: none;
}

.ranking-header {
    margin-bottom: 12px;
}

.ranking-header h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.ranking-shape-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.shape-tab {
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.shape-tab:hover {
    border-color: var(--accent-primary);
}

.shape-tab.active {
    background: var(--accent-primary);
    color: var(--bg-primary);
    border-color: var(--accent-primary);
}

.ranking-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ranking-empty {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-muted);
}

.ranking-empty p {
    font-size: 14px;
    margin-bottom: 4px;
}

.ranking-empty small {
    font-size: 12px;
}

.ranking-entry {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.ranking-entry.current-user {
    border-color: var(--accent-primary);
    background: rgba(0, 245, 212, 0.05);
}

.ranking-position {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.rank-number {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.medal {
    font-size: 20px;
}

.ranking-thumbnail {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.ranking-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.no-thumbnail {
    width: 100%;
    height: 100%;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
}

.no-thumbnail::after {
    content: '?';
    color: var(--text-muted);
    font-size: 18px;
}

.ranking-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ranking-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.ranking-score {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-primary);
}

/* ===== REMOTE CURSORS ===== */
.cursor-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 100;
    overflow: hidden;
}

.remote-cursor {
    position: absolute;
    transform: translate(-50%, -50%);
    transition: left 0.1s linear, top 0.1s linear, opacity 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.cursor-pointer {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-secondary);
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.remote-cursor.current-user .cursor-pointer {
    width: 16px;
    height: 16px;
    background: var(--accent-primary);
    box-shadow: 0 0 15px rgba(0, 245, 212, 0.5);
}

.cursor-name {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

/* ===== DIALOG STYLES ===== */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.dialog {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    width: 340px;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.dialog-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.dialog-close {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.dialog-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.dialog-content {
    padding: 20px;
}

.dialog-error {
    padding: 10px 14px;
    margin-bottom: 16px;
    background: rgba(255, 71, 87, 0.1);
    border: 1px solid rgba(255, 71, 87, 0.3);
    border-radius: var(--border-radius-sm);
    color: var(--poor-color);
    font-size: 13px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

.dialog-footer {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    justify-content: flex-end;
}

.dialog-btn {
    padding: 10px 20px;
    border-radius: var(--border-radius-sm);
    font-family: var(--font-main);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.dialog-btn.btn-secondary {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.dialog-btn.btn-secondary:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.dialog-btn.btn-primary {
    background: var(--accent-primary);
    color: var(--bg-primary);
    border-color: var(--accent-primary);
}

.dialog-btn.btn-primary:hover {
    background: #00d4b8;
    box-shadow: var(--glow-primary);
}

.dialog-btn.btn-danger {
    background: var(--poor-color);
    border-color: var(--poor-color);
}

.dialog-btn.btn-danger:hover {
    background: #ff3346;
}

/* Dialog Form Styles */
.dialog-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 14px;
    transition: all 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 245, 212, 0.1);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-group small {
    font-size: 11px;
    color: var(--text-muted);
}

/* ===== UTILITY CLASSES ===== */
.hidden {
    display: none !important;
}

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

/* ===== GROUP MODE RESPONSIVE ===== */
@media (max-width: 1200px) {
    .ranking-panel {
        width: 240px;
        min-width: 240px;
    }
}

@media (max-width: 900px) {
    .ranking-panel {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 200;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }
    
    .ranking-panel.visible {
        transform: translateX(0);
    }
    
    .group-section,
    .group-info-section {
        margin-top: 8px;
        padding-top: 8px;
    }
    
    .group-controls {
        padding: 0;
    }
    
    .group-btn {
        padding: 8px 10px;
        font-size: 11px;
    }
    
    .group-name-row {
        padding: 6px 10px;
    }
    
    .members-section {
        margin-top: 6px;
    }
}

/* ===== COLLAPSIBLE SECTIONS ===== */
.collapsible-section {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    overflow: hidden;
    background: var(--bg-tertiary);
}

.collapsible-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s ease;
}

.collapsible-header:hover {
    background: var(--bg-card);
}

.collapsible-header h3 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin: 0;
}

.collapse-icon {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.3s ease;
}

.collapsible-section.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.collapsible-content {
    padding: 0 12px 12px;
    transition: all 0.3s ease;
}

.collapsible-section.collapsed .collapsible-content {
    display: none;
}

.instructions-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.instructions-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--text-secondary);
}

.instructions-list .step {
    width: 20px;
    height: 20px;
    background: var(--accent-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

/* ===== CANVAS CLEAR BUTTON ===== */
.canvas-clear {
    position: absolute;
    bottom: 20px;
    right: 20px;
    padding: 10px 16px;
    background: rgba(255, 71, 87, 0.1);
    border: 1px solid rgba(255, 71, 87, 0.3);
    border-radius: var(--border-radius-sm);
    color: var(--poor-color);
    font-family: var(--font-main);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    z-index: 20;
}

.canvas-clear:hover {
    background: rgba(255, 71, 87, 0.2);
    border-color: var(--poor-color);
    box-shadow: 0 0 15px rgba(255, 71, 87, 0.3);
}

.canvas-clear .btn-icon {
    font-size: 14px;
}

/* ===== CURRENT SHAPE TAG ===== */
.current-shape-tag {
    display: inline-block;
    padding: 4px 12px;
    background: var(--accent-primary);
    color: var(--bg-primary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 12px;
}

/* Update ranking header to be inline */
.ranking-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.ranking-header h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

/* ===== GROUP COUNTDOWN TOAST ===== */
.group-countdown-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: linear-gradient(135deg, rgba(255, 107, 107, 0.95), rgba(255, 71, 87, 0.95));
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(255, 71, 87, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.1);
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(10px);
}

.group-countdown-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.countdown-icon {
    font-size: 24px;
    animation: pulse 1s ease-in-out infinite;
}

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

.countdown-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.countdown-label {
    font-size: 11px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.countdown-time {
    font-size: 24px;
    font-weight: 700;
    color: #fff;
    font-family: var(--font-mono);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    animation: countdownPulse 1s ease-in-out infinite;
}

@keyframes countdownPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

