/*=============== PROJECTS DESKTOP (Finder + Shell + Ame TUI) ===============*/
/* Page-specific styling for projects.html. Loaded only by that page, in the
 * same spirit as agent/chatroom.css and agent/recruiter.css.
 *
 * Replaces the old card grid with a macOS-style desktop:
 *   - a small bash-like terminal (agent/shell.js) as the front door
 *   - draggable project windows (agent/desktop.js)
 *   - a light, site-themed "Claude Code" TUI for Ame
 */

.desktop-page {
    --accent: hsl(230, 100%, 50%);
    --accent-soft: hsla(230, 100%, 50%, 0.09);
    --ink: #1f2937;
    --ink-soft: #6b7280;
    --line: #e3e6ea;
    --line-strong: #d5d8dd;
    --panel: #fbfbfd;
    --chrome: #f4f5f7;
    --folder-blue: #2b9bff;
    --term-green: #10b981;
    --term-red: #e53e3e;
}

/* Hide the site-wide floating agent on this page: Ame lives in the TUI here.
   The panel stays in the DOM (hidden) so the engine and its observer work. */
.projects-page .tp-launcher,
.projects-page .tp-panel {
    display: none !important;
}

.projects-page {
    background:
        radial-gradient(circle at 15% 0%, rgba(0, 60, 255, 0.05), transparent 42%),
        radial-gradient(circle at 90% 8%, rgba(39, 201, 63, 0.045), transparent 38%),
        hsl(0, 0, 98%);
}

/* ---------------------------------------------------------- terminal ---- */

.projects-terminal {
    margin-top: 26px;
}

.projects-terminal .terminal-title {
    font-size: 0.78rem;
    color: #6b7280;
    letter-spacing: 0.02em;
}

.terminal-hint {
    font-size: 0.72rem;
    color: #9aa1ab;
    white-space: nowrap;
}

.terminal-hint b {
    color: var(--accent);
    font-weight: 600;
}

/* Output above, prompt pinned to the bottom — reads like a real shell. */
.projects-terminal .terminal-body {
    display: flex;
    flex-direction: column;
    padding: 0;
}

.projects-terminal .terminal-output {
    order: 1;
    min-height: 132px;
    max-height: 264px;
    padding: 14px 16px 6px;
    font-size: 0.86rem;
    line-height: 1.62;
}

/* "Zoom" on the terminal title bar. */
.projects-terminal.is-expanded .terminal-output {
    max-height: 60vh;
}

/* Once desktop.js has moved the cards into windows, hide the empty source. */
.projects-page .projects-source[hidden] {
    display: none;
}

.projects-terminal .terminal-input-container {
    order: 2;
    margin: 0;
    padding: 10px 16px 12px;
    border-bottom: none;
    border-top: 1px solid var(--line);
    background: #fff;
}

.projects-terminal #bash-prompt {
    color: var(--accent);
}

.projects-terminal .send-button {
    background-color: var(--accent);
}

.projects-terminal .send-button:hover {
    background-color: hsl(230, 100%, 42%);
}

/* terminal line primitives (rendered by shell.js) */
.term-line {
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0 0 2px;
}

.term-line--cmd {
    color: #111827;
    margin-top: 6px;
}

.term-line--cmd .term-prompt-inline {
    color: var(--accent);
    font-weight: 700;
    margin-right: 8px;
}

.term-line--out {
    color: #374151;
}

.term-muted { color: #9aa1ab; }
.term-ok { color: var(--term-green); font-weight: 600; }
.term-err { color: var(--term-red); }
.term-dir { color: var(--accent); font-weight: 600; }
.term-key { color: #7c3aed; }

.term-cols {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 2px 20px;
    margin: 2px 0 4px;
}

.term-cols .term-entry {
    color: #374151;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.term-cols .term-entry:hover {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.term-cols .term-entry::before {
    content: "\1F4C1  ";
    font-size: 0.78em;
}

.term-bar {
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--accent), hsl(230, 100%, 70%));
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}

/* ------------------------------------------------------------- desktop -- */

.desktop {
    max-width: 1200px;
    margin: 26px auto 8px;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 22px 55px rgba(17, 24, 39, 0.14);
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
}

/* menubar */
.desktop-menubar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 34px;
    padding: 0 12px;
    background: rgba(248, 249, 251, 0.94);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    font-size: 0.78rem;
    color: #374151;
    position: relative;
    z-index: 60;
}

.menubar-left,
.menubar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.menubar-apple {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    color: #111827;
}

.menubar-app {
    font-weight: 700;
    margin-right: 6px;
}

.menubar-menu { position: relative; }

.menubar-item {
    border: none;
    background: none;
    font: inherit;
    color: inherit;
    padding: 4px 9px;
    border-radius: 6px;
    cursor: pointer;
}

.menubar-item:hover,
.menubar-menu.is-open .menubar-item {
    background: var(--accent);
    color: #fff;
}

.menu-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 186px;
    padding: 5px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 9px;
    box-shadow: 0 16px 40px rgba(17, 24, 39, 0.18);
    display: none;
    z-index: 80;
}

.menubar-menu.is-open .menu-dropdown { display: block; }

.menu-dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    background: none;
    font: inherit;
    color: #374151;
    padding: 7px 10px 7px 22px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    position: relative;
}

.menu-dropdown button:hover {
    background: var(--accent);
    color: #fff;
}

.menu-dropdown button.is-checked::before {
    content: "\2713";
    position: absolute;
    left: 7px;
    font-weight: 700;
}

.menu-sep {
    height: 1px;
    background: #eceef1;
    margin: 4px 8px;
}

.menubar-status {
    color: var(--ink-soft);
    padding-right: 6px;
}

.menubar-ame {
    border: 1px solid var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    font: inherit;
    font-weight: 700;
    padding: 3px 12px;
    border-radius: 999px;
    cursor: pointer;
}

.menubar-ame:hover {
    background: var(--accent);
    color: #fff;
}

.menubar-clock {
    color: var(--ink-soft);
    min-width: 46px;
    text-align: right;
}

/* body: sidebar + canvas */
.desktop-body {
    display: grid;
    grid-template-columns: 214px 1fr;
    min-height: 500px;
}

.finder-sidebar {
    background: rgba(245, 246, 248, 0.9);
    border-right: 1px solid var(--line);
    padding: 14px 10px;
    font-size: 0.8rem;
}

.sidebar-group { margin-bottom: 18px; }

.sidebar-title {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: #9aa1ab;
    padding: 0 8px 6px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: none;
    background: none;
    font: inherit;
    color: #374151;
    padding: 6px 8px;
    border-radius: 7px;
    cursor: pointer;
    text-align: left;
}

.sidebar-item:hover { background: #eceef2; }

.sidebar-item.is-active {
    background: var(--accent);
    color: #fff;
}

.sidebar-item.is-active .sidebar-count { color: rgba(255, 255, 255, 0.85); }

.sidebar-glyph {
    width: 14px;
    text-align: center;
    opacity: 0.85;
}

.sidebar-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-count {
    font-size: 0.72rem;
    color: #9aa1ab;
}

.sidebar-hint {
    margin-top: 6px;
    padding: 10px 8px 0;
    border-top: 1px solid var(--line);
    font-size: 0.72rem;
    line-height: 1.5;
    color: #9aa1ab;
}

/* canvas */
.desktop-canvas {
    position: relative;
    overflow: hidden;
    min-height: 500px;
    background-color: #eef3fb;
    background-image:
        radial-gradient(circle at 18% 12%, rgba(0, 60, 255, 0.06), transparent 46%),
        radial-gradient(circle at 86% 82%, rgba(39, 201, 63, 0.055), transparent 42%),
        linear-gradient(rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.62)),
        linear-gradient(rgba(148, 163, 184, 0.14) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.14) 1px, transparent 1px);
    background-size: auto, auto, auto, 26px 26px, 26px 26px;
}

.desktop-icons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
    gap: 16px 8px;
    align-content: start;
    padding: 22px 18px;
    position: relative;
    z-index: 1;
}

.desktop-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 10px 6px 8px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: none;
    font: inherit;
    cursor: pointer;
    color: #1f2937;
}

.desktop-icon:hover { background: rgba(255, 255, 255, 0.6); }

.desktop-icon.is-selected {
    background: var(--accent-soft);
    border-color: rgba(0, 60, 255, 0.35);
}

.desktop-icon svg {
    width: 58px;
    height: 48px;
    filter: drop-shadow(0 7px 9px rgba(31, 127, 224, 0.28));
}

.desktop-icon .icon-label {
    font-size: 0.76rem;
    line-height: 1.28;
    text-align: center;
    max-width: 100px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.desktop-empty {
    padding: 40px 20px;
    text-align: center;
    color: #9aa1ab;
    font-size: 0.82rem;
}

/* ------------------------------------------------------------- windows -- */

.desktop-window {
    position: absolute;
    top: 24px;
    left: 24px;
    width: 430px;
    max-width: calc(100% - 24px);
    max-height: calc(100% - 24px);
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    box-shadow: 0 14px 34px rgba(17, 24, 39, 0.18);
    overflow: hidden;
    z-index: 5;
    transition: box-shadow 0.15s ease;
}

.desktop-window[hidden] { display: none; }

.desktop-window.is-focused {
    box-shadow: 0 28px 64px rgba(17, 24, 39, 0.3);
    border-color: #b9c0c9;
}

.desktop-window.is-dragging {
    cursor: grabbing;
    box-shadow: 0 34px 70px rgba(17, 24, 39, 0.34);
}

.desktop-window.is-maximized {
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border-width: 0;
}

.desktop-window.is-minimized .window-body { display: none; }

.window-titlebar {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 38px;
    padding: 0 12px;
    background: linear-gradient(#fbfbfc, #f0f1f3);
    border-bottom: 1px solid var(--line);
    cursor: grab;
    user-select: none;
    touch-action: none;
    flex-shrink: 0;
}

.desktop-window.is-focused .window-titlebar {
    background: linear-gradient(#fdfdfe, #f2f3f5);
}

.window-lights {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.window-light {
    width: 12px;
    height: 12px;
    padding: 0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    position: relative;
}

.window-light.close { background: #ff5f56; }
.window-light.minimize { background: #ffbd2e; }
.window-light.maximize { background: #27c93f; }

.window-light:hover { filter: brightness(0.92); }

.window-title {
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.window-body {
    overflow: auto;
    overscroll-behavior: contain;
    flex: 1 1 auto;
    min-height: 0;
}

/* Blend the original project card into the window chrome. */
.window-body .model-card {
    border: none;
    border-radius: 0;
    box-shadow: none;
    min-height: 0;
    height: auto;
    background: transparent;
    display: block;
}

.window-body .model-card:hover {
    transform: none;
    box-shadow: none;
    border-color: transparent;
}

.window-body .model-card-header {
    background: transparent;
    border-bottom: 1px solid var(--line);
    min-height: 0;
    padding: 12px 20px;
    flex-direction: row;
    align-items: center;
}

.window-body .model-name { display: none; }

.window-body .model-tags { gap: 6px; }

.window-body .model-card-content { padding: 16px 20px 20px; }

.window-body .model-card-footer { margin-top: 18px; }

.window-body .repo-link {
    width: 100%;
    box-sizing: border-box;
}

/* ---------------------------------------------------------------- dock -- */

.desktop-dock {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 12px;
    padding: 12px 14px 14px;
    background: rgba(248, 249, 251, 0.94);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
}

.dock-item {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: #fff;
    cursor: pointer;
    position: relative;
    transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.dock-item:hover {
    transform: translateY(-7px) scale(1.06);
    box-shadow: 0 10px 20px rgba(17, 24, 39, 0.16);
}

.dock-item:active { transform: translateY(-3px) scale(1.02); }

.dock-glyph {
    font-size: 1.05rem;
    color: #374151;
    font-weight: 700;
}

.dock-glyph--mono { font-size: 0.92rem; }

.dock-svg {
    width: 20px;
    height: 20px;
    color: #374151;
}

.dock-item--home .dock-glyph {
    font-size: 1.2rem;
}

.dock-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
}

.dock-dot {
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: transparent;
}

.dock-item.is-active .dock-dot { background: var(--accent); }

.desktop-instruction {
    text-align: center;
    margin: 14px auto 30px;
}

.desktop-instruction code {
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 1px 6px;
    border-radius: 4px;
}

/* ------------------------------------------- Ame mode (inside the terminal) */

/* Typing `ame` switches the terminal window into a Claude Code-style
   assistant, instead of opening a separate window. `esc` returns to the shell. */

.ame-pane {
    display: none;
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    background: var(--panel);
}

.terminal-interface.is-ame .terminal-body { display: none; }
.terminal-interface.is-ame .ame-pane { display: flex; }

.ame-pane-bar {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    flex-shrink: 0;
    padding: 11px 14px;
    background: var(--chrome);
    border-bottom: 1px solid var(--line);
}

.ame-mascot {
    width: 28px;
    height: 24px;
    flex-shrink: 0;
    margin-top: 1px;
    display: inline-flex;
}

.ame-mascot svg {
    width: 100%;
    height: 100%;
    display: block;
}

.ame-pane-id {
    flex: 1;
    min-width: 0;
    line-height: 1.4;
}

.ame-pane-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: #111827;
}

.ame-pane-ver {
    font-weight: 400;
    color: var(--ink-soft);
    margin-left: 6px;
    font-size: 0.72rem;
}

.ame-pane-sub { font-size: 0.72rem; color: #4b5563; }
.ame-pane-path { font-size: 0.72rem; color: #9aa1ab; }

.ame-pane-hint {
    font-size: 0.7rem;
    color: #9aa1ab;
    white-space: nowrap;
}

.ame-pane-hint kbd {
    font-family: inherit;
    border: 1px solid var(--line-strong);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 0 4px;
    background: #fff;
    color: #4b5563;
}

.ame-tui-log {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 20px 22px;
    font-size: 0.86rem;
    line-height: 1.62;
    color: var(--ink);
    scrollbar-width: thin;
}

.ame-turn {
    margin: 0 0 14px;
    white-space: pre-wrap;
    word-break: break-word;
}

.ame-caret {
    display: inline-block;
    width: 1.05em;
    color: #9aa1ab;
}

.ame-you { color: #4b5563; }
.ame-you .ame-caret { color: var(--accent); font-weight: 700; }

.ame-bot .ame-caret { color: var(--term-green); }

.ame-tool {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 6px;
    padding: 5px 10px;
    border-left: 2px solid #cbd5e1;
    background: rgba(148, 163, 184, 0.08);
    border-radius: 0 6px 6px 0;
    font-size: 0.76rem;
    color: var(--ink-soft);
}

.ame-tool.is-done {
    color: var(--term-green);
    border-left-color: var(--term-green);
}

.ame-tool .ame-tool-mark { font-weight: 700; }

.ame-typing {
    display: inline-flex;
    gap: 4px;
    vertical-align: middle;
    padding: 3px 0;
}

.ame-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink-soft);
    animation: ame-tui-bounce 1s infinite ease-in-out;
}

.ame-typing span:nth-child(2) { animation-delay: 0.15s; }
.ame-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ame-tui-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40% { transform: translateY(-4px); opacity: 1; }
}

.ame-tui-form {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}

.ame-tui-promptsign {
    color: var(--accent);
    font-weight: 700;
}

.ame-tui-input {
    flex: 1;
    min-width: 0;
    border: 1px dashed #b9bdc4;
    border-radius: 6px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--ink);
    background: #fff;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ame-tui-input:focus {
    border-color: var(--accent);
    border-style: solid;
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.ame-tui-input::placeholder { color: #aab0b8; }

.ame-tui-send {
    border: none;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 700;
    padding: 10px 16px;
    border-radius: 6px;
    cursor: pointer;
}

.ame-tui-send:hover { background: hsl(230, 100%, 42%); }

.ame-tui-send:disabled {
    background: #c7cbd1;
    cursor: default;
}

/* ---------------------------------------------------------- responsive -- */

@media (max-width: 768px) {
    .projects-terminal { margin-top: 16px; }

    .terminal-hint { display: none; }

    .projects-terminal .terminal-output {
        min-height: 110px;
        max-height: 210px;
    }

    .desktop { border-radius: 12px; }

    .menubar-app,
    .menubar-menu,
    .menubar-status { display: none; }

    .desktop-body {
        display: block;
    }

    .finder-sidebar {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        padding: 9px 10px;
        border-right: none;
        border-bottom: 1px solid var(--line);
        -webkit-overflow-scrolling: touch;
    }

    .sidebar-group { margin: 0; display: flex; gap: 8px; }
    .sidebar-title,
    .sidebar-hint,
    .finder-sidebar .sidebar-group:nth-child(2) { display: none; }

    .sidebar-item {
        width: auto;
        white-space: nowrap;
        border: 1px solid var(--line);
        background: #fff;
        border-radius: 999px;
        padding: 6px 12px;
    }

    .sidebar-label { flex: none; }

    .desktop-canvas {
        overflow: visible;
        min-height: 0;
    }

    .desktop-icons {
        grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
        padding: 16px 12px;
    }

    .desktop-icon svg { width: 50px; height: 42px; }

    /* Windows become stacked panels on small screens. */
    .desktop-window {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        width: auto !important;
        max-width: none;
        max-height: none;
        margin: 0 12px 14px;
    }

    .desktop-window.is-maximized {
        width: auto !important;
        height: auto;
    }

    .window-titlebar { cursor: default; }
    .window-body { max-height: none; }

    .desktop-dock {
        flex-wrap: wrap;
    }

    .ame-tui-log { padding: 14px; }

    .ame-pane-bar { font-size: 0.7rem; }
}

@media (prefers-reduced-motion: reduce) {
    .dock-item { transition: none; }

    .ame-typing span { animation: none; }
}

/* ==================== Ame menu logo (replaces the Apple mark) ============ */

.menubar-item.menubar-logo {
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.menubar-logo img {
    width: 23px;
    height: 23px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.menubar-logo:hover img,
.menubar-menu.is-open .menubar-logo img {
    box-shadow: 0 0 0 2px var(--accent-soft), 0 0 0 1px var(--accent);
}

.menubar-logo:hover,
.menubar-menu.is-open .menubar-logo {
    background: transparent;
    color: inherit;
}

/* ==================== Full-screen desktop (Mac-like) ==================== */

@media (min-width: 769px) {
    /* Only take over the viewport once desktop.js has initialised. */
    body.desktop-ready {
        overflow: hidden;
        height: 100vh;
    }

    body.desktop-ready .nav-bar-container,
    body.desktop-ready .desktop-instruction {
        display: none;
    }

    body.desktop-ready .main-content {
        padding: 0;
        margin: 0;
        max-width: none;
    }

    body.desktop-ready .desktop {
        position: fixed;
        inset: 0;
        z-index: 60;
        margin: 0;
        max-width: none;
        border: none;
        border-radius: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column;
        height: 100dvh;
    }

    body.desktop-ready .desktop-body {
        display: block;
        position: relative;
        flex: 1 1 auto;
        min-height: 0;
    }

    body.desktop-ready .finder-sidebar {
        display: none;
    }

    body.desktop-ready .desktop-canvas {
        min-height: 0;
        height: 100%;
    }

    body.desktop-ready .desktop-icons {
        grid-template-columns: repeat(auto-fill, 112px);
        justify-content: start;
    }

    body.desktop-ready .desktop-dock {
        flex-shrink: 0;
    }
}

/* ==================== Terminal as an app window ==================== */

.desktop-window[data-window="terminal-app"] {
    width: min(760px, calc(100% - 48px));
    height: min(470px, calc(100% - 48px));
}

.window-body--terminal {
    padding: 0;
    overflow: hidden;
    display: flex;
}

.window-body--terminal #projects-terminal {
    margin: 0;
    max-width: none;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: #fafafa;
    display: flex;
    flex-direction: column;
}

.window-body--terminal #projects-terminal .terminal-header {
    display: none;
}

.window-body--terminal #projects-terminal .terminal-body {
    flex: 1 1 auto;
    min-height: 0;
}

.window-body--terminal #projects-terminal .terminal-output {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
}

@media (max-width: 768px) {
    .desktop-window[data-window="terminal-app"] {
        width: auto;
        height: auto;
    }

    .window-body--terminal #projects-terminal {
        height: auto;
    }
}

/* ==================== Group windows (nested folders) ==================== */

.desktop-window[data-window^="group-"] {
    width: min(560px, calc(100% - 48px));
    height: min(440px, calc(100% - 48px));
}

.window-body--group {
    padding: 16px;
    overflow: auto;
}

.group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
    gap: 16px 8px;
    align-content: start;
}

.group-empty {
    grid-column: 1 / -1;
    color: var(--ink-soft);
    font-size: 0.82rem;
    margin: 6px 4px;
}

.icon-folder-wrap {
    position: relative;
    display: inline-flex;
}

.icon-badge {
    position: absolute;
    top: -6px;
    right: -8px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font-size: 0.66rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(17, 24, 39, 0.25);
}

/* ==================== Mobile: simple folder view (no windows) ============ */
@media (max-width: 768px) {
    /* The terminal is a desktop app only. */
    .desktop-window[data-window="terminal-app"] { display: none !important; }

    /* Drop the desktop chrome. */
    .desktop-menubar,
    .finder-sidebar,
    .desktop-instruction { display: none; }

    .desktop-canvas { background: #fff; }

    .desktop-icons {
        grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
        padding: 16px 12px 4px;
    }

    /* Windows become plain stacked cards with a folder-style header. */
    .desktop-window {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        width: auto !important;
        max-width: none;
        max-height: none;
        margin: 0 12px 16px;
        border: 1px solid #e6e8eb;
        border-radius: 12px;
        box-shadow: none;
    }

    .window-titlebar {
        height: auto;
        padding: 12px 14px;
        cursor: default;
        justify-content: flex-start;
        background: #fff;
        border-bottom: 1px solid #eef0f3;
    }

    .window-lights,
    .window-spacer { display: none !important; }

    .window-title { text-align: left; font-size: 0.95rem; }

    /* Folder contents as an iOS-style list. */
    .group-grid {
        display: flex;
        flex-direction: column;
        gap: 0;
        padding: 4px 0;
    }

    .group-grid .desktop-icon {
        width: 100%;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 12px;
        padding: 12px 14px;
        border-radius: 0;
        border: none;
        border-bottom: 1px solid #f2f4f6;
    }

    .group-grid .desktop-icon:last-child { border-bottom: none; }

    .group-grid .desktop-icon svg { width: 26px; height: 22px; flex-shrink: 0; }

    .group-grid .desktop-icon .icon-label {
        text-align: left;
        -webkit-line-clamp: 1;
        line-clamp: 1;
        font-size: 0.85rem;
    }
}

/* Mobile: full-bleed folder view, no dock, bigger tap targets. */
@media (max-width: 768px) {
    .desktop-page { padding: 0; }

    .desktop {
        margin: 0;
        max-width: 100%;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }

    .desktop-dock { display: none; }

    .desktop-icons {
        grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
        gap: 10px 6px;
        padding: 12px 12px 4px;
    }

    .desktop-window {
        margin: 0 0 12px;
        border-left: none;
        border-right: none;
        border-radius: 0;
    }

    .group-grid .desktop-icon {
        padding: 16px 16px;
    }
}

/* Mobile projects (final override): full width, 2×2 folder grid, roomy rows. */
@media (max-width: 768px) {
    .desktop {
        width: 100%;
        max-width: 100%;
        margin: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }

    .desktop-body { display: block; }

    .desktop-dock { display: none; }

    .desktop-icons {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px 10px;
        padding: 18px 14px 10px;
    }

    .desktop-icon { padding: 16px 10px; }

    .desktop-icon svg {
        width: 62px;
        height: 52px;
    }

    .desktop-icon .icon-label { font-size: 0.9rem; }

    .desktop-window {
        margin: 0 0 14px;
        border-left: none;
        border-right: none;
        border-radius: 0;
    }

    .group-grid { padding: 4px 0; }

    .group-grid .desktop-icon {
        width: 100%;
        padding: 18px;
        gap: 14px;
        justify-content: flex-start;
    }

    .group-grid .desktop-icon svg {
        width: 32px;
        height: 27px;
    }

    .group-grid .desktop-icon .icon-label { font-size: 1rem; }
}

/* Mobile drill-down: tap a folder → its window replaces the folder grid;
   "‹ Back" steps up a level. Windows float as inset cards (not edge-to-edge). */
.window-back { display: none; }

@media (max-width: 768px) {
    .desktop-canvas.has-open-window .desktop-icons,
    .desktop-canvas.has-open-window .desktop-empty { display: none; }

    .desktop-canvas.has-open-window { padding-top: 12px; }

    .desktop-window {
        margin: 0 14px 18px;
        border: 1px solid #e6e8eb;
        border-radius: 14px;
        box-shadow: 0 6px 20px rgba(17, 24, 39, 0.07);
        overflow: hidden;
        animation: mobile-window-in 0.18s ease-out;
    }

    .window-titlebar {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 12px;
        min-height: 48px;
        box-sizing: border-box;
    }

    .window-back {
        display: inline-flex;
        align-items: center;
        gap: 2px;
        flex-shrink: 0;
        max-width: 55%;
        padding: 6px 10px 6px 6px;
        border: none;
        border-radius: 8px;
        background: transparent;
        color: hsl(230, 100%, 50%);
        font: inherit;
        font-size: 0.85rem;
        cursor: pointer;
    }

    .window-back span:first-child { font-size: 1.4rem; line-height: 1; margin-top: -2px; }

    .window-back-label {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .window-back:active { background: hsl(230, 100%, 96%); }

    .window-back:focus-visible { outline: 2px solid hsl(230, 100%, 50%); outline-offset: 1px; }

    .window-title {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: right;
        color: #6b7280;
        font-size: 0.8rem;
    }

    .window-body .model-card { box-shadow: none; }

    .desktop-window,
    .desktop-window.is-focused { box-shadow: 0 6px 20px rgba(17, 24, 39, 0.07); }

    /* Project rows show their full name (up to two lines). */
    .group-grid .desktop-icon .icon-label {
        flex: 1;
        max-width: none;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        font-size: 0.95rem;
    }

    .group-grid .desktop-icon::after {
        content: "\203A";
        color: #9ca3af;
        font-size: 1.3rem;
        line-height: 1;
    }
}

@keyframes mobile-window-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
    .desktop-window { animation: none; }
}
