/* ========================================================================
   Edmond Yang — macOS desktop portfolio
   ====================================================================== */

/* ---------- RESET ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }
button { font: inherit; color: inherit; background: transparent; border: 0; cursor: pointer; padding: 0; }
a { color: inherit; text-decoration: none; }
input, textarea { font: inherit; color: inherit; }

/* ---------- TOKENS ---------- */
:root {
    --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", system-ui, sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;

    --menubar-h: 0px;
    --dock-h: 72px;
    --dock-pad-bottom: 8px;
    --window-radius: 11px;
    --window-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.25);

    --text: #f5f5f7;
    --text-muted: #9a9aa0;
    --window-bg: rgba(38, 38, 42, 0.88);
    --sidebar-bg: rgba(28, 28, 32, 0.82);
    --titlebar-bg: rgba(52, 52, 56, 0.78);
    --border: rgba(255, 255, 255, 0.12);
    --hairline: rgba(255, 255, 255, 0.08);
    --surface-1: rgba(255, 255, 255, 0.04);
    --surface-2: rgba(255, 255, 255, 0.08);

    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.22);

    --traffic-red: #ff5f57;
    --traffic-yellow: #febc2e;
    --traffic-green: #28c840;
}

body {
    font-family: var(--font-system);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    background: #000;
}

/* ========================================================================
   DESKTOP
   ====================================================================== */
.desktop {
    position: fixed;
    inset: 0;
    background: #1c1c1e;
    overflow: hidden;
}

/* Particle canvas — sits behind icons/windows */
#canvas1 {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* Desktop icons (left rail) — each glyph is its own frosted-glass tile */
.desktop-icons {
    position: absolute;
    top: calc(var(--menubar-h) + 22px);
    left: 22px;
    display: flex; flex-direction: column;
    gap: 18px;
    z-index: 10;
}
.desktop-icon {
    width: 84px;
    display: flex; flex-direction: column; align-items: center;
    gap: 8px;
    padding: 0;
    text-align: center;
    color: #fff;
    cursor: default;
    background: transparent !important;  /* tile is the glyph itself */
    border: 0;
    outline: 0 !important;
}
.icon-glyph {
    width: 64px; height: 64px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border: 0.5px solid rgba(255, 255, 255, 0.22);
    box-shadow:
        0 8px 20px rgba(0, 0, 0, 0.4),
        inset 0 0 0 0.5px rgba(255, 255, 255, 0.10),
        inset 0 1px 0 rgba(255, 255, 255, 0.10);
    color: #fff;
    transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}
.icon-glyph ion-icon {
    font-size: 32px;
    --ionicon-stroke-width: 32px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}
.desktop-icon:hover .icon-glyph {
    background: rgba(255, 255, 255, 0.20);
    transform: translateY(-1px);
    box-shadow:
        0 12px 28px rgba(0, 0, 0, 0.45),
        inset 0 0 0 0.5px rgba(255, 255, 255, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.desktop-icon:focus-visible .icon-glyph,
.desktop-icon.selected .icon-glyph {
    background: rgba(120, 170, 255, 0.32);
    border-color: rgba(160, 200, 255, 0.7);
    box-shadow:
        0 0 0 2px rgba(120, 170, 255, 0.35),
        0 8px 20px rgba(0, 0, 0, 0.4),
        inset 0 0 0 0.5px rgba(255, 255, 255, 0.16);
}
.icon-label {
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
    overflow-wrap: break-word;
    padding: 1px 4px;
    border-radius: 3px;
    max-width: 100%;
}
.desktop-icon.selected .icon-label {
    background: var(--accent);
    text-shadow: none;
}

/* ========================================================================
   WINDOW LAYER
   ====================================================================== */
.window-layer { position: absolute; inset: 0; pointer-events: none; }
.window-layer > .window { pointer-events: auto; }

.window {
    position: absolute;
    background: var(--window-bg);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 0.5px solid var(--border);
    border-radius: var(--window-radius);
    box-shadow: var(--window-shadow);
    display: flex; flex-direction: column;
    min-width: 320px; min-height: 200px;
    overflow: hidden;
    transform-origin: center bottom;
    animation: window-open 0.22s cubic-bezier(0.25, 1.2, 0.4, 1);
}
.window.minimizing {
    animation: window-minimize 0.32s cubic-bezier(0.4, 0, 0.7, 0.2) forwards;
}
.window.closing {
    animation: window-close 0.15s ease-in forwards;
}
.window.inactive { box-shadow: 0 14px 36px rgba(0,0,0,0.5), 0 1px 3px rgba(0,0,0,0.35); }
.window.inactive .titlebar { background: rgba(42, 42, 46, 0.7); }
.window.inactive .titlebar .traffic span { background: #5a5a5e; border-color: rgba(255,255,255,0.06); }
.window.inactive .title-text { color: var(--text-muted); }

@keyframes window-open {
    from { opacity: 0; transform: scale(0.94) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes window-close {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.92); }
}
@keyframes window-minimize {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.1) translateY(40vh); }
}

/* Titlebar */
.titlebar {
    height: 38px;
    background: var(--titlebar-bg);
    border-bottom: 0.5px solid var(--hairline);
    display: flex; align-items: center;
    padding: 0 14px;
    gap: 14px;
    cursor: grab;
    user-select: none;
}
.titlebar:active { cursor: grabbing; }

/* Resize handles — absolute children naturally stack above the in-flow titlebar/body.
   Sizes/insets are tuned so the handles don't overlap the traffic-light buttons. */
.resize-handle { position: absolute; }
.window[data-maxed="1"] .resize-handle { display: none; }
.resize-n  { top: 0;    left: 10px;  right: 10px; height: 5px; cursor: ns-resize; }
.resize-s  { bottom: 0; left: 10px;  right: 10px; height: 5px; cursor: ns-resize; }
.resize-e  { top: 10px; bottom: 10px; right: 0;  width: 5px; cursor: ew-resize; }
.resize-w  { top: 10px; bottom: 10px; left: 0;   width: 5px; cursor: ew-resize; }
.resize-nw { top: 0;    left: 0;   width: 10px; height: 10px; cursor: nwse-resize; }
.resize-ne { top: 0;    right: 0;  width: 10px; height: 10px; cursor: nesw-resize; }
.resize-sw { bottom: 0; left: 0;   width: 10px; height: 10px; cursor: nesw-resize; }
.resize-se { bottom: 0; right: 0;  width: 14px; height: 14px; cursor: nwse-resize; }
.traffic { display: flex; gap: 8px; flex-shrink: 0; }
.traffic span {
    width: 12px; height: 12px;
    border-radius: 50%;
    display: inline-block;
    position: relative;
    cursor: pointer;
    transition: filter 0.1s;
    border: 0.5px solid rgba(0, 0, 0, 0.12);
}
.traffic .close   { background: var(--traffic-red); }
.traffic .min     { background: var(--traffic-yellow); }
.traffic .max     { background: var(--traffic-green); }

.title-text {
    flex: 1; text-align: center;
    font-size: 13px; font-weight: 600;
    color: var(--text);
    pointer-events: none;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.title-spacer { width: 52px; }  /* mirrors traffic width to center title */

/* Window body */
.window-body { flex: 1; min-height: 0; display: flex; }
.content { flex: 1; padding: 24px 28px; overflow: auto; min-height: 0; }
.content-flush { padding: 0; display: flex; flex-direction: column; }

/* ========================================================================
   WINDOW CONTENT: NOTES (About Me)
   ====================================================================== */
/* Notes (About) — matches Apple Notes dark-mode aesthetic */
.notes-paper {
    background: #1c1c1e;
    color: #e7e7e9;
    font-family: var(--font-system);
    font-size: 15px;
    line-height: 1.55;
    padding: 26px 32px 30px;
    letter-spacing: -0.01em;
}
.notes-paper .notes-header { margin-bottom: 18px; }
.notes-paper h2 {
    margin: 0 0 2px;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.015em;
    color: #fafafc;
}
.notes-paper p { margin: 0 0 12px; }
.notes-paper p:last-child { margin-bottom: 0; }
.notes-date {
    font-size: 12px !important;
    color: #8e8e93;
    letter-spacing: 0.01em;
}
.notes-signoff {
    margin-top: 6px;
    color: #aeaeb2;
}
.notes-paper .notes-section {
    margin-top: 18px;
    margin-bottom: 6px;
    color: #fafafc;
    font-weight: 600;
}
.notes-paper .notes-list {
    margin: 0 0 4px;
    padding-left: 22px;
    list-style: disc;
}
.notes-paper .notes-list li {
    margin: 0 0 8px;
    color: #e7e7e9;
}
.notes-paper .notes-list li::marker {
    color: #8e8e93;
}
.notes-paper strong {
    color: #fafafc;
    font-weight: 600;
}
.notes-cta {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    color: #0a84ff;
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.notes-cta:hover { color: #409cff; }

/* ========================================================================
   WINDOW CONTENT: RESUME (Preview)
   ====================================================================== */
.resume-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 14px;
    background: rgba(28, 28, 30, 0.85);
    border-bottom: 0.5px solid var(--hairline);
    font-size: 12px;
    color: var(--text-muted);
}
.resume-toolbar-info { display: flex; gap: 8px; align-items: baseline; }
.resume-toolbar-info strong { color: var(--text); font-weight: 600; }
.resume-download {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 0.5px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    font-size: 12px;
    transition: background 0.1s;
}
.resume-download:hover { background: rgba(255, 255, 255, 0.14); }
.resume-frame {
    flex: 1;
    width: 100%; height: 100%;
    border: 0;
    background: #525659;
}

/* ========================================================================
   WINDOW CONTENT: FINDER LIST (Experience)
   ====================================================================== */
.finder-list { padding: 0; display: flex; flex-direction: column; }
.finder-list-header {
    display: grid;
    grid-template-columns: 1fr 110px 110px;
    padding: 6px 14px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 0.5px solid var(--hairline);
    background: rgba(28, 28, 30, 0.9);
    position: sticky; top: 0;
}
.finder-rows { list-style: none; margin: 0; padding: 0; flex: 1; overflow: auto; }
.finder-row {
    display: grid;
    grid-template-columns: 1fr 110px 110px;
    padding: 6px 14px;
    font-size: 13px;
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.05);
    cursor: default;
}
.finder-row:nth-child(odd) { background: rgba(255, 255, 255, 0.025); }
.finder-row:hover { background: var(--accent-soft); }
.row-name { display: flex; align-items: center; gap: 8px; }
.row-icon { font-size: 16px; }
.row-meta { color: var(--text-muted); font-size: 12px; align-self: center; }
.finder-footer {
    padding: 6px 14px;
    font-size: 11px;
    color: var(--text-muted);
    border-top: 0.5px solid var(--hairline);
    background: rgba(28, 28, 30, 0.9);
    margin: 0;
}
.finder-footer code {
    font-family: var(--font-mono);
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 4px;
    border-radius: 3px;
}

/* ========================================================================
   WINDOW CONTENT: FINDER GRID (Portfolio)
   ====================================================================== */
.finder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 18px;
    align-content: start;
}
.finder-tile {
    display: flex; flex-direction: column; align-items: center;
    gap: 8px;
    padding: 10px 6px;
    border-radius: 8px;
    cursor: default;
    transition: background 0.1s;
}
.finder-tile:hover, .finder-tile:focus-visible {
    background: var(--accent-soft);
    outline: none;
}
.tile-thumb {
    width: 100%; aspect-ratio: 4/3;
    background-color: #2a4a5c;
    background-size: cover;
    background-position: center;
    border-radius: 6px;
    border: 0.5px solid rgba(255, 255, 255, 0.10);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.tile-label {
    font-size: 13px;
    font-weight: 500;
    text-align: center;
}

/* ========================================================================
   WINDOW CONTENT: PROJECT DETAIL
   ====================================================================== */
.project-detail { padding: 0; }
.proj-hero {
    width: 100%; height: 200px;
    background-color: #314E59;
    background-size: cover;
    background-position: center;
    border-bottom: 0.5px solid var(--hairline);
}
.proj-body { padding: 20px 26px 26px; }
.proj-body h2 { margin: 0 0 4px; font-size: 22px; font-weight: 700; }
.proj-meta { margin: 0 0 14px; color: var(--text-muted); font-size: 13px; }
.proj-body p { line-height: 1.55; margin: 0 0 16px; font-size: 14px; }
.proj-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.proj-tags span {
    background: rgba(255, 255, 255, 0.08);
    padding: 3px 9px;
    border-radius: 10px;
    font-size: 11.5px;
    color: var(--text);
    font-weight: 500;
}
.proj-links a {
    color: var(--accent);
    font-weight: 500;
    font-size: 13.5px;
    border-bottom: 1px solid rgba(10, 132, 255, 0.3);
    padding-bottom: 1px;
}

/* ========================================================================
   WINDOW CONTENT: MAIL COMPOSE (Contact)
   ====================================================================== */
.mail-compose { padding: 0; display: flex; flex-direction: column; }
.mail-fields {
    padding: 8px 14px;
    border-bottom: 0.5px solid var(--hairline);
    background: rgba(28, 28, 30, 0.55);
}
.mail-fields label {
    display: flex; align-items: center;
    border-bottom: 0.5px solid var(--hairline);
    padding: 4px 0;
    font-size: 13px;
}
.mail-fields label:last-child { border-bottom: 0; }
.mail-label {
    width: 64px;
    color: var(--text-muted);
    font-size: 12px;
    flex-shrink: 0;
}
.mail-fields input {
    flex: 1;
    border: 0; background: transparent;
    padding: 4px 6px;
    font-size: 13px;
    outline: none;
}
.mail-fields input[readonly] { color: var(--text-muted); }
.mail-body-wrap {
    flex: 1;
    display: flex; flex-direction: column;
    min-height: 0;
}
.mail-body-wrap textarea {
    flex: 1;
    border: 0; outline: none; resize: none;
    padding: 18px 20px;
    font-size: 14px; line-height: 1.55;
    font-family: var(--font-system);
    background: transparent;
}
.mail-actions {
    padding: 8px 14px;
    background: rgba(28, 28, 30, 0.85);
    border-top: 0.5px solid var(--hairline);
    display: flex; justify-content: flex-end;
}
.mail-send {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 14px;
    background: var(--accent);
    color: #fff;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(10, 132, 255, 0.4);
    transition: filter 0.1s, transform 0.05s;
}
.mail-send:hover { filter: brightness(1.05); }
.mail-send:active { transform: translateY(1px); }
.mail-send.success { background: #28c840; pointer-events: none; }

/* ========================================================================
   WINDOW CONTENT: GHOSTTY TERMINAL
   ====================================================================== */
.window:has(.terminal-body) { background: rgba(15, 15, 18, 0.96); border-color: rgba(255,255,255,0.06); }
.window:has(.terminal-body) .titlebar {
    background: rgba(22, 22, 26, 0.95);
    border-bottom-color: rgba(255,255,255,0.04);
    height: 32px;
}
.window:has(.terminal-body) .title-text {
    color: #b8b8bd;
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.2px;
}
.terminal-body {
    padding: 16px 20px 20px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.65;
    color: #ebebed;
    background: transparent;
}
.terminal-line { color: #ebebed; }
.terminal-line .prompt { color: #82d4a0; }
.terminal-line .path { color: #7dd3fc; }
.terminal-out { color: #c8c8cc; margin-bottom: 2px; padding-left: 4px; }
.cursor {
    display: inline-block;
    width: 7px; height: 15px;
    background: #ebebed;
    vertical-align: text-bottom;
    margin-left: 3px;
    animation: cursor-blink 1.1s steps(1) infinite;
}
@keyframes cursor-blink { 50% { opacity: 0; } }

/* ========================================================================
   WINDOW CONTENT: TRASH
   ====================================================================== */
.trash-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center;
    color: var(--text-muted);
    gap: 12px;
}

/* ========================================================================
   DOCK
   ====================================================================== */
.dock {
    position: fixed;
    bottom: var(--dock-pad-bottom);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(40px) saturate(200%);
    -webkit-backdrop-filter: blur(40px) saturate(200%);
    border: 0.5px solid rgba(255, 255, 255, 0.3);
    border-radius: 22px;
    padding: 6px 12px;
    display: flex; align-items: end; gap: 4px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), inset 0 0 0 0.5px rgba(255, 255, 255, 0.15);
    z-index: 9000;
    height: var(--dock-h);
}
.dock-app {
    width: 56px; height: 56px;
    border-radius: 15px;
    display: inline-flex; align-items: center; justify-content: center;
    transform-origin: bottom center;
    position: relative;
    overflow: visible;
    flex-shrink: 0;
}
.dock-app svg { width: 100%; height: 100%; border-radius: 15px; filter: drop-shadow(0 4px 10px rgba(0,0,0,0.32)); }
.dock-app img {
    width: 100%; height: 100%;
    display: block;
    object-fit: contain;
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.32));
    pointer-events: none;
    -webkit-user-drag: none;
}
.dock-app::before {
    content: "";
    position: absolute;
    bottom: -4px; left: 50%;
    width: 3px; height: 3px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0);
    transform: translateX(-50%);
    transition: background 0.15s;
}
.dock-app.active::before { background: rgba(255, 255, 255, 0.85); }

/* Bounce on launch */
@keyframes dock-bounce {
    0%   { transform: translateY(0); }
    30%  { transform: translateY(-22px); }
    60%  { transform: translateY(-4px); }
    80%  { transform: translateY(-10px); }
    100% { transform: translateY(0); }
}
.dock-app.launching { animation: dock-bounce 0.65s ease-in-out; }

.dock-divider {
    width: 1px;
    height: 38px;
    background: rgba(255, 255, 255, 0.3);
    margin: 0 4px;
    align-self: center;
    flex-shrink: 0;
}

/* Tooltip */
.dock-app[aria-label]:hover::after {
    content: attr(aria-label);
    position: absolute;
    bottom: calc(100% + 14px);
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 10px;
    background: rgba(40, 40, 42, 0.92);
    color: #fff;
    border-radius: 5px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* ========================================================================
   RESPONSIVE — phone / small tablet
   On narrow or touch-first devices the windowed desktop adapts:
   the dock shrinks, the left-rail icons hide, and windows take the full
   viewport so there's no overlap or off-screen content.
   ====================================================================== */
@media (max-width: 768px), (pointer: coarse) and (max-width: 900px) {
    :root {
        --dock-h: 60px;
        --dock-pad-bottom: 6px;
    }

    /* Compact dock — fits 7 icons across an iPhone-width viewport */
    .dock {
        height: 60px;
        gap: 2px;
        padding: 5px 8px;
        border-radius: 17px;
        max-width: calc(100vw - 12px);
        bottom: max(env(safe-area-inset-bottom), var(--dock-pad-bottom));
    }
    .dock-app {
        width: 44px; height: 44px;
        border-radius: 11px;
    }
    .dock-divider {
        height: 30px;
        margin: 0 2px;
    }
    /* Hide dock tooltips on touch — they'd stick around after taps */
    .dock-app[aria-label]:hover::after { display: none; }

    /* Shrink the left-rail desktop icons so they fit on a phone */
    .desktop-icons {
        top: max(env(safe-area-inset-top), 14px);
        left: 14px;
        gap: 14px;
    }
    .desktop-icon { width: 72px; }
    .icon-glyph { width: 56px; height: 56px; border-radius: 15px; }
    .icon-glyph ion-icon { font-size: 28px; }
    .icon-label { font-size: 11.5px; }

    /* Windows fill the viewport (one at a time on mobile). Inline width/
       height/left/top set by JS are overridden via !important. */
    .window {
        left: 8px !important;
        top: max(env(safe-area-inset-top), 12px) !important;
        width: calc(100vw - 16px) !important;
        height: calc(100dvh - var(--dock-h) - 32px) !important;
        min-width: 0; min-height: 0;
        border-radius: 14px;
    }
    .resize-handle { display: none; }
    .titlebar { cursor: default; }

    /* Tighten window content padding on phones */
    .notes-paper { padding: 22px 22px 26px; font-size: 15px; }
    .notes-paper h2 { font-size: 24px; }
    .proj-body { padding: 18px 20px 22px; }
    .mail-fields { padding: 8px 12px; }
    .resume-toolbar { padding: 8px 12px; }
    .finder-list-header, .finder-row { padding: 6px 12px; }
}

/* Very narrow phones — squeeze the dock a touch more so all icons fit */
@media (max-width: 360px) {
    .dock { gap: 1px; padding: 5px 6px; }
    .dock-app { width: 40px; height: 40px; }
    .dock-divider { margin: 0 1px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .window, .dock-app { animation: none !important; transition: none !important; }
    .cursor { animation: none; }
}
