/* ============================================================
   3D Crystal Sandbox Styles
   ============================================================ */

.sandbox3d-app {
    height: calc(100vh - 56px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sandbox3d-main {
    flex: 1;
    min-height: 0;
}

/* Mode tab bar */
.sb-mode-bar {
    display: flex;
    gap: 0;
    background: var(--mp-cream-dark, #e8e8d8);
    border-bottom: 1px solid var(--mp-tan-light, #cccc99);
    flex-shrink: 0;
}

.sb-mode-tab {
    padding: 6px 20px;
    border: none;
    background: transparent;
    font-size: 0.82rem;
    font-family: var(--mp-font-ui);
    font-weight: bold;
    color: #777;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

.sb-mode-tab:hover {
    color: #444;
}

.sb-mode-tab.active {
    color: var(--mp-maroon, #660000);
    border-bottom-color: var(--mp-maroon, #660000);
}

/* 3D Viewer area */
.viewer-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    background: #e8e8e4;
}

#viewer3d {
    width: 100%;
    height: 100%;
}

#viewer3d canvas {
    display: block;
}

/* Floating toolbar (top-right) */
.viewer-toolbar {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 6px;
    z-index: 10;
}

.toolbar-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.78rem;
    cursor: pointer;
    font-family: var(--mp-font-ui);
    transition: background 0.15s, border-color 0.15s;
}

.toolbar-btn:hover {
    background: #fff;
    border-color: #999;
}

/* Floating group badge (top-left) */
.viewer-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--mp-maroon, #660000);
    color: #fff;
    padding: 5px 14px;
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: var(--mp-font-ui);
    font-weight: bold;
    z-index: 10;
    pointer-events: none;
}

/* Sidebar */
.sidebar-wrapper {
    height: 100%;
    overflow-y: auto;
    background: var(--mp-cream, #f8f8f0);
    border-left: 1px solid var(--mp-tan-light, #cccc99);
}

.sidebar-scroll {
    padding: 10px;
}

/* Sidebar cards */
.sb-card {
    background: #fff;
    border: 1px solid var(--mp-tan-light, #cccc99);
    border-radius: 6px;
    margin-bottom: 10px;
    overflow: hidden;
}

.sb-card-header {
    background: var(--mp-maroon, #660000);
    color: #fff;
    padding: 6px 12px;
    font-size: 0.78rem;
    font-weight: bold;
    font-family: var(--mp-font-ui);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sb-card-body {
    padding: 10px 12px;
}

/* Space group select */
#group-select {
    font-size: 0.85rem;
}

#group-select optgroup {
    font-weight: bold;
    font-style: normal;
}

/* Motif picker grid */
.motif-picker {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.motif-btn {
    border: 2px solid #ddd;
    border-radius: 6px;
    background: #fff;
    font-size: 0.7rem;
    font-family: var(--mp-font-ui);
    cursor: pointer;
    padding: 6px 2px;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
    color: #555;
}

.motif-btn:hover {
    border-color: #999;
    background: #fafafa;
}

.motif-btn.active {
    border-color: var(--mp-maroon, #660000);
    background: #f5f0e8;
    color: var(--mp-maroon, #660000);
    font-weight: bold;
}

/* Labels */
.sb-label {
    font-size: 0.78rem;
    font-family: var(--mp-font-ui);
    color: #555;
    display: block;
    margin-bottom: 2px;
}

/* Range sliders */
.sb-card-body .form-range {
    height: 1.2rem;
    margin-bottom: 0.25rem;
}

/* Checkboxes */
.sb-card-body .form-check {
    margin-bottom: 0.2rem;
}

.sb-card-body .form-check-label {
    font-size: 0.8rem;
    font-family: var(--mp-font-ui);
}

/* Info panel */
.sb-info .info-row {
    font-size: 0.78rem;
    font-family: var(--mp-font-ui);
    padding: 2px 0;
    border-bottom: 1px solid #f0f0f0;
}

.sb-info .info-row:last-child {
    border-bottom: none;
}

.sb-info .info-label {
    color: #777;
    font-weight: bold;
    margin-right: 4px;
}

#info-lattice {
    font-size: 0.72rem;
    font-family: monospace;
    display: block;
    margin-top: 2px;
    color: #666;
}

/* 2D link button */
.btn-link-2d {
    font-size: 0.78rem;
}

/* ============================================================
   Tutorial Panel (bottom-docked over viewer)
   ============================================================ */

.tutorial-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(20, 20, 30, 0.92);
    color: #eee;
    padding: 12px 16px 10px;
    z-index: 20;
    font-family: var(--mp-font-ui);
    backdrop-filter: blur(4px);
}

.tutorial-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 6px;
}

.tutorial-lesson-tag {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #aaa;
    flex-shrink: 0;
}

.tutorial-title {
    font-size: 0.95rem;
    font-weight: bold;
    color: #DAA520;
}

.tutorial-body {
    font-size: 0.84rem;
    line-height: 1.5;
    color: #ddd;
    margin-bottom: 10px;
    max-height: 6em;
    overflow-y: auto;
}

.tutorial-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tutorial-btn {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #ccc;
    padding: 4px 14px;
    border-radius: 4px;
    font-size: 0.78rem;
    cursor: pointer;
    font-family: var(--mp-font-ui);
    transition: background 0.15s;
}

.tutorial-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.tutorial-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.tutorial-btn-primary {
    background: var(--mp-maroon, #660000);
    border-color: var(--mp-maroon, #660000);
    color: #fff;
}

.tutorial-btn-primary:hover:not(:disabled) {
    background: #7a3348;
}

.tutorial-step-tag {
    font-size: 0.72rem;
    color: #888;
}

/* ============================================================
   Lesson List (sidebar)
   ============================================================ */

.sb-card-body-lessons {
    padding: 6px 0;
}

.lesson-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.78rem;
    font-family: var(--mp-font-ui);
    border: 1px solid transparent;
    border-radius: 4px;
    transition: background 0.15s, border-color 0.15s;
}

.lesson-item:hover {
    background: #f5f0e8;
}

.lesson-item.active {
    background: #f0ebe0;
    border-color: var(--mp-maroon, #660000);
}

.lesson-check {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--mp-tan-light, #cccc99);
    color: #666;
    font-size: 0.68rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.lesson-item .lesson-check:has(+ .lesson-name) {
    /* completed lessons get a green check */
}

.lesson-check:empty::after {
    content: '?';
}

.lesson-name {
    flex: 1;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lesson-group-tag {
    font-size: 0.65rem;
    background: var(--mp-maroon, #660000);
    color: #fff;
    padding: 1px 6px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 991.98px) {
    .sandbox3d-app {
        height: auto;
        overflow: visible;
    }

    .sandbox3d-main {
        flex: none;
    }

    .viewer-wrapper {
        height: 60vh;
        min-height: 400px;
    }

    .sidebar-wrapper {
        height: auto;
        overflow-y: visible;
        border-left: none;
        border-top: 1px solid var(--mp-tan-light, #cccc99);
    }

    .motif-picker {
        grid-template-columns: repeat(4, 1fr);
    }

    .tutorial-body {
        max-height: 4em;
    }
}

@media (max-width: 575.98px) {
    .viewer-wrapper {
        height: 50vh;
        min-height: 300px;
    }

    .viewer-badge {
        font-size: 0.75rem;
        padding: 3px 10px;
    }
}
