/* ============================================================
   WRENNA — Complete App Styles
   Layout: Rail | Preview (left) | Code (right) | Sponsor
   ============================================================ */

/* ---- TOKENS ---- */
:root {
    --bg-0: #141210;
    --bg-1: #1a1714;
    --bg-2: #211d19;
    --bg-3: #2a2520;
    --bg-4: #332d27;
    --bg-5: #3e3730;
    
    --fg-0: #f2ead9;
    --fg-1: rgba(242, 234, 217, 0.7);
    --fg-2: rgba(242, 234, 217, 0.45);
    --fg-3: rgba(242, 234, 217, 0.2);
    
    --accent: #e8734a;
    --accent-bright: #f08560;
    --accent-dark: #c45830;
    --accent-glow: rgba(232, 115, 74, 0.15);
    --accent-glow-strong: rgba(232, 115, 74, 0.25);
    
    --moss: #7a8b52;
    --moss-bright: #8fa368;
    --moss-glow: rgba(122, 139, 82, 0.15);
    
    --amber: #d4a574;
    --amber-glow: rgba(212, 165, 116, 0.12);
    
    --syn-tag: #e8a87c;
    --syn-attr: #c4b49a;
    --syn-string: #a3b37c;
    --syn-comment: #5a5248;
    --syn-keyword: #e8734a;
    --syn-number: #b899b8;
    --syn-func: #d4b87c;
    --syn-var: #f2ead9;
    --syn-op: #8a7d70;
    --syn-type: #7aab8a;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', monospace;
    --font-serif: 'Lora', Georgia, serif;
    
    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
    --sp-5: 20px; --sp-6: 28px; --sp-7: 40px;
    
    --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
    --r-xl: 20px; --r-2xl: 28px; --r-full: 9999px;
    
    --sh-xs: 0 1px 2px rgba(0,0,0,0.12);
    --sh-sm: 0 2px 4px rgba(0,0,0,0.14), 0 4px 12px rgba(0,0,0,0.08);
    --sh-md: 0 4px 8px rgba(0,0,0,0.15), 0 8px 24px rgba(0,0,0,0.12);
    --sh-lg: 0 8px 16px rgba(0,0,0,0.18), 0 16px 48px rgba(0,0,0,0.16);
    --sh-xl: 0 12px 32px rgba(0,0,0,0.2), 0 24px 64px rgba(0,0,0,0.2);
    
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-glide: cubic-bezier(0.25, 0.1, 0.25, 1);
    --ease-out: cubic-bezier(0, 0, 0.2, 1);
    
    --dur-fast: 150ms; --dur-med: 250ms; --dur-slow: 400ms;
    
    --rail-w: 60px;
    --tab-h: 44px;
    --status-h: 32px;
    --sponsor-h: 40px;
    
    --z-rail: 100; --z-tree: 150; --z-modal: 300; --z-toast: 400;
}

/* ---- RESET ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

.app-body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--fg-0);
    background: var(--bg-0);
    display: flex;
    height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

.app-body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 60% at 20% 0%, rgba(232,115,74,0.04) 0%, transparent 60%),
        radial-gradient(ellipse 60% 50% at 100% 100%, rgba(122,139,82,0.03) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

::selection { background: var(--accent-glow-strong); color: var(--fg-0); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

.skip-link {
    position: fixed; top: -100%; left: 50%; transform: translateX(-50%);
    padding: var(--sp-2) var(--sp-5); background: var(--accent); color: var(--fg-0);
    border-radius: var(--r-md); font-weight: 600; z-index: 1000;
    transition: top var(--dur-fast) var(--ease-glide);
}
.skip-link:focus { top: var(--sp-3); }

kbd {
    font-family: var(--font-mono); font-size: 0.72em;
    padding: 3px 7px; background: var(--bg-2);
    border: 1px solid var(--bg-4); border-bottom-width: 2px;
    border-radius: var(--r-sm); color: var(--fg-1);
}

/* ---- RAIL ---- */
.rail {
    width: var(--rail-w); height: 100%;
    display: flex; flex-direction: column; align-items: center;
    padding: var(--sp-4) 0; gap: var(--sp-1);
    background: var(--bg-1); border-right: 1px solid var(--bg-2);
    z-index: var(--z-rail); flex-shrink: 0;
}

.rail-btn {
    width: 42px; height: 42px; display: grid; place-items: center;
    border: none; background: transparent; border-radius: var(--r-md);
    color: var(--fg-2); cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-glide),
                color var(--dur-fast) var(--ease-glide),
                transform var(--dur-fast) var(--ease-spring);
}

.rail-btn svg { width: 20px; height: 20px; transition: transform var(--dur-med) var(--ease-spring); }
.rail-btn:hover { background: var(--bg-2); color: var(--fg-0); }
.rail-btn:hover svg { transform: scale(1.1); }
.rail-btn:active { transform: scale(0.92); }
.rail-btn.active { background: var(--accent-glow); color: var(--accent); }

.rail-logo { width: 46px; height: 46px; color: var(--accent); margin-bottom: var(--sp-2); }
.rail-logo svg { width: 30px; height: 30px; filter: drop-shadow(0 2px 8px rgba(232,115,74,0.3)); }
.rail-logo:hover { color: var(--accent-bright); background: var(--accent-glow); }
.rail-logo:active svg { transform: scale(0.9) rotate(-5deg); }

.rail-sep { width: 24px; height: 1px; background: var(--bg-3); margin: var(--sp-2) 0; border-radius: 1px; }
.rail-spacer { flex: 1; }

.rail-run {
    background: var(--accent); color: #fff;
    box-shadow: 0 2px 8px rgba(232,115,74,0.3), inset 0 1px 0 rgba(255,255,255,0.15);
    margin-bottom: var(--sp-1);
}
.rail-run:hover {
    background: var(--accent-bright); color: #fff; transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(232,115,74,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}
.rail-run:active { transform: translateY(0) scale(0.94); }

.rail-ai:hover { color: var(--moss-bright); background: var(--moss-glow); }
.rail-pro:hover { color: var(--amber); background: var(--amber-glow); }

/* ---- FILE TREE ---- */
.file-tree {
    position: fixed; top: 0; left: var(--rail-w); bottom: var(--sponsor-h);
    width: 260px; background: var(--bg-1);
    border-right: 1px solid var(--bg-3); box-shadow: var(--sh-lg);
    z-index: var(--z-tree);
    transform: translateX(calc(-100% - var(--rail-w)));
    transition: transform var(--dur-slow) var(--ease-spring);
    display: flex; flex-direction: column;
}
.file-tree.open { transform: translateX(0); }
.file-tree-inner { display: flex; flex-direction: column; height: 100%; }

.file-tree-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-5) var(--sp-5) var(--sp-4); }
.file-tree-head h2 { font-family: var(--font-serif); font-size: 1.1rem; font-weight: 600; }

.file-tree-search { position: relative; padding: 0 var(--sp-5) var(--sp-4); }
.file-tree-search svg {
    position: absolute; left: calc(var(--sp-5) + 12px); top: 50%;
    transform: translateY(-50%); width: 14px; height: 14px;
    color: var(--fg-3); pointer-events: none;
}
.file-tree-search input {
    width: 100%; padding: 10px 12px 10px 38px;
    font-family: var(--font-mono); font-size: 0.8125rem; color: var(--fg-0);
    background: var(--bg-0); border: 1px solid var(--bg-3);
    border-radius: var(--r-md); outline: none;
    transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.file-tree-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.file-tree-search input::placeholder { color: var(--fg-3); }

.file-tree-body { flex: 1; overflow-y: auto; padding: 0 var(--sp-3); }
.file-tree-body::-webkit-scrollbar { width: 4px; }
.file-tree-body::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 2px; }

.file-item {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: 10px 14px; font-family: var(--font-mono); font-size: 0.8125rem;
    color: var(--fg-1); border-radius: var(--r-md); cursor: pointer; user-select: none;
    transition: background-color var(--dur-fast) var(--ease-glide),
                color var(--dur-fast) var(--ease-glide),
                transform var(--dur-fast) var(--ease-spring);
}
.file-item:hover { background: var(--bg-2); color: var(--fg-0); transform: translateX(3px); }
.file-item.active { background: var(--accent-glow); color: var(--accent); }

.file-tree-foot { display: flex; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--bg-2); }

/* ---- WORKSPACE ---- */
.workspace {
    flex: 1; display: flex; min-width: 0; min-height: 0;
    z-index: 1; padding-bottom: var(--sponsor-h);
}

/* Preview (LEFT) */
.preview-area {
    width: 34%; min-width: 300px; max-width: 440px;
    display: flex; flex-direction: column;
    background: var(--bg-1); padding: var(--sp-3); gap: var(--sp-3);
    overflow: hidden; border-right: 1px solid var(--bg-2); flex-shrink: 0;
}

/* Code (RIGHT) */
.code-area {
    flex: 1; display: flex; flex-direction: column;
    min-width: 0; min-height: 0; background: var(--bg-0);
}

/* ---- PREVIEW HEADER ---- */
.preview-header { display: flex; align-items: center; justify-content: space-between; padding: 0 var(--sp-1); flex-shrink: 0; }

.device-pill {
    display: flex; gap: 2px; padding: 3px;
    background: var(--bg-0); border: 1px solid var(--bg-3);
    border-radius: var(--r-full); box-shadow: var(--sh-xs);
}

.pill-btn {
    display: grid; place-items: center; width: 36px; height: 28px;
    color: var(--fg-3); background: transparent; border: none;
    border-radius: var(--r-full); cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-spring),
                color var(--dur-fast) var(--ease-glide),
                transform var(--dur-fast) var(--ease-spring);
}
.pill-btn svg { width: 14px; height: 14px; }
.pill-btn:hover { color: var(--fg-1); }
.pill-btn:active { transform: scale(0.9); }
.pill-btn.active {
    background: var(--accent); color: #fff;
    box-shadow: 0 2px 8px rgba(232,115,74,0.3), inset 0 1px 0 rgba(255,255,255,0.15);
    transform: scale(1.05);
}

/* ---- DEVICE STAGE ---- */
.device-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; }

.device {
    display: none; position: relative;
    transition: transform var(--dur-slow) var(--ease-spring), opacity var(--dur-slow) var(--ease-glide);
    will-change: transform;
}
.device.active { display: flex; flex-direction: column; animation: device-enter var(--dur-slow) var(--ease-spring); }

@keyframes device-enter {
    from { opacity: 0; transform: scale(0.92) translateY(12px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Mobile */
.device-mobile {
    width: min(100%, 340px);
    aspect-ratio: 9 / 19.5;
    max-height: min(100%, 720px);
    background: var(--bg-0);
    border: 3px solid var(--bg-4);
    border-radius: var(--r-2xl);
    box-shadow: var(--sh-xl), inset 0 1px 0 rgba(255,255,255,0.05);
    overflow: hidden;
    flex-shrink: 1;
}

.phone-status-bar {
    display: flex; align-items: center; justify-content: space-between;
    height: 36px; padding: 0 20px; background: var(--bg-2);
    font-size: 0.75rem; font-weight: 600; color: var(--fg-0);
    flex-shrink: 0; position: relative; z-index: 2;
}
.status-time { letter-spacing: 0.02em; }
.status-notch {
    position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
    width: 90px; height: 22px; background: var(--bg-0); border-radius: 12px;
}
.status-icons { display: flex; align-items: center; gap: 4px; }
.status-icons svg { height: 10px; fill: var(--fg-0); }

.phone-browser {
    display: flex; align-items: center; gap: var(--sp-2);
    height: 36px; padding: 0 var(--sp-3);
    background: var(--bg-1); border-bottom: 1px solid var(--bg-3); flex-shrink: 0;
}
.browser-dots { display: flex; gap: 4px; }
.b-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bg-4); }
.b-dot:first-child { background: #e05555; opacity: 0.6; }
.b-dot:nth-child(2) { background: #e0a855; opacity: 0.6; }
.b-dot:last-child { background: #55b380; opacity: 0.6; }

.browser-url {
    display: flex; align-items: center; gap: 6px; flex: 1;
    padding: 4px 12px; background: var(--bg-0); border-radius: var(--r-full);
    font-size: 0.6875rem; color: var(--fg-2); font-family: var(--font-mono);
}
.browser-url svg { width: 10px; height: 10px; color: var(--fg-3); flex-shrink: 0; }

.device-iframe { flex: 1; width: 100%; border: none; background: #fff; display: block; }

.phone-home-bar {
    height: 20px; display: flex; align-items: center; justify-content: center;
    background: var(--bg-1); flex-shrink: 0;
}
.phone-home-bar::after {
    content: ''; width: 100px; height: 4px;
    background: var(--fg-3); border-radius: 2px;
}

/* Tablet */
.device-tablet {
    width: min(100%, calc((100dvh - var(--sponsor-h) - 100px) * 0.75));
    aspect-ratio: 3 / 4; max-height: 100%;
    background: var(--bg-0); border: 4px solid var(--bg-4);
    border-radius: var(--r-xl); box-shadow: var(--sh-xl); overflow: hidden;
}

/* Desktop */
.device-desktop {
    width: 100%; aspect-ratio: 16 / 10; max-height: 100%;
    background: var(--bg-0); border: 2px solid var(--bg-4);
    border-radius: var(--r-lg); box-shadow: var(--sh-xl);
    overflow: hidden; flex-direction: column;
}
.desktop-chrome {
    display: flex; align-items: center; gap: var(--sp-3);
    height: 36px; padding: 0 var(--sp-4);
    background: var(--bg-2); border-bottom: 1px solid var(--bg-3); flex-shrink: 0;
}
.desktop-chrome .browser-url { flex: 1; justify-content: center; }

/* ---- EMPTY STATE + AD ---- */
.preview-empty {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    z-index: 5; transition: opacity var(--dur-med) var(--ease-glide), visibility var(--dur-med);
}
.preview-empty.hidden { opacity: 0; visibility: hidden; }

.empty-inner {
    display: flex; flex-direction: column; align-items: center; gap: var(--sp-4);
    padding: var(--sp-6); text-align: center; position: relative;
    width: 100%; height: 100%; max-width: 300px;
}

.empty-art { width: 140px; height: auto; margin-top: var(--sp-7); animation: float 3s ease-in-out infinite; }

@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

.empty-h1 { font-size: 0.9375rem; color: var(--fg-1); font-weight: 500; }
.empty-h2 { font-size: 0.8125rem; color: var(--fg-3); }

.ad-slot {
    position: absolute; inset: 0; border-radius: var(--r-xl);
    overflow: hidden; background: var(--bg-0);
    opacity: 0; visibility: hidden;
    transition: opacity var(--dur-slow) var(--ease-glide), visibility var(--dur-slow);
}
.ad-slot.active { opacity: 1; visibility: visible; }
.ad-video { width: 100%; height: 100%; object-fit: cover; }
.ad-badge {
    position: absolute; top: var(--sp-3); left: var(--sp-3);
    padding: 4px 10px; font-size: 0.625rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--fg-1); background: rgba(0,0,0,0.6); border-radius: var(--r-sm); z-index: 2;
}
.ad-mute {
    position: absolute; bottom: var(--sp-3); right: var(--sp-3);
    width: 32px; height: 32px; display: grid; place-items: center;
    background: rgba(0,0,0,0.6); border: none; border-radius: 50%;
    color: var(--fg-1); cursor: pointer; z-index: 2;
    transition: background-color var(--dur-fast) ease, transform var(--dur-fast) var(--ease-spring);
}
.ad-mute:hover { background: rgba(0,0,0,0.8); transform: scale(1.08); }
.ad-mute svg { width: 14px; height: 14px; }

/* ---- TABS ---- */
.tab-bar {
    display: flex; align-items: center; height: var(--tab-h);
    padding: 0 var(--sp-2); background: var(--bg-1);
    border-bottom: 1px solid var(--bg-2); gap: var(--sp-1);
    overflow-x: auto; scrollbar-width: none; flex-shrink: 0;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab {
    display: flex; align-items: center; gap: var(--sp-2);
    height: 32px; padding: 0 var(--sp-3);
    font-family: var(--font-mono); font-size: 0.75rem;
    color: var(--fg-2); background: transparent;
    border-radius: var(--r-md); cursor: pointer; white-space: nowrap;
    transition: background-color var(--dur-fast) var(--ease-glide), color var(--dur-fast) var(--ease-glide);
    flex-shrink: 0;
}
.tab:hover { background: var(--bg-2); color: var(--fg-1); }
.tab.active { background: var(--bg-2); color: var(--fg-0); box-shadow: var(--sh-xs); }
.tab-label { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }

.tab-close {
    display: grid; place-items: center; width: 16px; height: 16px;
    font-size: 14px; color: var(--fg-3); border: none; background: none;
    border-radius: 4px; cursor: pointer; opacity: 0;
    transition: opacity var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.tab:hover .tab-close, .tab.active .tab-close { opacity: 1; }
.tab-close:hover { background: var(--bg-4); color: var(--fg-0); }

.tab-add {
    display: grid; place-items: center; width: 28px; height: 28px;
    color: var(--fg-3); background: none; border: none;
    border-radius: var(--r-sm); cursor: pointer; flex-shrink: 0;
    transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.tab-add:hover { background: var(--bg-2); color: var(--fg-0); }
.tab-add svg { width: 14px; height: 14px; }

/* ---- EDITOR ---- */
.editor-container { flex: 1; min-height: 0; position: relative; overflow: hidden; }

.editor-welcome {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: var(--sp-3);
    z-index: 1; transition: opacity var(--dur-med) var(--ease-glide), visibility var(--dur-med);
}
.editor-welcome.hidden { opacity: 0; visibility: hidden; }
.welcome-wren { width: 100px; height: auto; opacity: 0.4; }
.welcome-title { font-size: 0.9375rem; color: var(--fg-1); font-weight: 500; }
.welcome-sub { font-family: var(--font-mono); font-size: 0.75rem; color: var(--fg-3); letter-spacing: 0.05em; }

/* CodeMirror */
.cm-editor { height: 100%; font-size: 13px; }
.cm-editor.cm-focused { outline: none !important; }
.cm-scroller { font-family: var(--font-mono) !important; line-height: 1.65 !important; padding: var(--sp-3) 0; }
.cm-gutters { background: var(--bg-0) !important; border-right: 1px solid var(--bg-2) !important; color: var(--fg-3) !important; }
.cm-gutterElement { padding: 0 12px 0 16px !important; }
.cm-activeLineGutter { background: var(--bg-1) !important; color: var(--fg-1) !important; }
.cm-activeLine { background: var(--bg-1) !important; }
.cm-cursor, .cm-cursor-primary { border-left: 2px solid var(--accent) !important; }
.cm-selectionBackground { background: rgba(232,115,74,0.18) !important; }
.cm-selectionMatch { background: rgba(232,115,74,0.1) !important; }

.cm-keyword { color: var(--syn-keyword); }
.cm-string, .cm-string-2 { color: var(--syn-string); }
.cm-number { color: var(--syn-number); }
.cm-comment { color: var(--syn-comment); font-style: italic; }
.cm-function { color: var(--syn-func); }
.cm-variable { color: var(--syn-var); }
.cm-variable-2 { color: var(--syn-attr); }
.cm-variable-3 { color: var(--syn-type); }
.cm-operator { color: var(--syn-op); }
.cm-tagName { color: var(--syn-tag); }
.cm-attributeName { color: var(--syn-attr); }
.cm-attributeValue { color: var(--syn-string); }
.cm-punctuation { color: var(--fg-3); }
.cm-typeName, .cm-namespace, .cm-className { color: var(--syn-type); }
.cm-atom, .cm-bool { color: var(--syn-number); }
.cm-def { color: var(--syn-func); }
.cm-meta { color: var(--fg-3); }
.cm-propertyName { color: var(--syn-attr); }

/* ---- STATUS BAR ---- */
.status-bar {
    display: flex; align-items: center; gap: var(--sp-5);
    height: var(--status-h); padding: 0 var(--sp-4);
    font-family: var(--font-mono); font-size: 0.6875rem; color: var(--fg-3);
    background: var(--bg-1); border-top: 1px solid var(--bg-2); flex-shrink: 0;
}
.status-lang { color: var(--accent); font-weight: 500; }
.status-live { display: flex; align-items: center; gap: 6px; margin-left: auto; color: var(--moss-bright); }
.live-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--moss-bright); animation: live-pulse 2s ease-in-out infinite;
}
@keyframes live-pulse {
    0%,100% { opacity: 1; box-shadow: 0 0 0 0 var(--moss-glow); }
    50% { opacity: 0.6; box-shadow: 0 0 0 4px var(--moss-glow); }
}

/* ---- MODALS ---- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(10,8,6,0.8);
    z-index: var(--z-modal); display: flex; align-items: center; justify-content: center;
    padding: var(--sp-4); opacity: 0; visibility: hidden;
    transition: opacity var(--dur-med) var(--ease-glide), visibility var(--dur-med);
}
.modal-overlay.open { opacity: 1; visibility: visible; }

.modal {
    width: 100%; max-width: 480px; background: var(--bg-1);
    border: 1px solid var(--bg-3); border-radius: var(--r-xl);
    box-shadow: var(--sh-xl); display: flex; flex-direction: column;
    max-height: 85vh; transform: translateY(24px) scale(0.96);
    transition: transform var(--dur-med) var(--ease-spring); overflow: hidden;
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }

.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--bg-2);
}
.modal-head h3 { display: flex; align-items: center; gap: var(--sp-2); font-size: 1rem; font-weight: 600; }

.ai-dot {
    width: 8px; height: 8px; background: var(--moss-bright);
    border-radius: 2px; transform: rotate(45deg);
    animation: ai-pulse 2s ease-in-out infinite;
}
@keyframes ai-pulse { 0%,100% { opacity: 1; box-shadow: 0 0 8px var(--moss-glow); } 50% { opacity: 0.5; box-shadow: 0 0 4px var(--moss-glow); } }

.modal-body { padding: var(--sp-5); overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: var(--sp-4); }
.modal-foot {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--bg-2);
}

.ai-context label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--fg-2); margin-bottom: var(--sp-2); text-transform: uppercase; letter-spacing: 0.05em; }
.ai-context pre {
    font-family: var(--font-mono); font-size: 0.75rem; line-height: 1.5;
    color: var(--fg-1); background: var(--bg-0); border: 1px solid var(--bg-3);
    border-radius: var(--r-md); padding: var(--sp-3);
    max-height: 100px; overflow-y: auto; white-space: pre-wrap;
}

.ai-prompt-group label { display: block; font-size: 0.875rem; font-weight: 500; color: var(--fg-0); margin-bottom: var(--sp-2); }
.ai-prompt-group textarea {
    width: 100%; padding: var(--sp-3); font-family: var(--font-sans);
    font-size: 0.875rem; color: var(--fg-0); background: var(--bg-0);
    border: 1px solid var(--bg-3); border-radius: var(--r-md);
    resize: vertical; outline: none;
    transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.ai-prompt-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.ai-prompt-group textarea::placeholder { color: var(--fg-3); }

.ai-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip {
    padding: 6px 14px; font-size: 0.75rem; font-weight: 500;
    color: var(--fg-1); background: var(--bg-2);
    border: 1px solid var(--bg-3); border-radius: var(--r-full); cursor: pointer;
    transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease, color var(--dur-fast) ease, transform var(--dur-fast) var(--ease-spring);
}
.chip:hover { background: var(--accent-glow); border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }

.ai-quota { font-family: var(--font-mono); font-size: 0.75rem; color: var(--fg-3); }
.share-desc { font-size: 0.875rem; color: var(--fg-1); line-height: 1.5; }
.share-row { display: flex; gap: var(--sp-2); }
.share-row input {
    flex: 1; padding: 10px 14px; font-family: var(--font-mono);
    font-size: 0.75rem; color: var(--fg-0); background: var(--bg-0);
    border: 1px solid var(--bg-3); border-radius: var(--r-md); outline: none;
}
.share-row input:focus { border-color: var(--accent); }
.share-row input::placeholder { color: var(--fg-3); }

/* ---- BUTTONS ---- */
.btn-accent {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    padding: 10px 20px; font-family: var(--font-sans);
    font-size: 0.875rem; font-weight: 600; color: #fff;
    background: var(--accent); border: none; border-radius: var(--r-md);
    cursor: pointer; box-shadow: 0 2px 8px rgba(232,115,74,0.25), inset 0 1px 0 rgba(255,255,255,0.1);
    transition: background-color var(--dur-fast) ease, transform var(--dur-fast) var(--ease-spring), box-shadow var(--dur-fast) ease;
}
.btn-accent:hover { background: var(--accent-bright); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(232,115,74,0.35), inset 0 1px 0 rgba(255,255,255,0.15); }
.btn-accent:active { transform: translateY(0) scale(0.97); }
.btn-accent:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-accent svg { width: 14px; height: 14px; }
.btn-sm { padding: 6px 14px; font-size: 0.8125rem; }

.btn-soft {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    padding: 8px 16px; font-family: var(--font-sans);
    font-size: 0.8125rem; font-weight: 500; color: var(--fg-1);
    background: var(--bg-2); border: 1px solid var(--bg-3);
    border-radius: var(--r-md); cursor: pointer; flex: 1; justify-content: center;
    transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.btn-soft:hover { background: var(--bg-3); color: var(--fg-0); border-color: var(--bg-4); }
.btn-soft svg { width: 14px; height: 14px; }
.btn-soft:disabled { opacity: 0.4; cursor: not-allowed; }

.icon-btn {
    width: 32px; height: 32px; display: grid; place-items: center;
    background: none; border: none; color: var(--fg-3);
    border-radius: var(--r-sm); cursor: pointer;
    transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.icon-btn:hover { background: var(--bg-2); color: var(--fg-0); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---- SPONSOR ---- */
.sponsor {
    position: fixed; bottom: 0; left: 0; right: 0; height: var(--sponsor-h);
    display: flex; align-items: center; justify-content: center; gap: var(--sp-3);
    background: var(--bg-1); border-top: 1px solid var(--bg-2);
    z-index: 90; padding: 0 var(--sp-4);
}
.sponsor-label {
    font-size: 0.625rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--fg-3);
    padding: 3px 8px; background: var(--bg-2); border-radius: var(--r-sm);
}
.sponsor-content { font-size: 0.8125rem; color: var(--fg-1); }
.sponsor-link { color: var(--fg-0); text-decoration: none; font-weight: 500; transition: color var(--dur-fast) ease; }
.sponsor-link:hover { color: var(--accent); }
.sponsor-cta {
    font-size: 0.75rem; color: var(--accent); text-decoration: none;
    font-weight: 500; margin-left: var(--sp-2); padding: 4px 12px;
    border: 1px solid var(--accent-glow-strong); border-radius: var(--r-full);
    transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease;
    white-space: nowrap;
}
.sponsor-cta:hover { background: var(--accent-glow); border-color: var(--accent); }

/* ---- TOASTS ---- */
.toasts {
    position: fixed; top: var(--sp-4); right: var(--sp-4);
    z-index: var(--z-toast); display: flex; flex-direction: column;
    gap: var(--sp-2); pointer-events: none; max-width: 320px;
}
.toast {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4); background: var(--bg-2);
    border: 1px solid var(--bg-3); border-left: 3px solid var(--accent);
    border-radius: var(--r-md); font-size: 0.875rem; color: var(--fg-0);
    box-shadow: var(--sh-md); pointer-events: auto;
    animation: toast-in var(--dur-med) var(--ease-spring);
}
.toast.success { border-left-color: var(--moss-bright); }
.toast.error { border-left-color: #e05555; }
.toast.closing { animation: toast-out var(--dur-med) var(--ease-glide) forwards; }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(120%) scale(0.95); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toast-out {
    to { opacity: 0; transform: translateX(120%) scale(0.95); }
}

/* ---- GESTURE HINT ---- */
.gesture-hint {
    position: fixed; bottom: calc(var(--sponsor-h) + var(--sp-4));
    left: 50%; transform: translateX(-50%); z-index: 350;
    display: flex; align-items: center; gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-4); background: var(--bg-2);
    border: 1px solid var(--bg-3); border-radius: var(--r-full);
    box-shadow: var(--sh-md); opacity: 0; visibility: hidden;
    transition: opacity var(--dur-med) ease, visibility var(--dur-med);
}
.gesture-hint.show { opacity: 1; visibility: visible; }
.gesture-hint svg { width: 14px; height: 14px; color: var(--accent); }
.gesture-hint span { font-size: 0.75rem; color: var(--fg-1); white-space: nowrap; }

/* ---- MOBILE ---- */
@media (max-width: 768px) {
    :root { --rail-w: 52px; --tab-h: 40px; --sponsor-h: 36px; }
    
    .app-body { flex-direction: column; }
    
    .rail {
        width: 100%; height: var(--rail-w); flex-direction: row;
        padding: 0 var(--sp-2); order: 3;
        border-right: none; border-top: 1px solid var(--bg-2);
    }
    .rail-logo { margin-bottom: 0; margin-right: var(--sp-2); }
    .rail-sep { width: 1px; height: 24px; margin: 0 var(--sp-2); }
    .rail-spacer { flex: 0; }
    .rail-btn { width: 38px; height: 38px; }
    .rail-btn svg { width: 18px; height: 18px; }
    
    .workspace { flex-direction: column; padding-bottom: calc(var(--rail-w) + var(--sponsor-h)); order: 1; }
    .preview-area { width: 100%; min-width: unset; max-width: unset; border-right: none; border-bottom: 1px solid var(--bg-2); flex: 1; }
    
    body.mobile-view:not(.show-code) .code-area { display: none; }
    body.mobile-view:not(.show-preview) .preview-area { display: none; }
    
    .sponsor { bottom: var(--rail-w); }
    .file-tree { left: 0; bottom: calc(var(--rail-w) + var(--sponsor-h)); width: 100%; max-width: 320px; }
    
    .modal { max-width: 100%; border-radius: var(--r-xl) var(--r-xl) 0 0; align-self: flex-end; max-height: 88dvh; }
    .modal-overlay { align-items: flex-end; padding: 0; }
    
    .status-bar { font-size: 0.625rem; gap: var(--sp-3); }
    .tab { height: 28px; font-size: 0.6875rem; }
}

@media (max-width: 926px) and (orientation: landscape) {
    .app-body { flex-direction: row; }
    .rail { width: var(--rail-w); height: 100%; flex-direction: column; order: 0; border-top: none; border-right: 1px solid var(--bg-2); padding: var(--sp-3) 0; }
    .workspace { flex-direction: row; padding-bottom: var(--sponsor-h); order: 1; }
    .sponsor { bottom: 0; }
}

/* ---- REDUCED MOTION ---- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .empty-art, .live-dot, .ai-dot { animation: none !important; }
    .device.active { animation: none !important; }
}
