:root {
    --bg: #ffe8b7;
    --panel: #151924;
    --panel2: #10141d;
    --ink: #e6edf7;
    --muted: #9aa3b2;
    --accent: #22d3ee;
    --sand: #f1c40f;
    --sand2: #f59e0b;
    --water: #1770ff;
    --solid: #5c6b85;
    --radius: 16px;
    --shadow: 0 12px 30px rgba(15, 15, 15, 0.35), 0 2px 10px rgba(0, 0, 0, .5);
    --success: #10b981;
    --error: #ef4444;
}

* {
    box-sizing: border-box
}

html,
body {
    height: 100%
}

body {
    margin: 0;
    background: radial-gradient(1100px 700px at 25% -10%, #18202b 0%, #0d1117 50%, #0c0f14 100%);
    color: var(--ink);
    font: 14px/1.4 ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, "Helvetica Neue", Arial
}

/* Main Menu Styles */
.menu-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.menu-card {
    background: var(--panel);
    border: 1px solid #1f2634;
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: 48px;
    max-width: 480px;
    width: 100%;
    text-align: center;
}

.menu-title {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--accent), #d8aa14);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.menu-subtitle {
    color: var(--muted);
    margin-bottom: 40px;
    font-size: 16px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 32px;
}

.btn {
    padding: 16px 24px;
    border-radius: 12px;
    border: none;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #3b82f6);
    color: white;
    box-shadow: 0 4px 14px rgba(34, 211, 238, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(34, 211, 238, 0.4);
}

.btn-secondary {
    background: var(--panel2);
    color: var(--ink);
    border: 1px solid #232a39;
}

.btn-secondary:hover {
    background: #1a1f2e;
    border-color: #2a3142;
}

.divider {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 24px 0;
    color: var(--muted);
    font-size: 14px;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #232a39;
}

.input-group {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.input-field {
    flex: 1;
    padding: 14px 16px;
    background: var(--panel2);
    border: 1px solid #232a39;
    border-radius: 12px;
    color: var(--ink);
    font-size: 16px;
    transition: all 0.3s ease;
}

.input-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

.input-field::placeholder {
    color: #6b7280;
}

.session-info {
    background: var(--panel2);
    border: 1px solid #232a39;
    border-radius: 12px;
    padding: 16px;
    margin-top: 24px;
    display: none;
}

.session-info.active {
    display: block;
    animation: slideIn 0.3s ease;
}

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

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

.session-code {
    font-size: 28px;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    color: var(--accent);
    margin: 8px 0;
    letter-spacing: 0.1em;
}

.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--panel);
    border: 1px solid #232a39;
    border-radius: 8px;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.copy-btn:hover {
    color: var(--ink);
    border-color: var(--accent);
}

.copy-btn.copied {
    color: var(--success);
    border-color: var(--success);
}

.status-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--panel);
    border-bottom: 1px solid #232a39;
    padding: 12px 20px;
    display: none;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
}

.status-bar.active {
    display: flex;
}

.status-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.user-count {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--panel2);
    border-radius: 8px;
    font-size: 13px;
}

.user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    margin-left: -8px;
    border: 2px solid var(--panel);
}

.user-avatar:first-child {
    margin-left: 0;
}

.error-message {
    color: var(--error);
    font-size: 14px;
    margin-top: 8px;
    display: none;
}

.error-message.active {
    display: block;
}

/* Sand Tray Styles */
.app {
    display: none;
    grid-template-columns: 320px 1fr;
    gap: 14px;
    height: 100%;
    padding: 14px;
    padding-top: 70px;
}

.app.active {
    display: grid;
}

.card {
    background: var(--panel);
    border: 1px solid #1f2634;
    border-radius: var(--radius);
    box-shadow: var(--shadow)
}

.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    padding: 10px
}

.seg {
    display: flex;
    background: var(--panel2);
    border: 1px solid #232a39;
    border-radius: 12px;
    overflow: hidden
}

.seg button {
    padding: 8px 12px;
    background: transparent;
    color: var(--muted);
    border: 0;
    cursor: pointer
}

.seg button.active {
    background: linear-gradient(180deg, #222a3a, #141a26);
    color: var(--ink)
}

.range {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px
}

.range input[type=range] {
    width: 100%
}

.title {
    padding: 10px 12px;
    border-bottom: 1px solid #222a39;
    font-weight: 700
}

.palette {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 10px
}

.chip {
    user-select: none;
    cursor: grab;
    border-radius: 12px;
    border: 1px solid #273043;
    background: linear-gradient(180deg, #202736, #121722);
    aspect-ratio: 1.2/1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center
}

.chip:active {
    cursor: grabbing
}

.chip .cap {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 11px;
    color: #9aa4b6
}

.stage {
    position: relative
}

.canvas-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center
}

#three {
    width: 100%;
    height: 100%;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid #1f2634
}

.help {
    position: absolute;
    bottom: 12px;
    left: 12px;
    font-size: 12px;
    color: #9aa4b6;
    background: #0d1118d0;
    padding: 8px 10px;
    border: 1px solid #1f2734;
    border-radius: 10px
}

.disconnect-btn {
    padding: 8px 16px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    color: var(--error);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.disconnect-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--error);
}

@media (max-width: 980px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        padding-top: 70px;
    }

    .menu-card {
        padding: 32px 24px;
    }
}

/* Make the whole app fit the viewport (padding stays inside because of border-box) */
.app {
    height: 100vh;
    /* was: height: 100% */
    overflow: hidden;
    /* prevent page scroll; inner areas will scroll */
}

/* Grid items must be allowed to shrink; otherwise they force page scroll */
.app>.sidebar,
.app>.stage {
    min-width: 0;
    min-height: 0;
}

/* Make the left column a flex column so the palette section can take remaining space */
.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* critical for nested scroll areas */
}

.toolbar .seg button {
    font-size: 11px;
}

.corner-btn {
    position: absolute;
    right: 14px;
    bottom: 14px;
    z-index: 20;
    /* above the canvas */
    pointer-events: auto;
    /* clickable */
}

.corner-stack {
    position: absolute;
    right: 12px;
    bottom: 12px;
    display: flex;
    flex-direction: column;
    /* stack vertically */
    gap: 8px;
    /* space between buttons */
    z-index: 10;
}

.corner-stack .btn {
    width: 44px;
    /* optional: consistent size */
    height: 44px;
    border-radius: 12px;
    padding: 0;
}

.help {
    position: absolute;
    bottom: 12px;
    left: 12px;
    font-size: 12px;
    color: #9aa4b6;
    background: rgba(13, 17, 24, 0.95);
    padding: 12px 16px;
    border: 1px solid #1f2734;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    max-width: 320px;
    line-height: 1.5;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.help b {
    color: var(--accent);
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
}

/* Object selection styles */
.object-selected {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Keyboard hints */
.keyboard-hint {
    display: inline-block;
    padding: 2px 6px;
    background: var(--panel2);
    border: 1px solid #232a39;
    border-radius: 4px;
    font-family: monospace;
    font-size: 11px;
    margin: 0 2px;
}