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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
    height: 100vh;
    overflow: hidden;
}

#app {
    display: grid;
    grid-template-columns: 320px 1fr;
    grid-template-rows: auto 1fr;
    height: 100vh;
}

/* Summary bar spans full width */
#summary-bar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 24px;
    background: #16213e;
    border-bottom: 1px solid #0f3460;
}

#summary-bar h1 {
    font-size: 18px;
    font-weight: 600;
    color: #e94560;
    margin-right: 16px;
}

.subtitle {
    font-size: 12px;
    color: #7a8ba0;
    letter-spacing: 0.5px;
}

#advanced-toggle-bar {
    margin: 8px 0 4px;
}

#advanced-toggle {
    font-size: 11px;
    padding: 4px 12px;
    background: #1a1a2e;
    border: 1px solid #0f3460;
    color: #7a8ba0;
    cursor: pointer;
    border-radius: 3px;
}

#advanced-toggle:hover {
    color: #4fc3f7;
    border-color: #4fc3f7;
}

/* Instructions box */
.explore-instructions {
    margin: 12px 0 8px;
    padding: 10px 12px;
    border-left: 3px solid #0f3460;
    background: rgba(15, 52, 96, 0.15);
    font-size: 11px;
    line-height: 1.7;
    color: #8a9ab5;
}
.explore-instructions strong {
    color: #4fc3f7;
    font-size: 10px;
    letter-spacing: 1px;
    display: block;
    margin-bottom: 4px;
}
.explore-instructions kbd {
    background: #0f3460;
    color: #c0d0e0;
    padding: 1px 5px;
    border-radius: 2px;
    font-size: 10px;
    font-family: inherit;
}

/* Mode switcher highlight */
.mode-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin: 10px 0 6px;
    background: rgba(15, 52, 96, 0.25);
    border: 1px solid #0f3460;
    border-radius: 4px;
}
.mode-bar label {
    font-size: 11px;
    color: #8a9ab5;
}
.mode-bar select {
    flex: 1;
}

/* Loading spinner */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
.loading-spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid #0f3460;
    border-top: 3px solid #4fc3f7;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

/* Loading overlay in viewer */
#viewer-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: #7a8ba0;
    font-size: 13px;
    line-height: 1.8;
    padding: 20px;
}
#viewer-placeholder .loading-fact {
    font-size: 11px;
    color: #5a6a80;
    font-style: italic;
    margin-top: 8px;
    min-height: 16px;
    transition: opacity 0.4s;
}

/* Sleep section rework */
.sleep-description {
    font-size: 11px;
    color: #8a9ab5;
    margin-bottom: 8px;
    line-height: 1.5;
}
.sleep-hint {
    font-size: 10px;
    color: #6a7a90;
    margin-top: 6px;
    font-style: italic;
}

/* Mining status overlay — centered in viewport */
#mine-status-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #4fc3f7;
    font-size: 14px;
    letter-spacing: 1px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    text-shadow: 0 0 8px rgba(0,0,0,0.8);
}
#mine-status-overlay.visible {
    opacity: 0.7;
}

.stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}

.stat-value {
    font-weight: 700;
    font-size: 16px;
}

.stat-value.green { color: #4ecca3; }
.stat-value.red { color: #e94560; }
.stat-value.blue { color: #4fc3f7; }

/* Left panel: results table */
#left-panel {
    overflow-y: auto;
    padding: 16px;
    border-right: 1px solid #0f3460;
}

#left-panel h2 {
    font-size: 15px;
    margin-bottom: 12px;
    color: #a0a0b8;
}

#results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

#results-table thead th {
    position: sticky;
    top: 0;
    background: #16213e;
    text-align: left;
    padding: 8px 10px;
    border-bottom: 2px solid #0f3460;
    color: #a0a0b8;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#results-table tbody tr {
    cursor: pointer;
    transition: background 0.15s;
}

#results-table tbody tr:nth-child(even) {
    background: rgba(255,255,255,0.02);
}

#results-table tbody tr:hover {
    background: rgba(79, 195, 247, 0.08);
}

#results-table tbody tr.selected {
    background: rgba(79, 195, 247, 0.15);
}

#results-table td {
    padding: 7px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-pass {
    background: rgba(78, 204, 163, 0.15);
    color: #4ecca3;
}

.badge-fail {
    background: rgba(233, 69, 96, 0.15);
    color: #e94560;
}

.btn-view {
    padding: 3px 10px;
    background: #0f3460;
    color: #4fc3f7;
    border: 1px solid #4fc3f7;
    border-radius: 3px;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-view:hover {
    background: #4fc3f7;
    color: #1a1a2e;
}

/* Right panel: 3D viewer */
#right-panel {
    display: flex;
    flex-direction: column;
    position: relative;
    background: #12121f;
}

#viewer-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: #16213e;
    border-bottom: 1px solid #0f3460;
    font-size: 13px;
    flex-wrap: wrap;
}

#viewer-toolbar label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    color: #a0a0b8;
}

#viewer-toolbar select {
    padding: 2px 6px;
    background: #1a1a2e;
    color: #e0e0e0;
    border: 1px solid #0f3460;
    border-radius: 3px;
    font-size: 12px;
    cursor: pointer;
}

#viewer-toolbar input[type="range"] {
    width: 80px;
    cursor: pointer;
}

#mine-radius-val {
    color: #4fc3f7;
    font-weight: 600;
    min-width: 16px;
    text-align: center;
}

#mesh-info {
    margin-left: auto;
    color: #a0a0b8;
    font-size: 12px;
}

/* Material legend */
#material-legend {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
    background: #16213e;
    border-bottom: 1px solid #0f3460;
    font-size: 12px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #a0a0b8;
}

.legend-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid rgba(255,255,255,0.15);
}

#viewer-container {
    flex: 1;
    position: relative;
}

#viewer-container canvas {
    display: block;
}

#viewer-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    font-size: 14px;
}

#run-batch-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: #16213e;
    border-top: 1px solid #0f3460;
    font-size: 13px;
}

#run-batch-bar button {
    padding: 5px 14px;
    background: #e94560;
    color: white;
    border: none;
    border-radius: 3px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
}

#run-batch-bar button:hover {
    background: #c73652;
}

#run-batch-bar button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#batch-status {
    color: #a0a0b8;
}

/* Multi-chunk generator panel */
#generate-panel {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #0f3460;
}

#generate-panel h2 {
    font-size: 15px;
    margin-bottom: 10px;
    color: #a0a0b8;
}

.gen-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.gen-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.gen-row label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: #a0a0b8;
}

.gen-row input[type="number"] {
    width: 60px;
    padding: 4px 6px;
    background: #16213e;
    color: #e0e0e0;
    border: 1px solid #0f3460;
    border-radius: 3px;
    font-size: 13px;
}

#gen-btn {
    padding: 5px 14px;
    background: #4fc3f7;
    color: #1a1a2e;
    border: none;
    border-radius: 3px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
}

#gen-btn:hover {
    background: #81d4fa;
}

#gen-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#gen-status {
    font-size: 12px;
    color: #a0a0b8;
}

/* Closed boundary toggle */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #a0a0b8;
    cursor: pointer;
}

.toggle-hint {
    font-size: 11px;
    color: #666;
}

/* Collapsible settings sections */
.settings-section {
    margin-top: 8px;
    border: 1px solid #0f3460;
    border-radius: 4px;
    overflow: hidden;
}

.settings-section summary {
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #a0a0b8;
    background: #16213e;
    cursor: pointer;
    user-select: none;
    list-style: none;
}

.settings-section summary::-webkit-details-marker {
    display: none;
}

.settings-section summary::before {
    content: "\25b6";
    display: inline-block;
    margin-right: 6px;
    font-size: 10px;
    transition: transform 0.15s;
}

.settings-section[open] summary::before {
    transform: rotate(90deg);
}

.settings-section summary:hover {
    background: #1a2a4e;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    padding: 8px 10px;
    background: rgba(22, 33, 62, 0.5);
}

.settings-grid label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    font-size: 12px;
    color: #a0a0b8;
}

.settings-grid input[type="number"] {
    width: 70px;
    padding: 3px 5px;
    background: #1a1a2e;
    color: #e0e0e0;
    border: 1px solid #0f3460;
    border-radius: 3px;
    font-size: 12px;
}

.settings-grid input[type="number"]:focus {
    outline: none;
    border-color: #4fc3f7;
    box-shadow: 0 0 4px rgba(79, 195, 247, 0.3);
}

.settings-grid input[type="number"]::placeholder {
    color: #555;
}

/* Ore settings subsections */
.ore-subsection {
    padding: 6px 10px;
    border-top: 1px solid rgba(15, 52, 96, 0.5);
}

.ore-label {
    font-weight: 600;
    font-size: 12px;
}

.ore-hint {
    font-size: 11px;
    color: #555;
    font-style: italic;
}

.ore-realism-toggles {
    padding: 4px 10px 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
}

.ore-realism-toggles .toggle-label {
    font-size: 11px;
    color: #8a8aaa;
}

.ore-realism-toggles input[type="checkbox"] {
    margin-right: 3px;
}

#custom-exports {
    margin-top: 10px;
}

.export-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    margin-top: 4px;
    background: rgba(79, 195, 247, 0.05);
    border: 1px solid rgba(79, 195, 247, 0.1);
    border-radius: 3px;
    font-size: 12px;
}

.export-item span {
    color: #4fc3f7;
}

.export-item.selected {
    background: rgba(79, 195, 247, 0.15);
    border-color: #4fc3f7;
}

.export-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.btn-delete {
    padding: 3px 8px;
    background: transparent;
    color: #e94560;
    border: 1px solid #e94560;
    border-radius: 3px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
    line-height: 1;
}

.btn-delete:hover {
    background: #e94560;
    color: #1a1a2e;
}

.settings-grid label[title],
.gen-row label[title] {
    cursor: help;
}

/* Preset bar */
.preset-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding: 6px 0;
}

.preset-label {
    font-size: 12px;
    color: #a0a0b8;
    margin-right: 4px;
    font-weight: 600;
}

.preset-slot {
    width: 28px;
    height: 24px;
    padding: 0;
    background: #16213e;
    color: #555;
    border: 1px solid #0f3460;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.preset-slot:hover {
    border-color: #4fc3f7;
    color: #a0a0b8;
}

.preset-slot.active {
    border-color: #4fc3f7;
    color: #4fc3f7;
    background: rgba(79, 195, 247, 0.1);
}

.preset-slot.filled {
    color: #4ecca3;
    border-color: rgba(78, 204, 163, 0.4);
}

.preset-slot.filled.active {
    color: #4ecca3;
    border-color: #4ecca3;
    background: rgba(78, 204, 163, 0.1);
}

#preset-save,
#preset-delete,
#preset-reset {
    padding: 3px 8px;
    background: #16213e;
    color: #a0a0b8;
    border: 1px solid #0f3460;
    border-radius: 3px;
    font-size: 11px;
    cursor: pointer;
    margin-left: 4px;
    transition: all 0.15s;
}

#preset-save:hover {
    border-color: #4ecca3;
    color: #4ecca3;
}

#preset-delete:hover {
    border-color: #e94560;
    color: #e94560;
}

#preset-reset:hover {
    border-color: #ffb74d;
    color: #ffb74d;
}

/* Scrollbar styling */
#left-panel::-webkit-scrollbar {
    width: 6px;
}

#left-panel::-webkit-scrollbar-track {
    background: transparent;
}

#left-panel::-webkit-scrollbar-thumb {
    background: #0f3460;
    border-radius: 3px;
}

/* Toast notifications */
#toast-container {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

.mine-toast {
    background: rgba(79,195,247,0.9);
    padding: 8px 20px;
    border-radius: 4px;
    color: #1a1a2e;
    font-weight: 600;
    font-size: 13px;
    margin-top: 4px;
    animation: toast-fade 3s ease-in-out forwards;
}

@keyframes toast-fade {
    0% { opacity: 0; transform: translateY(10px); }
    10% { opacity: 1; transform: translateY(0); }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

/* Deep Sleep section */
.sleep-section {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #0f3460;
}

.sleep-heading {
    font-size: 13px;
    font-weight: 600;
    color: #a0a0b8;
    margin-bottom: 8px;
}

.action-btn {
    padding: 5px 14px;
    background: #0f3460;
    color: #e0e0e0;
    border: 1px solid #4fc3f7;
    border-radius: 3px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

.action-btn:hover {
    background: #4fc3f7;
    color: #1a1a2e;
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#toggle-before-after-btn {
    background: #16213e;
    border-color: #a0a0b8;
    color: #a0a0b8;
}

#toggle-before-after-btn:hover {
    background: #a0a0b8;
    color: #1a1a2e;
}

#toggle-before-after-btn.showing-before {
    border-color: #ffb74d;
    color: #ffb74d;
}

#toggle-before-after-btn.showing-before:hover {
    background: #ffb74d;
    color: #1a1a2e;
}

#sleep-status {
    font-size: 12px;
    color: #a0a0b8;
}

/* Sleep transform log */
#sleep-log {
    margin-top: 8px;
    max-height: 200px;
    overflow-y: auto;
    background: #111122;
    border: 1px solid #0f3460;
    border-radius: 4px;
    padding: 8px 10px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 12px;
}

#sleep-log::-webkit-scrollbar {
    width: 5px;
}

#sleep-log::-webkit-scrollbar-track {
    background: transparent;
}

#sleep-log::-webkit-scrollbar-thumb {
    background: #0f3460;
    border-radius: 3px;
}

.sleep-log-entry {
    padding: 2px 0;
    color: #c0c0d0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.sleep-log-entry:last-child {
    border-bottom: none;
}

.sleep-log-count {
    color: #4fc3f7;
    font-weight: 600;
    margin-right: 4px;
}

/* Sleep stats summary */
.sleep-stats {
    margin-top: 6px;
    padding: 6px 10px;
    background: rgba(79,195,247,0.05);
    border: 1px solid rgba(79,195,247,0.1);
    border-radius: 4px;
    font-size: 12px;
    color: #a0a0b8;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.sleep-stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.sleep-stat-value {
    color: #4fc3f7;
    font-weight: 600;
}

/* Sleep material diff table */
#sleep-diff {
    margin-top: 8px;
}

#sleep-diff table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

#sleep-diff thead th {
    text-align: left;
    padding: 4px 8px;
    background: #16213e;
    color: #a0a0b8;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 1px solid #0f3460;
}

#sleep-diff tbody td {
    padding: 3px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    color: #c0c0d0;
}

#sleep-diff tbody tr:hover {
    background: rgba(79,195,247,0.05);
}

.diff-positive {
    color: #4ecca3;
    font-weight: 600;
}

.diff-negative {
    color: #e94560;
    font-weight: 600;
}

.diff-zero {
    color: #555;
}
