/* ==========================================================================
   MockupForge 3D — Apple Studio / Rotato Ultra High-End Design System
   ========================================================================== */

:root {
    --bg-dark: #05060A;
    --bg-header: rgba(11, 13, 19, 0.85);
    --bg-rail: #0B0D14;
    --bg-stage: #040508;
    --bg-inspector: #0E1018;
    --bg-card: #141722;
    --bg-card-hover: #1C202E;
    
    --border-subpixel: rgba(255, 255, 255, 0.07);
    --border-hover: rgba(255, 255, 255, 0.15);
    --border-active: rgba(168, 85, 247, 0.5);
    
    --accent-purple: #A855F7;
    --accent-purple-glow: rgba(168, 85, 247, 0.3);
    --accent-blue: #38BDF8;
    --accent-pink: #F43F5E;
    
    --text-primary: #F9FAFB;
    --text-secondary: #9CA3AF;
    --text-muted: #4B5563;
    
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    
    --font-main: -apple-system, BlinkMacSystemFont, 'Plus Jakarta Sans', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body.studio-layout {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.01em;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* ==========================================================================
   Header Bar — Floating Translucent Glass Bar
   ========================================================================== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--bg-header);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--border-subpixel);
    z-index: 30;
    height: 54px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    border-radius: var(--radius-sm);
}

.header-brand:hover .brand-title { opacity: 0.85; }

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(56, 189, 248, 0.2));
    border-radius: var(--radius-sm);
    border: 1px solid rgba(168, 85, 247, 0.35);
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.25);
}

.brand-title {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: #FFF;
}

.badge-3d {
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.version-tag {
    font-size: 0.62rem;
    font-weight: 800;
    padding: 2px 7px;
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-blue);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* Aspect Ratio Selector */
.aspect-ratio-selector {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.45);
    padding: 3px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subpixel);
}

.bar-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    padding: 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ratio-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    font-size: 0.74rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.ratio-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

.ratio-btn.active {
    background: rgba(168, 85, 247, 0.2);
    color: #FFF;
    border-color: rgba(168, 85, 247, 0.4);
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid transparent;
}

.btn:disabled {
    opacity: 0.55;
    cursor: progress;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border-color: var(--border-subpixel);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--border-hover);
}

.btn-primary {
    background: linear-gradient(135deg, #38BDF8, #2563EB);
    color: #FFF;
    font-weight: 700;
    box-shadow: 0 4px 16px rgba(56, 189, 248, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 22px rgba(56, 189, 248, 0.5);
    transform: translateY(-1px);
}

.btn-pro {
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
    color: #FFF;
    font-weight: 700;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.35);
}

.btn-pro:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 30px rgba(244, 63, 94, 0.5);
}

/* ==========================================================================
   Studio Workspace (Tool Rail + Stage + Inspector)
   ========================================================================== */
.studio-workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Left Tool Rail */
.tool-rail {
    width: 68px;
    background: var(--bg-rail);
    border-right: 1px solid var(--border-subpixel);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    gap: 12px;
    z-index: 20;
}

.rail-btn {
    width: 52px;
    height: 52px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.rail-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.rail-btn.active {
    background: rgba(168, 85, 247, 0.18);
    border-color: rgba(168, 85, 247, 0.4);
    color: #FFF;
    box-shadow: 0 4px 15px rgba(168, 85, 247, 0.25);
}

.rail-icon {
    font-size: 1.25rem;
}

.rail-text {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.rail-spacer {
    flex: 1;
}

.rail-reset {
    color: var(--text-muted);
}

.rail-reset:hover {
    color: var(--accent-pink);
    background: rgba(244, 63, 94, 0.1);
}

/* Center Stage Viewport */
.stage-container {
    flex: 1;
    background: var(--bg-stage);
    background-image: radial-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px);
    background-size: 28px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    /* Room for the floating hint above and the quick toolbar below */
    padding: 52px 28px 76px;
    min-height: 0;
    min-width: 0;
}

.stage-wrapper {
    position: relative;
    /* Bound by the stage, not the window. Sizing off vw ignored the inspector
       panel and clipped the canvas. */
    max-width: 100%;
    max-height: 100%;
    min-width: 0;
    min-height: 0;
    box-shadow: 0 35px 90px -20px rgba(0, 0, 0, 0.95);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.12s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: center center;
}

#main-canvas {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

/* Floating Quick Toolbar */
.quick-toolbar {
    position: absolute;
    bottom: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(11, 13, 19, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-subpixel);
    padding: 6px 18px;
    border-radius: 30px;
    z-index: 20;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.quick-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s ease;
}

.quick-btn:hover {
    color: var(--text-primary);
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.45);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subpixel);
}

.zoom-btn {
    padding: 2px 6px;
    font-size: 0.82rem;
    font-weight: 700;
    border-radius: 4px;
}

.zoom-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.zoom-indicator {
    font-size: 0.7rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

/* Right Floating Inspector Panel */
.inspector-panel {
    width: 320px;
    background: var(--bg-inspector);
    border-left: 1px solid var(--border-subpixel);
    display: flex;
    flex-direction: column;
    z-index: 20;
}

.inspector-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subpixel);
    background: rgba(0, 0, 0, 0.2);
}

.inspector-title {
    font-size: 0.92rem;
    font-weight: 800;
    color: #FFF;
    letter-spacing: -0.01em;
}

.inspector-subtitle {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tab-contents {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.tab-contents::-webkit-scrollbar {
    width: 4px;
}

.tab-contents::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 2px;
}

.tab-pane {
    display: none;
    flex-direction: column;
    gap: 14px;
}

.tab-pane.active {
    display: flex;
}

/* Inspector Cards */
.inspector-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subpixel);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.card-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.slider-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.val-badge {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-blue);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 6px;
    border: 1px solid rgba(56, 189, 248, 0.2);
}

/* Device Cards Grid */
.device-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.device-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subpixel);
    border-radius: var(--radius-sm);
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
}

.device-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
}

.device-card.active {
    background: rgba(168, 85, 247, 0.16);
    border-color: var(--accent-purple);
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.2);
}

.dev-icon {
    font-size: 1.3rem;
}

.dev-name {
    font-size: 0.72rem;
    font-weight: 600;
}

/* Color Swatches */
.color-swatch-row {
    display: flex;
    gap: 10px;
}

.swatch-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--border-subpixel);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.swatch-btn:hover {
    transform: scale(1.15);
}

.swatch-btn.active {
    border-color: var(--accent-purple);
    box-shadow: 0 0 12px var(--accent-purple);
}

/* 3D Angle Presets Grid */
.angle-presets-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.angle-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subpixel);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 8px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all 0.2s ease;
}

.angle-btn:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
}

.angle-btn.active {
    background: rgba(56, 189, 248, 0.18);
    color: var(--accent-blue);
    border-color: var(--accent-blue);
}

/* Dropzone Upload */
.upload-dropzone {
    border: 2px dashed rgba(168, 85, 247, 0.35);
    border-radius: var(--radius-sm);
    padding: 18px 10px;
    text-align: center;
    background: rgba(168, 85, 247, 0.04);
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

.upload-dropzone:hover {
    border-color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.08);
}

.file-hidden {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.drop-icon {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.drop-text {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
}

.drop-text span {
    color: var(--accent-purple);
    text-decoration: underline;
}

.drop-sub {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Sample Screens Preset */
.sample-preset-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.sample-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subpixel);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 8px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all 0.2s ease;
}

.sample-btn:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
}

.sample-btn.active {
    background: rgba(168, 85, 247, 0.18);
    color: var(--accent-purple);
    border-color: var(--accent-purple);
}

/* Select & Inputs */
.select-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-subpixel);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.78rem;
    padding: 8px 10px;
    border-radius: var(--radius-xs);
    outline: none;
}

/* Gradient Presets Grid */
.gradient-preset-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
}

.grad-preset-btn {
    height: 32px;
    border-radius: var(--radius-xs);
    border: 1.5px solid var(--border-subpixel);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.grad-preset-btn:hover {
    transform: scale(1.1);
}

.grad-preset-btn.active {
    border-color: #FFF;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.color-picker-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-picker {
    -webkit-appearance: none;
    border: none;
    width: 36px;
    height: 32px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    background: transparent;
}

.color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker::-webkit-color-swatch {
    border: 1px solid var(--border-subpixel);
    border-radius: var(--radius-xs);
}

.btn-icon-small {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-subpixel);
    color: var(--text-primary);
    padding: 6px 10px;
    font-size: 0.75rem;
    border-radius: var(--radius-xs);
    cursor: pointer;
}

/* Toggle Checkbox */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toggle-checkbox {
    width: 34px;
    height: 18px;
    cursor: pointer;
}

.input-sub {
    font-size: 0.68rem;
    color: var(--text-muted);
}

/* ==========================================================================
   Pro VIP Beta Modal — Ultra High-End Glass
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(4, 5, 8, 0.88);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-backdrop.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-card {
    background: #0B0D15;
    border: 1px solid rgba(168, 85, 247, 0.35);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 500px;
    padding: 36px 32px;
    position: relative;
    box-shadow: 0 0 80px rgba(168, 85, 247, 0.3);
    text-align: center;
}

.modal-close {
    position: absolute;
    top: 18px;
    right: 20px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-header-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 6px;
    color: #FFF;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.beta-chip {
    font-size: 0.62rem;
    font-weight: 800;
    padding: 3px 8px;
    background: rgba(244, 63, 94, 0.2);
    color: var(--accent-pink);
    border: 1px solid rgba(244, 63, 94, 0.4);
    border-radius: 12px;
}

.modal-subtitle {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.beta-email-box.featured-box {
    background: rgba(168, 85, 247, 0.08);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: var(--radius-lg);
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.beta-badge-pill {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--accent-purple);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.email-input-group {
    display: flex;
    gap: 8px;
    width: 100%;
}

.email-field {
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-subpixel);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.82rem;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    outline: none;
}

.email-field:focus {
    border-color: var(--accent-purple);
}

.beta-perks-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
    text-align: left;
}

.perk-item {
    font-size: 0.76rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.beta-subtext {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(11, 13, 19, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--accent-purple);
    color: #FFF;
    padding: 12px 18px;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.toast.success { border-color: rgba(16, 185, 129, 0.65); }
.toast.error   { border-color: rgba(244, 63, 94, 0.7); }
.toast.info    { border-color: rgba(56, 189, 248, 0.6); }

.hidden {
    display: none !important;
}

/* ==========================================================================
   Dialog visibility — kept in the layout so the fade can actually run
   ========================================================================== */
.modal-backdrop.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-card {
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
}

.modal-backdrop.is-hidden .modal-card {
    transform: scale(0.97) translateY(6px);
    opacity: 0;
}

.modal-card-narrow {
    max-width: 380px;
    padding: 30px 28px;
}

/* ==========================================================================
   Range Sliders — fourteen of these carry the whole tool, so they get styled
   ========================================================================== */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 16px;
    background: transparent;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(168, 85, 247, 0.6), rgba(56, 189, 248, 0.28));
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    margin-top: -5px;
    border-radius: 50%;
    background: #FFF;
    border: 1px solid rgba(0, 0, 0, 0.45);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.6);
    transition: box-shadow 0.18s ease, transform 0.18s ease;
}

input[type="range"]:hover::-webkit-slider-thumb {
    transform: scale(1.14);
}

input[type="range"]:active::-webkit-slider-thumb {
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.6), 0 0 0 6px var(--accent-purple-glow);
}

input[type="range"]::-moz-range-track {
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: 1px solid rgba(0, 0, 0, 0.45);
    border-radius: 50%;
    background: #FFF;
}

.toggle-checkbox {
    accent-color: var(--accent-purple);
}

/* ==========================================================================
   Focus & Screen-reader Utilities
   ========================================================================== */
:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

.modal-backdrop:focus-visible,
.stage-container:focus-visible {
    outline: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   Export Group (button + resolution)
   ========================================================================== */
.export-group {
    display: flex;
    align-items: stretch;
}

.export-group .btn-primary {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.export-scale-select {
    background: rgba(56, 189, 248, 0.14);
    border: 1px solid rgba(56, 189, 248, 0.35);
    border-left: none;
    border-top-right-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0 6px;
    cursor: pointer;
    outline: none;
}

/* ==========================================================================
   Looks (built-in presets + saved)
   ========================================================================== */
.look-preset-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.look-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subpixel);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 8px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all 0.2s ease;
}

.look-btn:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
}

.saved-look-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.saved-look-row .select-input {
    flex: 1;
    min-width: 0;
}

.btn-icon-small:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-hover);
}

.btn-icon-small.danger:hover {
    color: var(--accent-pink);
    border-color: rgba(244, 63, 94, 0.5);
    background: rgba(244, 63, 94, 0.1);
}

/* ==========================================================================
   Stage Interaction
   ========================================================================== */
#main-canvas {
    cursor: grab;
    touch-action: none;
}

#main-canvas.is-dragging {
    cursor: grabbing;
}

.stage-hint {
    position: absolute;
    top: 16px;
    font-size: 0.7rem;
    color: var(--text-muted);
    background: rgba(11, 13, 19, 0.7);
    border: 1px solid var(--border-subpixel);
    padding: 5px 12px;
    border-radius: 999px;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.stage-hint.is-faded {
    opacity: 0;
}

.rail-help {
    color: var(--text-muted);
}

.rail-help:hover {
    color: var(--accent-blue);
    background: rgba(56, 189, 248, 0.1);
}

/* ==========================================================================
   Shortcuts List
   ========================================================================== */
.keys-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 9px;
    text-align: left;
    margin-top: 18px;
}

.keys-list li {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.keys-list li span {
    margin-left: auto;
    color: var(--text-primary);
}

kbd {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    min-width: 22px;
    text-align: center;
    padding: 3px 6px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--border-hover);
    border-bottom-width: 2px;
    border-radius: 5px;
    color: var(--text-primary);
}

/* ==========================================================================
   Bottom-sheet chrome — inert on desktop, the whole layout on small screens
   ========================================================================== */
.inspector-heading {
    display: flex;
    flex-direction: column;
}

.sheet-close {
    display: none;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-subpixel);
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
}

.sheet-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.12);
}

.sheet-scrim {
    display: none;
}

/* ==========================================================================
   Tablet & phone — stage on top, sections as a bottom bar, inspector as a sheet
   ========================================================================== */
@media (max-width: 899px) {
    :root {
        --rail-h: 62px;
        /* A definite height, not just a cap, so the stage can reserve exactly
           this much room and keep the canvas visible while the sheet is up. */
        --sheet-h: min(56dvh, 480px);
    }

    body.studio-layout {
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }

    .app-container {
        height: 100vh;
        height: 100dvh;
    }

    /* Header wraps to two rows so the actions stay reachable */
    .app-header {
        height: auto;
        flex-wrap: wrap;
        row-gap: 8px;
        padding: 9px 12px;
    }

    .header-brand { order: 1; }

    .header-actions {
        order: 2;
        margin-left: auto;
        gap: 6px;
    }

    .aspect-ratio-selector {
        order: 3;
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .aspect-ratio-selector::-webkit-scrollbar { display: none; }

    .bar-label,
    .version-tag,
    .stage-hint { display: none; }

    .header-actions .btn span { display: none; }
    .header-actions .btn { padding: 8px 10px; }
    .header-actions .btn-pro span { display: inline; }

    .brand-title { font-size: 0.95rem; }

    /* Stage first, section tabs pinned underneath it */
    .studio-workspace {
        flex-direction: column;
        min-height: 0;
    }

    .stage-container {
        order: 1;
        flex: 1;
        min-height: 0;
        padding: 14px 12px 58px;
        transition: padding-bottom 0.32s cubic-bezier(0.16, 1, 0.3, 1);
    }

    /* Editing something you can't see is useless, so the preview stays above the sheet */
    body.sheet-open .stage-container {
        padding-bottom: calc(var(--sheet-h) + 16px);
    }

    .quick-toolbar {
        bottom: 10px;
        gap: 10px;
        padding: 5px 12px;
        max-width: calc(100% - 24px);
        overflow-x: auto;
        scrollbar-width: none;
    }

    .quick-toolbar::-webkit-scrollbar { display: none; }

    #canvas-res-text,
    #btn-center-device { display: none; }

    .tool-rail {
        order: 2;
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        width: 100%;
        height: var(--rail-h);
        flex-shrink: 0;
        padding: 0 6px;
        gap: 4px;
        border-right: none;
        border-top: 1px solid var(--border-subpixel);
    }

    .rail-spacer,
    .rail-help { display: none; }

    .rail-btn {
        width: 64px;
        height: 48px;
    }

    /* The inspector is the same DOM, re-hung as a sheet above the tab bar */
    .inspector-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: var(--rail-h);
        width: 100%;
        height: var(--sheet-h);
        max-height: var(--sheet-h);
        z-index: 40;
        border-left: none;
        border-top: 1px solid var(--border-hover);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.7);
        transform: translateY(calc(100% + var(--rail-h)));
        visibility: hidden;
        transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.32s;
    }

    body.sheet-open .inspector-panel {
        transform: translateY(0);
        visibility: visible;
    }

    .inspector-header {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
    }

    .sheet-close { display: inline-flex; }

    .sheet-scrim {
        display: block;
        position: fixed;
        inset: 0;
        bottom: var(--rail-h);
        z-index: 35;
        /* Tap-to-dismiss only. Dimming here would darken the canvas, which is
           the one thing the user is watching. */
        background: transparent;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.28s ease;
    }

    body.sheet-open .sheet-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    .tab-contents { padding: 14px 14px 24px; }

    .modal-card { padding: 30px 20px; }
    .beta-perks-list { grid-template-columns: 1fr; }
    .email-input-group { flex-direction: column; }
}

/* Phones */
@media (max-width: 560px) {
    :root {
        --sheet-h: min(52dvh, 430px);
    }

    .app-header { padding: 8px 10px; }

    .header-actions { gap: 4px; }
    .header-actions .btn { padding: 7px 9px; }

    .gradient-preset-grid { grid-template-columns: repeat(3, 1fr); }

    .rail-btn { width: 100%; }
    .rail-text { font-size: 0.58rem; }

    .swatch-btn { width: 28px; height: 28px; }

    .quick-toolbar { gap: 8px; font-size: 0.72rem; }
    #btn-reset-camera { display: none; }

    .keys-list li { font-size: 0.74rem; }
}

/* Landscape phones and short windows. A bottom sheet plus a bottom tab bar leaves
   nothing for the canvas here, and there is width to spare — so go back to
   side-by-side and let the panel take the right edge in the normal flow. */
@media (max-width: 899px) and (max-height: 560px) {
    .studio-workspace {
        flex-direction: row;
    }

    .tool-rail {
        order: 1;
        width: 56px;
        height: auto;
        flex-direction: column;
        justify-content: flex-start;
        padding: 8px 0;
        gap: 8px;
        border-top: none;
        border-right: 1px solid var(--border-subpixel);
    }

    .rail-btn {
        width: 46px;
        height: 44px;
    }

    .stage-container {
        order: 2;
        padding: 10px;
    }

    body.sheet-open .stage-container {
        padding-bottom: 10px;
    }

    .quick-toolbar { display: none; }

    /* In-flow panel: flex does the arithmetic, so the stage can never collapse */
    .inspector-panel {
        order: 3;
        position: static;
        display: none;
        width: min(300px, 42vw);
        height: auto;
        max-height: none;
        transform: none;
        visibility: visible;
        border-radius: 0;
        border-top: none;
        border-left: 1px solid var(--border-hover);
        box-shadow: none;
    }

    body.sheet-open .inspector-panel {
        display: flex;
    }

    .sheet-scrim { display: none; }
}

/* Laptops and narrow desktops: give the stage back some room */
@media (min-width: 900px) and (max-width: 1280px) {
    .inspector-panel {
        width: 272px;
    }

    .tool-rail {
        width: 58px;
    }

    .rail-btn {
        width: 46px;
        height: 46px;
    }

    .bar-label {
        display: none;
    }

    .header-actions .btn span {
        display: none;
    }

    .header-actions .btn-pro span {
        display: inline;
    }

    .stage-hint {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
