:root {
    /* No viewport-fit=cover (2026-10-08): with it, iOS blurs the top ~90pt of a Home Screen web
       app over the page. Without it env(safe-area-inset-bottom) is 0 there, yet the page still runs
       under the home indicator, so the Home Screen app gets the indicator's 34pt back here. */
    --home-bar: env(safe-area-inset-bottom, 0px);
}
@media (display-mode: standalone) {
    :root {
        --home-bar: max(env(safe-area-inset-bottom, 0px), 34px);
    }
}

:root {
    --bg: #f2f1ed;
    --bg-glow: #ffffff;
    --ink: #1d2327;
    --muted: #6b7075;
    --ring: rgb(0 0 0 / 0.08);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 8px 24px rgb(29 35 39 / 0.14);
    --shadow-lift: 0 2px 4px rgb(0 0 0 / 0.1), 0 16px 36px rgb(29 35 39 / 0.2);
    /* The Cities folder: its tile, and the panel it opens into. */
    --folder: rgb(255 255 255 / 0.62);
    --folder-open: rgb(255 255 255 / 0.72);
    --scrim: rgb(242 241 237 / 0.45);
    /* The glow behind the page, in viewport units so the sticky header can paint the same one
       and line up with it exactly. */
    --glow: radial-gradient(120vw 70vh at 50vw 0, var(--bg-glow), var(--bg) 70%);
    --side-l: max(16px, env(safe-area-inset-left));
    --side-r: max(16px, env(safe-area-inset-right));
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121517;
        --bg-glow: #232a2f;
        --ink: #eef0f1;
        --muted: #8d9499;
        --ring: rgb(255 255 255 / 0.12);
        --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.45);
        --shadow-lift: 0 2px 4px rgb(0 0 0 / 0.45), 0 16px 36px rgb(0 0 0 / 0.6);
        --folder: rgb(255 255 255 / 0.13);
        --folder-open: rgb(52 60 66 / 0.72);
        --scrim: rgb(0 0 0 / 0.35);
    }
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--glow) fixed, var(--bg);
    color: var(--ink);
    font: 16px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    padding: 0 var(--side-r) max(24px, var(--home-bar)) var(--side-l);
}

/* Logo + title in the middle, the pencil on the right. The empty first column balances
   the pencil's so the title stays centred. Kept short (2026-10-08, Corey: it pushed the
   tiles off a phone screen). */
header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    margin: 0 calc(-1 * var(--side-r)) calc(clamp(20px, 4vh, 40px) - 10px) calc(-1 * var(--side-l));
    padding: calc(max(12px, env(safe-area-inset-top)) + clamp(4px, 3vh, 32px))
        max(var(--side-r), calc((100vw - 760px) / 2)) 10px max(var(--side-l), calc((100vw - 760px) / 2));
    /* Inside the Hub's Home Screen app the page runs under the status bar, and iOS blurs whatever
       sits in the top ~90pt unless an opaque sticky bar owns that strip (clucasdesigns HANDOFF,
       status bar part 3). So the header sticks, full width, painting the page's own glow. Under
       a tile being dragged (z-index 2). */
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--glow), var(--bg);
}
/* iOS paints the status-bar strip flat in body's colour (--bg), so the white glow would start
   with a hard line under the clock. Fade from --bg into the glow instead. */
@media (display-mode: standalone) {
    header {
        background: linear-gradient(var(--bg) env(safe-area-inset-top), transparent calc(env(safe-area-inset-top) + 40px)),
            var(--glow), var(--bg);
    }
}

.mark {
    width: 36px;
    height: 36px;
    border-radius: 22.5%;
    box-shadow: 0 0 0 1px var(--ring);
}

h1 {
    grid-column: 2;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* The portfolio's edit pencil (apps/portfolio/public/edit.js, #pf-pencil), smaller and in
   the header rather than on the right edge, where on a phone it would sit over a tile. */
.pencil {
    grid-column: 3;
    justify-self: end;
    width: 32px;
    height: 32px;
    padding: 0;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid rgb(255 255 255 / 0.12);
    background: #3b3b3b;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.2);
    transition: background 0.15s, opacity 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.pencil:hover {
    background: #555;
}

.pencil svg {
    width: 15px;
    height: 15px;
}

.editing .pencil {
    opacity: 0;
    pointer-events: none;
}

.grid {
    /* Smaller on short windows, so the rows fit a laptop screen without scrolling. */
    --icon: clamp(88px, min(26vw, 15vh), 132px);
    --gap: 20px;
    position: relative;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 32px var(--gap);
    /* grid.js sets --cols so the rows come out even, at most four per row
       (4 apps = 2 + 2, 5 = 3 + 2). Without it, this falls back to four per row. */
    max-width: calc(var(--cols, 4) * (var(--icon) + 16px) + (var(--cols, 4) - 1) * var(--gap));
    margin: 0 auto;
}

.app {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: calc(var(--icon) + 16px);
    text-align: center;
    color: inherit;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* The folder tile is a <button>. */
button.app {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    cursor: pointer;
}

.app .icon {
    width: var(--icon);
    height: var(--icon);
    border-radius: 22.5%;
    box-shadow: var(--shadow), 0 0 0 1px var(--ring);
    transition: transform 180ms ease, box-shadow 180ms ease;
    -webkit-user-drag: none;
}

.app:hover .icon,
.app:focus-visible .icon {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lift), 0 0 0 1px var(--ring);
}

.app:active .icon {
    transform: scale(0.94);
    transition-duration: 80ms;
}

.app:focus-visible {
    outline: none;
}

.app:focus-visible .name {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.name {
    margin-top: 12px;
    font-size: 16px;
    font-weight: 600;
}

.note {
    margin-top: 2px;
    font-size: 13px;
    color: var(--muted);
}

/* ---- The Cities folder (folder.js) ---- */

/* iOS-style: the apps inside as small icons on a frosted square, here 2 × 2. */
.folder-icon {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 9%;
    padding: 15%;
    background: var(--folder);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    backdrop-filter: blur(20px) saturate(1.4);
}

.folder-icon img {
    width: 100%;
    height: 100%;
    border-radius: 24%;
    box-shadow: 0 0 0 0.5px var(--ring);
}

.folder-view {
    /* Fills the screen, so a click anywhere outside the panel lands on the dialog itself
       and closes it. */
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 24px 16px;
    border: 0;
    /* The blur is on the dialog, not ::backdrop, so it fades out with it (folder.js). */
    background: var(--scrim);
    -webkit-backdrop-filter: blur(22px) saturate(1.3);
    backdrop-filter: blur(22px) saturate(1.3);
    color: var(--ink);
    place-content: center;
    justify-items: center;
}

.folder-view[open] {
    display: grid;
}

.folder-view::backdrop {
    background: transparent;
}

.folder-view h2 {
    margin: 0 0 20px;
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.folder-panel {
    --icon: clamp(68px, 19vw, 88px);
    display: grid;
    grid-template-columns: repeat(2, calc(var(--icon) + 24px));
    /* Two rows even with two apps, the way an iOS folder keeps its shape. */
    grid-template-rows: repeat(2, calc(var(--icon) + 40px));
    gap: 16px 20px;
    justify-items: center;
    align-items: start;
    padding: 28px 28px 20px;
    border-radius: 38px;
    background: var(--folder-open);
    -webkit-backdrop-filter: blur(30px) saturate(1.6);
    backdrop-filter: blur(30px) saturate(1.6);
    box-shadow: 0 0 0 1px var(--ring), 0 20px 60px rgb(0 0 0 / 0.18);
}

.folder-panel .app {
    width: calc(var(--icon) + 24px);
}

.folder-panel .name {
    margin-top: 8px;
    font-size: 14px;
}

/* ---- Rearranging (arrange.js) ---- */

/* iOS's jiggle, on the icon only: the tile itself is moved with transforms while dragging. */
.editing .grid .icon {
    animation: jiggle 0.28s ease-in-out infinite alternate;
}

.editing .grid .app:nth-child(2n) .icon {
    animation-delay: -0.14s;
    animation-direction: alternate-reverse;
}

.editing .grid .app:nth-child(3n) .icon {
    animation-duration: 0.32s;
}

@keyframes jiggle {
    from {
        transform: rotate(-1.6deg);
    }
    to {
        transform: rotate(1.6deg);
    }
}

.editing .grid .app {
    cursor: grab;
    touch-action: none;
}

.editing .grid .app:hover .icon {
    box-shadow: var(--shadow), 0 0 0 1px var(--ring);
}

.grid .app.dragging {
    position: relative;
    z-index: 2;
    cursor: grabbing;
}

.grid .app.dragging .icon {
    animation: none;
    transform: scale(1.08);
    box-shadow: var(--shadow-lift), 0 0 0 1px var(--ring);
}

/* The portfolio's edit bar (#pf-bar in its edit.js). */
.arrange-bar {
    position: fixed;
    left: 50%;
    bottom: calc(var(--home-bar) + 16px);
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px 8px 16px;
    border-radius: 999px;
    background: #111;
    color: #fff;
    font: 500 14px/1.2 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
    box-shadow: 0 8px 30px rgb(0 0 0 / 0.25);
    max-width: calc(100vw - 32px);
    white-space: nowrap;
}

.arrange-bar[hidden] {
    display: none;
}

.arrange-bar span {
    margin-right: 4px;
}

.arrange-bar button {
    font: inherit;
    border: 0;
    border-radius: 999px;
    padding: 8px 14px;
    cursor: pointer;
    background: #333;
    color: #fff;
}

.arrange-bar button.primary {
    background: #fff;
    color: #111;
}

/* Room for the bar under the last row. */
.editing main {
    padding-bottom: 72px;
}

/* Phones: always three across. The icon shrinks to whatever leaves room for three
   tiles (icon + 16px each) and two gaps inside the body's 16px side padding. */
@media (max-width: 600px) {
    header {
        margin-bottom: 8px; /* + its 10px bottom padding */
        padding-top: calc(max(12px, env(safe-area-inset-top)) + 2px);
    }

    .grid {
        --gap: 10px;
        --icon: min(108px, calc((100vw - 32px - 2 * var(--gap)) / 3 - 16px));
        row-gap: 20px;
    }

    .name {
        margin-top: 10px;
        font-size: 15px;
    }

    .note {
        font-size: 12px;
    }
}

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

    .editing .grid .icon {
        animation: none;
    }
}
