:root {
    --bg-color: #fcfcfc;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --accent: #2d3436;
    --picker-bg: rgba(255, 255, 255, 0.82);
    --font-sf: "SF Pro Display", "SF Pro Text", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --modal-bg: rgba(255, 255, 255, 0.9);
}

[data-theme="dark"] {
    --bg-color: #0f0f0f;
    --text-primary: #f5f5f7;
    --text-secondary: #9a9a9e;
    --accent: #f5f5f7;
    --picker-bg: rgba(20, 20, 20, 0.85);
    --modal-bg: rgba(20, 20, 20, 0.95);
}

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

body {
    font-family: var(--font-sf);
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    transition: background-color 0.4s ease;
    cursor: crosshair;

    /* REPEATING TEXTURE - MOVED FROM BEFORE TO BODY FOR VISIBILITY */
    background-image: url("https://images.unsplash.com/photo-1586075010633-247fe1bd693b?auto=format&fit=crop&q=80&w=2000");
    background-repeat: repeat;
    background-size: 1000px;
    background-attachment: fixed;
}

[data-theme="dark"] body {
    background-blend-mode: soft-light;
    filter: brightness(0.95);
}

/* Real-time Presence Cursors */
.remote-cursor {
    position: absolute;
    pointer-events: none;
    z-index: 999;
    transition: transform 0.1s linear;
    will-change: transform;
}

.ghost-crayon {
    width: 24px;
    height: 24px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.cursor-label {
    position: absolute;
    top: 28px;
    left: 12px;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--picker-bg);
    padding: 0.2rem 0.5rem;
    border-radius: 2rem;
    font-size: 0.65rem;
    white-space: nowrap;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(128, 128, 128, 0.1);
}

.cursor-avatar {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    overflow: hidden;
}

/* Administrative & Overlay Logic */

/* Admin Logic - Only show clear button in admin mode */
.reset-link {
    display: none;
}

body.is-admin .reset-link {
    display: block !important;
}

/* Admin Overrides */
body.is-admin {
    cursor: default !important;
}

body.is-admin main {
    cursor: default !important;
}

body.is-admin #interface-overlay {
    display: none !important;
}

.admin-dashboard {
    display: flex;
    gap: 1.5rem;
    padding: 1rem;
    background: var(--picker-bg);
    border-radius: 1rem;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(128, 128, 128, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
}

.stat-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
}

.admin-view {
    bottom: 2rem !important;
}

/* Modal Styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    transition: opacity 0.5s, visibility 0.5s;
}

.modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-content {
    background: var(--modal-bg);
    padding: 3rem;
    border-radius: 2rem;
    text-align: center;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.12);
    max-width: 400px;
    width: 90%;
    border: 1px solid rgba(128, 128, 128, 0.1);
}

.modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    font-weight: 400;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.modal-content input {
    width: 100%;
    padding: 1rem;
    background: rgba(128, 128, 128, 0.05);
    border: 1px solid rgba(128, 128, 128, 0.1);
    border-radius: 1rem;
    color: var(--text-primary);
    font-family: var(--font-sf);
    margin-bottom: 1.5rem;
    outline: none;
    text-align: center;
}

.modal-content button {
    padding: 0.8rem 2.5rem;
    background: var(--text-primary);
    color: var(--bg-color);
    border: none;
    border-radius: 2rem;
    cursor: pointer;
    font-family: var(--font-sf);
    transition: transform 0.2s;
}

.modal-content button:hover {
    transform: scale(1.05);
}

header {
    display: flex;
    justify-content: space-between;
    padding: 2.5rem 3rem;
    z-index: 100;
    pointer-events: none;
    position: fixed;
    top: 0;
    width: 100%;
}

.philosophical-header {
    pointer-events: auto;
}

.top-right-controls {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
}

.philosophical-header h1 {
    font-size: 1.8rem;
    font-weight: 300;
    letter-spacing: -0.01em;
    margin-bottom: 0.25rem;
}

.philosophical-header p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    max-width: 400px;
    line-height: 1.4;
    margin-bottom: 0.75rem;
}

.reset-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-sf);
    font-size: 0.8rem;
    cursor: pointer;
    text-decoration: underline;
    opacity: 0.5;
    transition: opacity 0.2s;
    padding: 0;
    margin-right: 1rem;
}

.reset-link:hover {
    opacity: 1;
}

.icon-btn {
    background: var(--picker-bg);
    border: 1px solid rgba(128, 128, 128, 0.1);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
    backdrop-filter: blur(10px);
}

.mode-icon {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1.5px solid var(--text-primary);
    transition: background 0.3s;
}

[data-theme="dark"] .mode-icon {
    background: var(--text-primary);
}

main {
    height: 100vh;
    width: 100vw;
    position: relative;
    cursor: inherit;
    overflow: hidden;
    /* Header/Footer/Overlays stay fixed */
}

#canvas-viewport {
    width: 100%;
    height: 100%;
    overflow: auto;
    /* Enable scrolling */
    -webkit-overflow-scrolling: touch;
}

#trace-canvas {
    display: block;
    /* Define world size (larger than viewport for scrollability) */
    width: 3000px;
    height: 3000px;
    background: transparent;
}

#interface-overlay {
    position: absolute;
    bottom: 2.5rem;
    left: 3rem;
    z-index: 20;
}

.controls-container {
    background: var(--picker-bg);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    padding: 0.6rem;
    border-radius: 3rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(128, 128, 128, 0.08);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.color-picker {
    display: flex;
    gap: 0.6rem;
}

.color-btn {
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: transform 0.2s;
}

.color-btn.active {
    border-color: var(--text-primary);
    transform: scale(1.1);
}

.divider {
    width: 1px;
    height: 20px;
    background: rgba(128, 128, 128, 0.15);
}

.size-controls input {
    width: 80px;
    cursor: pointer;
    accent-color: var(--text-primary);
}

/* Avatar Styling */
.pixel-avatar-tiny {
    width: 20px;
    height: 20px;
}

.pixel-avatar-small {
    width: 28px;
    height: 28px;
}

.pixel-avatar-tiny img,
.pixel-avatar-small img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    /* Maintain waxy/pixel feel */
}

/* Tooltip */
.tooltip {
    position: absolute;
    pointer-events: none;
    z-index: 1000;
    background: var(--picker-bg);
    backdrop-filter: blur(10px);
    padding: 0.4rem 0.8rem;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(128, 128, 128, 0.1);
    font-size: 0.8rem;
    transition: opacity 0.2s;
}

.tooltip.hidden {
    opacity: 0;
}

footer {
    position: fixed;
    bottom: 2.5rem;
    right: 3rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    opacity: 0.8;
}

.stats {
    opacity: 0.5;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    header {
        position: fixed;
        padding: 1.5rem;
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
        width: 100%;
        background: none;
        pointer-events: none;
    }

    .philosophical-header {
        pointer-events: auto;
        max-width: 60%;
    }

    .philosophical-header h1 {
        font-size: 1.1rem;
    }

    .philosophical-header p {
        font-size: 0.75rem;
        line-height: 1.3;
    }

    .top-right-controls {
        position: relative;
        top: 0;
        right: 0;
        pointer-events: auto;
    }

    #interface-overlay {
        position: fixed;
        bottom: 1.5rem;
        left: 1.5rem;
        transform: none;
        z-index: 100;
    }

    .controls-container {
        padding: 0.4rem;
        gap: 0.4rem;
    }

    #remote-cursors-layer,
    #trace-canvas {
        /* Zoomed out for phone */
        transform: scale(0.5);
        transform-origin: top left;
        width: 3000px;
        height: 3000px;
    }

    #canvas-viewport {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        overflow: auto;
    }

    footer {
        position: fixed;
        bottom: 1.5rem;
        right: 1.5rem;
        padding: 0;
        width: auto;
        pointer-events: none;
    }

    .user-info {
        pointer-events: auto;
        justify-content: flex-end;
    }
}

/* Touch device adjustments */
@media (hover: none) {
    body {
        cursor: crosshair;
    }

    .tooltip {
        display: none !important;
    }

    .color-btn:active,
    .icon-btn:active {
        transform: scale(0.9);
    }
}