/* =========================================================================
   THEME
   ========================================================================= */

:root {
    --bg-deep: #0a0e17;
    --bg-panel: #121826;
    --bg-panel-2: #1a2234;
    --accent: #527cca;
    --accent-glow: rgba(42, 76, 122, 0.35);
    --danger: #e5484d;
    --text: #e6edf3;
    --text-dim: #8b98a9;
    --border: #323e54;
}

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

html, body {
    height: 100%;
    background: var(--bg-deep);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
}

/* =========================================================================
   TOP BAR
   ========================================================================= */

.topbar {
    height: 56px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
}

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

.brand-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 10px var(--danger);
    animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.35; }
}

.brand-name {
    font-weight: 700;
    letter-spacing: 1.5px;
    font-size: 14px;
}

.brand-tag {
    font-size: 10px;
    letter-spacing: 1.5px;
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 2px 6px;
    border-radius: 3px;
    background: BLACK;
}

.status { font-size: 12px; color: var(--text-dim); }

/* =========================================================================
   STAGE
   ========================================================================= */

.stage-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    min-height: 0;
}


.stage {
    position: relative;
    aspect-ratio: 16 / 9;
    max-width: 100%;
    max-height: 100%;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 0 1px var(--border), 0 20px 60px rgba(0, 0, 0, 0.6);
}

/* Portrait variant — taller than it is wide */
.stage.stage-portrait {
    aspect-ratio: 9 / 16;
}
#outputCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.overlay-message {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 14, 23, 0.85);
    color: var(--text-dim);
    font-size: 14px;
    transition: opacity 0.3s ease;
}

.overlay-message.hidden {
    opacity: 0;
    pointer-events: none;
}

/* =========================================================================
   CONTROL BAR
   ========================================================================= */

/* =========================================================================
   CONTROL BAR (two-row layout)
   ========================================================================= */

.controlbar {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 20px 12px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
}

/* Row 1: buttons and selects */
.controlbar-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 18px;
    width: 100%;
}

/* Row 2: audio meter + timer */
.controlbar-meter-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}

.push-right {
    margin-left: auto;
    justify-content: flex-end;
}

/* Small icon-only labels (for Camera / Mic selectors) */
.control-icon-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    color: var(--text-dim);
    flex-shrink: 0;
    cursor: pointer;
    transition: color 0.15s;
}

.control-icon-label svg {
    width: 16px;
    height: 16px;
    display: block;
    color: var(--text-dim);
}

.control-icon-label:hover { color: var(--accent); }

.control-select {
    background: var(--bg-panel-2);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 11px;
    min-width: 140px;
    max-width: 220px;
    flex: 1 1 140px;
    outline: none;
    transition: border-color 0.15s;
}

.control-select:focus { border-color: var(--accent); }

/* =========================================================================
   BUTTONS
   ========================================================================= */

.btn {
    background: var(--bg-panel-2);
    color: var(--text);
    border: 2px solid var(--border);
    border-radius: 6px;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    position: relative;
}

.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover:not(:disabled) {
    box-shadow: 0 0 16px var(--accent-glow);
}

.btn-record {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}
.btn-record:hover:not(:disabled) {
    background: var(--danger);
    color: #fff;
}
.btn-record.recording {
    background: var(--danger);
    color: #fff;
    animation: pulse 1.2s ease-in-out infinite;
}

/* Icon-only square buttons */
.btn-icon {
     border-color: var(--text);
   border: 2px solid var(--border);  
    width: 38px;
    height: 38px;
    padding: 0;
    flex: 0 0 auto;
}

.btn-icon svg {
    width: 18px;
    height: 18px;
    display: block;
    color: inherit;
}

/* Record icon swap */
.btn-record .icon-stop { display: none; }
.btn-record.recording .icon-record { display: none; }
.btn-record.recording .icon-stop  { display: block; }

/* =========================================================================
   AUDIO LEVEL METER (lives on its own row)
   ========================================================================= */

.audio-meter {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 520px;
    height: 14px;
    border-radius: 4px;
    background: #05070d;
    border: 1px solid #2a3550;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6);
    transition: opacity 0.2s;
}

body:not(.camera-live) .audio-meter {
    opacity: 0.55;
}

/* Timer sits at the end of the meter row */
.timer {
    font-variant-numeric: tabular-nums;
    font-size: 14px;
    color: var(--text-dim);
    min-width: 52px;
    text-align: right;
    flex: 0 0 auto;
    margin-left: auto;
}
.timer {
    font-variant-numeric: tabular-nums;
    font-size: 14px;
    color: var(--text-dim);
    min-width: 48px;
    text-align: right;
}

/* =========================================================================
   PREVIEW MODAL
   ========================================================================= */

.preview-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.preview-modal.hidden { display: none; }

.preview-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: min(720px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
}

.preview-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 16px;
}

.preview-video {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: 8px;
    display: block;
    margin-bottom: 12px;
}

.preview-meta {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 20px;
}

.preview-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* =========================================================================
   UPLOAD PROGRESS
   ========================================================================= */

.upload-progress { margin-top: 20px; }
.upload-progress.hidden { display: none; }

.upload-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-panel-2);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.upload-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.15s ease;
    box-shadow: 0 0 12px var(--accent-glow);
}

.upload-status {
    font-size: 12px;
    color: var(--text-dim);
}

/* =========================================================================
   BACKGROUND PICKER MODAL
   ========================================================================= */

.bg-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.bg-modal.hidden { display: none; }

.bg-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: min(960px, 100%);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
}

.bg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.bg-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
}

.btn-close {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 20px;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-close:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Filter tabs */
.bg-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-panel-2);
    border-radius: 8px;
    margin-bottom: 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.bg-tabs::-webkit-scrollbar { display: none; }

.bg-tab {
    flex: 0 0 auto;
    padding: 7px 12px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.bg-tab:hover { color: var(--text); }

.bg-tab.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 12px var(--accent-glow);
}

.bg-tab-count {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: inherit;
    font-weight: 700;
    line-height: 1.4;
}

.bg-tab.active .bg-tab-count {
    background: rgba(255, 255, 255, 0.25);
}

/* Grid of tiles */
.bg-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    overflow-y: auto;
    padding: 4px;
    margin-bottom: 16px;
    flex: 1;
    min-height: 120px;
}

.bg-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    padding: 40px 0;
}

.bg-item {
    position: relative;
    background: var(--bg-panel-2);
    border: 2px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
}

.bg-item:hover { border-color: var(--accent); }

.bg-item.selected {
    border: 3px
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow), 0 0 20px var(--accent-glow);
}

.bg-item-preview {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    object-fit: cover;
    display: block;
}

.bg-item-preview-placeholder {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: linear-gradient(135deg, #1a2234, #0a0e17);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 28px;
}

.bg-item-meta {
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.bg-item-name {
    font-size: 12px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.bg-item-badge {
    font-size: 9px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 3px;
    background: var(--bg-deep);
    color: var(--text-dim);
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.bg-item-badge.video { color: #f0a020; border-color: #f0a02044; }
.bg-item-badge.uploaded { color: var(--accent); border-color: var(--accent-glow); }

.bg-item-badge.category          { color: #a5b4fc; border-color: #a5b4fc44; }
.bg-item-badge.category.free     { color: #34d399; border-color: #34d39944; }
.bg-item-badge.category.premium  { color: #fbbf24; border-color: #fbbf2444; }
.bg-item-badge.category.ai       { color: #f472b6; border-color: #f472b644; }
.bg-item-badge.category.uploaded { color: var(--accent); border-color: var(--accent-glow); }

/* Delete button on uploaded tiles */
.bg-item-delete {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: rgba(10, 14, 23, 0.85);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, transform 0.15s;
    z-index: 3;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.bg-item:hover .bg-item-delete { opacity: 1; }
.bg-item-delete:hover {
    background: var(--danger);
    transform: scale(1.1);
}

@media (hover: none) {
    .bg-item-delete { opacity: 1; }
}

.bg-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* =========================================================================
   TELEPROMPTER
   ========================================================================= */

.teleprompter {
    position: absolute;
    inset: 0;
    z-index: 20;
    pointer-events: none;
    overflow: hidden;
}

.teleprompter[hidden] { display: none; }

.teleprompter-viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.85);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 14%, #000 86%, transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0%, #000 14%, #000 86%, transparent 100%);
}

.teleprompter-scroller {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 0 8%;
    will-change: transform;
    transform: translateY(0);
}

.teleprompter-text {
    font-size: 32px;
    line-height: 1.5;
    color: #fff;
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.01em;
    text-shadow: 0 2px 14px rgba(0, 0, 0, 0.85);
    padding-bottom: 200px;
}

.teleprompter-text p { margin: 0 0 1.2em; }
.teleprompter-text p:last-child { margin-bottom: 0; }

.teleprompter-text .tp-empty {
    color: rgba(255, 255, 255, 0.45);
    font-style: italic;
    font-weight: 400;
}

.teleprompter-reading-line {
    position: absolute;
    left: 8%;
    right: 8%;
    top: 30%;
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(47, 129, 247, 0.55), transparent);
    pointer-events: none;
}

.teleprompter-toolbar {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px;
    background: rgba(10, 14, 23, 0.92);
    border: 1px solid var(--border);
    border-radius: 999px;
    pointer-events: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
}

.tp-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
    line-height: 1;
}

.tp-btn:hover { background: var(--bg-panel-2); }

.tp-btn-play { background: var(--accent); color: #fff; }
.tp-btn-play:hover { background: #4a92ff; }

.tp-btn-close { color: var(--text-dim); }
.tp-btn-close:hover { background: var(--danger); color: #fff; }

.tp-speed-label {
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: var(--text-dim);
    min-width: 26px;
    text-align: center;
}

/* Editor modal */
.tp-editor-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 110;
    backdrop-filter: blur(4px);
}

.tp-editor-modal.hidden { display: none; }

.tp-editor-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: min(720px, 100%);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
}

.tp-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.tp-editor-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
}

.tp-script {
    width: 100%;
    min-height: 220px;
    resize: vertical;
    background: var(--bg-panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
    outline: none;
    margin-bottom: 16px;
}

.tp-script:focus { border-color: var(--accent); }

.tp-settings {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.tp-setting {
    display: grid;
    grid-template-columns: 90px 1fr 56px;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--text-dim);
}

.tp-setting input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--bg-panel-2);
    border-radius: 2px;
    outline: none;
}

.tp-setting input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 8px var(--accent-glow);
}

.tp-setting input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 8px var(--accent-glow);
}

.tp-value {
    font-variant-numeric: tabular-nums;
    color: var(--text);
    text-align: right;
    font-size: 12px;
}

.tp-editor-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* =========================================================================
   SOUNDBOARD PANEL
   ========================================================================= */

.soundboard {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 72px;
    max-height: 55vh;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    box-shadow: 0 -20px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transform: translateY(0);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.soundboard.hidden {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}

.sb-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sb-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    flex-shrink: 0;
}

.sb-notice {
    flex: 1;
    text-align: center;
    font-size: 11px;
    color: #fbbf24;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 8px;
}

.sb-notice.visible { opacity: 1; }

.sb-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
    flex-shrink: 0;
}

.sb-vol {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sb-vol input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 4px;
    background: var(--bg-panel-2);
    border-radius: 2px;
    outline: none;
}

.sb-vol input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 6px var(--accent-glow);
}

.sb-vol input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

.sb-icon-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
    padding: 0;
    line-height: 1;
}

.sb-icon-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.sb-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    scrollbar-width: none;
    flex-shrink: 0;
}

.sb-tabs::-webkit-scrollbar { display: none; }

.sb-tab {
    flex: 0 0 auto;
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.sb-tab:hover { color: var(--text); }

.sb-tab.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 10px var(--accent-glow);
}

.sb-tab-count {
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: inherit;
    font-weight: 700;
}

.sb-tab.active .sb-tab-count {
    background: rgba(255, 255, 255, 0.25);
}

.sb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 8px;
    padding: 12px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.sb-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    padding: 30px 0;
}

.sb-btn {
    position: relative;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 10px 26px;
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    min-height: 64px;
    text-align: left;
    line-height: 1.3;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.sb-btn:hover {
    border-color: var(--accent);
    background: #1e2840;
}

.sb-btn:active,
.sb-btn.playing {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    transform: scale(0.97);
    box-shadow: 0 0 16px var(--accent-glow);
}

.sb-btn-num {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-dim);
    letter-spacing: 0.5px;
}

.sb-btn.playing .sb-btn-num {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.sb-btn-cat {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    margin-top: 4px;
    font-weight: 500;
}

.sb-btn.playing .sb-btn-cat {
    color: rgba(255, 255, 255, 0.75);
}

/* Favourite star (bottom-right) */
.sb-btn-fav {
    position: absolute;
    bottom: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border-radius: 5px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    padding: 0;
    z-index: 2;
    opacity: 0.45;
    -webkit-tap-highlight-color: transparent;
}

.sb-btn:hover .sb-btn-fav { opacity: 1; }

.sb-btn-fav:hover {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.15);
    transform: scale(1.1);
}

.sb-btn-fav.active {
    color: #fbbf24;
    opacity: 1;
}

.sb-btn.playing .sb-btn-fav.active { color: #fff; }

@media (hover: none) {
    .sb-btn-fav { opacity: 0.7; }
}

/* =========================================================================
   AUDIO LEVEL METER
   ========================================================================= */

.audio-meter {
    display: block;
    width: 90px;
    height: 14px;
    border-radius: 4px;
    background: #05070d;
    border: 1px solid #2a3550;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6);
    flex-shrink: 0;
    transition: opacity 0.2s;
}

body:not(.camera-live) .audio-meter {
    opacity: 0.55;
}

/* =========================================================================
   RESPONSIVE — TABLET (<= 900px)
   ========================================================================= */

@media (max-width: 900px) {
    .topbar {
        height: 52px;
        padding: 0 14px;
    }

    .brand-name { font-size: 13px; }
    .brand-tag { font-size: 9px; }
    .status { font-size: 11px; }

    .stage-wrap { padding: 12px; }

    .controlbar {
        gap: 8px 12px;
        padding: 10px 14px;
    }

    .control-select {
        flex: 1 1 120px;
        min-width: 0;
        max-width: none;
    }

    .bg-card {
        width: 100%;
        padding: 18px;
    }

    .bg-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
    }
}

/* =========================================================================
   RESPONSIVE — MOBILE (<= 600px)
   ========================================================================= */
@media (max-width: 600px) {
    body { overflow-y: auto; }

    .topbar {
        height: 44px;
        padding: 0 10px;
    }

    .brand-name { font-size: 12px; letter-spacing: 1px; }
    .brand-tag { display: none; }

    .status {
        font-size: 10px;
        max-width: 120px;
        text-align: right;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* ---- STAGE: fill all available vertical space, minimal padding ---- */
    .stage-wrap {
        padding: 4px;
        flex: 1 1 auto;
        min-height: 0;
    }

    .stage { border-radius: 6px; }

    /* ---- CONTROL BAR: compact, centered ---- */
    .controlbar {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        padding: 8px 10px 10px;
    }

    .controlbar-row {
        justify-content: center;
        gap: 6px;
        row-gap: 8px;
    }

    /* Button groups size to their content — stay on one row */
    .control-group {
        width: auto;
        flex: 0 0 auto;
        justify-content: center;
        gap: 6px;
    }

    /* Groups containing a <select> take the full row (camera, mic) */
    .control-group:has(.control-select) {
        flex: 1 1 100%;
        width: 100%;
    }

    /* Studio tools row spans the full width, buttons centered */
    .control-group.push-right {
        margin-left: 0;
        flex: 1 1 100%;
        width: 100%;
        justify-content: center;
    }

    .control-select {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none;
        font-size: 12px;
        padding: 7px 10px;
    }

    .control-icon-label {
        width: 26px;
        height: 26px;
    }

    .control-icon-label svg {
        width: 14px;
        height: 14px;
    }

    .btn-icon {
        width: 40px;
        height: 40px;
    }

    .btn-icon svg {
        width: 19px;
        height: 19px;
    }

    .shape-btn,
    .matting-btn {
        width: 40px;
        height: 40px;
    }

    /* Meter row — compact, centered */
    .controlbar-meter-row {
        padding-top: 6px;
        gap: 10px;
        justify-content: center;
    }

    .meter-group { margin-left: 0; }

    .audio-meter {
        flex: 1 1 auto;
        width: auto;
        max-width: 200px;
        height: 12px;
    }

    .timer {
        font-size: 13px;
        min-width: 42px;
        margin-left: 0;
    }

    /* ---------- Preview modal ---------- */
    .preview-card { padding: 16px; border-radius: 10px; }
    .preview-title { font-size: 13px; }
    .preview-actions { flex-direction: column; }
    .preview-actions .btn { width: 100%; padding: 12px; }

    /* ---------- Background picker modal ---------- */
    .bg-modal { padding: 0; }
    .bg-card {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        border: none;
        padding: 16px;
    }
    .bg-header { margin-bottom: 12px; }
    .bg-title { font-size: 13px; }
    .bg-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .bg-item-name { font-size: 11px; }
    .bg-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding-top: 12px;
    }
    .bg-footer .btn { width: 100%; padding: 12px; }

    /* ---------- Teleprompter ---------- */
    .teleprompter-text { font-size: 22px; }
    .teleprompter-scroller { padding: 0 6%; }
    .teleprompter-toolbar { bottom: 8px; gap: 2px; padding: 4px; }
    .tp-btn { width: 28px; height: 28px; font-size: 12px; }
    .tp-speed-label { font-size: 10px; min-width: 22px; }
    .tp-editor-card { padding: 18px; }
    .tp-setting { grid-template-columns: 70px 1fr 46px; font-size: 11px; }
    .tp-editor-actions { flex-direction: column-reverse; }
    .tp-editor-actions .btn { width: 100%; padding: 12px; }

    /* ---------- Soundboard ---------- */
    .soundboard { bottom: 0; max-height: 70vh; }
    .sb-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        gap: 6px;
        padding: 10px;
    }
    .sb-btn { font-size: 11px; min-height: 56px; padding: 10px 8px 8px; }
    .sb-vol input[type="range"] { width: 70px; }
    .sb-btn-fav { width: 24px; height: 24px; font-size: 15px; }
    .sb-notice { font-size: 10px; }
}
/* =========================================================================
   VERY SMALL (<= 380px)
   ========================================================================= */

@media (max-width: 380px) {
    .brand-name { font-size: 11px; }

    .btn-icon { width: 36px; height: 36px; }
    .btn-icon svg { width: 17px; height: 17px; }

    .audio-meter { width: 60px; height: 10px; }

    .bg-grid { grid-template-columns: 1fr; }
}
/* =========================================================================
   LIBRARY PANEL
   ========================================================================= */

.library-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 96px;
    max-height: 60vh;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    box-shadow: 0 -20px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    z-index: 51;
    transform: translateY(0);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.library-panel.hidden {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}

.lib-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.lib-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    flex-shrink: 0;
}

.lib-count {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-panel-2);
    color: var(--text-dim);
    font-weight: 700;
    flex-shrink: 0;
}

.lib-notice {
    flex: 1;
    text-align: center;
    font-size: 11px;
    color: var(--accent);
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 8px;
}

.lib-notice.visible { opacity: 1; }

.lib-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    flex-shrink: 0;
}

.lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    padding: 14px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.lib-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    padding: 40px 0;
}

/* ---------- Card ---------- */

.lib-item {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
}

.lib-item:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

/* =========================================================================
   LIBRARY THUMBNAIL — reliable 16:9 aspect ratio
   Uses the padding-bottom technique instead of `aspect-ratio`, because
   the latter is ignored on some mobile browsers when the tile's width
   resolves late during grid layout. This works everywhere.
   ========================================================================= */

.lib-thumb {
    position: relative;
    width: 100%;
    background: linear-gradient(135deg, #1a2234, #0a0e17);
    overflow: hidden;
    /* No aspect-ratio, no flex — the ::before spacer establishes height */
}

/* Spacer block: padding-top of 56.25% of the container's width = 16:9 */
.lib-thumb::before {
    content: '';
    display: block;
    padding-top: 56.25%;
}

/* Real thumbnail image fills the tile */
.lib-thumb-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: #0a0e17;
    z-index: 0;
}

/* Play icon — absolutely centred so it doesn't affect the tile's height */
.lib-thumb-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 36px;
    height: 36px;
    opacity: 0.65;
    color: #fff;
    transition: opacity 0.15s, transform 0.15s;
    z-index: 1;
    pointer-events: none;
}

.lib-item:hover .lib-thumb-play {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
}

.lib-item:hover .lib-thumb-play {
    opacity: 1;
    transform: scale(1.08);
}

.lib-thumb-duration {
    position: absolute;
    bottom: 6px;
    right: 6px;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.3px;
}

.lib-thumb-voice {
    position: absolute;
    top: 6px;
    left: 6px;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(47, 129, 247, 0.85);
    color: #fff;
    letter-spacing: 0.5px;
}

.lib-item-info {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.lib-item-date {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}

.lib-item-size {
    font-size: 11px;
    color: var(--text-dim);
}

/* ---------- Player modal ---------- */

.lib-player-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 120;
    backdrop-filter: blur(6px);
}

.lib-player-modal.hidden { display: none; }

.lib-player-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    width: min(900px, 100%);
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
}

.lib-player-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.lib-player-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text);
}

.lib-player-video {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: 8px;
    display: block;
    margin-bottom: 12px;
}

.lib-player-meta {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 16px;
}

.lib-player-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger);
    color: #fff;
}

/* ---------- Mobile ---------- */

@media (max-width: 600px) {
    .library-panel {
        bottom: 0;
        max-height: 75vh;
    }
 .brand-logo {
        width: 22px;
        height: 22px;
    }
    .lib-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 10px;
    }

    .lib-player-card {
        padding: 14px;
        border-radius: 10px;
    }

    .lib-player-actions {
        flex-direction: column;
    }

    .lib-player-actions .btn {
        width: 100%;
        padding: 12px;
    }
}
/* =========================================================================
   LIBRARY — DELETE BUTTON ON CARD
   ========================================================================= */

.lib-item-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(10, 14, 23, 0.85);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, transform 0.15s;
    z-index: 3;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.lib-item:hover .lib-item-delete { opacity: 1; }

.lib-item-delete:hover {
    background: var(--danger);
    transform: scale(1.1);
}

@media (hover: none) {
    .lib-item-delete { opacity: 1; }
}

/* The VOICE badge was at top-left; make room for delete at top-right */
.lib-thumb-voice {
    /* unchanged — stays top-left */
}

/* =========================================================================
   LIBRARY — CONFIRMATION MODAL
   ========================================================================= */

.lib-confirm-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 130;
    backdrop-filter: blur(6px);
}

.lib-confirm-modal.hidden { display: none; }

.lib-confirm-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: min(420px, 100%);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
    text-align: center;
}

.lib-confirm-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
}

.lib-confirm-message {
    font-size: 13px;
    color: var(--text);
    line-height: 1.5;
    margin-bottom: 8px;
    word-break: break-word;
}

.lib-confirm-warning {
    font-size: 12px;
    color: var(--danger);
    margin-bottom: 22px;
    font-weight: 600;
}

.lib-confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.lib-confirm-actions .btn {
    min-width: 100px;
}

@media (max-width: 600px) {
    .lib-confirm-actions {
        flex-direction: column-reverse;
    }
    .lib-confirm-actions .btn {
        width: 100%;
        padding: 12px;
    }
}
/* =========================================================================
   TRIM EDITOR (inside the preview modal)
   ========================================================================= */

.preview-trim {
    margin: 16px 0 4px;
    user-select: none;
    -webkit-user-select: none;
}

.preview-trim.hidden { display: none; }

.trim-track {
    position: relative;
    height: 34px;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin: 22px 0 6px;
    overflow: visible;
    touch-action: none;
}

.trim-selection {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(47, 129, 247, 0.14);
    border-left: 2px solid var(--accent);
    border-right: 2px solid var(--accent);
    cursor: grab;
    transition: background 0.12s;
}

.trim-selection:hover {
    background: rgba(47, 129, 247, 0.22);
}

.trim-selection:active {
    cursor: grabbing;
}

.trim-handle {
    position: absolute;
    top: -6px;
    bottom: -6px;
    width: 16px;
    margin-left: -8px;
    cursor: ew-resize;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.trim-handle::before {
    content: '';
    position: absolute;
    top: 6px;
    bottom: 6px;
    width: 4px;
    background: var(--accent);
    border-radius: 2px;
    box-shadow: 0 0 8px var(--accent-glow);
    transition: background 0.12s, box-shadow 0.12s;
}

.trim-handle:hover::before {
    background: #4a92ff;
    box-shadow: 0 0 14px var(--accent-glow);
}

.trim-handle-label {
    position: absolute;
    top: -24px;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    background: var(--bg-deep);
    border: 1px solid var(--border);
    padding: 2px 7px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s;
    font-weight: 600;
}

.preview-trim:hover .trim-handle-label,
.trim-handle:hover .trim-handle-label {
    opacity: 1;
}

.trim-readout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 11px;
    color: var(--text-dim);
    min-height: 20px;
}

.trim-readout span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.trim-reset {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.15s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.trim-reset:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Mobile */
@media (max-width: 600px) {
    .trim-track {
        height: 30px;
        margin: 20px 0 6px;
    }

    .trim-handle { width: 22px; margin-left: -11px; }

    .trim-handle::before {
        width: 5px;
        top: 5px;
        bottom: 5px;
    }

    .preview-trim:hover .trim-handle-label,
    .trim-handle:hover .trim-handle-label {
        opacity: 1;
    }

    .trim-readout {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .trim-reset { align-self: flex-end; }
}
/* =========================================================================
   PREVIEW MODAL — TITLE INPUT (set at upload time)
   ========================================================================= */

.preview-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    padding: 10px 12px;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.preview-title-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    flex-shrink: 0;
}

.preview-title-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    padding: 4px 0;
    min-width: 0;
}

.preview-title-input::placeholder {
    color: var(--text-dim);
    opacity: 0.7;
}

/* =========================================================================
   LIBRARY PLAYER — TITLE INPUT (rename after upload)
   ========================================================================= */

.lib-player-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.lib-player-title-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 6px 10px;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}

.lib-player-title-input:hover {
    border-color: var(--border);
    background: var(--bg-panel-2);
}

.lib-player-title-input:focus {
    border-color: var(--accent);
    background: var(--bg-panel-2);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.lib-player-title-input::placeholder {
    color: var(--text-dim);
    font-weight: 500;
    font-style: italic;
}

.lib-player-title-status {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.2s;
}

.lib-player-title-status.visible {
    opacity: 1;
}

.lib-player-title-status.saving { color: var(--text-dim); }
.lib-player-title-status.saved  { color: #22c55e; }
.lib-player-title-status.error  { color: var(--danger); }

/* =========================================================================
   LIBRARY CARD — TITLE ON CARD
   ========================================================================= */

.lib-item-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.lib-item-sub {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* Mobile */
@media (max-width: 600px) {
    .lib-player-title-input {
        font-size: 14px;
        padding: 5px 8px;
    }

    .preview-title-row {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .preview-title-label {
        font-size: 10px;
    }
}
/* =========================================================================
   LIBRARY — SEARCH TOOLBAR
   ========================================================================= */

.lib-searchbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.lib-search-wrap {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    min-width: 0;
}

.lib-search-icon {
    position: absolute;
    left: 11px;
    width: 15px;
    height: 15px;
    color: var(--text-dim);
    pointer-events: none;
}

.lib-search-input {
    width: 100%;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    padding: 8px 32px 8px 34px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    min-width: 0;
}

.lib-search-input::placeholder {
    color: var(--text-dim);
    opacity: 0.7;
}

.lib-search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.lib-search-clear {
    position: absolute;
    right: 8px;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-dim);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.lib-search-clear:hover {
    background: var(--bg-deep);
    color: var(--text);
}

.lib-search-clear.hidden { display: none; }

.lib-sort-select {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    padding: 8px 10px;
    outline: none;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.15s;
}

.lib-sort-select:focus { border-color: var(--accent); }

/* Mobile: stack the search and sort */
@media (max-width: 600px) {
    .lib-searchbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 10px 12px;
    }

    .lib-sort-select { width: 100%; }

    .lib-search-input { font-size: 12px; padding: 7px 30px 7px 32px; }
}
/* =========================================================================
   LIBRARY — STORAGE USAGE BAR
   ========================================================================= */

.lib-storage-bar {
    position: relative;
    height: 22px;
    background: var(--bg-panel-2);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    flex-shrink: 0;
}

.lib-storage-bar.hidden { display: none; }

.lib-storage-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0%;
    background: linear-gradient(90deg, #22c55e, #22c55e);
    transition: width 0.3s ease, background 0.3s ease;
}

.lib-storage-bar.warning .lib-storage-fill {
    background: linear-gradient(90deg, #f59e0b, #f59e0b);
}

.lib-storage-bar.danger .lib-storage-fill {
    background: linear-gradient(90deg, #ef4444, #ef4444);
}

.lib-storage-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
    letter-spacing: 0.3px;
    pointer-events: none;
}
/* =========================================================================
   GUEST CALL MODAL
   ========================================================================= */

.guest-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 130;
    backdrop-filter: blur(6px);
}

.guest-modal.hidden { display: none; }

.guest-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 22px;
    width: min(620px, 100%);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
}

.guest-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.guest-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text);
}

.guest-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.guest-help {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-dim);
}

.guest-link-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.guest-link-input {
    flex: 1;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    padding: 10px 12px;
    outline: none;
    min-width: 0;
}

.guest-link-input:focus { border-color: var(--accent); }

.guest-status {
    font-size: 12px;
    color: var(--text-dim);
    padding: 10px 12px;
    background: var(--bg-panel-2);
    border-radius: 6px;
    border: 1px solid var(--border);
}

.guest-status.connected {
    color: #22c55e;
    border-color: #22c55e44;
}

.guest-video-wrap {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    aspect-ratio: 16 / 9;
}

.guest-video-wrap.hidden { display: none; }

.guest-video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.guest-video-label {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 4px;
    background: rgba(10, 14, 23, 0.85);
    color: #fff;
}

.guest-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

/* Hidden iframe — kept in the DOM but never rendered */
.vdo-hidden-iframe {
    position: fixed;
    left: -9999px;
    top: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    border: 0;
}

/* Guest button in the control bar */
#btnGuest.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 12px var(--accent-glow);
}

/* Mobile */
@media (max-width: 600px) {
    .guest-card { padding: 16px; }
    .guest-link-row { flex-direction: column; }
    .guest-link-row .btn { width: 100%; }
    .guest-footer { flex-direction: column-reverse; }
    .guest-footer .btn { width: 100%; }
}
/* =========================================================================
   GUEST AUDIO CONTROLS
   ========================================================================= */

.guest-audio-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.guest-audio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    flex-shrink: 0;
}

.guest-audio-label svg {
    width: 14px;
    height: 14px;
    color: var(--accent);
}

.guest-audio-row input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 4px;
    background: var(--bg-deep);
    border-radius: 2px;
    outline: none;
    min-width: 0;
}

.guest-audio-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 8px var(--accent-glow);
}

.guest-audio-row input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}
/* =========================================================================
   CAPTURE SHAPE SWITCHER
   ========================================================================= */

.shape-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    flex: 0 0 auto;
    opacity: 0.55;
    transition: all 0.15s;
}

.shape-btn svg {
    width: 16px;
    height: 16px;
}

.shape-btn:hover:not(:disabled) {
    opacity: 1;
    border-color: var(--accent);
}

.shape-btn.active {
    opacity: 1;
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 12px var(--accent-glow);
}

.shape-btn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}

/* Portrait stage variant — swaps the aspect ratio of the preview box */
.stage.stage-portrait {
    aspect-ratio: 9 / 16;
}

/* On mobile, keep both the switcher and its siblings reachable */
@media (max-width: 600px) {
    .shape-btn {
        width: 36px;
        height: 36px;
    }
}
/* =========================================================================
   "NO BACKGROUND" TILE
   ========================================================================= */

.bg-item-none .bg-item-preview-placeholder {
    background: linear-gradient(135deg, #1e2840, #0a0e17);
    color: var(--accent);
}

.bg-item-none .bg-item-preview-placeholder svg {
    width: 34px;
    height: 34px;
    opacity: 0.75;
}

.bg-item-none .bg-item-badge {
    color: #22c55e;
    border-color: #22c55e44;
}
/* =========================================================================
   AI BACKGROUND GENERATOR
   ========================================================================= */

.bg-ai-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.bg-ai-input-wrap {
    position: relative;
    flex: 1 1 260px;
    display: flex;
    align-items: center;
    min-width: 0;
}

.bg-ai-icon {
    position: absolute;
    left: 11px;
    width: 14px;
    height: 14px;
    color: var(--accent);
    pointer-events: none;
}

.bg-ai-input {
    width: 100%;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    padding: 9px 12px 9px 34px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    min-width: 0;
}

.bg-ai-input::placeholder {
    color: var(--text-dim);
    opacity: 0.7;
}

.bg-ai-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.bg-ai-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.bg-ai-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.bg-ai-btn svg {
    width: 14px;
    height: 14px;
}

.bg-ai-btn.generating {
    opacity: 0.65;
    cursor: wait;
}

.bg-ai-status {
    font-size: 11px;
    color: var(--text-dim);
    flex-basis: 100%;
    min-height: 14px;
}

.bg-ai-status.success { color: #22c55e; }
.bg-ai-status.error   { color: var(--danger); }

@media (max-width: 600px) {
    .bg-ai-row {
        flex-direction: column;
        align-items: stretch;
    }
    .bg-ai-btn {
        width: 100%;
        justify-content: center;
        padding: 12px;
    }
}
.shape-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    flex: 0 0 auto;
    opacity: 0.55;
    transition: all 0.15s;
}

.shape-btn svg { width: 16px; height: 16px; }

.shape-btn:hover:not(:disabled) {
    opacity: 1;
    border-color: var(--accent);
}

.shape-btn.active {
    opacity: 1;
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 12px var(--accent-glow);
}

.shape-btn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}

.stage.stage-portrait {
    aspect-ratio: 9 / 16;
}

.bg-item-none .bg-item-preview-placeholder {
    background: linear-gradient(135deg, #1e2840, #0a0e17);
    color: var(--accent);
}

.bg-item-none .bg-item-preview-placeholder svg {
    width: 34px;
    height: 34px;
    opacity: 0.75;
}

.bg-item-none .bg-item-badge {
    color: #22c55e;
    border-color: #22c55e44;
}

/* =========================================================================
   SOUNDBOARD — LIST LAYOUT (compact rows)
   ========================================================================= */

/* When the grid is switched to list mode */
.sb-grid-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 8px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    align-content: start;
}

/* Each row is a button that spans the full width */
.sb-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
    padding: 9px 8px;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background 0.1s, border-color 0.1s, color 0.1s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    line-height: 1.3;
    min-width: 0;
}

.sb-row:hover {
    background: var(--bg-panel-2);
    border-color: var(--border);
}

.sb-row:active,
.sb-row.playing {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ---- Left side ---- */

.sb-row-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.sb-row-num {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-dim);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.3px;
    line-height: 1.4;
}

.sb-row.playing .sb-row-num {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.sb-row-name {
    font-size: 13px;
    color: inherit;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
    min-width: 0;
}

.sb-row-cat {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    font-weight: 500;
    flex-shrink: 0;
    opacity: 0.7;
}

.sb-row.playing .sb-row-cat {
    color: rgba(255, 255, 255, 0.75);
    opacity: 1;
}

/* ---- Right side — the star ---- */

.sb-row-star {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s, transform 0.1s, opacity 0.15s;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    opacity: 0.45;
}

.sb-row:hover .sb-row-star {
    opacity: 1;
}

.sb-row-star:hover {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.15);
    transform: scale(1.12);
}

.sb-row-star.active {
    color: #fbbf24;
    opacity: 1;
}

.sb-row.playing .sb-row-star.active {
    color: #fff;
}

/* On touch devices the star is always visible */
@media (hover: none) {
    .sb-row-star {
        opacity: 0.85;
    }
}

/* ---- Mobile tweaks ---- */

@media (max-width: 600px) {
    .sb-row {
        padding: 11px 10px;
        font-size: 12px;
    }

    .sb-row-name {
        font-size: 12px;
    }

    .sb-row-star {
        width: 30px;
        height: 30px;
        font-size: 16px;
    }
}
/* Tablet — 2 columns */
@media (max-width: 900px) {
    .sb-grid-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 5px;
    }
}

/* Mobile — 2 columns still (rows stay readable) */
@media (max-width: 600px) {
    .sb-grid-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
        padding: 6px;
    }

    .sb-row {
        padding: 8px 7px;
        font-size: 12px;
    }

    .sb-row-name {
        font-size: 12px;
    }

    .sb-row-star {
        width: 24px;
        height: 24px;
        font-size: 14px;
    }
}

/* Very small — single column */
@media (max-width: 380px) {
    .sb-grid-list {
        grid-template-columns: 1fr;
    }
}
/* =========================================================================
   MEDIA OVERLAY CONTROLS
   ========================================================================= */

.overlay-controls {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(10, 14, 23, 0.92);
    border: 1px solid var(--border);
    border-radius: 999px;
    z-index: 25;
    pointer-events: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    font-size: 11px;
}

.overlay-controls.hidden { display: none; }

.overlay-controls-label {
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    padding: 0 4px;
    flex-shrink: 0;
}

.overlay-pos-group {
    display: flex;
    gap: 2px;
    padding: 2px;
    background: var(--bg-deep);
    border-radius: 6px;
}

.overlay-pos-btn {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 13px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    padding: 0;
    line-height: 1;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.overlay-pos-btn:hover {
    background: var(--bg-panel-2);
    color: var(--text);
}

.overlay-pos-btn.active {
    background: var(--accent);
    color: #fff;
}

.overlay-remove { color: var(--text-dim); }
.overlay-remove:hover { background: var(--danger); color: #fff; }

.overlay-size {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    background: var(--bg-deep);
    border-radius: 2px;
    outline: none;
    flex-shrink: 0;
}

.overlay-size::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 6px var(--accent-glow);
}

.overlay-size::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 6px var(--accent-glow);
}

/* Active state for the overlay button in the control bar */
#btnOverlay.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 12px var(--accent-glow);
}

@media (max-width: 600px) {
    .overlay-controls {
        bottom: 8px;
        padding: 4px 8px;
        gap: 4px;
    }
    .overlay-controls-label { display: none; }
    .overlay-pos-btn { width: 24px; height: 24px; font-size: 12px; }
    .overlay-size { width: 60px; }
}
/* =========================================================================
   TRANSCRIPT VIEWER MODAL
   ========================================================================= */

.transcript-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 125;
    backdrop-filter: blur(6px);
}

.transcript-modal.hidden { display: none; }

.transcript-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    width: min(760px, 100%);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
}

.transcript-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.transcript-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text);
}

.transcript-body {
    flex: 1;
    min-height: 200px;
    overflow-y: auto;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 14px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.transcript-loading {
    color: var(--text-dim);
    text-align: center;
    padding: 40px 0;
    font-style: italic;
}

.transcript-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.transcript-meta {
    font-size: 11px;
    color: var(--text-dim);
}

.transcript-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.transcript-actions .btn {
    font-size: 12px;
    padding: 7px 14px;
}

/* Transcribe button inside the library player modal */
.lib-player-actions .btn-transcribe {
    background: transparent;
    border-color: #22c55e;
    color: #22c55e;
}

.lib-player-actions .btn-transcribe:hover:not(:disabled) {
    background: #22c55e;
    color: #fff;
}

.lib-player-actions .btn-transcribe.transcribing {
    opacity: 0.6;
    cursor: wait;
}

/* Mobile */
@media (max-width: 600px) {
    .transcript-card {
        padding: 16px;
        border-radius: 10px;
        max-height: 100vh;
        height: 100%;
    }

    .transcript-body {
        font-size: 12px;
        padding: 12px;
    }

    .transcript-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .transcript-actions {
        flex-direction: column;
    }

    .transcript-actions .btn {
        width: 100%;
        padding: 11px;
    }
}
/* =========================================================================
   MATTING QUALITY SWITCHER
   ========================================================================= */

.matting-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    flex: 0 0 auto;
    opacity: 0.55;
    transition: all 0.15s;
}

.matting-btn svg { width: 16px; height: 16px; }

.matting-btn:hover:not(:disabled) {
    opacity: 1;
    border-color: var(--accent);
}

.matting-btn.active {
    opacity: 1;
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 12px var(--accent-glow);
}

.matting-btn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}

/* While RVM is loading, show a subtle pulse on the Best button */
.matting-btn.loading {
    animation: pulse 1.2s ease-in-out infinite;
    pointer-events: none;
}

@media (max-width: 600px) {
    .matting-btn { width: 36px; height: 36px; }
}
/* studio.css */
#btnShare:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}
#btnShare:not(:disabled):hover {
    background: var(--accent);
    color: #fff;
}

/* =========================================================================
   GUEST LEVEL METER (floating, draggable)
   ========================================================================= */

.guest-eq-panel {
    position: fixed;
    bottom: 110px;
    right: 20px;
    width: 320px;
    background: rgba(10, 14, 23, 0.95);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.65);
    z-index: 60;
    user-select: none;
    -webkit-user-select: none;
    backdrop-filter: blur(6px);
    overflow: hidden;
}

.guest-eq-panel.hidden { display: none; }

.guest-eq-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    cursor: grab;
    touch-action: none;
}

.guest-eq-header:active { cursor: grabbing; }

.guest-eq-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    pointer-events: none;
}

.guest-eq-close {
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, color 0.15s;
}

.guest-eq-close:hover {
    background: var(--danger);
    color: #fff;
}

#guestEqCanvas {
    display: block;
    width: 100%;
    height: 100px;
}

@media (max-width: 600px) {
    .guest-eq-panel {
        width: 260px;
        bottom: 80px;
        right: 10px;
    }
    #guestEqCanvas { height: 80px; }
}.brand-logo {
    width: 28px;
    height: 28px;
    display: block;
    object-fit: contain;
    flex-shrink: 0;
    /* Subtle glow so the logo sits well against the dark panel.
       Remove if your logo already has its own background. */
    filter: drop-shadow(0 0 6px rgba(47, 129, 247, 0.35));
}   
/* =========================================================================
 /* =========================================================================
   MOBILE / TABLET — LANDSCAPE (tilted)
   Stage on the left, controls docked to the right.
   Triggers on touch devices when the viewport is wider than it is tall
   and the vertical space is tight.
   ========================================================================= */

@media (orientation: landscape) and (max-height: 800px) and (pointer: coarse) {

    /* ---- Grid: topbar spans the top, stage left, controls right ---- */
    body {
        display: grid;
        grid-template-columns: 1fr min(280px, 34vw);
        grid-template-rows: 40px 1fr;
        grid-template-areas:
            "topbar   topbar"
            "stage    controls";

        /* Fallback for older browsers */
        height: 100vh;
        /* Modern browsers: accounts for mobile chrome appearing/disappearing */
        height: 100dvh;

        overflow: hidden;
        overscroll-behavior: none;
    }

    /* Safety net: never let the grid grow past the real viewport */
    html, body {
        max-height: 100dvh;
        overflow: hidden;
    }

    /* ---- Topbar: thin, pinned, single line ---- */
    .topbar {
        grid-area: topbar;
        position: sticky;
        top: 0;
        z-index: 5;
        height: 40px;
        padding: 0 12px;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .brand-logo { width: 22px; height: 22px; }
    .brand-name { font-size: 12px; letter-spacing: 1px; }
    .brand-tag  { display: none; }

    .status {
        font-size: 10px;
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* ---- Stage: fills the left column ---- */
    .stage-wrap {
        grid-area: stage;
        padding: 6px;
        min-height: 0;
        min-width: 0;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .stage {
        border-radius: 6px;
        max-height: 100%;
        max-width: 100%;
    }

    /* ---- Control bar: right sidebar ---- */
    .controlbar {
        grid-area: controls;
        flex-direction: column;
        gap: 6px;
        padding: 6px 8px 10px;
        border-top: none;
        border-left: 1px solid var(--border);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        min-width: 0;
        min-height: 0;
    }

    .controlbar-row {
        flex-direction: column;
        align-items: stretch;
        flex-wrap: nowrap;
        gap: 6px;
        width: 100%;
    }

    /* Button groups: full-width rows, wrapped and centered */
    .control-group {
        width: 100%;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }

    /* Camera / mic: icon + select stay on one row */
    .control-group:has(.control-select) {
        flex-wrap: nowrap;
        align-items: center;
    }

    .control-select {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none;
        font-size: 11px;
        padding: 6px 8px;
    }

    .control-icon-label {
        width: 26px;
        height: 26px;
        flex-shrink: 0;
    }

    .control-icon-label svg { width: 13px; height: 13px; }

    #shapeSwitcher {
        justify-content: center;
    }

    /* Studio tools: separated by a divider, wrapped and centered */
    .control-group.push-right {
        margin-left: 0;
        justify-content: center;
        padding-top: 6px;
        border-top: 1px solid var(--border);
    }

    /* Compact tap targets so more fits in the narrow column */
    .btn-icon,
    .shape-btn,
    .matting-btn {
        width: 32px;
        height: 32px;
    }

    .btn-icon svg { width: 15px; height: 15px; }

    /* ---- Meter row: pinned to the bottom of the sidebar ---- */
    .controlbar-meter-row {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        padding-top: 8px;
        margin-top: auto;
        border-top: 1px solid var(--border);
        flex-shrink: 0;
    }

    /* Full-width meter. The !importants defeat the earlier
       `.audio-meter { width: 90px; flex-shrink: 0 }` rule that
       was winning by source order. */
    .audio-meter {
        display: block !important;
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        height: 16px !important;
        flex: 0 0 auto !important;
        box-sizing: border-box;
    }

    .timer {
        text-align: center;
        margin: 0;
        min-width: 0;
        font-size: 13px;
        font-variant-numeric: tabular-nums;
    }

    /* ---- Overlay controls: tightened on the stage ---- */
    .overlay-controls {
        bottom: 6px;
        padding: 4px 8px;
        gap: 4px;
    }
    .overlay-controls-label { display: none; }
    .overlay-pos-btn { width: 24px; height: 24px; font-size: 12px; }
    .overlay-size { width: 60px; }
}
/* =========================================================================
   TRANSCRIBE MODAL — must sit above the library player (z-index: 120)
   The base .tp-editor-modal class uses z-index: 110, which is correct
   for the teleprompter (opened from the main stage) but too low here.
   ========================================================================= */

#transcribeModal {
    z-index: 140;
}

/* =========================================================================
   RECOVERY BANNER (local drafts)
   ========================================================================= */

.recovery-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: linear-gradient(90deg,
        rgba(47, 129, 247, 0.18),
        rgba(47, 129, 247, 0.06));
    border-bottom: 1px solid rgba(47, 129, 247, 0.35);
    color: var(--text);
    flex-shrink: 0;
    animation: recoverySlideIn 0.25s ease-out;
}

.recovery-banner.hidden {
    display: none;
}

@keyframes recoverySlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.recovery-banner-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(47, 129, 247, 0.25);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
}

.recovery-banner-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 13px;
}

.recovery-banner-text strong {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recovery-banner-text span {
    font-size: 11px;
    color: var(--text-dim);
}

.recovery-banner-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.recovery-banner-actions .btn {
    padding: 6px 14px;
    font-size: 12px;
}

@media (max-width: 600px) {
    .recovery-banner {
        padding: 8px 12px;
        gap: 8px;
    }
    .recovery-banner-icon { width: 24px; height: 24px; font-size: 14px; }
    .recovery-banner-text strong { font-size: 12px; }
    .recovery-banner-actions .btn { padding: 6px 10px; font-size: 11px; }
    .recovery-banner-actions .btn:first-child { display: none; }
}
/* =========================================================================
   TRANSCRIBE MODAL — must sit above the library player on every screen
   ========================================================================= */

#transcribeModal {
    z-index: 200 !important;
}

@media (max-width: 600px) {
    #transcribeModal {
        padding: 16px;
    }
    #transcribeModal .tp-editor-card {
        width: 100%;
        max-width: 100%;
        padding: 18px;
        border-radius: 10px;
        max-height: 85vh;
        overflow-y: auto;
    }
    #transcribeModal .tp-editor-actions {
        flex-direction: column-reverse;
        gap: 8px;
    }
    #transcribeModal .tp-editor-actions .btn {
        width: 100%;
        padding: 12px;
    }
}
/* Real thumbnail image fills the tile */
.lib-thumb-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: #0a0e17;
}

/* The play icon sits on top, dimmed until hover */
.lib-thumb-play {
    position: relative;
    z-index: 1;
}
/* =========================================================================
   AUTH MODAL
   ========================================================================= */

.auth-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 210;
    backdrop-filter: blur(6px);
    overflow-y: auto;
}

.auth-modal.hidden { display: none; }

.auth-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    width: min(880px, 100%);
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
}

.auth-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.auth-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.3px;
    color: var(--text);
}

.auth-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-panel-2);
    border-radius: 8px;
    margin-bottom: 20px;
    width: max-content;
}

.auth-tab {
    padding: 8px 20px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.auth-tab.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 10px var(--accent-glow);
}

.auth-form { display: block; }
.auth-form.hidden { display: none; }

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.auth-field label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
}

.auth-field input {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    padding: 10px 14px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.auth-field-hint {
    font-size: 11px;
    color: var(--text-dim);
    opacity: 0.7;
}

.auth-plan-heading {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin: 22px 0 12px;
}

.auth-plans {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 18px;
}

.auth-plan {
    position: relative;
    display: block;
    cursor: pointer;
}

.auth-plan input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.auth-plan-inner {
    background: var(--bg-panel-2);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 16px 14px;
    height: 100%;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
    position: relative;
}

.auth-plan:hover .auth-plan-inner {
    border-color: #2f81f7aa;
}

.auth-plan input:checked + .auth-plan-inner {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.auth-plan-featured .auth-plan-inner {
    border-color: #2f81f755;
}

.auth-plan-badge {
    position: absolute;
    top: -8px;
    right: 10px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
}

.auth-plan-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}

.auth-plan-price {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 12px;
    line-height: 1.4;
}

.auth-plan-price strong {
    font-size: 20px;
    color: var(--text);
    font-weight: 700;
    margin-right: 4px;
}

.auth-plan-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.auth-plan-list li {
    font-size: 11.5px;
    color: var(--text-dim);
    line-height: 1.4;
    padding-left: 14px;
    position: relative;
}

.auth-plan-list li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: 700;
}

.auth-status {
    min-height: 18px;
    font-size: 12px;
    text-align: center;
    margin: 8px 0;
    color: var(--text-dim);
}

.auth-status.error   { color: var(--danger); }
.auth-status.success { color: #22c55e; }
.auth-status.working { color: var(--accent); }

.auth-submit {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    margin-top: 6px;
}

.auth-terms {
    font-size: 11px;
    color: var(--text-dim);
    text-align: center;
    margin-top: 12px;
    opacity: 0.75;
}

/* Mobile */
@media (max-width: 700px) {
    .auth-card { padding: 18px; }
    .auth-title { font-size: 15px; }

    .auth-plans {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .auth-plan-inner { padding: 14px; }
    .auth-plan-list li { font-size: 12px; }

    .auth-tabs {
        width: 100%;
    }

    .auth-tab { flex: 1; }
}
/* =========================================================================
   AUTH GATE — full-screen, shown until logged in
   ========================================================================= */

.auth-gate {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at 50% 30%,
        rgba(47, 129, 247, 0.10) 0%,
        var(--bg-deep) 45%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 500;
    overflow-y: auto;
}

.auth-gate.hidden { display: none; }

.auth-gate-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 28px 24px;
    width: min(420px, 100%);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
    animation: authGateIn 0.35s ease-out;
}

@keyframes authGateIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.auth-gate-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.brand-logo-large {
    width: 44px;
    height: 44px;
    filter: drop-shadow(0 0 10px rgba(47, 129, 247, 0.5));
}

.auth-gate-brand-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.auth-gate-brand-text .brand-name {
    font-size: 14px;
    letter-spacing: 1.5px;
}

.auth-gate-tagline {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.55;
    margin-bottom: 22px;
}

.auth-divider {
    position: relative;
    text-align: center;
    margin: 18px 0 14px;
    color: var(--text-dim);
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.auth-divider::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 50%;
    height: 1px;
    background: var(--border);
}

.auth-divider span {
    position: relative;
    background: var(--bg-panel);
    padding: 0 12px;
}

.google-signin-wrap {
    display: flex;
    justify-content: center;
    min-height: 44px;
}

.google-signin-wrap.hidden { display: none; }

.google-signin-fallback {
    text-align: center;
    font-size: 11px;
    color: var(--text-dim);
    padding: 12px;
    border: 1px dashed var(--border);
    border-radius: 8px;
}

.google-signin-fallback.hidden { display: none; }

/* =========================================================================
   STUDIO ROOT — flex wrapper matching the old body layout
   ========================================================================= */

.studio-root {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100%;
}

.studio-root.hidden { display: none; }

/* =========================================================================
   PROFILE MODAL
   ========================================================================= */

.profile-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 220;
    backdrop-filter: blur(6px);
    overflow-y: auto;
}

.profile-modal.hidden { display: none; }

.profile-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    width: min(880px, 100%);
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
}

.profile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.profile-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text);
}

.profile-user {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 16px;
}

.profile-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(47, 129, 247, 0.15);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.profile-avatar svg {
    width: 26px;
    height: 26px;
}

.profile-user-info {
    flex: 1;
    min-width: 0;
}

.profile-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.3;
    word-break: break-word;
}

.profile-email {
    font-size: 12px;
    color: var(--text-dim);
    word-break: break-all;
}

.profile-plan-badge {
    padding: 6px 12px;
    border-radius: 20px;
    background: rgba(47, 129, 247, 0.15);
    border: 1px solid rgba(47, 129, 247, 0.4);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.profile-trial-notice {
    padding: 12px 14px;
    background: rgba(251, 191, 36, 0.10);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 8px;
    color: #fbbf24;
    font-size: 12px;
    margin-bottom: 16px;
}

.profile-trial-notice.hidden { display: none; }

.profile-section-heading {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin: 22px 0 12px;
}

.profile-plans {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 18px;
}

.profile-plans .auth-plan-inner {
    display: flex;
    flex-direction: column;
}

.profile-plans .auth-plan-list {
    flex: 1;
    margin-bottom: 14px;
}

.btn-plan-action {
    width: 100%;
    padding: 10px;
    font-size: 12px;
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    letter-spacing: 0.3px;
    transition: all 0.15s;
}

.btn-plan-action:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-plan-action:disabled,
.btn-plan-action.btn-plan-current {
    background: rgba(47, 129, 247, 0.1);
    border-color: rgba(47, 129, 247, 0.4);
    color: var(--accent);
    cursor: default;
    opacity: 1;
}

.profile-payment-note {
    font-size: 11px;
    color: var(--text-dim);
    text-align: center;
    margin-bottom: 18px;
    opacity: 0.8;
}

.profile-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* =========================================================================
   MOBILE — profile + auth gate
   ========================================================================= */

@media (max-width: 700px) {
    .auth-gate { padding: 12px; }
    .auth-gate-card { padding: 24px 20px 20px; }

    .profile-card { padding: 18px; }
    .profile-user { padding: 14px; gap: 10px; }
    .profile-avatar { width: 40px; height: 40px; }
    .profile-avatar svg { width: 22px; height: 22px; }
    .profile-plan-badge { padding: 4px 10px; font-size: 10px; }

    .profile-plans {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .profile-actions {
        flex-direction: column-reverse;
    }
    .profile-actions .btn { width: 100%; }
}
.auth-gate-logo {
    width: 72px;
    height: 72px;
    filter: drop-shadow(0 0 18px rgba(47, 129, 247, 0.55));
}
/* =========================================================================
   PROFILE MODAL — logo header
   ========================================================================= */

.profile-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-bottom: 18px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.profile-logo {
    width: 60px;
    height: 60px;
    display: block;
    object-fit: contain;
    flex-shrink: 0;
    filter: drop-shadow(0 0 14px rgba(47, 129, 247, 0.5));
}

.profile-brand-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.profile-brand-name {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--text);
}

.profile-brand-tag {
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 2px 8px;
    border-radius: 3px;
    width: max-content;
}

/* The header with just the title now sits under the brand */
.profile-header {
    margin-bottom: 18px;
}

.profile-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
}

/* Mobile: shrink the logo a bit */
@media (max-width: 700px) {
    .auth-gate-logo { width: 60px; height: 60px; }
    .profile-logo   { width: 48px; height: 48px; }
    .profile-brand-name { font-size: 13px; letter-spacing: 1.5px; }
    .profile-brand-tag  { font-size: 9px; letter-spacing: 1.5px; }
}
/* =========================================================================
   TOPBAR — user chip
   ========================================================================= */

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.3px;
    max-width: 220px;
    overflow: hidden;
    cursor: default;
}

.user-chip.hidden { display: none; }

.user-chip-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(47, 129, 247, 0.2);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.user-chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.user-chip-plan {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 10px;
    background: rgba(47, 129, 247, 0.15);
    color: var(--accent);
    flex-shrink: 0;
}

.user-chip-plan.pro   { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.user-chip-plan.free  { background: rgba(139, 152, 169, 0.15); color: var(--text-dim); }

@media (max-width: 700px) {
    .user-chip { max-width: 140px; font-size: 10px; padding: 3px 8px 3px 3px; }
    .user-chip-avatar { width: 18px; height: 18px; font-size: 9px; }
    .user-chip-name { display: none; }   /* just show avatar + plan on phones */
    .user-chip-plan { font-size: 8px; padding: 1px 5px; }
}
/* =========================================================================
   PROFILE — SUPPORT SECTION
   ========================================================================= */

.profile-support {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.profile-support .profile-section-heading {
    margin-top: 0;
    margin-bottom: 12px;
}

.profile-support-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.profile-support-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-panel-2);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
    text-align: left;
    font-family: inherit;
    color: var(--text);
}

.profile-support-btn:hover {
    border-color: var(--accent);
    background: rgba(47, 129, 247, 0.06);
}

.profile-support-btn:active {
    transform: translateY(1px);
}

.profile-support-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.profile-support-icon {
    font-size: 24px;
    flex-shrink: 0;
    line-height: 1;
}

.profile-support-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.profile-support-text strong {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
}

.profile-support-text small {
    font-size: 11px;
    color: var(--text-dim);
    line-height: 1.3;
}

@media (max-width: 700px) {
    .profile-support-grid {
        grid-template-columns: 1fr;
    }
}

/* =========================================================================
   DONATE MODAL
   ========================================================================= */

.donate-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 240;
    backdrop-filter: blur(6px);
}

.donate-modal.hidden { display: none; }

.donate-card {
    position: relative;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 26px 24px;
    width: min(440px, 100%);
    text-align: center;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
    animation: modalPop 0.25s ease-out;
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.donate-card .btn-close {
    position: absolute;
    top: 14px;
    right: 14px;
}

.donate-icon {
    font-size: 48px;
    line-height: 1;
    margin-bottom: 12px;
    animation: heartbeat 1.8s ease-in-out infinite;
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.08); }
}

.donate-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.3px;
    color: var(--text);
    margin-bottom: 14px;
}

.donate-text {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-dim);
    margin-bottom: 12px;
}

.donate-amounts {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 22px 0 18px;
}

.donate-amount {
    padding: 12px 8px;
    background: var(--bg-panel-2);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.donate-amount:hover {
    border-color: var(--accent);
}

.donate-amount.active {
    background: rgba(47, 129, 247, 0.15);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.donate-submit {
    width: 100%;
    padding: 14px;
    font-size: 15px;
    margin-bottom: 12px;
}

.donate-fineprint {
    font-size: 11px;
    color: var(--text-dim);
    opacity: 0.7;
}

@media (max-width: 500px) {
    .donate-card { padding: 28px 20px 22px; }
    .donate-icon { font-size: 40px; }
    .donate-title { font-size: 18px; }
    .donate-amounts { grid-template-columns: repeat(2, 1fr); }
}

/* =========================================================================
   PARTNERSHIP MODAL
   ========================================================================= */

.partnership-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 240;
    backdrop-filter: blur(6px);
    overflow-y: auto;
}

.partnership-modal.hidden { display: none; }

.partnership-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    width: min(560px, 100%);
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
    animation: modalPop 0.25s ease-out;
}

.partnership-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.partnership-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.partnership-intro {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-dim);
    margin-bottom: 20px;
}

.partnership-form .auth-field {
    margin-bottom: 12px;
}

.partnership-form .optional {
    font-size: 10px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-dim);
    opacity: 0.7;
}

.partnership-form textarea {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    padding: 10px 14px;
    outline: none;
    resize: vertical;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}

.partnership-form textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.partnership-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

@media (max-width: 500px) {
    .partnership-card { padding: 18px; }
    .partnership-title { font-size: 16px; }
    .partnership-actions {
        flex-direction: column-reverse;
    }
    .partnership-actions .btn { width: 100%; padding: 12px; }
}
.cleanup-modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.7);
    display: flex; align-items: center; justify-content: center; z-index: 9999;
}
.cleanup-card {
    background: #0d1117; border: 1px solid #2a3240; border-radius: 12px;
    width: min(1100px, 94vw); max-height: 92vh; overflow: auto; padding: 20px;
}
.cleanup-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.cleanup-title { font-size: 18px; color: #e6edf3; margin: 0; }
.cleanup-loading { text-align: center; padding: 40px 20px; }
.cleanup-spinner {
    width: 40px; height: 40px; border: 3px solid #2f81f7;
    border-top-color: transparent; border-radius: 50%;
    animation: spin 0.9s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.cleanup-loading-text { color: #8b98a9; font-size: 14px; }
.cleanup-preview {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px;
}
.cleanup-preview video { width: 100%; border-radius: 8px; background: #000; }
.cleanup-preview-label {
    font-size: 12px; color: #8b98a9; text-transform: uppercase;
    letter-spacing: 1px; margin-bottom: 6px;
}
.cleanup-error {
    background: rgba(248, 81, 73, 0.1); color: #f85149;
    border: 1px solid rgba(248, 81, 73, 0.3); border-radius: 8px;
    padding: 12px 16px; font-size: 13px; margin-bottom: 16px;
}
.cleanup-actions { display: flex; gap: 12px; justify-content: flex-end; }

#cleanupModal.hidden { display: none !important; }
/* =========================================================================
   GUEST LAYOUT SWITCHER
   ========================================================================= */

.guest-layout-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.guest-layout-label {
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    flex-shrink: 0;
}

.guest-layout-group {
    display: flex;
    gap: 4px;
    margin-left: auto;
    padding: 3px;
    background: var(--bg-deep);
    border-radius: 8px;
}

.guest-layout-btn {
    width: 34px;
    height: 30px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.guest-layout-btn svg {
    width: 18px;
    height: 18px;
}

.guest-layout-btn:hover {
    color: var(--text);
    background: var(--bg-panel-2);
}

.guest-layout-btn.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 10px var(--accent-glow);
}

@media (max-width: 600px) {
    .guest-layout-btn { width: 40px; height: 36px; }
    .guest-layout-btn svg { width: 20px; height: 20px; }
}
/* =========================================================================
   STAGE — GUEST LAYOUT SWITCHER (floating)
   Appears at the bottom-right of the stage while a guest is connected.
   ========================================================================= */

.stage-guest-layout {
    position: absolute;
    bottom: 14px;
    right: 14px;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    background: rgba(10, 14, 23, 0.88);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    z-index: 26;
    pointer-events: auto;
}

.stage-guest-layout.hidden { display: none; }

.stage-layout-btn {
    width: 34px;
    height: 30px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.stage-layout-btn svg {
    width: 18px;
    height: 18px;
    display: block;
}

.stage-layout-btn:hover {
    color: var(--text);
    background: var(--bg-panel-2);
}

.stage-layout-btn.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 10px var(--accent-glow);
}

/* Compact on mobile */
@media (max-width: 600px) {
    .stage-guest-layout { bottom: 8px; right: 8px; padding: 3px; }
    .stage-layout-btn { width: 32px; height: 28px; }
    .stage-layout-btn svg { width: 16px; height: 16px; }
}
/* =========================================================================
   MEDIA OVERLAY — maximise / minimise + screen share
   ========================================================================= */

.overlay-maximised-only { display: none; }

.overlay-controls.overlay-maximised .overlay-pos-group,
.overlay-controls.overlay-maximised .overlay-size,
.overlay-controls.overlay-maximised > .overlay-controls-label:not(.overlay-maximised-only) {
    display: none;
}

.overlay-controls.overlay-maximised .overlay-maximised-only {
    display: inline-block;
}

.overlay-maximize {
    color: var(--text-dim);
}

.overlay-maximize:hover {
    background: var(--bg-panel-2);
    color: var(--text);
}

.overlay-maximize.active {
    background: var(--accent);
    color: #fff;
}

#btnShareScreen.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 12px var(--accent-glow);
}

/* On the mobile sidebar, the label "Full screen" would crowd the row */
@media (max-width: 600px) {
    .overlay-controls.overlay-maximised .overlay-maximised-only { display: none !important; }
}

/* =========================================================================
   SOUNDBOARD — custom sound uploads
   ========================================================================= */

.sb-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1.5px solid var(--accent);
    background: transparent;
    color: var(--accent);
    border-radius: 6px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

.sb-upload-btn svg { width: 12px; height: 12px; display: block; }

.sb-upload-btn:hover:not(:disabled) {
    background: var(--accent);
    color: #fff;
}

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

.sb-upload-btn.hidden { display: none; }

/* Delete button on user sound rows */
.sb-row-delete {
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
    opacity: 0;
    transition: color 0.15s, background 0.15s, opacity 0.15s;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    margin-left: 2px;
}

.sb-row:hover .sb-row-delete { opacity: 0.7; }
.sb-row-delete:hover {
    background: var(--danger);
    color: #fff;
    opacity: 1;
}

@media (hover: none) {
    .sb-row-delete { opacity: 0.7; }
}

/* Free-user upgrade card inside the My Sounds tab */
.sb-upgrade {
    grid-column: 1 / -1;
    text-align: center;
    padding: 32px 16px;
    color: var(--text-dim);
    font-size: 13px;
    line-height: 1.6;
}

.sb-upgrade strong {
    display: block;
    color: var(--text);
    font-size: 15px;
    margin-bottom: 8px;
}

.sb-upgrade a,
.sb-upgrade button {
    margin-top: 14px;
    display: inline-block;
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
}

/* =========================================================================
   PROFILE — ACTIVITY STATS
   ========================================================================= */

.profile-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.profile-stat {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 10px;
    text-align: center;
}

.profile-stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    margin-bottom: 4px;
}

.profile-stat-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    line-height: 1.2;
}

/* ---------- Storage bar ---------- */

.profile-storage-row {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 12px;
}

.profile-storage-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.profile-storage-text {
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    font-variant-numeric: tabular-nums;
}

.profile-storage-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-deep);
    border-radius: 4px;
    overflow: hidden;
}

.profile-storage-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #22c55e, #22c55e);
    transition: width 0.3s ease, background 0.3s ease;
}

.profile-storage-fill.warning { background: linear-gradient(90deg, #f59e0b, #f59e0b); }
.profile-storage-fill.danger  { background: linear-gradient(90deg, #ef4444, #ef4444); }

/* ---------- Meta row ---------- */

.profile-meta-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.profile-meta-item {
    font-size: 11px;
    color: var(--text-dim);
    padding: 4px 10px;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 20px;
}

/* ---------- Footer with legal links ---------- */

.profile-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding-top: 18px;
    margin-top: 18px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.profile-footer-link {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.profile-footer-link:hover {
    color: var(--accent);
    background: rgba(47, 129, 247, 0.08);
}

.profile-footer-dot {
    color: var(--border);
    font-size: 12px;
    user-select: none;
}

@media (max-width: 700px) {
    .profile-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    .profile-stat-value { font-size: 18px; }
    .profile-footer { gap: 4px; padding-top: 14px; margin-top: 14px; }
    .profile-footer-link { font-size: 11px; padding: 3px 5px; }
}

/* =========================================================================
   SUPPORT MODAL
   ========================================================================= */

.support-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 260;
    backdrop-filter: blur(6px);
    overflow-y: auto;
}
.support-modal.hidden { display: none; }

.support-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    width: min(560px, 100%);
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
    animation: modalPop 0.25s ease-out;
}

.support-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.support-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.support-intro {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-dim);
    margin-bottom: 20px;
}

.support-form textarea {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    padding: 10px 14px;
    outline: none;
    resize: vertical;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
    min-height: 140px;
    line-height: 1.5;
}

.support-form textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.support-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

@media (max-width: 500px) {
    .support-card { padding: 18px; }
    .support-actions { flex-direction: column-reverse; }
    .support-actions .btn { width: 100%; padding: 12px; }
}

/* =========================================================================
   LEGAL MODALS (Terms + Privacy)
   ========================================================================= */

.legal-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 270;
    backdrop-filter: blur(6px);
    overflow-y: auto;
}
.legal-modal.hidden { display: none; }

.legal-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: min(760px, 100%);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
    animation: modalPop 0.25s ease-out;
}

.legal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.legal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.legal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-dim);
}

.legal-body h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    margin: 20px 0 6px;
    letter-spacing: 0.3px;
}

.legal-body h3:first-of-type {
    margin-top: 8px;
}

.legal-body p {
    margin-bottom: 10px;
}

.legal-body strong {
    color: var(--text);
    font-weight: 600;
}

.legal-body ul {
    padding-left: 20px;
    margin-bottom: 10px;
}

.legal-body li {
    margin-bottom: 4px;
}

.legal-body a {
    color: var(--accent);
    text-decoration: none;
}

.legal-body a:hover {
    text-decoration: underline;
}

.legal-updated {
    font-size: 11px;
    font-style: italic;
    color: var(--text-dim);
    opacity: 0.75;
    margin-bottom: 16px !important;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.legal-actions {
    display: flex;
    justify-content: flex-end;
    padding: 14px 24px 20px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

@media (max-width: 600px) {
    .legal-modal { padding: 0; }
    .legal-card {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        border: none;
    }
    .legal-header { padding: 16px 18px 12px; }
    .legal-title { font-size: 16px; }
    .legal-body { padding: 16px 18px; font-size: 12.5px; }
    .legal-actions { padding: 12px 18px 16px; }
    .legal-actions .btn { width: 100%; padding: 12px; }
}

/* =========================================================================
   ADMIN — RESPONSIVE OVERRIDES
   The rules above are desktop-first. The blocks below progressively
   adapt the layout for tablet and mobile screens. Anything that appears
   here wins by source order.
   ========================================================================= */

/* ---------- Fluid base — applies at every size ---------- */

.admin-wrap {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
    box-sizing: border-box;
}

/* auto-fit means the grid picks the number of columns on its own —
   no breakpoints needed for the KPI row. */
.admin-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
}

/* Same trick for the two-column sections. minmax(340px) means two
   columns where there's room, and one column when there isn't. */
.admin-two-col {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
    align-items: start;
}

/* Prevent long emails/base names from blowing out their container */
.admin-card,
.admin-kpi {
    min-width: 0;
}

.admin-list-item,
.admin-partner-item,
.admin-user {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Charts should never exceed their parent */
.admin-chart {
    width: 100%;
    position: relative;
}

.admin-chart canvas,
.admin-chart svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Topbar: single line on desktop, wraps gracefully */
.admin-topbar {
    flex-wrap: wrap;
    gap: 12px;
}

.admin-topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    flex-wrap: wrap;
}

/* Partnership tabs: scroll horizontally instead of squishing */
.admin-tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}

.admin-tabs::-webkit-scrollbar { display: none; }

.admin-tab { flex-shrink: 0; }


/* =========================================================================
   TABLET  (<= 900px)
   ========================================================================= */

@media (max-width: 900px) {

    .admin-wrap {
        padding: 18px;
    }

    /* Two-per-row KPIs on tablet — the MRR card spans both columns
       since it's the headline metric. */
    .admin-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .admin-kpi-accent {
        grid-column: 1 / -1;
    }

    /* Stack the two-column sections */
    .admin-two-col {
        grid-template-columns: 1fr;
    }

    .admin-user {
        font-size: 12px;
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .admin-topbar {
        padding: 10px 16px;
    }
}


/* =========================================================================
   MOBILE  (<= 600px)
   ========================================================================= */

@media (max-width: 600px) {

    .admin-body {
        font-size: 14px;
    }

    .admin-wrap {
        padding: 12px;
    }

    /* ---------- Topbar ---------- */

    .admin-topbar {
        padding: 10px 12px;
        gap: 8px;
    }

    .admin-logo {
        width: 26px;
        height: 26px;
    }

    .admin-brand-name { font-size: 12px; letter-spacing: 1px; }
    .admin-brand-tag  { font-size: 9px; letter-spacing: 1px; }

    /* The "Signed in as…" text is too much on a phone. The email is
       available via the back-to-Studio flow. */
    .admin-user {
        display: none;
    }

    .admin-topbar-btn {
        width: 34px;
        height: 34px;
    }

    /* ---------- KPI grid: single column ---------- */

    .admin-kpi-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .admin-kpi {
        padding: 14px 16px;
    }

    .admin-kpi-value  { font-size: 24px; }
    .admin-kpi-label  { font-size: 10px; letter-spacing: 1px; }
    .admin-kpi-sub    { font-size: 11px; }

    /* ---------- Sections & cards ---------- */

    .admin-section {
        margin-bottom: 16px;
    }

    .admin-card {
        padding: 14px;
        border-radius: 10px;
    }

    .admin-card-header {
        flex-wrap: wrap;
        gap: 6px;
        margin-bottom: 12px;
    }

    .admin-card-title { font-size: 13px; }
    .admin-card-note  { font-size: 11px; }

    .admin-chart {
        min-height: 140px;
    }

    /* ---------- Plan distribution bar ---------- */

    .admin-plan-bar {
        height: 10px;
        border-radius: 5px;
    }

    .admin-plan-legend {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px 12px;
        font-size: 12px;
    }

    /* ---------- Tabs ---------- */

    .admin-tab {
        padding: 6px 10px;
        font-size: 12px;
    }

    /* ---------- Lists ---------- */

    .admin-list-item,
    .admin-partner-item {
        padding: 10px 12px;
        font-size: 12px;
    }
}


/* =========================================================================
   VERY SMALL  (<= 400px)
   ========================================================================= */

@media (max-width: 400px) {

    .admin-wrap { padding: 10px; }

    .admin-kpi-value { font-size: 22px; }

    /* Plan legend back to single column */
    .admin-plan-legend {
        grid-template-columns: 1fr;
    }
}
/* =========================================================================
   AI BACKGROUND GENERATOR — header with quota counter
   ========================================================================= */

.bg-ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    flex-basis: 100%;
    margin-bottom: 2px;
}

.bg-ai-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-dim);
}

.bg-ai-quota {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    transition: color 0.15s;
}

.bg-ai-quota.warning {
    color: #fbbf24;
}

.bg-ai-quota.danger {
    color: var(--danger);
}

.bg-ai-quota.unlimited {
    color: #22c55e;
}

/* The button and input wrap into their own rows; ensure the header
   sits on its own line above them. */
.bg-ai-row {
    flex-wrap: wrap;
}

/* =========================================================================
   RESPONSIVE FIXES
   1) Mobile landscape: target .studio-root (not body) so the grid actually
      applies to the real flex container.
   2) Background gallery: card is a strict flex column, only the grid
      scrolls → header/tabs/AI/footer are always visible.
   3) Short viewports: compact the gallery chrome so nothing gets clipped.
   ========================================================================= */

/* ---------------------------------------------------------------------
   1. STUDIO — mobile landscape
   --------------------------------------------------------------------- */
@media (orientation: landscape) and (max-height: 800px) and (pointer: coarse) {

    /* Undo the earlier (broken) grid-on-body rules */
    body {
        display: block;
        height: 100dvh;
        overflow: hidden;
    }

    .studio-root {
        position: relative;
        display: grid;
        grid-template-columns: 1fr min(280px, 34vw);
        grid-template-rows: 40px 1fr;
        grid-template-areas:
            "topbar   topbar"
            "stage    controls";
        height: 100dvh;
        width: 100%;
        overflow: hidden;
    }

    /* Keep the recovery banner out of the grid flow */
    .recovery-banner {
        position: absolute;
        top: 40px;
        left: 0;
        right: 0;
        z-index: 5;
    }

    .topbar {
        grid-area: topbar;
        height: 40px;
        padding: 0 12px;
        min-width: 0;
    }

    .stage-wrap {
        grid-area: stage;
        padding: 6px;
        min-height: 0;
        min-width: 0;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .stage {
        border-radius: 6px;
        max-height: 100%;
        max-width: 100%;
    }

    .controlbar {
        grid-area: controls;
        flex-direction: column;
        gap: 6px;
        padding: 6px 8px 10px;
        border-top: none;
        border-left: 1px solid var(--border);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        min-width: 0;
        min-height: 0;
    }

    .controlbar-row {
        flex-direction: column;
        align-items: stretch;
        flex-wrap: nowrap;
        gap: 6px;
        width: 100%;
    }

    .control-group {
        width: 100%;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }

    .control-group:has(.control-select) {
        flex-wrap: nowrap;
        align-items: center;
    }

    .control-select {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none;
        font-size: 11px;
        padding: 6px 8px;
    }

    .control-icon-label { width: 26px; height: 26px; flex-shrink: 0; }
    .control-icon-label svg { width: 13px; height: 13px; }

    #shapeSwitcher { justify-content: center; }

    .control-group.push-right {
        margin-left: 0;
        justify-content: center;
        padding-top: 6px;
        border-top: 1px solid var(--border);
    }

    .btn-icon,
    .shape-btn,
    .matting-btn {
        width: 32px;
        height: 32px;
    }

    .btn-icon svg { width: 15px; height: 15px; }

    .controlbar-meter-row {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        padding-top: 8px;
        margin-top: auto;
        border-top: 1px solid var(--border);
        flex-shrink: 0;
    }

    .audio-meter {
        display: block !important;
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        height: 16px !important;
        flex: 0 0 auto !important;
        box-sizing: border-box;
    }

    .timer {
        text-align: center;
        margin: 0;
        min-width: 0;
        font-size: 13px;
        font-variant-numeric: tabular-nums;
    }

    .overlay-controls { bottom: 6px; padding: 4px 8px; gap: 4px; }
    .overlay-controls-label { display: none; }
    .overlay-pos-btn { width: 24px; height: 24px; font-size: 12px; }
    .overlay-size { width: 60px; }
}

/* ---------------------------------------------------------------------
   2. BACKGROUND GALLERY — fix tiny tiles + off-screen AI generator
   --------------------------------------------------------------------- */

.bg-card {
    overflow: hidden;         /* clip instead of spill */
    min-height: 0;            /* let flex children size correctly */
}

/* Chrome around the grid must never shrink */
.bg-header,
.bg-tabs,
.bg-ai-row,
.bg-footer {
    flex-shrink: 0;
}

/* Grid is the only thing that scrolls / grows. Rows stay at their
   natural (aspect-ratio-derived) size, so tiles never collapse. */
.bg-grid {
    flex: 1 1 0;
    min-height: 220px;
    overflow-y: auto;
    overflow-x: hidden;
    align-content: start;
    grid-auto-rows: max-content;
}

/* Long prompt rows wrap cleanly */
.bg-ai-input-wrap {
    flex: 1 1 220px;
    min-width: 0;
}

/* ---------------------------------------------------------------------
   3. SHORT VIEWPORTS — compact chrome so the AI row + footer always fit
      (landscape phones, small laptops with devtools open, etc.)
   --------------------------------------------------------------------- */
@media (max-height: 520px) {

    .bg-modal { padding: 0; }

    .bg-card {
        width: 100%;
        height: 100%;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        padding: 10px 14px;
    }

    .bg-header { margin-bottom: 8px; }
    .bg-title  { font-size: 12px; }

    .bg-tabs {
        padding: 3px;
        margin-bottom: 8px;
    }
    .bg-tab {
        padding: 5px 10px;
        font-size: 11px;
    }

    /* More, smaller columns is better than one clipped row */
    .bg-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 8px;
        min-height: 80px;      /* allow shrink on the shortest screens */
        margin-bottom: 8px;
    }

    .bg-item-meta { padding: 6px 8px; }
    .bg-item-name { font-size: 11px; }

    .bg-ai-row { padding: 8px 0; gap: 8px; }
    .bg-ai-quota { font-size: 10px; }
    .bg-ai-input { padding: 7px 10px 7px 30px; font-size: 12px; }
    .bg-ai-btn   { padding: 8px 14px; font-size: 12px; }
    .bg-ai-status { font-size: 10px; }

    .bg-footer { padding-top: 8px; gap: 8px; }
    .bg-footer .btn { padding: 8px 14px; font-size: 12px; }
}

/* ---------------------------------------------------------------------
   4. NARROW PHONES — one big tile per row beats two tiny ones
   --------------------------------------------------------------------- */
@media (max-width: 380px) {
    .bg-grid {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }
}
/* =========================================================================
   AUTH GATE — "Learn more" link
   ========================================================================= */

.auth-learn-more {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 22px;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
    border: 1px solid rgba(82, 124, 202, 0.35);
    border-radius: 8px;
    background: rgba(82, 124, 202, 0.06);
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.auth-learn-more:hover {
    background: rgba(82, 124, 202, 0.14);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.auth-learn-more:active {
    transform: translateY(0);
}

.auth-learn-more svg {
    flex-shrink: 0;
    transition: transform 0.15s;
}

.auth-learn-more:hover svg {
    transform: translateX(3px);
}