/* touch-action: none prevents mobile scrolling while interacting with 3D scene */
body { margin: 0; overflow: hidden; background-color: #f3f4f6; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; user-select: none; touch-action: none; height: 100%; width: 100%; }
html { height: 100%; width: 100%; }
canvas { display: block; outline: none; }

/* --- Landing Page --- */
#landing-page {
    position: fixed; inset: 0; background: #fffbeb; z-index: 50; overflow-y: auto; text-align: center;
    transition: opacity 0.5s ease;
}
.landing-content {
    max-width: 600px; margin: 0 auto; padding: 40px 20px;
}
.hero-img {
    width: 100%; max-width: 400px; margin: 20px auto; border-radius: 20px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: rotate(-2deg); transition: transform 0.3s;
}
.hero-img:hover { transform: rotate(2deg) scale(1.02); }

.cta-btn {
    background: #eab308; color: white; font-size: 1.5rem; font-weight: 900; padding: 15px 40px; border-radius: 50px;
    border: 4px solid #854d0e; cursor: pointer; margin-top: 20px; margin-bottom: 60px;
    box-shadow: 0 10px 0 #854d0e; transition: all 0.1s; text-transform: uppercase; letter-spacing: 2px;
}
.cta-btn:active { transform: translateY(10px); box-shadow: 0 0 0 #854d0e; }

.explainer-section {
    border-top: 2px dashed #d1d5db; padding-top: 40px; color: #4b5563;
}
.lore-img {
    width: 100%; border-radius: 10px; margin: 20px 0; border: 1px solid #e5e7eb;
}

/* --- Layout Containers --- */

/* Collapsible Tool Panel (Right) */
#ui-container {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 300px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 20px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-height: 80vh;
    overflow-y: auto;
    pointer-events: auto;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
    z-index: 10;
    display: none; /* Hidden until started */
}
#ui-container.collapsed {
    transform: translateX(340px); /* Slide out to right */
    opacity: 0;
    pointer-events: none;
}

/* Menu Toggle Button */
#menu-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 20;
    background: white;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.2s;
    display: none;
}
#menu-toggle:hover { background: #f9fafb; }

/* Bottom Navigation Bar */
#bottom-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 10px 20px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
    display: none;
}

/* Undo/Redo Container (Bottom Left) */
#history-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    display: flex;
    gap: 10px;
    z-index: 15;
    display: none;
}

/* Info Button */
#info-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #6b7280;
    cursor: pointer;
    border: 1px solid #e5e7eb;
    z-index: 10;
    display: none;
}
#info-btn:hover { background: white; color: #3b82f6; }

/* Toast Message */
#toast {
    position: absolute; top: 15%; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.8); color: #fff; padding: 12px 24px; border-radius: 50px;
    font-size: 0.9rem; pointer-events: none; opacity: 0; transition: opacity 0.5s; z-index: 100;
    text-align: center; width: 80%; max-width: 400px;
}

/* --- UI Components --- */

.stage-nav { display: flex; align-items: center; gap: 15px; width: 100%; justify-content: center; }
.stage-dots { display: flex; gap: 6px; }
.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #e5e7eb;
    transition: all 0.3s;
}
.dot.active { background: #eab308; transform: scale(1.2); }

.nav-btn {
    background: none;
    border: none;
    color: #4b5563;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.2rem;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.nav-btn:hover:not(:disabled) { background: #f3f4f6; color: #1f2937; }
.nav-btn:disabled { opacity: 0.3; cursor: default; }

/* Content Area in Side Panel */
.stage-pane { display: none; animation: fadeIn 0.3s ease; }
.stage-pane.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.stage-title {
    font-size: 1.1rem;
    font-weight: 800;
    color: #854d0e;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.stage-desc { font-size: 0.85rem; color: #6b7280; margin-bottom: 15px; }

/* Buttons */
.btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    background: white;
    color: #374151;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.btn:hover { background: #f9fafb; border-color: #d1d5db; transform: translateY(-1px); }
.btn.active { 
    background: #fef08a; 
    border-color: #eab308; 
    color: #854d0e; 
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05); 
}
.btn-action { background: #3b82f6; color: white; border: none; }
.btn-action:hover { background: #2563eb; }
.btn-celebrate { background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%); color: white; border: none; font-size: 1.1rem; }
.btn-celebrate:hover { transform: scale(1.05); box-shadow: 0 10px 20px rgba(245, 158, 11, 0.3); }

.btn-icon { width: 44px; height: 44px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid #e5e7eb; background: white; cursor: pointer; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); }
.btn-icon:hover:not(:disabled) { background: #f9fafb; border-color: #d1d5db; transform: translateY(-1px); }
.btn-icon:disabled { opacity: 0.5; cursor: default; box-shadow: none; transform: none; }

/* Toggle Switch for Draw/Move */
.toggle-switch {
    display: flex; background: #f3f4f6; padding: 4px; border-radius: 8px; margin-bottom: 12px;
}
.toggle-option {
    flex: 1; text-align: center; padding: 6px; font-size: 0.85rem; cursor: pointer; border-radius: 6px; font-weight: 600; color: #6b7280; transition: all 0.2s;
}
.toggle-option.selected {
    background: white; color: #374151; box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Toggle Switch (Visual) */
.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    margin-bottom: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.control-label { font-weight: 600; color: #374151; display: flex; align-items: center; gap: 8px; }

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #e5e7eb;
    transition: .4s;
    border-radius: 34px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .slider { background-color: #eab308; }
input:checked + .slider:before { transform: translateX(22px); }

/* Inputs */
.slider-container { margin-bottom: 15px; background: #f9fafb; padding: 10px; border-radius: 8px; }
.slider-label { display: flex; justify-content: space-between; font-size: 0.8rem; margin-bottom: 8px; color: #4b5563; font-weight: 600; }
input[type=range] { width: 100%; accent-color: #eab308; }

/* Color Picker Row */
.color-row { display: flex; align-items: center; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.color-dot { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 2px solid white; box-shadow: 0 0 0 1px #d1d5db; transition: transform 0.2s;}
.color-dot:hover { transform: scale(1.1); }
.color-dot.selected { transform: scale(1.2); box-shadow: 0 0 0 2px #3b82f6; }

input[type="color"] {
    -webkit-appearance: none; border: none; width: 32px; height: 32px; border-radius: 50%; overflow: hidden; cursor: pointer; padding: 0; background: none;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 2px solid white; border-radius: 50%; box-shadow: 0 0 0 1px #d1d5db; }

/* Modals */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100; justify-content: center; align-items: center;
}
.modal-card {
    background: white; padding: 25px; border-radius: 20px; text-align: center; max-width: 400px; width: 90%;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#ear-canvas { border: 2px dashed #d1d5db; border-radius: 12px; cursor: crosshair; margin: 15px 0; background: #fafafa; }

#instructions {
    position: absolute; top: 30px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.8); color: white; padding: 10px 20px; border-radius: 30px;
    font-size: 0.95rem; pointer-events: none; opacity: 0; transition: opacity 0.3s;
    font-weight: 500; backdrop-filter: blur(4px); z-index: 5;
}