
/* ================================================================
   CUSTOM FONT PICKER
   ================================================================ */
.fpicker {
    position: relative;
    width: 100%;
    user-select: none;
}

.fpicker-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
    min-height: 36px;
}

.fpicker-trigger:hover {
    border-color: rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.05);
}

.fpicker.open .fpicker-trigger {
    border-color: rgba(255,255,255,0.35);
}

.fpicker.open .fpicker-trigger svg {
    transform: rotate(180deg);
}

.fpicker-trigger svg {
    flex-shrink: 0;
    color: var(--muted);
    transition: transform 0.2s ease;
}

.fpicker-current {
    font-size: 0.88rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.fpicker-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 12px 32px rgba(0,0,0,0.12);
    z-index: 9999;
    max-height: 260px;
    overflow-y: auto;
    padding: 0.25rem 0;
}

.fpicker.open .fpicker-dropdown {
    display: block;
    animation: fpickerIn 0.15s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.fpicker-group-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #fff;
    background: color-mix(in srgb, var(--fpicker-accent, var(--accent)) 20%, transparent);
    border-left: 2px solid var(--fpicker-accent, var(--accent));
    padding: 0.35rem 0.65rem;
    margin: 0.4rem 0 0;
    pointer-events: none;
}

.fpicker-option {
    padding: 0.45rem 0.75rem;
    font-size: 0.92rem;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fpicker-option:hover {
    /* Use theme-aware surface and text so hover remains readable in light/dark themes */
    background: color-mix(in srgb, var(--surface2) 86%, transparent);
    color: var(--text);
}


/* ================================================================
   LANDING SCREEN
   ================================================================ */
#landing-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    overflow: hidden;
}

/* ================================================================
   AMBIENT BACKGROUND (Replaces ASCII)
   ================================================================ */
#ambient-background {
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: -1;
    pointer-events: none;
    background: var(--bg);
}

#char-counter {
  opacity: 0;
  transition: opacity 0.2s ease, color 0.3s;
}

.chat-counter-row {
    display: flex;
    justify-content: flex-end;
    width: 100%;
    margin-top: -1rem;
    padding-right: 1.5rem;
    z-index: 2;
}

#char-counter.visible {
  opacity: 1;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(0.8);
    }
}

.app-microcopy {
    font-family: var(--font-body);
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.52);
    text-align: center;
    margin-top: 0.55rem;
    cursor: default;
    user-select: none;
}

.top-control-panel {
    width: min(1240px, calc(100% - 2.4rem));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0 auto;
}

.top-control-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 220;
    height: 54px;
    display: flex;
    align-items: center;
    background: transparent;
    border-bottom: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    /* Force composite layer to prevent flickering in Edge/Chrome on fixed elements with transforms */
    transform: translate3d(0, 0, 0);
    will-change: transform;
}

.top-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.top-brand-logo {
    width: 30px;
    height: auto;
}

.top-brand-name {
    font-family: 'Plus Jakarta Sans', var(--font-body);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
}

.top-controls {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.theme-toggle-btn {
    background: var(--surface2);
    border: none;
    border-radius: 12px;
    padding: 0.5rem;
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease, color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle-btn:focus,
.btn-mode-toggle:focus,
.control-select-overlay:focus {
    outline: none;
}

.theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.theme-icon {
    display: none;
}

:root[data-theme="dark"] .theme-toggle-btn .icon-moon,
:root:not([data-theme]) .theme-toggle-btn .icon-moon {
    display: block;
}

:root[data-theme="light"] .theme-toggle-btn .icon-sun {
    display: block;
}

.control-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border: none;
    border-radius: 12px;
    padding: 0.35rem 0.5rem;
    background: var(--surface2);
}

.control-label {
    font-size: 0.72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.control-select {
    border: none;
    background: transparent;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.84rem;
    outline: none;
    cursor: pointer;
}

.control-pill-icon {
    position: relative;
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    gap: 0;
    overflow: visible;
    cursor: pointer;
    border: none;
    transition: background 0.2s ease, transform 0.15s ease;
}

.control-pill-icon:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateY(-1px);
}

.theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.control-icon {
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.control-select-overlay {
    position: absolute;
    inset: 0;
    opacity: 0;
    z-index: 1;
    -webkit-appearance: none;
    appearance: none;
}

/* Unified keyboard focus visibility for top-right controls */
.theme-toggle-btn:focus-visible,
.btn-mode-toggle:focus-visible,
.control-pill-icon:focus-within {
    outline: 2px solid rgba(0, 102, 255, 0.9);
    outline-offset: 2px;
}

:root[data-theme="light"] .theme-toggle-btn:focus-visible,
:root[data-theme="light"] .btn-mode-toggle:focus-visible,
:root[data-theme="light"] .control-pill-icon:focus-within {
    outline-color: rgba(0, 102, 255, 0.85);
}

:root[data-theme="light"] .top-control-bar {
    background: transparent;
    border-bottom: none;
    backdrop-filter: none;
}

:root[data-theme="light"] .control-pill {
    background: rgba(0, 0, 0, 0.03);
    border: none;
}

:root[data-theme="light"] .theme-toggle-btn {
    background: rgba(0, 0, 0, 0.03);
    border: none;
    border-radius: 12px;
}

:root[data-theme="light"] .control-pill-icon {
    background: rgba(0, 0, 0, 0.03);
    border: none;
}

:root[data-theme="light"] .control-pill-icon:hover {
    background: rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

:root[data-theme="light"] .control-icon {
    color: var(--text);
}

:root[data-theme="light"] .theme-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

:root[data-theme="light"] .chat-input-wrapper {
    background: #FFFFFF;
    border: 1px solid #E2E8F0;
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
}

:root[data-theme="light"] .chat-input-wrapper.is-pro {
    border-color: #93C5FD;
}

:root[data-theme="light"] .chat-input-wrapper.is-pro:focus-within {
    border-color: #60A5FA;
    outline: none;
}

:root[data-theme="light"] .chat-input-wrapper.is-pro:hover:not(:focus-within) {
    border-color: #93C5FD;
}

:root[data-theme="light"] .chat-input-wrapper:not(.is-pro):hover:not(:focus-within) {
    border-color: #D1D5DB;
    box-shadow: var(--shadow-md);
}

:root[data-theme="light"] .chat-input-wrapper:not(.is-pro):focus-within {
    border-color: #60A5FA;
    outline: none;
    box-shadow: var(--shadow-md);
}

:root[data-theme="light"] .chat-input {
    color: var(--text);
}

:root[data-theme="light"] .btn-generate-chat {
    background: #111827;
    color: #FFFFFF;
    border: 1px solid #111827;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

:root[data-theme="light"] .btn-generate-chat:hover:not(:disabled) {
    background: #1F2937;
    box-shadow: var(--shadow-md);
}

:root[data-theme="light"] .btn-generate-chat:disabled {
    background: #F3F4F6 !important;
    color: #6B7280 !important;
    border-color: #E2E8F0 !important;
    box-shadow: none;
    opacity: 1;
}

:root[data-theme="light"] .chat-input::placeholder {
    color: var(--placeholder);
}

/* Light-theme specific placeholder/readability fixes for editor controls */
:root[data-theme="light"] .settings-textarea-borderless::placeholder {
    color: rgba(23, 23, 23, 0.45);
}

:root[data-theme="light"] .fpicker-dropdown {
    background: var(--surface);
    border-color: var(--border);
    box-shadow: 0 12px 28px rgba(0,0,0,0.06);
}

:root[data-theme="light"] .fpicker-group-label {
    color: var(--text);
}

:root[data-theme="light"] .tool-input {
    background: var(--surface2) !important;
    color: var(--text) !important;
}

:root[data-theme="light"] .tool-btn-group {
    background: var(--surface2);
}

/* ========== Light-mode editor-specific fixes ========== */
/* Improve contrast for right tools panel, minimap, dots and PDF animation */


/* Slide dots: use muted color in light mode so they remain visible */
:root[data-theme="light"] .slide-dot {
    background: var(--muted);
}

/* Active dot glow should use the accent (dark) rather than white */
:root[data-theme="light"] .slide-dot.active {
    background: var(--accent);
    box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 45%, transparent);
}

/* PDF / primary pulse button: avoid white border/glow in light mode */
:root[data-theme="light"] .pulse-btn,
:root[data-theme="light"] .btn-primary {
    border: 1px solid var(--border);
    box-shadow: 0 8px 20px rgba(0,0,0,0.06);
}

:root[data-theme="light"] .pulse-btn:hover,
:root[data-theme="light"] .btn-primary:hover {
    box-shadow: 0 12px 30px rgba(0,0,0,0.08);
    filter: brightness(0.98);
}

/* Tools panel: prefer the slightly toned surface2 in light mode to reduce glare */
:root[data-theme="light"] .editor-tools-panel {
    background: var(--surface2);
    border-left-color: var(--border);
}

/* ================================================================
   CHAT INTERFACE           
   ================================================================ */

.app-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    margin-bottom: 1rem;
    animation: fadeInSlideDown 0.6s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.hero-title {
    font-family: 'Plus Jakarta Sans', var(--font-body);
    font-weight: 700;
    font-size: clamp(2rem, 4.7vw, 3.35rem);
    text-align: center;
    letter-spacing: -0.02em;
    line-height: 1.06;
    color: var(--text);
    max-width: 18ch;
    transition: opacity 0.22s ease, filter 0.22s ease;
    animation: heroGlow 5.5s ease-in-out infinite;
    will-change: transform;
}

.hero-title-single {
    margin-bottom: 0.1rem;
}

/* Logo styling */
.app-logo {
    font-family: 'Syne', var(--font-display);
    font-size: clamp(2rem, 4.5vw, 3.4rem);
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: -0.02em;
}

.logo-brand {
    background: linear-gradient(110deg, #f0f0f0 0%, var(--accent) 50%, #f0f0f0 100%);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: textShimmer 3.5s linear infinite;
    filter: drop-shadow(0 0 15px rgba(255, 255, 255, 0.15));
}

.logo-lab {
    color: var(--accent);
}

@keyframes textShimmer {
    from {
        background-position: 200% 0;
    }

    to {
        background-position: -200% 0;
    }
}

.app-logo .dot {
    width: 0.22em;
    height: 0.22em;
    background-color: var(--accent);
    border-radius: 50%;
    margin-left: 0.1em;
    align-self: flex-end;
    margin-bottom: 0.3em;
    animation: pulse 2s infinite cubic-bezier(0.4, 0, 0.6, 1);
}



#chat-screen {
    position: relative;
    width: 100%;
    min-height: 100vh; /* Exactly full screen */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100; /* Over everything at start */
    background: var(--bg);
    padding: 2rem;
    padding-top: 5.3rem;
    padding-bottom: 0px; 
    margin: 0;
}

.chat-container {
    width: 100%;
    max-width: 800px;
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 1.4rem;
    animation: stepSlideIn 0.45s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.chat-input-container {
    position: relative;
    flex: 1;
    display: flex;
    align-items: flex-start;
}

.chat-input-wrapper {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    position: relative;
    background: rgba(12, 12, 12, 0.8);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 18px;
    padding: 0.62rem 0.82rem 0.74rem;
    min-height: 0;
    /* Smooth transition for border and box-shadow for a "light-up" effect */
    transition: border-color 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-input-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    z-index: -1;
    opacity: 0;
    /* The core "light turning on/off" transition */
    transition: opacity 1.2s cubic-bezier(0.4, 0, 0.2, 1);
    /* Base glow state - matching neonInputPulse 0% for seamless start after transition */
    box-shadow: 0 0 0 1px rgba(0, 102, 255, 0.3), 0 0 25px rgba(0, 102, 255, 0.25);
}

/* Pro mode: activate neon glow on wrapper */
.chat-input-wrapper.is-pro {
    border-color: rgba(0, 102, 255, 0.45);
}

.chat-input-wrapper.is-pro::before {
    opacity: 1;
}

/* Specific desktop logic: Add a delayed pulse after the "light on" transition completes */
@media (min-width: 851px) {
    .chat-input-wrapper.is-pro::before {
        animation: neonInputPulse 5s ease-in-out infinite 1.2s;
    }
}

.chat-input-wrapper.is-pro:hover:not(:focus-within) {
    border-color: rgba(0, 102, 255, 0.38);
}



.chat-input-wrapper.is-pro:focus-within {
    border-color: rgba(0, 102, 255, 0.78);
    outline: none;
}



/* Non-pro hover: simple neutral highlight */
.chat-input-wrapper:not(.is-pro):hover:not(:focus-within) {
    border-color: rgba(255, 255, 255, 0.22);
}

.chat-input-wrapper:not(.is-pro):focus-within {
    border-color: rgba(0, 102, 255, 0.65);
    outline: none;
}

.chat-input-wrapper:focus-within #chat-typewriter-cursor {
    display: none !important;
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 1.12rem;
    padding: 0.25rem 0.25rem 0.3rem;
    min-height: 3.4rem;
    resize: none;
    outline: none;
    max-height: 250px;
    overflow-y: auto;
}

.chat-input::placeholder {
    color: var(--muted);
}

.chat-actions {
    display: flex;
    align-items: stretch;
    width: 100%;
    margin-top: 0.6rem;
    gap: 0.75rem;
}

.chat-actions .btn-debug-last-generated {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: auto;
    min-width: 152px;
    min-height: 50px;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    white-space: nowrap;
    font-size: 0.92rem;
    font-weight: 600;
}

.chat-actions .btn-debug-last-generated[hidden] {
    display: none !important;
}

/* ── Mode Toggle Button ─────────────────────────────────────────────── */
.btn-mode-toggle {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0 1rem;
    min-height: 50px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.88rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    white-space: nowrap;
    /* Only transition cheap properties — no filter, no box-shadow to avoid page flicker */
    transition:
        background 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        border-color 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.btn-mode-toggle:hover {
    border-color: rgba(255, 255, 255, 0.28);
    background: var(--surface);
}

/* Active (Pro mode on) — use plain rgba, no color-mix() to avoid repaint cost */
.btn-mode-toggle.is-active {
    background: rgba(0, 102, 255, 0.10);
    border-color: rgba(0, 102, 255, 0.55);
    color: #5c9fff;
}

.btn-mode-toggle.is-active:hover {
    background: rgba(0, 102, 255, 0.16);
    border-color: rgba(0, 102, 255, 0.75);
}

.btn-mode-toggle:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--surface2) !important;
    color: var(--muted) !important;
    border-color: var(--border) !important;
    filter: brightness(0.85) saturate(0.75);
    pointer-events: none;
}

.btn-mode-toggle:disabled:hover {
    background: var(--surface2);
    border-color: var(--border);
}

/* Light theme overrides */
:root[data-theme="light"] .btn-mode-toggle {
    background: #FFFFFF;
    border-color: #E2E8F0;
    color: #374151;
}

:root[data-theme="light"] .btn-mode-toggle:hover {
    background: #F9FAFB;
    border-color: #CAD5E0;
}

:root[data-theme="light"] .btn-mode-toggle.is-active {
    background: #EFF6FF;
    border-color: #93C5FD;
    color: #1F2937;
}

:root[data-theme="light"] .btn-mode-toggle.is-active:hover {
    background: #DBEAFE;
    border-color: #60A5FA;
}

:root[data-theme="light"] .btn-mode-toggle:disabled {
    opacity: 1;
    cursor: not-allowed;
    background: #F9FAFB !important;
    color: #9CA3AF !important;
    border-color: #E2E8F0 !important;
    filter: none;
    pointer-events: none;
}

:root[data-theme="light"] .btn-mode-toggle:disabled:hover {
    background: #F9FAFB;
    border-color: #E2E8F0;
}

/* ── Tooltip singleton (JS-controlled, position: fixed) ── */
#js-tooltip {
    position: fixed;
    z-index: 99999;
    background: #111111;
    border: 1px solid rgba(255,255,255,0.15);
    color: #FFFFFF;
    font-size: 0.74rem;
    font-weight: 500;
    padding: 0.45rem 0.75rem;
    border-radius: 8px;
    white-space: normal;
    text-align: center;
    pointer-events: none;
    max-width: 220px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
}

#js-tooltip.visible {
    opacity: 1;
    visibility: visible;
}

:root[data-theme="light"] #js-tooltip {
    background: #FFFFFF;
    border: 1px solid #E5E7EB;
    color: #111827;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Icon management — show one at a time */
.btn-mode-icon {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.btn-mode-chevron,
.mode-select-mobile {
    display: none;
}

/* Default state: show lightning (flash), hide sparks (pro) */
.btn-mode-icon--pro  { display: none; }
.btn-mode-icon--flash { display: flex; }

.btn-mode-toggle.is-active .btn-mode-icon--pro  { display: flex; }
.btn-mode-toggle.is-active .btn-mode-icon--flash { display: none; }

/* Switch animation — only animate the label text, not the icons */
.btn-mode-label {
    display: inline-block;
}

.btn-mode-toggle.is-animating .btn-mode-label {
    animation: modeLabelPop 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes modeLabelPop {
    0%   { opacity: 0; transform: translateY(5px) scale(0.9); }
    60%  { opacity: 1; transform: translateY(-1px) scale(1.04); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
/* ─────────────────────────────────────────────────────────────────────── */

.btn-settings {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-settings svg {
    display: block;
    transform-origin: 50% 50% !important;
    will-change: transform;
    /* Force GPU acceleration to reduce jagged pixel-snapping */
    transform: translateZ(0);
}

.btn-settings:hover,
.btn-settings.active {
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
}

.btn-settings:hover svg,
.btn-settings.active svg {
    animation: spinGear 3s linear infinite;
}

@keyframes spinGear {
    from {
        transform: translateZ(0) rotate(0deg);
    }

    to {
        transform: translateZ(0) rotate(360deg);
    }
}

.btn-generate-chat {
    background: #ffffff;
    color: #101010;
    border: 1px solid rgba(255, 255, 255, 0.75);
    border-radius: 12px;
    width: 100%;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.8rem 1rem;
    font-family: var(--font-body);
    font-size: 0.98rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    opacity: 1;
    filter: brightness(1) saturate(1);
    transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, opacity 0.24s ease, filter 0.28s ease;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.btn-generate-chat:not(:disabled) {
    animation: generateWarmOn 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

.btn-generate-chat:hover:not(:disabled) {
    background: #f1f1f1;
    transform: translateY(-1px);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.34);
}

.btn-generate-chat:disabled {
    opacity: 0.72;
    cursor: not-allowed;
    background: #ffffff !important;
    color: #111111 !important;
    border-color: rgba(255, 255, 255, 0.74) !important;
    filter: brightness(0.88) saturate(0.9);
    transform: none !important;
    box-shadow: none !important;
}

.btn-generate-label {
    line-height: 1;
}

@keyframes generateWarmOn {
    0% {
        filter: brightness(0.88) saturate(0.9);
    }

    62% {
        filter: brightness(1.06) saturate(1.04);
    }

    100% {
        filter: brightness(1) saturate(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .btn-generate-chat:not(:disabled) {
        animation: none;
    }
}

@property --neon-spin {
    syntax: '<angle>';
    initial-value: 0deg;
    inherits: false;
}

@keyframes neonBorderSpin {
    to { --neon-spin: 360deg; }
}

@keyframes neonInputPulse {
    0%,
    100% {
        box-shadow: 0 0 0 1px rgba(0, 102, 255, 0.3), 0 0 25px rgba(0, 102, 255, 0.25);
    }

    50% {
        box-shadow: 0 0 0 2px rgba(0, 102, 255, 0.5), 0 0 45px rgba(0, 102, 255, 0.45);
    }
}

@keyframes heroGlow {
    0%,
    100% {
        text-shadow: 0 0 0 rgba(0, 102, 255, 0);
    }

    50% {
        text-shadow: 0 0 14px rgba(0, 102, 255, 0.12);
    }
}

.loader-icon {
    animation: spin 1s linear infinite;
    color: currentColor;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Settings Panel */
.settings-panel {
    background: rgba(24, 24, 24, 0.7);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    padding: 1.5rem 2rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);

    /* Animation origin from the gear icon location roughly */
    transform-origin: top left;
    animation: scaleInOrigin 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.settings-panel.hidden {
    display: none;
}

.settings-panel.closing {
    animation: scaleOutOrigin 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes scaleInOrigin {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-5px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes scaleOutOrigin {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }

    to {
        opacity: 0;
        transform: scale(0.95) translateY(-5px);
    }
}

.settings-layout-modern {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 2.5rem;
}

@media (max-width: 900px) {
    .settings-layout-modern {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
}

.settings-modern-col {
    display: flex;
    flex-direction: column;
}

.settings-section-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--muted);
    margin: 0 0 0.8rem 0.8rem;
}

.settings-modern-card {
    background: rgba(10, 12, 20, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.settings-modern-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 1.4rem;
}

.settings-modern-row label {
    font-family: var(--font-display);
    font-weight: 500;
    color: var(--text);
    font-size: 0.95rem;
}

.settings-modern-input-row {
    display: grid;
    grid-template-columns: 100px 1fr;
    align-items: center;
    padding: 0 1.4rem;
    transition: background 0.2s ease;
}

.settings-modern-input-row:focus-within {
    background: rgba(255, 255, 255, 0.03);
}

.settings-modern-input-row label {
    font-family: var(--font-display);
    font-weight: 500;
    color: var(--muted);
    font-size: 0.9rem;
}

.settings-modern-input-row input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    padding: 1.1rem 0;
    width: 100%;
}

.settings-modern-input-row input::placeholder {
    color: rgba(255, 255, 255, 0.25);
    font-style: normal;
}

/* Fix browser auto-fill background styles overriding transparent inputs */
.settings-modern-input-row input:-webkit-autofill,
.settings-modern-input-row input:-webkit-autofill:hover,
.settings-modern-input-row input:-webkit-autofill:focus,
.settings-modern-input-row input:-webkit-autofill:active {
    transition: background-color 5000s ease-in-out 0s;
    -webkit-text-fill-color: var(--text) !important;
}

.settings-modern-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.05);
    margin: 0 1.4rem;
}

.settings-textarea-borderless {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    padding: 1.4rem;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    resize: none;
    min-height: 15rem;
}

.settings-textarea-borderless::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

/* Error msg */
.error-msg {
    display: none;
    color: #ff5b5b;
    font-size: 0.85rem;
    margin-top: -0.5rem;
}

#tema-error {
    margin-top: 5px;
    text-align: center;
}

.error-msg.visible {
    display: block;
}

@keyframes stepSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ================================================================
   BUTTON GROUPS (reused in wizard)
   ================================================================ */
.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.option-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
}

.option-btn:hover {
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--text);
    transform: translateY(-1px);
}

.option-btn.active {
    background-color: var(--accent);
    border-color: var(--accent);
    color: white;
    transform: scale(1.02);
}

/* ================================================================
   COLOR PICKER
   ================================================================ */
.color-picker-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
}

.preset-colors {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.color-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.25s ease;
}

.color-circle:hover {
    transform: scale(1.15);
}

.color-circle.selected {
    outline: 2px solid white;
    outline-offset: 3px;
    transform: scale(1.1);
}

/* Custom color trigger — RGB rounded square + plus icon */
.color-custom-trigger {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.35rem 0.65rem 0.35rem 0.35rem;
    border-radius: 14px;
    transition: all 0.2s ease;
}

.color-custom-trigger:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.03);
}

.color-custom-trigger.selected {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.05);
}

.color-custom-border {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    /* Inner square with rounded corners */
    padding: 2px;
    background: linear-gradient(135deg, #6366f1, #ec4899, #f97316, #eab308, #10b981, #06b6d4, #8b5cf6, #6366f1);
    background-size: 300% 300%;
    animation: gradientShift 6s ease infinite;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.color-custom-inner {
    width: 100%;
    height: 100%;
    border-radius: 6px;
    background: var(--surface);
    transition: background 0.2s ease;
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

.color-custom-plus {
    font-size: 1.4rem;
    font-weight: 300;
    color: var(--muted);
    line-height: 1;
    transition: all 0.3s ease;
}

.color-custom-trigger:hover .color-custom-plus {
    color: var(--text);
    transform: rotate(90deg) scale(1.1);
}

.color-custom-trigger:hover .color-custom-border {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.color-custom-trigger.selected .color-custom-border {
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.3);
}

/* Beautiful Custom RGB/Hex Picker Popup */
.custom-picker-popup {
    position: absolute;
    left: 0;
    bottom: calc(100% + 0.75rem);
    background: rgba(20, 21, 38, 0.95);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 1.25rem;
    width: 280px;
    z-index: 50;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    animation: pickerFadeIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: bottom left;
}

.custom-picker-popup.hidden {
    display: none !important;
    animation: none;
}

@keyframes pickerFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.picker-hue-bar {
    width: 100%;
    height: 16px;
    border-radius: 8px;
    background: linear-gradient(to right,
            hsl(0, 85%, 55%), hsl(60, 85%, 55%), hsl(120, 85%, 55%),
            hsl(180, 85%, 55%), hsl(240, 85%, 55%), hsl(300, 85%, 55%),
            hsl(360, 85%, 55%));
    cursor: pointer;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.picker-hue-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 3px solid white;
    background: var(--accent);
    position: absolute;
    top: 50%;
    left: 60%;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    transition: left 0.05s ease;
}

.picker-inputs {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.picker-hex-layer {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 0.35rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.picker-color-disc {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--accent);
    margin-right: 0.75rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.picker-hex-input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-family: 'DM Sans', monospace;
    font-size: 1.05rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    outline: none;
    font-weight: 500;
}

.picker-rgb-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.rgb-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.rgb-col input {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: white;
    padding: 0.4rem 0;
    text-align: center;
    border-radius: 6px;
    font-family: 'DM Sans', monospace;
    font-size: 0.95rem;
    transition: border-color 0.2s;
    outline: none;
    -moz-appearance: textfield;
    appearance: textfield;
}

.rgb-col input::-webkit-outer-spin-button,
.rgb-col input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.rgb-col input:focus {
    border-color: var(--accent);
}

.rgb-col label {
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ================================================================
   LOADING (skeleton)
   ================================================================ */
.hidden {
    display: none !important;
}

#loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    min-height: 80vh;
    text-align: center;
    animation: sectionFadeIn 0.5s ease;
}

#result-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    min-height: 80vh;
    text-align: center;
    animation: sectionFadeIn 0.5s ease;
}

/* ================================================================
   ERROR / REFUSED MODALS (overlay on top of any screen)
   ================================================================ */
.app-modal {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.app-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    animation: modalBackdropIn 0.22s ease forwards;
}

@keyframes modalBackdropIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.app-modal-card {
    position: relative;
    z-index: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2.5rem 2.5rem 2rem;
    max-width: 460px;
    width: 100%;
    text-align: center;
    animation: modalCardIn 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes modalCardIn {
    from { opacity: 0; transform: scale(0.93) translateY(14px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes modalCardOut {
    from { opacity: 1; transform: scale(1) translateY(0); }
    to   { opacity: 0; transform: scale(0.96) translateY(8px); }
}

@keyframes modalBackdropOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

.app-modal.is-closing .app-modal-backdrop {
    animation: modalBackdropOut 0.18s ease forwards;
}

.app-modal.is-closing .app-modal-card {
    animation: modalCardOut 0.18s ease forwards;
}

.app-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.app-modal-close:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.2);
}

.app-modal-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 14px;
    margin: 0 auto 1.5rem;
}

.app-modal-icon--error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.22);
    color: #f87171;
}

.app-modal-icon--refused {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.22);
    color: #fbbf24;
}

.app-modal-card h2 {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 0.55rem;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.app-modal-subtitle {
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.6;
    margin: 0 0 1.4rem;
}

.app-modal-details {
    margin-bottom: 1.4rem;
    text-align: left;
}

.app-modal-details summary {
    color: var(--muted);
    font-size: 0.78rem;
    cursor: pointer;
    padding: 0.3rem 0;
    transition: color 0.2s;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.app-modal-details summary::-webkit-details-marker { display: none; }

.app-modal-details summary::before {
    content: '›';
    display: inline-block;
    transition: transform 0.2s;
    font-size: 1rem;
    line-height: 1;
    color: var(--muted);
}

.app-modal-details[open] summary::before { transform: rotate(90deg); }
.app-modal-details summary:hover { color: var(--text); }

#error-message {
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    color: var(--muted);
    font-size: 0.74rem;
    line-height: 1.5;
    font-family: 'JetBrains Mono', monospace;
    word-break: break-word;
    max-height: 110px;
    overflow-y: auto;
    margin: 0.5rem 0 0;
    text-align: left;
}

.app-modal-refused-body {
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.9rem 1rem;
    margin-bottom: 1.4rem;
    text-align: left;
    color: var(--muted);
    font-size: 0.87rem;
    line-height: 1.6;
    max-height: 160px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.app-modal-actions { margin-top: 0.5rem; }

.app-modal-action-btn {
    width: 100%;
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.app-modal-action-btn:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.app-modal-action-btn:active { transform: translateY(0); }

/* Light-mode overrides */
:root[data-theme="light"] .app-modal-backdrop   { background: rgba(0, 0, 0, 0.3); }
:root[data-theme="light"] .app-modal-close:hover { background: rgba(0, 0, 0, 0.04); border-color: var(--border); }
:root[data-theme="light"] .app-modal-icon--error   { background: rgba(239, 68, 68, 0.06); }
:root[data-theme="light"] .app-modal-icon--refused { background: rgba(245, 158, 11, 0.06); }
:root[data-theme="light"] #error-message           { background: var(--bg); }
:root[data-theme="light"] .app-modal-refused-body  { background: var(--bg); }
:root[data-theme="light"] .app-modal-action-btn:hover { background: rgba(0, 0, 0, 0.04); border-color: var(--border); }

@keyframes sectionFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}



/* ================================================================
   CARDS (success)
   ================================================================ */
.success-card {
    position: relative;
    background: rgba(20, 21, 31, 0.7);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 3.5rem 3rem;
    max-width: 480px;
    width: 100%;
    animation: successCardPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    text-align: center;
}

.success-glow {
    position: absolute;
    top: -50%;
    left: 50%;
    transform: translateX(-50%);
    width: 150%;
    height: 150%;
    background: radial-gradient(circle at top, rgba(255, 255, 255, 0.1) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

@keyframes cardPop {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes successCardPop {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(30px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.success-icon-wrap {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
    margin: 0 auto 2rem auto;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.05);
    animation: iconFloat 3s ease-in-out infinite;
}

@keyframes iconFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

.success-icon-wrap svg {
    width: 38px;
    height: 38px;
    color: #f0f0f0;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.5));
}

.success-title {
    position: relative;
    z-index: 1;
    font-family: var(--font-display);
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: white;
    letter-spacing: -0.02em;
}

.success-subtitle {
    position: relative;
    z-index: 1;
    color: var(--muted);
    font-size: 1.05rem;
    margin-bottom: 2.5rem;
}

.success-actions {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.pulse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.95rem;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.pulse-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
    filter: brightness(1.1);
}

/* ================================================================
    REFUSED CARD
    (moved to .app-modal / .app-modal-refused-body)
    ================================================================ */
/* Note: visual styles for the refused modal are handled by the
    .app-modal and .app-modal-refused-body selectors above. The
    legacy #refused-container / .refused-message rules were removed
    to avoid empty-rule lint errors. */

/* ================================================================
   BUTTONS (primary / secondary)
   ================================================================ */
.btn-primary {
    display: block;
    width: 100%;
    background-color: var(--accent);
    color: #121212;
    text-decoration: none;
    text-align: center;
    padding: 1rem;
    border-radius: var(--radius);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 1rem;
    transition: all 0.25s ease;
}

.btn-primary:hover {
    filter: brightness(0.9);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 255, 255, 0.2);
}

.btn-primary-form {
    width: 100%;
    background-color: var(--accent);
    color: #121212;
    border: none;
    padding: 1.25rem;
    border-radius: var(--radius);
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.25s ease;
}

.btn-primary-form:hover:not(:disabled) {
    filter: brightness(0.9);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 255, 255, 0.2);
}

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

.btn-secondary {
    display: block;
    width: 100%;
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 1rem;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* ================================================================
   PREVIEW SYSTEM - PREMIUM TRANSITIONS
   ================================================================ */
.s-premium-transition {
    transition: transform var(--transition-premium) !important;
}

/* Subtle slide + Fade effect for elements inside slides */
section.s > * {
    transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.6s ease;
}

section.s:not(.active) > * {
    opacity: 0;
    transform: translateY(10px);
}

section.s.active > * {
    opacity: 1;
    transform: translateY(0);
}
#preview-container {
    display: flex;
    flex-direction: column;
    animation: sectionFadeIn 0.5s ease;
    width: 100%;
    height: 100vh;
    padding: 0;
    overflow: hidden;
    position: fixed;
    /* Bound to viewport strictly */
    inset: 0;
    z-index: 500;
    background: var(--bg);
    overscroll-behavior: none; /* Block browser's own swipe-to-navigate patterns */
}

.preview-unified-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 1rem;
    background: var(--bg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
    z-index: 20;
    position: relative;
    min-height: 52px;
    height: auto;
    transform: translateY(-100%);
    opacity: 0;
    transition: transform 0.8s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.preview-unified-header.slide-down {
    transform: translateY(0);
    opacity: 1;
}




.preview-unified-left {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    overflow: hidden;
}

.preview-unified-center {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.preview-unified-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Make theme button in the preview header icon-only (no visible border) */
.preview-unified-right .theme-toggle-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 0.5rem;
    border-radius: 6px;
    width: auto;
    height: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.preview-unified-right .theme-toggle-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
    transform: none;
}

/* Ensure preview header theme toggle is icon-only across themes and overrides theme-specific rules */
:root[data-theme="light"] .preview-unified-right .action-btn.icon-only.theme-toggle-btn,
:root[data-theme="dark"] .preview-unified-right .action-btn.icon-only.theme-toggle-btn,
.preview-unified-right .action-btn.icon-only.theme-toggle-btn {
    background: transparent !important;
    border: none !important;
    color: var(--muted) !important;
    padding: 0.5rem !important;
    border-radius: 6px !important;
    width: auto !important;
    height: auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: none !important;
}

:root[data-theme="light"] .preview-unified-right .action-btn.icon-only.theme-toggle-btn:hover,
:root[data-theme="dark"] .preview-unified-right .action-btn.icon-only.theme-toggle-btn:hover,
.preview-unified-right .action-btn.icon-only.theme-toggle-btn:hover {
    color: var(--text) !important;
    background: rgba(255, 255, 255, 0.05) !important;
}

#canvas-zoom-select,
.zoom-display {
    background: transparent;
    border: none;
    cursor: default;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0 2px;
    min-width: 45px;
    text-align: center;
}

.zoom-display {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

#btn-zoom-in,
#btn-zoom-out {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.9rem;
}

.preview-topic-label {
    font-family: var(--font-body);
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 300;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.02em;
    max-width: 200px;
}

.header-icon-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

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

.header-v-separator {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 0.5rem;
    flex-shrink: 0;
}

:root[data-theme="light"] .preview-unified-header {
    background: var(--surface2);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

:root[data-theme="light"] .header-v-separator {
    background: rgba(0, 0, 0, 0.06);
}

.nav-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    pointer-events: auto;
}


.slide-label {
    font-family: monospace;
    font-size: 0.65rem;
    color: var(--muted);
    opacity: 0.8;
}


.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.8rem;
    border-radius: 6px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.action-btn:disabled,
.header-icon-btn:disabled {
    opacity: 0.3 !important;
    cursor: not-allowed !important;
    filter: grayscale(1);
    pointer-events: none;
}

.btn-content-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    z-index: 1;
    transition: opacity 0.3s;
}

.action-btn.loading .btn-content-wrap {
    opacity: 0;
}

.action-btn.loading {
    pointer-events: none;
}

.btn-progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0%;
    background: var(--accent);
    z-index: 0;
    transition: width 0.3s ease;
}

.action-btn.icon-only {
    background: transparent;
    color: var(--muted);
    padding: 0.5rem;
    border-radius: 6px;
}

.action-btn.icon-only:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

.action-btn.text-link {
    background: transparent;
    color: var(--muted);
    font-size: 0.75rem;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
}

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

.action-btn.bordered-primary {
    background: transparent;
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 0.4rem 1rem;
    border-radius: 8px;
    font-size: 0.8rem;
    margin-left: 0.5rem;
}

.action-btn.bordered-primary:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.3);
}



.action-btn.ghost {
    background: transparent;
    color: var(--muted);
    padding: 0.45rem 0.6rem;
}

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

.action-btn svg {
    flex-shrink: 0;
}



/* Slide dots */
.slide-dots {
    display: flex;
    align-items: center;
    gap: 5px;
}

.slide-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--surface2);
    border: none;
    padding: 0;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

.slide-dot:hover {
    background: var(--muted);
    transform: scale(1.3);
}

.slide-dot.active {
    background: var(--accent);
    transform: scale(1.4);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

/* Stage (slide + arrows) */
.preview-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-top: 0;
    min-height: 0;
    /* Allow shrinking below content size */
    position: relative;
    background: var(--bg);
}

.preview-stage:fullscreen,
.preview-stage:-webkit-full-screen,
.preview-stage:-moz-full-screen,
.preview-stage:-ms-fullscreen {
    background: var(--bg);
    width: 100vw;
    height: 100vh;
}

.preview-stage:fullscreen .preview-wrapper,
.preview-stage:-webkit-full-screen .preview-wrapper,
.preview-stage:-moz-full-screen .preview-wrapper,
.preview-stage:-ms-fullscreen .preview-wrapper {
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    border: none !important;
}

.preview-stage:fullscreen .stage-arrow,
.preview-stage:-webkit-full-screen .stage-arrow,
.preview-stage:-moz-full-screen .stage-arrow,
.preview-stage:-ms-fullscreen .stage-arrow {
    z-index: 100;
}



/* Full-height hover panels for arrows */
.stage-arrow {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 70px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0);
    cursor: pointer;
    transition: all 0.4s ease;
    opacity: 0;
}

.stage-arrow.left {
    left: 0;
}

.stage-arrow.right {
    right: 0;
}

.stage-arrow.left svg {
    transform: translateX(-12px);
}

.stage-arrow.right svg {
    transform: translateX(12px);
}

.stage-arrow:hover:not(:disabled) {
    opacity: 1;
    color: white;
}

.stage-arrow.left:hover:not(:disabled) {
    background: radial-gradient(ellipse at left center, rgba(255, 255, 255, 0.07) 0%, transparent 70%);
}

.stage-arrow.right:hover:not(:disabled) {
    background: radial-gradient(ellipse at right center, rgba(255, 255, 255, 0.07) 0%, transparent 70%);
}

.stage-arrow.left:hover:not(:disabled) svg {
    transform: translateX(0);
}

.stage-arrow.right:hover:not(:disabled) svg {
    transform: translateX(0);
}

.stage-arrow:disabled {
    opacity: 0 !important;
    pointer-events: none;
}

.stage-arrow svg {
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.5));
}

/* Slide wrapper */
.preview-wrapper {
    width: 100%;
    margin: 0 auto;
    border-radius: 0;
    overflow: visible;
    background: var(--surface);
    touch-action: pan-y; 
}

#preview-iframe {
    width: 297mm;
    height: 167mm;
    border: none;
    transform-origin: top left;
    pointer-events: auto;
    overflow: hidden;
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 900px) {
    .preview-unified-header {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.6rem 0.75rem;
        position: absolute;
        /* Match PC: absolute to allow slide-down animation */
        height: auto;
        min-height: 90px;
    }

    .preview-unified-left {
        flex: 1 1 auto;
        justify-content: flex-start;
        order: 1;
    }

    .preview-unified-right {
        flex: 0 0 auto;
        justify-content: flex-end;
        order: 2;
        gap: 0.4rem;
    }

    .preview-unified-center {
        flex: 1 1 100%;
        position: static;
        transform: none;
        order: 3;
        margin-top: 0.25rem;
        padding: 0.4rem 0;
        border-top: 1px solid rgba(255, 255, 255, 0.05);
        pointer-events: auto;
    }

    .nav-group {
        width: 100%;
        justify-content: center;
    }

    .preview-topic-label {
        max-width: 120px;
    }

    .action-btn.bordered-primary {
        margin-left: 0;
        padding: 0.35rem 0.6rem;
    }

    .preview-stage {
        margin-top: 90px;
        /* Non-overlapping space for mobile header */
        height: calc(100vh - 90px);
    }

    .preview-wrapper {
        width: 100vw;
        max-width: 100vw;
        aspect-ratio: 16 / 9;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .stage-arrow {
        width: 40px;
        opacity: 0.1;
    }

    .stage-arrow.left {
        left: 0;
    }

    .stage-arrow.right {
        right: 0;
    }
}

@media (max-width: 600px) {
    .wizard-container {
        padding: 0 0.5rem;
    }

    .wizard-label {
        font-size: 1.3rem;
    }

    .preset-colors {
        gap: 0.5rem;
    }

    .color-circle {
        width: 28px;
        height: 28px;
    }

    .toolbar-btn span {
        display: none;
    }
}

/* ================================================================
   GENERATING STATE — hide chrome, show only skeleton
   ================================================================ */

/* Instant collapse: no transition while entering generating state */
#preview-container.is-generating .editor-minimap {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: none !important;
}

#preview-container.is-generating .editor-tools-panel {
    transform: translateX(100px) scale(0.9);
    opacity: 0 !important;
    pointer-events: none !important;
}

#preview-container.is-generating .preview-unified-header {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* While streaming/settling, side panels must not reserve layout width. */
#preview-container.is-generating .editor-minimap,
#preview-container.is-generating .editor-tools-panel,
#preview-container.is-settling .editor-minimap,
#preview-container.is-settling .editor-tools-panel {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    overflow: hidden !important;
}

/* ================================================================
   SETTLING STATE — slide is animating to its resting position.
   ================================================================ */
#preview-container.is-settling .editor-minimap {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: none !important;
}

#preview-container.is-settling .editor-tools-panel {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: none !important;
}

/* CINEMATIC GENERATION MODE & FLOATING LAYOUT */
@media (min-width: 769px) {
    #preview-container:not(.hidden) {
        padding: 0;
        background: var(--bg);
        display: flex !important;
        flex-direction: column;
        position: fixed; 
        inset: 0;
        overflow: hidden;
    }

    #preview-container.hidden {
        display: none !important;
    }

    #preview-container.is-generating {
        padding: 0 !important;
    }

    /* Clear any GSAP-set inline padding on the stage so the slide fills the
       full viewport during streaming. This overrides leftover values from the
       previous generation’s settling animation. */
    #preview-container.is-generating .preview-stage {
        padding: 0 !important;
    }

    /* Cabecera Flotante Centrada */
    .preview-unified-header {
        position: absolute !important;
        top: 8px;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 98% !important; 
        max-width: 1100px;
        height: 46px !important;
        z-index: 1000 !important;
        background: color-mix(in srgb, var(--surface2) 45%, transparent) !important;
        backdrop-filter: blur(30px) saturate(2);
        -webkit-backdrop-filter: blur(30px) saturate(2);
        border: 1px solid var(--border) !important;
        border-radius: 50px !important;
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        padding: 0 20px !important;
        transition: all 0.8s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }

    .preview-unified-center {
        position: absolute;
        left: 50%;
        transform: translateX(calc(-50% - 56px));
    }

    .editor-main-layout {
        display: block; 
        position: relative;
        width: 100%;
        flex: 1; /* Ocupa todo el espacio restante bajo la cabecera */
        margin: 0;
        overflow: hidden;
    }

    .preview-wrapper {
        border-radius: 0 !important;
        box-shadow: none !important;
        overflow: hidden;
        border: none !important;
    }

    .preview-stage {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        padding: 0;
        z-index: 1;
        display: flex !important;
        align-items: center;
        justify-content: center;
        background: var(--bg) !important;
    }

    .editor-minimap {
        position: absolute !important;
        left: 15px; 
        top: 50%;
        transform: translateY(-50%);
        z-index: 10;
        height: auto !important;
        max-height: 320px;
        width: 140px; 
        border-radius: 20px;
        background: color-mix(in srgb, var(--surface2) 45%, transparent) !important;
        backdrop-filter: blur(30px) saturate(2);
        -webkit-backdrop-filter: blur(30px) saturate(2);
        border: 1px solid var(--border) !important;
        box-shadow: none !important;
        padding: 8px 0 !important;
        transition: all 0.6s cubic-bezier(0.16, 1, 0.3, 1) !important;
        overflow: hidden !important;
    }

    .editor-tools-panel {
        position: absolute !important;
        right: 24px;
        top: 50%;
        transform: translateY(-50%);
        z-index: 10;
        height: auto !important;
        max-height: 85vh;
        width: 260px;
        border-radius: 24px;
        background: color-mix(in srgb, var(--surface) 82%, transparent) !important;
        backdrop-filter: blur(18px) saturate(1.2);
        -webkit-backdrop-filter: blur(18px) saturate(1.2);
        border: 1px solid var(--border) !important;
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 8px 30px rgba(0, 0, 0, 0.18) !important;
        padding: 1.25rem !important;
        transition: all 0.6s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }

    :root[data-theme="light"] .editor-tools-panel {
        background: color-mix(in srgb, var(--surface) 90%, transparent) !important;
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 8px 24px rgba(17, 24, 39, 0.10) !important;
    }

    .editor-tools-panel:not(.active) {
        transform: translateY(-50%) translateX(100px);
        opacity: 0;
        pointer-events: none;
    }

    /* Floating Master Toolbar (Bottom) */
    .tools-add-elements {
        position: absolute !important;
        bottom: 8px;
        left: 50%;
        transform: translateX(-50%) translateY(16px); /* shifted down = hidden state */
        z-index: 100;
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        gap: 8px;
        padding: 8px 12px !important;
        background: rgba(18, 18, 18, 0.5) !important;
        backdrop-filter: blur(20px) saturate(1.5);
        -webkit-backdrop-filter: blur(20px) saturate(1.5);
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
        border-radius: 40px !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.5s ease, transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
    }

    /* Reveal toolbar once the slide has settled in editor mode */
    #preview-container.is-editor-ready .tools-add-elements {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
        pointer-events: auto;
    }

    .tools-add-elements .add-el-btn {
        flex-direction: column !important;
        gap: 4px !important;
        padding: 8px 12px !important;
        height: auto !important;
        min-width: 70px;
        border-radius: 20px !important;
        background: transparent !important;
        border: none !important;
        font-size: 10px !important;
        font-weight: 700 !important;
        letter-spacing: 0.05em;
        color: rgba(255, 255, 255, 0.6) !important;
        transition: all 0.3s ease;
    }

    .tools-add-elements .add-el-btn:hover {
        background: rgba(255, 255, 255, 0.08) !important;
        color: #fff !important;
        transform: translateY(-2px);
    }

    .tools-add-elements .add-el-btn svg {
        width: 20px !important;
        height: 20px !important;
        margin-bottom: 2px;
        opacity: 0.8;
    }

    .tools-v-separator {
        width: 1px;
        height: 30px;
        background: rgba(255, 255, 255, 0.1);
        margin: 0 4px;
    }

    /* Unified Header Redesign (Floating style) */
    .preview-unified-header {
        opacity: 1;
        transition: all 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    }
    
    /* Asegurar que el contenido interno de la cabecera se mantenga horizontal */
    .header-left, .header-right {
        display: flex !important;
        align-items: center;
        gap: 10px;
    }
}

/* Reveal animation — applied via .reveal-chrome on the container */
/* Reveal: staggered sequence helpers
   We animate header, then minimap, then tools with small delays to feel less chaotic. */

/* Minimap reveal (trigger by adding `reveal-minimap` on the container) */
/* Start the panels slightly offset and invisible when the reveal sequence begins */
#preview-container.reveal-sequence .editor-minimap {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    border-right: none !important;
    overflow: hidden !important;
    transform: translateY(-50%) translateX(-28px);
    opacity: 0;
    transition: none !important;
}

/* Minimap reveal (trigger by adding `reveal-minimap` on the container) */
#preview-container.reveal-minimap .editor-minimap {
    width: 180px !important;
    min-width: 180px !important;
    transform: translateY(-50%) translateX(0) !important;
    opacity: 1 !important;
    overflow: hidden !important;
    transition:
        transform 0.85s cubic-bezier(0.16, 1, 0.3, 1),
        opacity 0.65s ease,
        width 0.85s cubic-bezier(0.16, 1, 0.3, 1),
        min-width 0.85s cubic-bezier(0.16, 1, 0.3, 1),
        border-right 0.3s ease !important;
}

/* Tools start offset to the right during the sequence */
#preview-container.reveal-sequence .editor-tools-panel {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    border-left: none !important;
    overflow: hidden !important;
    transform: translateY(-50%) translateX(28px);
    opacity: 0;
    transition: none !important;
}

/* Tools reveal (trigger by adding `reveal-tools` on the container) */
#preview-container.reveal-tools .editor-tools-panel {
    width: 260px !important;
    min-width: 260px !important;
    padding: 1rem !important;
    transform: translateY(-50%) translateX(0) !important;
    opacity: 1 !important;
    overflow: hidden !important;
    transition:
        transform 0.85s cubic-bezier(0.16, 1, 0.3, 1),
        opacity 0.65s ease,
        width 0.85s cubic-bezier(0.16, 1, 0.3, 1),
        min-width 0.85s cubic-bezier(0.16, 1, 0.3, 1),
        padding 0.55s ease,
        border-left 0.3s ease !important;
}

/* The header slide-down already has its own transition. Keep explicit timings to match sequence. */
#preview-container.reveal-sequence .preview-unified-header {
    transition:
        transform 0.9s cubic-bezier(0.16, 1, 0.3, 1) 0s,
        opacity 0.9s cubic-bezier(0.16, 1, 0.3, 1) 0s !important;
}

/* Mobile layout extracted to mobile/css/style-mobile-overrides.css */

.preview-topic-input {
    background: transparent;
    border: 1px dashed transparent;
    color: var(--text);
    font-size: 0.9rem;
    font-family: var(--font-display);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    width: 250px;
    max-width: 100%;
    outline: none;
    transition: border 0.2s, background 0.2s;
}

.preview-topic-input:hover,
.preview-topic-input:focus {
    border-color: var(--border);
    background: rgba(255, 255, 255, 0.05);
}

/* ================================================================
   EDITOR LAYOUT (Left, Center, Right)
   ================================================================ */
.editor-main-layout {
    display: flex;
    flex-direction: row;
    flex: 1;
    width: 100%;
    margin-top: 0;
    background-color: var(--bg);
    overflow: hidden;
    /* PREVENT VERTICAL GROWTH */
    height: 0;
    /* Let flex-1 take over and stabilize height */
}


/* Center Stage (Override existing) */
.preview-stage {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--editor-bg, var(--bg));
    overflow: hidden;
    height: 100%;
    padding: 0;
    /* Removed padding to maximize canvas space */
}

.preview-wrapper-scrollable {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: auto;
    display: flex;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: none;
    -ms-overflow-style: none;
    overscroll-behavior: none; /* Block browser's own swipe-to-navigate patterns */
    touch-action: pan-y; /* Block browser's own swipe-to-navigate patterns */
}

.preview-wrapper-scrollable::-webkit-scrollbar {
    display: none;
}

.preview-wrapper {
    transition: transform 0.2s ease, width 0.2s ease, height 0.2s ease;
    flex-shrink: 0;
    margin: auto;
    /* Centering trick for scrollable flex items */
}

/* Right Tools Panel */
/* ================================================================
   RESPONSIVE HEADER ADJUSTMENTS
   ================================================================ */
@media (max-width: 1200px) {
    .preview-topic-label {
        max-width: 160px;
    }
}

@media (max-width: 1080px) {
    #t-finalize-text, 
    #t-reset-text,
    .header-v-separator {
        display: none !important;
    }
    
    .preview-unified-header {
        padding: 0 0.5rem;
        gap: 0.25rem;
    }

    .preview-topic-label {
        max-width: 120px;
    }

    .action-btn {
        padding: 0.35rem 0.6rem;
    }
}

@media (max-width: 900px) {
    .preview-unified-center {
        display: none;
    }
    .preview-unified-header {
        grid-template-columns: 1fr 1fr;
    }
    .preview-topic-label {
        max-width: 100px;
    }
}

@media (max-width: 600px) {
    .preview-unified-header {
        min-height: 48px;
    }
    .preview-topic-label {
        display: none;
    }
}

/* Theme toggle circular transition */
html.theme-transitioning::view-transition-old(root),
html.theme-transitioning::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}
html.theme-transitioning::view-transition-old(root) {
    z-index: 1;
}
html.theme-transitioning::view-transition-new(root) {
    z-index: 2;
}