*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --sidebar-bg: #1e1e2e;
    --sidebar-text: #cdd6f4;
    --sidebar-muted: #6c7086;
    --accent: #89b4fa;
    --accent-hover: #74c7ec;
    --danger: #f38ba8;
    --success: #a6e3a1;
    --warning: #fab387;
    --surface: #313244;
    --surface-hover: #45475a;
    --viewport-bg: #f0f0f0;
    --input-bg: #1e1e2e;
    --input-border: #45475a;
    --radius: 4px;
}

/* ── Dark scrollbars (global) ── */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--surface-hover) transparent;
}

*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--surface-hover);
    border-radius: 3px;
}

*::-webkit-scrollbar-thumb:hover {
    background: #585b70;
}

/* ── Hide number input spinners globally ── */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--sidebar-text);
    background: var(--sidebar-bg);
    overflow: hidden;
    height: 100vh;
}

#app {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
    width: 580px;
    min-width: 580px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Tabs ── */
#tab-bar {
    display: flex;
    border-bottom: 1px solid var(--surface);
    flex-shrink: 0;
}

#tab-bar .tab-home {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    padding: 10px 0;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--sidebar-muted);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.15s;
}

#tab-bar .tab-home:hover {
    color: var(--accent);
}

#tab-bar .tab {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--sidebar-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

#tab-bar .tab:hover {
    color: var(--sidebar-text);
}

#tab-bar .tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    display: none;
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#sidebar h2, #sidebar h3 {
    font-size: 14px;
    font-weight: 600;
    margin-top: 12px;
    margin-bottom: 6px;
    color: var(--sidebar-text);
}

#sidebar h2:first-child {
    margin-top: 0;
}

.section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--sidebar-muted);
    margin-bottom: 6px;
}

/* ── Viewport ── */
#viewport {
    flex: 1;
    position: relative;
    background: var(--viewport-bg);
}

#three-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ── Tables ── */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 4px;
}

thead th {
    text-align: left;
    font-weight: 500;
    font-size: 13px;
    color: var(--sidebar-muted);
    padding: 2px 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Item Cards ── */
#items-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 4px;
}

.item-card {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    padding: 6px 8px;
}

.item-card .item-cube-cell {
    flex-shrink: 0;
    padding-top: 4px;
    cursor: pointer;
    position: relative;
}

.item-card .item-cube-cell:hover { opacity: 0.8; }

.item-card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.item-main-line,
.item-dims-line {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.item-main-line .item-name {
    flex: 1;
    min-width: 80px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 3px 6px;
    font-size: 14px;
}

.item-field {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--sidebar-muted);
    white-space: nowrap;
}

.item-field input[type="number"] {
    width: 48px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 3px 4px;
    font-size: 13px;
}

.item-field input.item-wt {
    width: 52px;
}

.item-field input.item-qty {
    width: 52px;
}

.item-field-up {
    gap: 2px;
}

.item-field-up input[type="checkbox"] {
    margin: 0;
}

.item-vol-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--sidebar-muted);
    white-space: nowrap;
}

.item-vol-label .vol {
    color: var(--sidebar-text);
    font-size: 12px;
}

.item-field-wt {
    margin-left: auto;
}

.item-card > .btn-remove,
.cont-card > .btn-remove {
    flex-shrink: 0;
    margin-top: 2px;
}

.vol-unit-label {
    font-size: 12px;
    font-weight: 400;
    color: var(--sidebar-muted);
}

.item-card input:focus,
.cont-card input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ── Container Cards ── */
#containers-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 4px;
}

.cont-card {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    padding: 6px 8px;
}

.cont-card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cont-main-line,
.cont-dims-line {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.cont-main-line .cont-name {
    flex: 1;
    min-width: 80px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 3px 6px;
    font-size: 14px;
}

.cont-field {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--sidebar-muted);
    white-space: nowrap;
}

.cont-field input[type="number"] {
    width: 48px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 3px 4px;
    font-size: 13px;
}

.cont-field select {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 2px 4px;
    font-size: 12px;
}

.cont-vol-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--sidebar-muted);
    white-space: nowrap;
}

.cont-vol-label .vol {
    color: var(--sidebar-text);
    font-size: 12px;
}

.cont-field-cost {
    margin-left: auto;
}

.cont-field-cost input {
    width: 52px;
}

/* ── Color Picker Popover ── */
.color-picker {
    position: fixed;
    z-index: 100;
    background: var(--surface);
    border: 1px solid var(--input-border);
    border-radius: 6px;
    padding: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
}

.color-picker-swatch {
    cursor: pointer;
    padding: 2px;
    border-radius: 3px;
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.1s;
}

.color-picker-swatch:hover {
    border-color: var(--accent);
}

.color-picker-swatch.active {
    border-color: var(--sidebar-text);
}

.color-picker-custom {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0 0;
    border-top: 1px solid var(--input-border);
    margin-top: 2px;
    padding-top: 6px;
}

.color-picker-custom label {
    font-size: 13px;
    color: var(--sidebar-muted);
    cursor: pointer;
    white-space: nowrap;
}

.color-picker-custom input[type="color"] {
    width: 24px;
    height: 20px;
    border: 1px solid var(--input-border);
    border-radius: 3px;
    background: none;
    cursor: pointer;
    padding: 0;
}

.color-picker-custom input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 1px;
}

.color-picker-custom input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

#containers-table td input[type="number"] {
    width: 48px;
}

tbody td {
    padding: 2px 4px;
}

td .cube {
    font-size: 13px;
    color: var(--sidebar-muted);
    white-space: nowrap;
}

td .vol {
    font-size: 13px;
    color: var(--sidebar-muted);
    white-space: nowrap;
}

td input[type="text"] {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 4px 6px;
    font-size: 13px;
}

td input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
}

td select {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 4px 6px;
    font-size: 13px;
}

td select option {
    background: var(--input-bg);
    color: var(--sidebar-text);
}

td select:focus {
    outline: none;
    border-color: var(--accent);
}

td input[type="number"] {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 4px 6px;
    font-size: 13px;
    text-align: right;
}

td input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-remove {
    background: none;
    border: none;
    color: var(--sidebar-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: var(--radius);
    line-height: 1;
}

.btn-remove:hover {
    color: var(--danger);
    background: var(--surface);
}

/* ── Buttons ── */
.btn-primary {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: #1e1e2e;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: none;
    border: 1px dashed var(--input-border);
    color: var(--sidebar-muted);
    padding: 4px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    margin-bottom: 4px;
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-small {
    background: var(--surface);
    border: 1px solid var(--input-border);
    color: var(--sidebar-text);
    padding: 4px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
}

.btn-small:hover {
    background: var(--surface-hover);
}

/* ── Form ── */
.form-group {
    margin-bottom: 8px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--sidebar-muted);
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group select,
.form-group input[type="number"] {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 6px 8px;
    font-size: 13px;
}

.form-group select:focus,
.form-group input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}

.form-row {
    display: flex;
    gap: 8px;
}

.form-row .form-group {
    flex: 1;
}

/* ── Generator Details ── */
.generator-details {
    margin-bottom: 6px;
}

.generator-details summary {
    cursor: pointer;
    font-size: 13px;
    color: var(--sidebar-muted);
    padding: 4px 0;
    user-select: none;
}

.generator-details summary:hover {
    color: var(--accent);
}

.gen-body {
    padding: 6px 0;
}

.gen-body .form-row {
    margin-bottom: 4px;
}

.gen-body .form-group {
    margin-bottom: 2px;
}

.gen-body .btn-secondary {
    margin-top: 4px;
}

/* ── Options Card ── */
.options-card {
    background: var(--surface);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    padding: 8px 10px;
    margin-top: 8px;
}

.options-card__title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--sidebar-muted);
    margin-bottom: 6px;
}

.options-card__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 3px 0;
}

.options-card__label {
    font-size: 13px;
    color: var(--sidebar-text);
    white-space: nowrap;
    flex-shrink: 0;
    width: 130px;
}

.options-card__input-group {
    display: flex;
    gap: 4px;
    align-items: center;
    flex: 1;
}

.options-card__input-group input[type="number"] {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 4px 6px;
    font-size: 13px;
    text-align: right;
}

.options-card__input-group input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}

.options-card__input-group select {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 4px 6px;
    font-size: 13px;
    min-width: 52px;
}

.options-card__input-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.options-card__select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 4px 6px;
    font-size: 13px;
}

.options-card__select:focus {
    outline: none;
    border-color: var(--accent);
}

.options-card__check-label {
    font-size: 13px;
    color: var(--sidebar-text);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.options-card__check-label input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
}

/* ── Error Box ── */
#error-box {
    background: rgba(243, 139, 168, 0.15);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    color: var(--danger);
    padding: 8px 10px;
    margin-top: 8px;
    font-size: 13px;
    white-space: pre-wrap;
}

/* ── Result Cards ── */
.result-card, #summary-panel {
    background: var(--surface);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    padding: 8px 10px;
    margin-bottom: 8px;
}

/* ── Result Containers Table ── */
#result-content {
    display: flex;
    flex-direction: column;
}

#result-containers-table {
    margin-bottom: 0;
}

#result-containers-table thead th {
    background: var(--sidebar-bg);
}

#result-containers-table tbody tr {
    cursor: pointer;
    border-radius: var(--radius);
    transition: background 0.1s;
}

#result-containers-table tbody tr:hover {
    background: var(--surface-hover);
}

#result-containers-table tbody tr.selected {
    background: var(--surface);
    outline: 1px solid var(--accent);
    outline-offset: -1px;
}

#result-containers-table tbody td {
    padding: 4px 6px;
    font-size: 13px;
    white-space: nowrap;
}

.td-action {
    width: 28px;
    text-align: center;
}

.btn-copy-json,
.btn-embed,
.btn-copy-inline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-dim);
    padding: 2px;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

.btn-copy-json:hover,
.btn-embed:hover,
.btn-copy-inline:hover {
    color: var(--accent);
    background: var(--surface-hover);
}

#info-panel {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 8px 10px;
    margin-top: 8px;
}

.contents-row {
    cursor: pointer;
    transition: background 0.15s;
}

.contents-row:hover {
    background: var(--surface-hover);
}


.unit-select {
    font-size: 13px;
    font-weight: 400;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-muted);
    padding: 1px 4px;
    margin-left: 4px;
    vertical-align: middle;
}

.unit-select:focus {
    outline: none;
    border-color: var(--accent);
}

.upright-label {
    display: flex;
    justify-content: center;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 13px;
}

.info-row span:first-child {
    color: var(--sidebar-fg);
}

.info-row span:last-child {
    font-weight: 500;
}

#summary-share {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 6px 10px;
    margin-bottom: 8px;
}

.share-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    font-size: 13px;
    min-width: 0;
}

.share-label {
    color: var(--sidebar-fg);
    flex-shrink: 0;
}

.share-value {
    font-family: var(--font-mono, monospace);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.share-link {
    font-family: var(--font-mono, monospace);
    font-size: 13px;
    color: var(--accent);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.share-link:hover {
    text-decoration: underline;
}

.btn-icon {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--sidebar-muted);
    cursor: pointer;
    padding: 2px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    transition: color 0.15s, background 0.15s;
}

.btn-icon:hover {
    color: var(--sidebar-fg);
    background: rgba(255, 255, 255, 0.08);
}

/* ── Embed Modal ── */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--sidebar-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    width: 520px;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--input-border);
}

.modal-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.modal-close {
    font-size: 18px;
    line-height: 1;
    color: var(--sidebar-muted);
}

.modal-close:hover {
    color: var(--sidebar-text);
}

.modal-body {
    padding: 16px;
    overflow-y: auto;
}

.modal-section {
    margin-bottom: 16px;
}

.modal-section:last-child {
    margin-bottom: 0;
}

.modal-section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--sidebar-muted);
    margin-bottom: 6px;
}

.embed-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 16px;
    font-size: 13px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 8px 10px;
}

.embed-summary .label {
    color: var(--sidebar-fg);
}

.embed-summary .value {
    text-align: right;
    font-weight: 500;
}

.embed-code-wrap {
    position: relative;
}

.embed-code {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 10px 12px;
    padding-right: 36px;
    font-family: var(--font-mono, monospace);
    font-size: 13px;
    line-height: 1.5;
    color: var(--accent);
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

.embed-code-copy {
    position: absolute;
    top: 6px;
    right: 6px;
}

.embed-preview {
    background: var(--surface);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    padding: 16px;
}

.embed-preview svg {
    max-width: 100%;
    max-height: 350px;
}

/* ── Color Legend (viewport overlay) ── */
#color-legend {
    position: absolute;
    bottom: 8px;
    left: 12px;
    background: rgba(15, 15, 25, 0.80);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    z-index: 5;
    pointer-events: auto;
    min-width: 150px;
    max-height: calc(100% - 20px);
    display: flex;
    flex-direction: column;
}

.legend-toggle {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    font-family: monospace;
    padding: 5px 10px;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    border-radius: 6px 6px 0 0;
}

.legend-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
}

.legend-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 2px 10px 8px 10px;
    overflow-y: auto;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-family: monospace;
    line-height: 1.4;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    user-select: none;
}

.legend-item:hover {
    background: rgba(255, 255, 255, 0.10);
}

.legend-item--selected {
    background: rgba(255, 255, 255, 0.18);
    outline: 1px solid rgba(255, 255, 255, 0.45);
}

.legend-cube {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.legend-label {
    color: rgba(255, 255, 255, 0.80);
    white-space: nowrap;
}

/* ── Unpacked Warning ── */
#unpacked-warning {
    background: rgba(250, 179, 135, 0.15);
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    color: var(--warning);
    padding: 8px 10px;
    font-size: 13px;
}

#unpacked-panel {
    background: rgba(250, 179, 135, 0.10);
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    padding: 6px 10px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

#unpacked-panel h3 {
    color: var(--warning);
    font-size: 13px;
    margin: 0 0 4px;
}

#unpacked-panel table {
    margin: 0;
}

#unpacked-panel td,
#unpacked-panel th {
    font-size: 13px;
    padding: 1px 4px;
}

#unpacked-panel th {
    color: var(--warning);
    opacity: 0.7;
}

/* ── Controls Legend ── */
#controls-legend {
    position: absolute;
    top: 8px;
    left: 12px;
    font-family: monospace;
    font-size: 13px;
    color: #555;
    line-height: 1.6;
    pointer-events: none;
    z-index: 5;
}

.legend-section-title {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #999;
    margin-top: 4px;
}

.legend-section-title:first-child {
    margin-top: 0;
}

#controls-legend kbd {
    display: inline-block;
    background: #e0e0e0;
    border: 1px solid #bbb;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 13px;
    min-width: 24px;
    text-align: center;
    color: #333;
    line-height: 1.4;
}

.controls-grid {
    display: grid;
    grid-template-columns: 50px 1fr 50px 1fr;
    gap: 4px 8px;
    align-items: center;
    margin-top: 2px;
}

.controls-grid span {
    font-size: 13px;
}

.controls-grid kbd {
    width: 100%;
}

#controls-legend kbd[data-key] {
    pointer-events: auto;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s, border-color 0.1s;
}

#controls-legend kbd[data-key]:hover {
    background: #ccc;
    border-color: #999;
}

#controls-legend kbd[data-key].pressed {
    background: #aaa;
    border-color: #777;
}

/* ── Speed HUD ── */
#speed-hud {
    position: absolute;
    top: 8px;
    right: 12px;
    font-family: monospace;
    font-size: 13px;
    color: rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 5;
}

/* ── Loading Overlay ── */
#loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Playback Controls ── */
#playback-controls {
    margin: 8px 0;
}

.playback-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

#playback-slider {
    flex: 1;
    accent-color: var(--accent);
}

#playback-counter {
    font-size: 13px;
    font-family: monospace;
    white-space: nowrap;
    color: var(--sidebar-muted);
}

.btn-speed {
    font-size: 13px;
    min-width: 32px;
    text-align: center;
    font-family: monospace;
}

.speed-display {
    font-size: 13px;
    min-width: 36px;
    text-align: center;
    font-family: monospace;
    display: inline-block;
}

/* ── Utility ── */
.hidden {
    display: none !important;
}


/* ── No-result placeholder ── */
#no-result-placeholder {
    padding: 16px;
    color: var(--sidebar-muted);
    font-size: 13px;
    text-align: center;
    border: 1px dashed var(--input-border);
    border-radius: var(--radius);
    margin-bottom: 12px;
}

/* ── Zone Builder ── */
.zone-card {
    background: var(--surface);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    padding: 8px;
    margin-bottom: 6px;
}

.zone-header {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-bottom: 6px;
}

.zone-name {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 4px 6px;
    font-size: 13px;
}

.zone-name:focus {
    outline: none;
    border-color: var(--accent);
}

.zone-item-row {
    display: grid;
    grid-template-columns: 28px 1fr 1fr 1fr;
    gap: 4px;
    align-items: center;
    margin-bottom: 3px;
}

.zone-row {
    display: grid;
    grid-template-columns: 28px 1fr 14px 1fr;
    gap: 4px;
    align-items: center;
    margin-bottom: 3px;
}

.zone-label {
    font-size: 13px;
    color: var(--sidebar-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: right;
}

.zone-arrow {
    text-align: center;
    color: var(--sidebar-muted);
    font-size: 13px;
}

.zone-card input[type="number"] {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    padding: 4px 6px;
    font-size: 13px;
    text-align: right;
}

.zone-card input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}

.zone-preview {
    font-size: 13px;
    color: var(--sidebar-muted);
    text-align: right;
    margin-top: 4px;
    font-family: monospace;
}

#builder-error {
    background: rgba(243, 139, 168, 0.15);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    color: var(--danger);
    padding: 8px 10px;
    margin-top: 8px;
    font-size: 13px;
}

/* ── Orientation Controls ── */
.orientation-row td {
    padding: 2px 4px 6px 4px;
}

.orientation-label {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 13px;
    color: var(--sidebar-muted);
    cursor: pointer;
    padding: 2px 5px;
    margin-right: 3px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    background: var(--input-bg);
    transition: border-color 0.15s, background 0.15s;
}

.orientation-label:hover {
    border-color: var(--accent);
    background: var(--surface);
}

.orientation-label input[type="checkbox"] {
    width: 12px;
    height: 12px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* ── Mobile Gate ──────────────────────────────────────────────────────────── */

.mobile-gate {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
    min-height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
}

.mobile-gate__icon {
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    color: var(--accent);
}

.mobile-gate h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
    color: #fff;
}

.mobile-gate p {
    font-size: 15px;
    color: var(--sidebar-muted);
    max-width: 360px;
    line-height: 1.6;
    margin-bottom: 28px;
}

.mobile-gate__links {
    display: flex;
    gap: 12px;
}

@media (max-width: 900px) {
    .mobile-gate { display: flex; }
    #app { display: none !important; }
}

/* Small touch devices (phones) — JS adds class when both small AND touch-only */
.mobile-gate.touch-device { display: flex; }
.touch-device ~ #app { display: none !important; }

/* ── View Mode ── */
body.view-mode #tab-bar { display: none; }
body.view-mode #input-tab { display: none !important; }
body.view-mode #result-tab { display: flex !important; flex-direction: column; gap: 4px; }
body.view-mode #no-result-placeholder { display: none !important; }
body.view-mode #btn-reset { display: none; }
body.view-mode #share-view-url,
body.view-mode #share-sandbox-url { display: none; }

/* ── Social Share ── */
.share-social {
    display: flex;
    justify-content: center;
    padding: 10px 0 2px;
    border-top: 1px solid var(--input-border);
    margin-top: 4px;
}

.share-social__buttons {
    display: flex;
    gap: 6px;
}

.share-social__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    background: var(--surface-hover);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--sidebar-text);
    text-decoration: none;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.share-social__btn svg {
    width: 18px;
    height: 18px;
}

.share-social__btn:hover {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}
