/* Camera variables belong to the grid, not the card tree. Inheriting these
   per-frame values through every card forces a full style recalculation.
   https://web.dev/blog/at-property-performance */
@property --grid-x { syntax: '<length>'; inherits: false; initial-value: 0px; }
@property --grid-y { syntax: '<length>'; inherits: false; initial-value: 0px; }
@property --grid-size { syntax: '<length>'; inherits: false; initial-value: 22px; }

#canvas-app {
    --grid-x: 0px;
    --grid-y: 0px;
    --grid-size: 22px;
    width: 100vw;
    height: 100vh;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(ellipse 60% 50% at 70% 10%, rgba(255, 255, 255, 0.55), transparent 70%),
        var(--bg);
}

/* While the entrance covers it, the map is neither laid out nor painted, and
   its lazy images wait. The launch reveals it before the entrance fades. */
#terminal-entry:not(.hidden):not(.is-launching) + #canvas-app {
    content-visibility: hidden;
}

/* The paper grid is the floor under the map (the YC brand's ruled-paper
   texture). It moves at half the camera's speed (entry in pan-zoom.js), so
   the regions read as standing above it. */
#canvas-app::before {
    --grid-x: inherit;
    --grid-y: inherit;
    --grid-size: inherit;
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: var(--grid-size) var(--grid-size);
    background-position: var(--grid-x) var(--grid-y);
    pointer-events: none;
    z-index: 0;
}

#canvas-viewport {
    position: absolute;
    inset: 0;
    transform-origin: 0 0;
    /* One persistent camera layer reuses the painted map while scaling.
       Promoting every card instead increases layer churn and texture cost. */
    will-change: transform;
    z-index: 1;
    /* The camera owns every gesture on the map, cards included: without
       this a pinch that starts on a card zooms the page instead. */
    touch-action: none;
}

.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    background: var(--chrome-bg);
    backdrop-filter: blur(20px) saturate(160%);
    border-bottom: 1px solid var(--hairline);
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 1000;
    gap: 14px;
}

.sidebar-toggle {
    width: 36px;
    height: 36px;
    border-radius: var(--r-sm);
    border: 1px solid var(--hairline);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: background 0.16s ease, color 0.16s ease;
}

.sidebar-toggle:hover {
    background: var(--surface-solid);
    color: var(--text);
}

.logo {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

/* The same physical key as the entrance CTA and brand mark. */
.logo-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: var(--r-sm);
    background: var(--brand-fill);
    color: var(--on-brand);
    font-family: ui-monospace, SFMono-Regular, 'JetBrains Mono', Menlo, monospace;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 3px 0 var(--brand-edge), 0 8px 16px rgba(122, 35, 49, 0.2);
}

.logo-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.logo-title {
    font-size: 14.5px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
    line-height: 1.15;
}

.logo-subtitle {
    margin-top: 3px;
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.2;
    white-space: nowrap;
}

/* The view switch belongs to the whole app, so it sits in the middle of the bar. */
.top-view-switch {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.top-actions {
    display: flex;
    /* Utilities cluster tight; the primary action and the avatar get real air. */
    gap: 10px;
    margin-left: auto;
    position: relative;
    align-items: center;
}

.top-action-utils {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-right: 4px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 15px;
    border-radius: var(--r-md);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
    font-family: inherit;
    font-weight: 600;
}

.btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.btn:focus-visible,
.top-panel-close:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 3px;
}

/* Contact is the primary action in the bar: the brand's physical wine key. */
.btn-primary {
    background: var(--brand-fill);
    color: var(--on-brand);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 3px 0 var(--brand-edge), 0 8px 18px rgba(122, 35, 49, 0.2);
}

.top-resume {
    text-decoration: none;
    border: 1px solid var(--hairline);
}

.btn-primary:hover {
    color: var(--on-brand);
    background: var(--brand-hover);
}

.btn-primary:active {
    transform: translateY(2px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 1px 0 var(--brand-edge);
}

/* YC himself opens the personal system: the 3D figure's head, cropped. The
   initials stay in the DOM for the accessible name. */
.btn-avatar {
    padding: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 0;
    color: transparent;
    background: url('../images/yc/yc-3d-wave.webp') -12px -3px / 58px auto no-repeat, var(--surface-sunken);
    box-shadow: 0 0 0 1px var(--hairline), 0 4px 10px rgba(26, 26, 46, 0.1);
}

.btn-avatar:hover {
    background: url('../images/yc/yc-3d-wave.webp') -12px -3px / 58px auto no-repeat, var(--accent-soft);
    box-shadow: 0 0 0 2px var(--accent), 0 4px 10px rgba(26, 26, 46, 0.1);
}

.btn-icon {
    padding: 0;
    width: 32px;
    height: 32px;
    font-size: 16px;
}

.audio-pulse,
.settings-glyph {
    width: 20px;
    height: 20px;
}

.audio-pulse svg,
.settings-glyph,
.ui-icon {
    display: block;
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.audio-pulse svg {
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.audio-pulse[data-state='off'] svg {
    opacity: 0.85;
    transform: scaleY(0.55);
}

.audio-pulse[data-state='on'] svg {
    opacity: 1;
    transform: scaleY(1);
}

.icon-fill {
    fill: currentColor;
    stroke: none;
}

.top-actions .btn[aria-expanded='true'] {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.top-actions .btn-primary[aria-expanded='true'] {
    background: linear-gradient(135deg, #ef7b9b, #d95984);
    color: white;
}

.top-action-popovers {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 1250;
    pointer-events: none;
}

/* One card, then flat content inside it. No boxes nested in boxes. */
.top-action-panel {
    width: min(330px, calc(100vw - 24px));
    max-height: calc(100dvh - 104px);
    padding: 16px 16px 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--hairline);
    border-radius: var(--r-xl);
    background: var(--surface-solid);
    box-shadow: var(--elev-3);
    color: var(--text);
    pointer-events: auto;
    scrollbar-gutter: stable;
    animation: top-panel-in 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

.top-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.top-action-panel h2 {
    margin: 3px 0 0;
    color: var(--text);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.top-action-panel p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 12.5px;
    line-height: 1.55;
}

.top-panel-kicker {
    color: var(--accent-strong);
    font-size: 9.5px;
    font-weight: 800;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.top-panel-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    line-height: 1;
    cursor: pointer;
    transition: background 0.16s ease, color 0.16s ease;
}

.top-panel-close:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.top-panel-close .ui-icon {
    width: 14px;
    height: 14px;
}

/* The share link, shown the way the site's own terminal shows things. */
.share-url {
    display: flex;
    align-items: center;
    gap: 0;
    margin-top: 14px;
    padding: 5px 5px 5px 11px;
    border-radius: var(--r-md);
    background: var(--surface-sunken);
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
    font-size: 11.5px;
    line-height: 1;
}

.share-url-host {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
    font-weight: 600;
}

.share-url-copy {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex: 0 0 auto;
    height: 26px;
    margin-left: 8px;
    padding: 0 10px;
    border: none;
    border-radius: var(--r-xs);
    background: var(--surface-thumb);
    box-shadow: var(--elev-1);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: color 0.16s ease, transform 0.16s ease;
}

.share-url-copy:hover {
    color: var(--accent-strong);
}

.share-url-copy:active {
    transform: scale(0.96);
}

.share-url-copy .ui-icon {
    width: 12px;
    height: 12px;
}

/* Flat action rows separated by hairlines — a list, not a grid of chips. */
.panel-list {
    margin-top: 12px;
    border-top: 1px solid var(--hairline-soft);
}

.panel-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 42px;
    padding: 8px 8px 8px 0;
    border: none;
    border-bottom: 1px solid var(--hairline-soft);
    border-radius: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.14s ease, padding-left 0.14s ease;
}

.panel-row:last-child {
    border-bottom: none;
}

.panel-row:hover {
    background: var(--surface-hover);
    padding-left: 8px;
}

.panel-row:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: -2px;
    border-radius: var(--r-sm);
}

.panel-row-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    border-radius: var(--r-xs);
    background: var(--surface-sunken);
    color: var(--text-secondary);
}

.panel-row-icon svg {
    display: block;
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.panel-row-icon--accent {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.panel-row-icon--brand {
    background: var(--brand-fill);
    color: var(--on-brand);
}

.panel-row-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1;
    min-width: 0;
}

.panel-row-label {
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.panel-row-hint {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
}

.panel-row-chevron {
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.14s ease;
}

.panel-row:hover .panel-row-chevron,
.panel-row:focus-visible .panel-row-chevron {
    opacity: 1;
}

.panel-section-label {
    margin-top: 16px;
    color: var(--text-muted);
    font-size: 9.5px;
    font-weight: 800;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.top-panel-status {
    min-height: 15px;
    margin-top: 10px;
    color: var(--accent-strong);
    font-size: 11px;
    font-weight: 600;
}

.top-panel-status:empty {
    display: none;
}

/* Settings: label on the left, control on the right — no wrapper boxes. */
.settings-panel {
    width: min(348px, calc(100vw - 24px));
}

.settings-rows {
    margin-top: 14px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0;
}

.settings-row + .settings-row {
    border-top: 1px solid var(--hairline-soft);
}

.settings-row-label {
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 600;
}

.settings-row .seg {
    background: var(--surface-sunken);
    border-color: transparent;
    box-shadow: none;
}

.settings-row .seg > button {
    padding: 0 9px;
    font-size: 11.5px;
}

@keyframes top-panel-in {
    from {
        opacity: 0;
        transform: translateY(-5px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    width: var(--sidebar-w);
    height: calc(100vh - var(--topbar-h));
    background: var(--chrome-bg);
    backdrop-filter: blur(18px) saturate(160%);
    border-right: 1px solid var(--hairline);
    z-index: 1000;
    padding: 20px 14px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-footer {
    margin-top: auto;
}

.sidebar-scrim {
    display: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.sidebar-title {
    margin: 0 0 10px 10px;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.14em;
}

.sidebar-header .sidebar-title {
    margin-bottom: 0;
}

.sidebar-header + .layer-list {
    margin-top: 10px;
}

.layer-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.sidebar-close {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.16s ease, color 0.16s ease;
    display: none;
    align-items: center;
    justify-content: center;
}

.sidebar-close .ui-icon {
    width: 15px;
    height: 15px;
}

.sidebar-close:hover {
    background: var(--surface-hover);
    color: var(--text);
}

/* Each layer: index, glyph, name, count. The region the camera is over gets
   a quiet fill; a spotlit layer takes the wine fill and rule. "Whole map" is
   the neutral state, so it is never drawn as a spotlight. */
.layer-item {
    display: grid;
    grid-template-columns: 20px 26px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 38px;
    padding: 6px 10px 6px 8px;
    border: none;
    border-radius: var(--r-md);
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.16s ease, color 0.16s ease;
    position: relative;
}

.layer-item:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.layer-item.is-in-view {
    background: var(--surface-sunken);
    color: var(--text);
    font-weight: 650;
}

/* Each layer wears its region's hue: the icon tile always, the fill and
   rule when it is spotlit. */
.layer-item.active:not(.layer-item-all) {
    background: var(--hue-wash, var(--accent-soft));
    color: var(--hue-ink, var(--accent-strong));
    font-weight: 650;
}

.layer-item.active:not(.layer-item-all)::before {
    content: '';
    position: absolute;
    left: 0;
    top: 9px;
    bottom: 9px;
    width: 3px;
    border-radius: 2px;
    background: var(--hue, var(--accent));
}

.layer-item-home {
    margin-bottom: 6px;
}

.layer-item-all {
    margin-top: 6px;
}

.layer-item-home::after,
.layer-item-all::after {
    content: '';
    position: absolute;
    left: 10px;
    right: 10px;
    height: 1px;
    background: var(--hairline);
}

.layer-item-home::after {
    bottom: -4px;
}

.layer-item-all::after {
    top: -4px;
}

.layer-item:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: -2px;
}

.layer-index {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.layer-icon {
    width: 26px;
    height: 26px;
    border-radius: var(--r-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--hue-ink, currentColor);
    background: var(--hue-wash, var(--surface-sunken));
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hue, transparent) 18%, transparent);
}

.layer-item.active:not(.layer-item-all) .layer-icon {
    color: var(--on-brand);
    background: var(--hue, var(--accent));
}

.layer-icon svg {
    display: block;
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.layer-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.layer-count {
    min-width: 22px;
    padding: 2px 6px;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 10.5px;
    text-align: center;
    color: var(--hue-ink, var(--text-muted));
    background: color-mix(in srgb, var(--hue-wash, transparent) 80%, transparent);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 1180px) {
    .logo-subtitle {
        display: none;
    }
    :root {
        --sidebar-w: 244px;
    }

    .top-bar {
        padding: 0 16px;
    }

    .top-actions {
        gap: 8px;
    }

    .btn {
        padding: 10px 14px;
    }
}

@media (max-width: 900px) {
    :root {
        --sidebar-w: min(88vw, 320px);
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    .sidebar-close {
        display: inline-flex;
    }

    .sidebar-scrim {
        display: block;
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.34);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
        z-index: 999;
    }

    .sidebar-scrim.is-open {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar {
        transform: translateX(-105%);
        transition: transform 0.25s ease;
        box-shadow: 0 28px 60px rgba(0, 0, 0, 0.22);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }
}

@media (max-width: 900px) {
    .top-view-switch {
        position: fixed;
        top: calc(var(--topbar-h) + 8px);
        left: 12px;
        right: 12px;
        transform: none;
        z-index: 990;
        display: flex;
        box-shadow: var(--elev-2);
    }

    .top-view-switch > button {
        flex: 1;
    }
}

@media (max-width: 767px) {
    #yc-logic-action {
        display: none;
    }
    .top-bar {
        padding: 0 12px;
    }

    .logo-title {
        font-size: 14px;
        white-space: nowrap;
    }

    .logo-subtitle {
        font-size: 11px;
    }

    .logo-icon {
        width: 38px;
        height: 38px;
        border-radius: 12px;
    }

    .top-actions {
        gap: 6px;
    }

    .top-actions .btn {
        min-height: 36px;
        padding: 8px 12px;
        border-radius: 12px;
        font-size: 12px;
    }

    .top-actions .btn-avatar,
    .top-actions .btn-icon {
        display: inline-flex;
        width: 36px;
        height: 36px;
        padding: 0;
    }

    .top-action-popovers {
        position: fixed;
        top: calc(var(--topbar-h) + 8px);
        right: 12px;
        left: 12px;
    }

    .top-action-panel,
    .settings-panel {
        width: 100%;
        max-height: calc(100dvh - 92px);
        margin-right: 0;
    }

}

@media (max-width: 430px) {
    .logo-copy {
        display: none;
    }

    .top-action-panel {
        padding: 16px;
        border-radius: 18px;
    }

    .settings-row {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .settings-row .seg {
        justify-content: stretch;
    }

    .settings-row .seg > button {
        flex: 1;
    }
}
