:root {
    --accent: #38bdf8;
    --accent-2: #a78bfa;
    --font: "Inter", "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
    --bg: #0f172a;
    --panel: #111827;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --card: #0b1220;
    --border: #1f2937;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    --surface-gradient-1: rgba(56, 189, 248, 0.08);
    --surface-gradient-2: rgba(167, 139, 250, 0.1);
    --fade-bg: rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
    --bg: #f8fafc;
    --panel: #ffffff;
    --text: #0f172a;
    --muted: #475569;
    --card: #f1f5f9;
    --border: #e2e8f0;
    --shadow: 0 12px 40px rgba(15, 23, 42, 0.16);
    --surface-gradient-1: rgba(56, 189, 248, 0.12);
    --surface-gradient-2: rgba(167, 139, 250, 0.15);
    --fade-bg: rgba(255, 255, 255, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: radial-gradient(circle at 20% 20%, var(--surface-gradient-1), transparent 30%),
    radial-gradient(circle at 80% 0%, var(--surface-gradient-2), transparent 32%),
    var(--bg);
    color: var(--text);
    font-family: var(--font);
    min-height: 100vh;
}

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 20px 60px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

h1 {
    margin: 0;
    letter-spacing: 0.5px;
}

.subtitle {
    margin: 4px 0 0;
    color: var(--muted);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pill-btn.auth-btn {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: #0b1727;
    border: none;
    padding: 8px 12px;
}

.pill-btn.auth-btn:hover {
    background: linear-gradient(135deg, #34d399, #22c55e);
}

.app-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 1rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    gap: 0.75rem;
    overflow: visible;
}

.app-bar-left .app-logo {
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--text);
}

.app-bar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

.app-bar-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(148, 163, 184, 0.08);
    color: var(--text);
    cursor: pointer;
    transition: background 120ms ease, transform 120ms ease;
}

.app-bar-btn:hover {
    background: rgba(148, 163, 184, 0.18);
    transform: translateY(-1px);
}

.app-bar-icon {
    font-size: 1rem;
    line-height: 1;
}

.app-bar-label {
    font-size: 0.92rem;
}

.export-menu {
    position: absolute;
    display: none;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: 12px;
    padding: 0.35rem;
    min-width: 160px;
    z-index: 1000;
    pointer-events: auto;
}

.export-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.export-modal {
    background: var(--panel);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: 14px;
    padding: 1rem;
    min-width: 220px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.export-modal h4 {
    margin: 0 0 0.25rem 0;
    color: var(--text);
    font-size: 1rem;
}

.export-modal button {
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: var(--text);
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
}

.export-modal button:hover {
    background: rgba(148, 163, 184, 0.18);
}

.export-menu.open {
    display: flex;
}

.export-menu button {
    background: transparent;
    border: none;
    text-align: left;
    color: var(--text);
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    cursor: pointer;
}

.export-menu button:hover {
    background: rgba(148, 163, 184, 0.12);
}

@media (max-width: 640px) {
    .app-bar {
        padding: 0.35rem 0.75rem;
    }
    .app-bar-label {
        display: none;
    }
    .app-bar-btn {
        padding: 0.4rem 0.55rem;
        border-radius: 12px;
    }
}

.floating-export-menu {
    position: absolute;
}

.sheet-handle,
.sheet-tabs {
    display: none;
}

.full-width {
    width: 100%;
    justify-content: center;
}

.scene-search {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

.scene-search input {
    border-radius: 14px;
}

.search-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #0b1220;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
    padding: 8px 0;
    display: none;
    max-height: 280px;
    overflow-y: auto;
    z-index: 20;
    animation: dropdownIn 180ms ease;
}

.search-dropdown.open {
    display: block;
}

.search-item {
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: var(--text);
    cursor: pointer;
}

.search-item:hover,
.search-item.active {
    background: rgba(56, 189, 248, 0.08);
}

.search-item .name {
    font-weight: 700;
}

.search-item .meta {
    font-size: 12px;
    color: var(--muted);
}

.search-item .desc {
    font-size: 12px;
    color: var(--muted);
}

@keyframes dropdownIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.badge {
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    color: #0b1021;
    padding: 8px 14px;
    border-radius: 999px;
    font-weight: 700;
    box-shadow: var(--shadow);
}

.layout {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 18px;
}

.layout.sidebar-collapsed {
    grid-template-columns: 1fr 72px;
}

.canvas-wrapper {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    position: relative;
    box-shadow: var(--shadow);
    overflow: hidden;
}

#scene {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 16px;
    background: radial-gradient(circle at 30% 30%, var(--surface-gradient-1), transparent 35%),
    radial-gradient(circle at 70% 20%, var(--surface-gradient-2), transparent 40%),
    var(--bg);
    cursor: grab;
}

#overlay {
    position: absolute;
    inset: 12px;
    pointer-events: none;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.controls {
    background: var(--panel);
    border-radius: 16px;
    padding: 0;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
    width: 100%;
    max-width: 380px;
}

/* Desktop sidebar toggle + rail */
.sidebar-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    z-index: 4;
}
.sidebar-toggle .chevron {
    display: inline-block;
    transform: rotate(0deg);
    transition: transform 0.18s ease;
}
.controls.sidebar--collapsed .sidebar-toggle .chevron {
    transform: rotate(180deg);
}
.sidebar-toggle:hover {
    box-shadow: 0 8px 20px rgba(0,0,0,0.35);
}

.icon-rail {
    display: none;
    position: absolute;
    inset: 0 0 0 auto;
    width: 64px;
    background: var(--panel);
    border-left: 1px solid var(--border);
    padding: 72px 12px 12px;
    box-shadow: inset 1px 0 0 rgba(255,255,255,0.02);
    z-index: 3;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}
.icon-rail .rail-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--card);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    flex: 0 0 auto;
}
.icon-rail .rail-icon img {
    width: 20px;
    height: 20px;
    display: block;
}
.icon-rail .rail-icon:hover {
    transform: scale(1.04);
    border-color: var(--accent);
    box-shadow: 0 6px 16px rgba(0,0,0,0.35), 0 0 8px rgba(56,189,248,0.3);
}

/* Accordion headers */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    border: 1px solid var(--border);
    background: linear-gradient(145deg, var(--card), rgba(255,255,255,0.02));
    color: var(--text);
    border-radius: 12px;
    padding: 10px 12px;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
    margin-bottom: 10px;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.section-header:hover {
    transform: scale(1.01);
    box-shadow: 0 10px 24px rgba(0,0,0,0.3), 0 0 8px rgba(56,189,248,0.18);
}
.section-header .header-left {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}
.section-header .section-icon {
    width: 18px;
    height: 18px;
}
.section-header .chevron {
    transition: transform 0.2s ease;
}
.control-card.collapsed .section-header .chevron {
    transform: rotate(-90deg);
}
.section-body {
    overflow: hidden;
    transition: max-height 0.2s ease, opacity 0.18s ease;
    max-height: 2000px;
    opacity: 1;
}
.control-card.collapsed .section-body {
    max-height: 0;
    opacity: 0;
    padding-bottom: 0;
}

.mobile-tabs {
    display: none;
}

.mobile-tabs .tabs-left {
    display: flex;
    gap: 8px;
    flex: 1;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* --- Tab Overflow Fade Hints --- */
.mobile-tabs-fade-left,
.mobile-tabs-fade-right {
    position: absolute;
    top: 0;
    width: 24px;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    opacity: 0; /* default hidden */
    transition: opacity 0.15s ease;
}

.mobile-tabs-fade-left {
    left: 0;
    background: linear-gradient(to right, var(--fade-bg), transparent);
}

.mobile-tabs-fade-right {
    right: 0;
    background: linear-gradient(to left, var(--fade-bg), transparent);
}


.control-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 18px 10px;
    max-height: calc(620px + 40px);
    overflow-y: auto;
}

.control-stack::-webkit-scrollbar {
    width: 10px;
}

.control-stack::-webkit-scrollbar-track {
    background: var(--panel);
    border-radius: 10px;
}

.control-stack::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--accent), var(--accent-2));
    border-radius: 10px;
    border: 2px solid var(--panel);
}

.control-stack::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--accent-2), var(--accent));
}

.control-stack {
    scrollbar-color: var(--accent) var(--panel);
    scrollbar-width: thin;
}

.control-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 14px 10px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
    position: relative;
    overflow: visible;
}

.control-group {
    margin-bottom: 14px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    color: var(--muted);
}

.card-header h3 {
    margin: 0;
    color: var(--text);
    letter-spacing: 0.3px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    border: 1px solid var(--border);
    background: linear-gradient(145deg, var(--card), rgba(255,255,255,0.02));
    color: var(--text);
    border-radius: 12px;
    padding: 10px 12px;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
    margin-bottom: 10px;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.section-body {
    display: block;
    overflow: hidden;
    transition: max-height 0.2s ease, opacity 0.18s ease;
    max-height: 2000px;
    opacity: 1;
}

.pill-btn {
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    border-radius: 999px;
    padding: 8px 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow);
}

.pill-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.pill-btn.primary {
    background: linear-gradient(135deg, var(--accent), #22c55e);
    color: #0b1727;
    border: none;
    box-shadow: var(--shadow);
}

.pill-btn.primary:hover {
    background: linear-gradient(135deg, #34d399, var(--accent));
}

.pill-btn.secondary {
    background: var(--card);
    color: var(--text);
}

.scene-card input[type="text"] {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 15px;
}

.mobile-theme {
    display: none;
    margin: 8px 0 4px;
}

.desktop-theme {
    display: inline-flex;
}

.mobile-handle {
    display: none;
    width: 100%;
    background: transparent;
    border: none;
    padding: 8px 0 2px;
    text-align: center;
    margin: 0;
    cursor: ns-resize;
    touch-action: none;
}

.handle-bars {
    display: inline-block;
    width: 42px;
    height: 12px;
    position: relative;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.15);
}
.handle-bars::before,
.handle-bars::after {
    content: "";
    position: absolute;
    left: 8px;
    right: 8px;
    height: 3px;
    background: rgba(148, 163, 184, 0.7);
    border-radius: 6px;
}
.handle-bars::before { top: 3px; }
.handle-bars::after { bottom: 3px; }


/* Desktop layout and collapsible sidebar */
@media (min-width: 1024px) {
  .layout {
    grid-template-columns: 1.1fr 0.9fr;
  }

  .controls {
    width: 100%;
    max-width: 380px;
    position: relative;
    overflow: visible;
  }

  .sidebar-toggle {
    display: inline-flex;
    z-index: 5;
  }

  .section-header {
    display: flex;
  }

  /* Collapsed sidebar = only icon rail + toggle visible */
  .controls.sidebar--collapsed {
    width: 72px;
    min-width: 72px;
    max-width: 72px;
    padding: 12px 0;
    border: 1px solid var(--border);
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  /* Hide everything in the panel except the toggle + icon rail */
  .controls.sidebar--collapsed > *:not(.sidebar-toggle):not(.icon-rail) {
    display: none !important;
  }

  .controls.sidebar--collapsed .sidebar-toggle {
    right: 8px;
    z-index: 6;
  }

  .controls.sidebar--collapsed .icon-rail {
    display: flex;
    position: absolute;
    top: 56px;
    bottom: 12px;
    left: 8px;
    right: 8px;
    width: auto;
    padding: 0;
    gap: 12px;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-y: auto;
  }

  .controls.sidebar--collapsed .icon-rail .rail-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--card);
  }

  .controls.sidebar--collapsed .icon-rail .rail-icon img {
    width: 22px;
    height: 22px;
    opacity: 0.9;
    filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.4));
  }
}


label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
}

select, input[type="range"] {
    width: 100%;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    font-size: 15px;
}

.custom-select {
    position: relative;
}

.custom-select button {
    width: 100%;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    cursor: pointer;
    box-shadow: var(--shadow);
}

.custom-select .chevron {
    color: var(--muted);
    font-size: 13px;
}

.shape-icon {
    width: 22px;
    text-align: center;
    display: inline-block;
}

.custom-select .options {
    position: absolute;
    z-index: 10;
    top: 110%;
    left: 0;
    right: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: none;
}

.custom-select .options.open {
    display: block;
    max-height: 60vh;
    overflow-y: auto;
}

.custom-select .option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    color: var(--text);
}

.custom-select .option:hover {
    background: rgba(148, 163, 184, 0.12);
}

.custom-select .option .label {
    flex: 1;
}

.scene-card .scene-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
}

.button-row {
    width: 100%;
    gap: 10px;
}

.row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.label-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.strong { font-weight: 700; }
.muted { color: var(--muted); font-size: 12px; }

.scene-load {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.scene-load input {
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 15px;
}

.scene-status {
    min-height: 18px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.3;
}

.scene-status.success { color: #22c55e; }
.scene-status.error { color: #f87171; }
.scene-status.info { color: var(--muted); }

.scene-lists {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    align-self: stretch;
}

.scene-list {
    min-height: 80px;
    max-height: 320px;
    height: auto;
    flex: 1 1 auto;
    width: 100%;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    background: var(--card);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.scene-list-block .list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    color: var(--muted);
}

.scene-list-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    width: 100%;
}

.scene-list .item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;         /* keep padding on items instead */
    border-radius: 10px;
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid var(--border);
    cursor: pointer;
}

.scene-list .item:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.scene-list .item.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.25), 0 8px 30px rgba(56, 189, 248, 0.08);
}

.scene-list .meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 14px;
    min-width: 0;
}

.scene-list .tag {
    font-size: 12px;
    color: var(--muted);
}

.scene-list .pill-public {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.12);
    color: #38bdf8;
    font-size: 12px;
    font-weight: 700;
    width: 80px;
    min-width: 80px;
}

.scene-list .desc {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.4;
}

.scene-list .actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.scene-list .actions button {
    padding: 6px 12px;
    font-size: 13px;
}

.scene-status {
    min-height: 18px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.3;
}

.share-row {
    justify-content: space-between;
    gap: 10px;
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--card);
}

.public-header {
    gap: 8px;
}

.public-header input {
    flex: 1;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
}

.scene-lists {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 16px;
    align-items: stretch;
}

.scene-list-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 110px;
}

.scene-list-block .list-header {
    align-items: center;
}
.control-grid {
    display: grid;
    grid-template-columns: 1fr 2fr auto;
    align-items: center;
    gap: 8px 12px;
    margin-bottom: 12px;
}

.parametric-section {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: linear-gradient(145deg, var(--card), var(--panel));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.parametric-section h4 {
    margin: 0 0 8px;
    color: var(--text);
}

.parametric-note {
    margin: 6px 0 10px;
    color: var(--muted);
    font-size: 13px;
}

.parametric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}

.parametric-grid.full {
    grid-template-columns: 1fr;
}

.parametric-section label {
    color: var(--muted);
    font-weight: 600;
    font-size: 14px;
}

.parametric-section input,
.parametric-section textarea {
    width: 100%;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    color: var(--text);
    font-family: var(--font);
}

.parametric-section textarea {
    min-height: 56px;
    resize: vertical;
}

.parametric-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 6px 0 8px;
}

.parametric-presets button {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 12px;
    color: var(--text);
    cursor: pointer;
}

.parametric-presets button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.parametric-error {
    display: none;
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid #f87171;
    background: rgba(248, 113, 113, 0.12);
    color: #fecdd3;
    font-size: 13px;
}

.parametric-error.visible {
    display: block;
}

.value {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    min-width: 50px;
    text-align: right;
}

@media (max-width: 900px) {
    body {
        overflow-x: hidden;
    }
    .layout {
        display: block;
    }
    .controls {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: var(--sheet-height, 60vh);
        max-height: 100vh;
        border-radius: 24px 24px 0 0;
        border: 1px solid var(--border);
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
        z-index: 40;
        overflow: visible;
        transition: transform 0.2s ease;
        margin: 0;
    }

    /* 🔽 hide desktop accordion headers on mobile */
    .section-header {
        display: none;
    }

    .sidebar-toggle {
        display: none !important;
      }

    .mobile-handle {
        display: block;
    }

    .control-stack {
        max-height: calc(var(--sheet-height, 60vh) - 96px);
        overflow-y: auto;
        padding: 8px 16px 18px;
    }
    .mobile-tabs {
        overflow-x: auto;
        width: 100%;
        scrollbar-width: none;
    }
    .mobile-tabs::-webkit-scrollbar { display: none; }
    .mobile-tabs .tabs-left {
        display: inline-flex;
        gap: 8px;
        min-width: max-content;
    }
    .mobile-tabs .tab {
        flex: 0 0 auto;
        min-width: 86px;
    }
    /* Let the shape dropdown fill the sheet and scroll */
    .custom-select .options.open {
        max-height: calc(var(--sheet-height, 60vh) - 140px);
        overflow-y: auto;
    }
    /* On mobile, lift the dropdown out of the scrolling stack so it can fill height and scroll */
    .custom-select {
        position: static;
    }
    .custom-select .options {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: 12px;
        top: auto;
        max-height: 60vh;
        z-index: 120;
    }
    .sheet-handle {
        width: 28%;
        max-width: 96px;
        min-width: 64px;
        height: 4px;
        background: transparent;
        border: none;
        padding: 0;
        margin: 10px auto 8px;
        cursor: grab;
        position: relative;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3), 0 0 6px rgba(56, 189, 248, 0.05);
    }
    .handle-icon {
        width: 72px;          /* fixed size: try 64px, 72px, or 80px */
        height: auto;         /* keeps SVG aspect ratio */
        display: block;
        margin: 0 auto;       /* centers it inside .mobile-handle */
        pointer-events: none;
        filter: drop-shadow(0 1px 2px rgba(0,0,0,0.18)) saturate(0.85);
    }


    .sheet-handle::before {
        content: "";
        position: absolute;
        top: -12px;
        left: -24px;
        right: -24px;
        height: 14px;
        background: linear-gradient(180deg, rgba(0,0,0,0.28), rgba(0,0,0,0));
        opacity: 0.7;
        pointer-events: none;
    }
    .sheet-tabs {
        display: flex;
        gap: 8px;
        padding: 0 16px 10px;
        overflow-x: auto;
        scrollbar-width: none;
        position: relative;
    }
    .sheet-tabs::-webkit-scrollbar {
        display: none;
    }
    .sheet-tabs::after {
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        width: 48px;
        height: 100%;
        pointer-events: none;
        background: linear-gradient(90deg, rgba(11, 18, 32, 0), rgba(11, 18, 32, 0.85));
    }
    .sheet-tab {
        border: 1px solid var(--border);
        background: var(--card);
        color: var(--text);
        border-radius: 18px;
        padding: 8px 14px;
        font-weight: 700;
        cursor: pointer;
        box-shadow: var(--shadow);
        white-space: nowrap;
    }
    .sheet-tab.active {
        border-color: var(--accent);
        color: var(--accent);
        box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.25), var(--shadow);
    }
    .sheet-tab.theme-toggle {
        margin-left: auto;
    }
    .sheet-bounce {
        animation: sheetBounce 480ms ease 1;
    }
    @keyframes sheetBounce {
        0% { transform: translateY(0); }
        40% { transform: translateY(-5px); }
        100% { transform: translateY(0); }
    }
    .control-card {
        display: none;
        margin: 0;
    }
    .control-card.active-pane {
        display: block;
    }
    .control-stack .control-card {
        display: none !important;
    }
    .control-stack .control-card.active-pane {
        display: block !important;
    }
}

.switch-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 6px 0 14px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #374151;
    transition: .3s;
    border-radius: 26px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.info {
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid rgba(148, 163, 184, 0.2);
    color: var(--muted);
    border-radius: 12px;
    padding: 12px 14px;
    line-height: 1.5;
    font-size: 14px;
}

@media (max-width: 960px) {
    .layout {
        grid-template-columns: 1fr;
    }
    #scene {
        height: 480px;
    }
}
