/* ============================================================
   OPTIMIST · Xcode clone
   A 1:1-ish parody of Apple's Xcode IDE. Light default + dark.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
    /* --- Light (Xcode default) --- */
    --win-bg: #ececec;
    --toolbar-bg: #e9e9e9;
    --toolbar-border: #d0d0d0;
    --panel-bg: #f2f2f2;
    --editor-bg: #ffffff;
    --tab-bg: #e4e4e4;
    --tab-active-bg: #ffffff;
    --text: #1d1d1f;
    --text-2: #6e6e73;
    --text-3: #9a9a9f;
    --line: #e2e2e2;
    --line-strong: #d4d4d4;
    --sel-bg: #b3d7ff;
    --accent: #0a63d6;           /* Xcode blue */
    --gutter: #b0b0b5;
    --gutter-bg: #fafafa;
    --hover: rgba(0,0,0,0.05);
    --console-bg: #f6f6f6;
    --highlight-line: #eef4ff;

    /* Syntax (Xcode "Default" light) */
    --sx-kw:   #9b2393;   /* keyword purple */
    --sx-type: #0b4f79;   /* type teal-blue */
    --sx-str:  #c41a16;   /* string red */
    --sx-num:  #1c00cf;   /* number blue */
    --sx-cmt:  #5d6c79;   /* comment gray-green */
    --sx-fn:   #326d74;   /* function */
    --sx-prop: #0f68a0;   /* property/member */
    --sx-punc: #3a3a3a;
    --md-head: #1d1d1f;
    --md-link: #0a63d6;

    --mono: 'SF Mono', ui-monospace, 'JetBrains Mono', 'Menlo', 'Consolas', monospace;
    --ui: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;

    --nav-w: 260px;
    --insp-w: 300px;
    --radius: 8px;
}

.theme-dark {
    --win-bg: #1e1e1e;
    --toolbar-bg: #323232;
    --toolbar-border: #000000;
    --panel-bg: #252526;
    --editor-bg: #1f1f1f;
    --tab-bg: #2b2b2b;
    --tab-active-bg: #1f1f1f;
    --text: #e6e6e6;
    --text-2: #a0a0a5;
    --text-3: #6e6e73;
    --line: #333336;
    --line-strong: #3f3f43;
    --sel-bg: #3a5f8a;
    --accent: #4a9eff;
    --gutter: #5a5a60;
    --gutter-bg: #1f1f1f;
    --hover: rgba(255,255,255,0.06);
    --console-bg: #1a1a1a;
    --highlight-line: #2a2f3a;

    /* Syntax (Xcode "Default Dark") */
    --sx-kw:   #fc5fa3;
    --sx-type: #9ef1dd;
    --sx-str:  #fc6a5d;
    --sx-num:  #d0bf69;
    --sx-cmt:  #6c7986;
    --sx-fn:   #5dd8ff;
    --sx-prop: #67b7a4;
    --sx-punc: #d6d6d6;
    --md-head: #ffffff;
    --md-link: #4a9eff;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) {
        color-scheme: dark;
    }
}

html, body { height: 100%; }
body {
    font-family: var(--ui);
    color: var(--text);
    background: #d8d8d8;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    font-size: 13px;
}
.theme-dark body { background: #0d0d0d; }

/* ============================================================
   Window shell
   ============================================================ */
.ide {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--win-bg);
    overflow: hidden;
    animation: ideIn 0.5s cubic-bezier(0.2,0.8,0.2,1);
}
@keyframes ideIn {
    from { opacity: 0; transform: scale(0.995); }
    to   { opacity: 1; transform: scale(1); }
}

/* ---- Toolbar ---- */
.toolbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: 52px;
    padding: 0 14px;
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--toolbar-border);
    gap: 12px;
    user-select: none;
}
.tb-left  { display: flex; align-items: center; gap: 10px; }
.tb-center{ display: flex; align-items: center; gap: 12px; justify-self: center; }
.tb-right { display: flex; align-items: center; gap: 8px; justify-self: end; }

.traffic { display: flex; gap: 8px; margin-right: 8px; }
.tl { width: 12px; height: 12px; border-radius: 50%; display: inline-block; position: relative; }
.tl-close { background: #ff5f57; }
.tl-min   { background: #febc2e; }
.tl-zoom  { background: #28c840; }
.traffic:hover .tl-close::after,
.traffic:hover .tl-min::after,
.traffic:hover .tl-zoom::after {
    content: ''; position: absolute; inset: 0; border-radius: 50%;
    border: 0.5px solid rgba(0,0,0,0.25);
}

.tb-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 26px; border-radius: 6px;
    background: transparent; border: none; cursor: pointer;
    color: var(--text-2); transition: background 0.15s, color 0.15s;
}
.tb-btn:hover { background: var(--hover); color: var(--text); }
.tb-btn:active { transform: scale(0.94); }

/* Theme toggle: moon in light mode (→ go dark), sun in dark mode (→ go light) */
#themeBtn .icon-sun { display: none; }
#themeBtn .icon-moon { display: inline-flex; }
.theme-dark #themeBtn .icon-sun { display: inline-flex; }
.theme-dark #themeBtn .icon-moon { display: none; }

.scheme {
    display: flex; align-items: center; gap: 8px;
    height: 30px; padding: 0 12px;
    background: var(--editor-bg);
    border: 1px solid var(--line-strong);
    border-radius: 7px; font-size: 12.5px; color: var(--text);
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}
.app-chip { display: inline-flex; align-items: center; gap: 5px; font-weight: 500; }
.hammer { color: var(--accent); }
.chev { color: var(--text-3); font-size: 12px; }
.dest { display: inline-flex; align-items: center; gap: 5px; color: var(--text-2); }
.status-pill {
    font-size: 11.5px; color: var(--text-2);
    padding: 5px 12px; border-radius: 6px; white-space: nowrap;
}
.dot-sep { color: var(--text-3); margin: 0 2px; }

/* ============================================================
   Body layout
   ============================================================ */
.body { flex: 1; display: flex; min-height: 0; }

.resizer { width: 4px; cursor: col-resize; background: transparent; flex-shrink: 0; z-index: 5; }
.resizer:hover { background: var(--accent); opacity: 0.4; }

/* ---- Navigator ---- */
.navigator {
    width: var(--nav-w); flex-shrink: 0;
    background: var(--panel-bg);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column; min-height: 0;
    transition: margin-left 0.28s cubic-bezier(0.2,0.8,0.2,1);
}
.ide.nav-hidden .navigator { margin-left: calc(var(--nav-w) * -1 - 4px); }
.ide.nav-hidden #navResizer { display: none; }

/* Mobile navigator scrim — hidden except when nav is open on mobile (see media query) */
.nav-scrim { display: none; }

.nav-tabs {
    display: flex; align-items: center; gap: 2px;
    height: 30px; padding: 0 8px;
    border-bottom: 1px solid var(--line);
}
.nav-tab {
    width: 26px; height: 22px; border: none; background: transparent;
    color: var(--text-3); cursor: pointer; border-radius: 5px;
    display: inline-flex; align-items: center; justify-content: center;
}
.nav-tab.is-active { color: var(--accent); }

.nav-tree { flex: 1; overflow-y: auto; padding: 6px 0; }

.tree-row {
    display: flex; align-items: center; gap: 5px;
    height: 24px; padding: 0 10px; cursor: pointer;
    font-size: 12.5px; color: var(--text); white-space: nowrap;
    position: relative; user-select: none;
}
.tree-row:hover { background: var(--hover); }
.tree-row.is-selected { background: var(--accent); color: #fff; }
.tree-row.is-selected .tree-icon,
.tree-row.is-selected .disclosure { color: rgba(255,255,255,0.9); }
.tree-row.is-selected .tree-badge { background: rgba(255,255,255,0.25); color:#fff; }
.tree-indent { display: inline-block; }
.disclosure {
    width: 12px; text-align: center; color: var(--text-3);
    transition: transform 0.18s ease; font-size: 9px; flex-shrink: 0;
}
.disclosure.open { transform: rotate(90deg); }
.disclosure.leaf { visibility: hidden; }
.tree-icon { width: 15px; height: 15px; flex-shrink: 0; display:inline-flex; }
.tree-name { overflow: hidden; text-overflow: ellipsis; }
.tree-badge {
    margin-left: auto; font-size: 9px; font-weight: 600; letter-spacing: 0.02em;
    padding: 1px 5px; border-radius: 4px; text-transform: uppercase;
}
.tree-badge.research { background: rgba(10,99,214,0.14); color: var(--accent); }
.tree-badge.opinion  { background: rgba(196,26,22,0.14); color: #c41a16; }
.theme-dark .tree-badge.opinion { color: #fc6a5d; }

.tree-children { overflow: hidden; }

.nav-filter {
    display: flex; align-items: center; gap: 6px;
    height: 30px; padding: 0 10px;
    border-top: 1px solid var(--line); color: var(--text-3);
}
.nav-filter input {
    flex: 1; border: none; background: transparent; outline: none;
    font-family: var(--ui); font-size: 12px; color: var(--text);
}

/* ============================================================
   Editor column
   ============================================================ */
.editor-col { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--editor-bg); }

/* Tab bar */
.tabbar {
    display: flex; align-items: stretch; height: 30px;
    background: var(--tab-bg); border-bottom: 1px solid var(--line);
    overflow-x: auto; scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tab {
    display: flex; align-items: center; gap: 6px;
    padding: 0 12px; min-width: 130px; max-width: 220px;
    font-size: 12px; color: var(--text-2); cursor: pointer;
    border-right: 1px solid var(--line);
    background: var(--tab-bg); position: relative; white-space: nowrap;
    animation: tabIn 0.22s cubic-bezier(0.2,0.8,0.2,1);
}
@keyframes tabIn { from { opacity: 0; transform: translateX(-6px);} to {opacity:1; transform:none;} }
.tab.is-active { background: var(--tab-active-bg); color: var(--text); }
.tab .tab-icon { width: 13px; height: 13px; flex-shrink: 0; }
.tab .tab-name { overflow: hidden; text-overflow: ellipsis; }
.tab .tab-close {
    width: 15px; height: 15px; border-radius: 4px; display: inline-flex;
    align-items: center; justify-content: center; margin-left: auto;
    color: var(--text-3); opacity: 0; transition: opacity 0.15s, background 0.15s; font-size: 12px;
}
.tab:hover .tab-close { opacity: 1; }
.tab .tab-close:hover { background: var(--hover); color: var(--text); }

/* Jump bar / breadcrumbs */
.jumpbar {
    display: flex; align-items: center; gap: 4px; height: 28px;
    padding: 0 10px; border-bottom: 1px solid var(--line);
    background: var(--editor-bg); font-size: 12px; color: var(--text-2);
}
.jb-nav {
    width: 20px; height: 20px; border: none; background: transparent;
    color: var(--text-3); cursor: pointer; border-radius: 4px; font-size: 15px; line-height: 1;
}
.jb-nav:hover { background: var(--hover); color: var(--text); }
.crumbs { display: flex; align-items: center; gap: 4px; overflow: hidden; }
.crumb { display: inline-flex; align-items: center; gap: 5px; padding: 2px 5px; border-radius: 4px; cursor: default; }
.crumb.link { cursor: pointer; }
.crumb.link:hover { background: var(--hover); }
.crumb .c-icon { width: 13px; height: 13px; }
.crumb-sep { color: var(--text-3); }
.crumb.current { color: var(--text); font-weight: 500; }

/* Editor surface */
.editor {
    flex: 1; overflow: auto; background: var(--editor-bg);
    font-family: var(--mono); font-size: 13px; line-height: 1.55;
}
.code { padding: 8px 0 40vh; min-width: max-content; }
.code-line { display: flex; align-items: flex-start; }
.code-line:hover .ln { color: var(--text-2); }
.ln {
    flex-shrink: 0; width: 46px; text-align: right; padding-right: 12px;
    color: var(--gutter); user-select: none; font-variant-numeric: tabular-nums;
    position: sticky; left: 0; background: var(--editor-bg);
}
.src { padding-right: 24px; white-space: pre; color: var(--text); }
.code-line.hl { background: var(--highlight-line); }
.code-line.hl .ln { background: var(--highlight-line); }

/* Prose wrap mode — markdown files soft-wrap like Xcode's "Wrap lines" */
.editor.wrap .code { min-width: 0; }
.editor.wrap .src {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    max-width: 760px;
    padding-right: 32px;
    line-height: 1.7;
}
.editor.wrap .code-line { align-items: flex-start; }

/* Syntax tokens */
.kw   { color: var(--sx-kw); }
.type { color: var(--sx-type); }
.str  { color: var(--sx-str); }
.num  { color: var(--sx-num); }
.cmt, .comment span, .code-line.comment .src, .code-line.doc .src { color: var(--sx-cmt); }
.code-line.comment .src, .code-line.doc .src { color: var(--sx-cmt); font-style: italic; }
.fn   { color: var(--sx-fn); }
.prop { color: var(--sx-prop); }
.punc { color: var(--sx-punc); }

/* Markdown rendered in editor */
.md-head { color: var(--md-head); font-weight: 700; }
.md-quote { color: var(--text-2); font-style: italic; }
.md-bullet { color: var(--accent); }
.md-rule { color: var(--text-3); }
.md-link { color: var(--md-link); text-decoration: none; }
.md-link:hover { text-decoration: underline; }
.md-strong { color: var(--text); font-weight: 700; }
.md-em { color: var(--text); font-style: italic; }

/* Member row link in JSON view */
.code-line .m-open { color: var(--md-link); text-decoration: none; }
.code-line .m-open:hover { text-decoration: underline; }

/* ============================================================
   Debug area
   ============================================================ */
.debug-area {
    border-top: 1px solid var(--line-strong);
    background: var(--console-bg);
    display: flex; flex-direction: column;
    height: 210px; min-height: 32px;
    transition: height 0.28s cubic-bezier(0.2,0.8,0.2,1);
}
.debug-area.collapsed { height: 32px; }
.debug-bar {
    display: flex; align-items: center; gap: 8px; height: 32px;
    padding: 0 10px; border-bottom: 1px solid var(--line);
    font-size: 11.5px; color: var(--text-2); flex-shrink: 0;
}
.dbg-toggle { width: 24px; height: 22px; border: none; background: transparent; color: var(--text-2); cursor: pointer; border-radius: 4px; }
.dbg-toggle:hover { background: var(--hover); color: var(--text); }
.dbg-spacer { flex: 1; }
.debug-area.collapsed .console,
.debug-area.collapsed .console-input-row { display: none; }
.console {
    flex: 1; overflow-y: auto; padding: 8px 12px;
    font-family: var(--mono); font-size: 12px; line-height: 1.55; color: var(--text);
}
.console .out { white-space: pre-wrap; }
.console .cmd-echo { color: var(--text-2); }
.console .accent { color: var(--accent); }
.console .warn { color: #c41a16; }
.theme-dark .console .warn { color: #fc6a5d; }
.console-input-row {
    display: flex; align-items: center; gap: 8px; padding: 6px 12px;
    border-top: 1px solid var(--line); flex-shrink: 0;
}
.lldb { color: var(--text-3); font-family: var(--mono); font-size: 12px; }
.console-input {
    flex: 1; border: none; background: transparent; outline: none;
    font-family: var(--mono); font-size: 12px; color: var(--text);
}

/* ============================================================
   Inspector
   ============================================================ */
.inspector {
    width: var(--insp-w); flex-shrink: 0;
    background: var(--panel-bg);
    border-left: 1px solid var(--line);
    display: flex; flex-direction: column;
    transition: margin-right 0.28s cubic-bezier(0.2,0.8,0.2,1);
}
.ide.insp-hidden .inspector { margin-right: calc(var(--insp-w) * -1 - 4px); }
.ide.insp-hidden #inspResizer { display: none; }
.insp-tabs {
    display: flex; align-items: center; height: 30px; padding: 0 10px;
    border-bottom: 1px solid var(--line);
}
.insp-tab { width: 26px; height: 22px; border: none; background: transparent; color: var(--accent); cursor: pointer; }
.insp-body { flex: 1; overflow-y: auto; padding: 14px; }

.insp-thumb {
    width: 100%; aspect-ratio: 16/10; border-radius: 6px; object-fit: cover;
    border: 1px solid var(--line); margin-bottom: 12px; background: var(--editor-bg);
}
.insp-section { margin-bottom: 18px; }
.insp-h { font-size: 11px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.insp-kv { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; padding: 3px 0; }
.insp-kv .k { color: var(--text-2); }
.insp-kv .v { color: var(--text); text-align: right; }
.insp-empty { color: var(--text-3); font-size: 12px; text-align: center; margin-top: 40px; }

/* ============================================================
   Status bar
   ============================================================ */
.statusbar {
    height: 24px; flex-shrink: 0;
    display: flex; align-items: center; gap: 12px; padding: 0 12px;
    background: var(--toolbar-bg); border-top: 1px solid var(--toolbar-border);
    font-size: 11px; color: var(--text-2);
}
.sb-spacer { flex: 1; }
.sb-hint { color: var(--text-3); }

/* ============================================================
   Spotlight
   ============================================================ */
.spotlight-overlay[hidden] { display: none !important; }
.spotlight-overlay {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: flex-start; justify-content: center;
    padding-top: 14vh;
    background: rgba(0,0,0,0.28);
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
    animation: fadeIn 0.16s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.spotlight {
    width: min(640px, 92vw);
    background: var(--panel-bg);
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.35);
    overflow: hidden;
    animation: spIn 0.2s cubic-bezier(0.2,0.9,0.3,1);
}
@keyframes spIn { from { opacity: 0; transform: scale(0.97) translateY(-6px);} to {opacity:1; transform:none;} }
.sp-input-row {
    display: flex; align-items: center; gap: 10px; padding: 14px 16px;
    border-bottom: 1px solid var(--line); color: var(--text-3);
}
.sp-input-row input {
    flex: 1; border: none; background: transparent; outline: none;
    font-family: var(--ui); font-size: 18px; color: var(--text);
}
.sp-results { list-style: none; max-height: 46vh; overflow-y: auto; padding: 6px; }
.sp-item {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px;
    border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text);
}
.sp-item .sp-icon { width: 16px; height: 16px; flex-shrink: 0; }
.sp-item .sp-sub { margin-left: auto; color: var(--text-3); font-size: 11px; }
.sp-item.is-active { background: var(--accent); color: #fff; }
.sp-item.is-active .sp-sub { color: rgba(255,255,255,0.8); }
.sp-item.is-active .sp-icon { color: #fff; }
.sp-empty { padding: 24px; text-align: center; color: var(--text-3); font-size: 13px; }
.sp-group { padding: 8px 12px 4px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); }

/* Generic file-icon colors */
.fi-swift { color: #f05138; }
.fi-md    { color: #4a9eff; }
.fi-json  { color: #d0a020; }
.fi-folder{ color: #58a6ff; }
.theme-dark .fi-folder { color: #6cb6ff; }

/* Scrollbars */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.4); border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(128,128,128,0.6); background-clip: content-box; }

/* ============================================================
   Mobile
   ============================================================ */
@media (max-width: 760px) {
    body { font-size: 14px; }
    .toolbar { grid-template-columns: auto 1fr auto; height: 46px; padding: 0 8px; }
    .tb-center .scheme, .status-pill, .sb-hint { display: none; }
    .navigator {
        position: absolute; top: 0; bottom: 0; left: 0; z-index: 40;
        box-shadow: 8px 0 30px rgba(0,0,0,0.25);
    }
    .ide:not(.nav-open) .navigator { margin-left: calc(var(--nav-w) * -1 - 10px); }
    /* Inspector becomes a right-side slide-over drawer */
    .inspector {
        position: absolute; top: 0; bottom: 0; right: 0; z-index: 40;
        display: flex;
        box-shadow: -8px 0 30px rgba(0,0,0,0.25);
    }
    .ide:not(.insp-open) .inspector { margin-right: calc(var(--insp-w) * -1 - 10px); }

    /* Shared scrim: shown when either drawer is open */
    .ide.nav-open .nav-scrim,
    .ide.insp-open .nav-scrim {
        display: block;
        position: absolute; inset: 0; z-index: 35;
        background: rgba(0,0,0,0.32);
        animation: fadeIn 0.16s ease;
    }
    #inspResizer, #navResizer { display: none; }
    .debug-area { height: 160px; }

    /* On mobile, wrap & pad EVERY file type (not just markdown) so nothing
       runs off-screen horizontally. Desktop keeps code unwrapped. */
    .editor .code { min-width: 0; }
    .editor .src {
        white-space: pre-wrap;
        overflow-wrap: anywhere;
        max-width: none;
        padding-right: 18px;
    }
    .editor .code-line { align-items: flex-start; }
}
