/* ================================================================
   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: var(--muted);
    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;
    cursor: pointer;
    user-select: none;
    transition: opacity 0.2s ease;
}

.top-brand:hover {
    opacity: 0.85;
}

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

.top-brand-name {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
}

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

.credits-header-control { position: relative; }
.credits-balance-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 36px;
    padding: 0.4rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface2);
    color: var(--text);
    font: inherit;
    font-size: 0.76rem;
    font-weight: 650;
    white-space: nowrap;
    cursor: pointer;
}
.credits-balance-chip:hover,
.credits-balance-chip[aria-expanded="true"] { background: var(--surface-hover); }
.credits-balance-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.credits-ring { flex: 0 0 auto; fill: none; stroke-width: 2; }
.credits-ring-track { stroke: currentColor; opacity: .22; }
.credits-ring-arc { stroke: currentColor; stroke-linecap: round; stroke-dasharray: 50.265; stroke-dashoffset: var(--ring-offset, 0); transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .2s ease; }
#credits-balance-trigger:not([data-state="ready"]) #credits-balance-label { display: none; }
.credits-ring[data-state="low"] { color: #ffbd58; }
.credits-ring[data-state="empty"] { color: #ff6b75; }
.credits-popover-head strong { display: inline-flex; align-items: center; gap: .4rem; }
:root[data-theme="light"] .credits-ring[data-state="low"] { color: #a96700; }
:root[data-theme="light"] .credits-ring[data-state="empty"] { color: #c72f3b; }
@media (prefers-reduced-motion: reduce) { .credits-ring-arc { transition: none; } }
.credits-popover {
    position: absolute;
    top: calc(100% + 0.55rem);
    right: 0;
    z-index: 120;
    width: min(295px, calc(100vw - 2rem));
    padding: 0.9rem;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    color: var(--text);
    font-size: 0.78rem;
}
.credits-popover[hidden] { display: none; }
.credits-popover-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.7rem; }
.credits-popover-head strong { font-size: 0.83rem; }
.credits-popover-head span { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.credits-progress { height: 3px; overflow: hidden; border-radius: 999px; background: var(--border); }
.credits-progress span { display: block; height: 100%; width: 100%; border-radius: inherit; background: var(--text-secondary); opacity: 0.55; transition: width 0.2s ease; }
.credits-reset-label { margin: 0.7rem 0 0; color: var(--text-secondary); }
.credits-rates { margin: 0.55rem 0 0; padding-top: 0.55rem; border-top: 1px solid var(--border); color: var(--text-secondary); line-height: 1.45; }

.home-donation-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 36px;
    padding: 0.45rem 0.7rem;
    border: 1px solid rgba(19, 195, 255, 0.35);
    border-radius: 999px;
    color: #f7fcff;
    background: linear-gradient(135deg, #168ed0, #087eb9);
    font-size: 0.78rem;
    font-weight: 650;
    text-decoration: none;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.kofi-cup-icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    object-fit: contain;
}

.home-donation-link:hover {
    border-color: #52d5ff;
    background: linear-gradient(135deg, #087eb9, #066a9f);
    transform: translateY(-1px);
}

.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;
}







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





/* Unified keyboard focus visibility for top-right controls */
.theme-toggle-btn:focus-visible,
.btn-mode-toggle:focus-visible {
    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 {
    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"] .theme-toggle-btn {
    background: rgba(0, 0, 0, 0.03);
    border: none;
    border-radius: 12px;
}







: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: #3B82F6;
    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: #94A3B8;
    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: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.5rem, 6.5vw, 3.35rem);
    text-align: center;
    letter-spacing: -0.02em;
    line-height: 1.1;
    color: var(--text);
    max-width: 90vw;
    transition: filter 0.22s ease;
    animation: heroGlow 5.5s ease-in-out infinite;
    will-change: transform;
}

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

.hero-subtitle {
    font-size: 0.88rem;
    color: var(--muted);
    text-align: center;
    margin-top: 0.35rem;
    letter-spacing: 0.01em;
    opacity: 0.75;
}

.hero-title {
    overflow: visible;
    padding-bottom: 0.1em;
}

.hero-title-text {
    display: inline;
}

.hero-cursor {
    display: inline-block;
    margin-left: 2px;
    color: var(--accent);
    font-weight: 300;
    animation: heroCursorBlink 1.1s step-start infinite;
    user-select: none;
}

@keyframes heroCursorBlink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Logo styling */
.app-logo {
    font-family: 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);
}
