/* ============================================================
   Top ribbon — persistent global nav, retro terminal style.
   Shared between the homepage and the blog.
   ============================================================ */

#site-ribbon {
    /* Shared clearance for fixed-header offset (blog body, home ASCII hero, etc.) */
    --ribbon-block-size: calc(0.55rem + 0.55rem + 1.75em + 1px);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    /* Use 100%, not 100vw — vw includes the vertical scrollbar gutter and
       causes a few px of permanent horizontal overflow on many browsers. */
    max-width: 100%;
    z-index: 50;
    overflow: visible;
    background: rgba(10, 10, 10, 0.78);
    backdrop-filter: blur(6px) saturate(140%);
    -webkit-backdrop-filter: blur(6px) saturate(140%);
    border-bottom: 1px solid #2a2a2a;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 2px 0 rgba(0, 0, 0, 0.55),
        0 12px 28px -16px rgba(0, 0, 0, 0.7);
    pointer-events: auto;
    opacity: 0;
    transform: translateY(-6px);
    animation: ribbon-fade-in 1.4s cubic-bezier(0.2, 0.7, 0.2, 1) 0.5s forwards;
}

@keyframes ribbon-fade-in {
    to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    #site-ribbon {
        animation: none;
        opacity: 1;
        transform: none;
    }
}

#site-ribbon::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.12) 30%,
        rgba(255, 255, 255, 0.12) 70%,
        transparent 100%
    );
    pointer-events: none;
}

.ribbon-inner {
    width: 100%;
    max-width: min(1200px, 100%);
    margin: 0 auto;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
    padding-left: max(env(safe-area-inset-left, 0px), clamp(1rem, 4.5vw, 1.85rem));
    padding-right: max(env(safe-area-inset-right, 0px), clamp(1rem, 4.5vw, 1.85rem));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-width: 0;
    font-family: 'Press Start 2P', cursive;
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: unset;
}

.ribbon-brand {
    color: #fff;
    text-decoration: none;
    font-size: clamp(9px, 2.4vw, 11px);
    letter-spacing: 0.12em;
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    flex-shrink: 0;
}

.ribbon-brand__bracket {
    color: #6a6a6a;
    transition: color 0.2s ease;
}

.ribbon-brand__name {
    color: #f5f5f5;
    transition: color 0.2s ease, text-shadow 0.2s ease;
}

.ribbon-brand__caret {
    color: #f0a05a;
    animation: ribbon-caret 1s steps(2) infinite;
}

@keyframes ribbon-caret {
    50% { opacity: 0; }
}

.ribbon-brand:hover .ribbon-brand__name {
    color: #fff;
    text-shadow: 0 0 8px rgba(240, 160, 90, 0.6);
}

.ribbon-brand:hover .ribbon-brand__bracket {
    color: #f0a05a;
}

.ribbon-nav {
    display: flex;
    align-items: center;
    gap: clamp(0.4rem, 1.6vw, 1rem);
    flex-wrap: nowrap;
    /* Let the nav shrink below the intrinsic width of all links so
       overflow-x: auto can engage instead of widening the whole page. */
    flex: 1 1 0%;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.ribbon-nav::-webkit-scrollbar { display: none; }

/* Wide screens: pin the link cluster to the right without disabling shrink/scroll. */
@media (min-width: 961px) {
    .ribbon-nav {
        margin-left: auto;
        justify-content: flex-end;
    }
}

.ribbon-link {
    color: #c4c4c4;
    text-decoration: none;
    font-size: clamp(8px, 2.1vw, 10px);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 0.35rem 0.5rem;
    white-space: nowrap;
    position: relative;
    transition: color 0.15s ease, transform 0.15s ease;
    flex-shrink: 0;
}

.ribbon-link::before {
    content: '> ';
    opacity: 0;
    color: #f0a05a;
    transition: opacity 0.15s ease, margin 0.15s ease;
    margin-right: 0;
}

.ribbon-link:hover {
    color: #fff;
    text-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
}

.ribbon-link:hover::before {
    opacity: 1;
    margin-right: 0.15em;
}

.ribbon-link--accent {
    color: #f0a05a;
}

.ribbon-link--accent:hover {
    color: #ffd29b;
    text-shadow: 0 0 8px rgba(240, 160, 90, 0.55);
}

.ribbon-sep {
    color: #444;
    font-size: clamp(8px, 2vw, 10px);
    user-select: none;
    flex-shrink: 0;
}

/* Default: socials are inline siblings inside the nav */
.ribbon-socials {
    display: contents;
}

/* Mobile-only toggle for socials */
.ribbon-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid #3a3a3a;
    color: #c4c4c4;
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(9px, 2.4vw, 11px);
    letter-spacing: 0.1em;
    padding: 0.35rem 0.55rem;
    cursor: pointer;
    border-radius: 0;
    line-height: 1;
    flex-shrink: 0;
    -webkit-font-smoothing: none;
    transition: color 0.15s ease, border-color 0.15s ease,
                background 0.15s ease, transform 0.15s ease;
}

.ribbon-toggle:hover {
    color: #fff;
    border-color: #f0a05a;
}

.ribbon-toggle:focus-visible {
    outline: 1px solid #f0a05a;
    outline-offset: 2px;
}

.ribbon-toggle__icon {
    display: inline-block;
    transition: transform 0.25s ease;
}

#site-ribbon.ribbon--socials-open .ribbon-toggle {
    color: #f0a05a;
    border-color: #f0a05a;
    background: rgba(240, 160, 90, 0.08);
}

#site-ribbon.ribbon--socials-open .ribbon-toggle__icon {
    transform: rotate(45deg);
}

/* Collapse socials into the “+” drawer from tablet widths down — avoids a
   crowded single row that still overflows between ~560px and ~960px. */
@media (max-width: 960px) {
    .ribbon-sep { display: none; }
    .ribbon-inner { gap: 0.5rem; }
    .ribbon-link { padding: 0.35rem 0.35rem; }
    .ribbon-toggle { display: inline-flex; }

    /* Socials drop into a panel just below the ribbon */
    .ribbon-socials {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 0.4rem 0.85rem;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        padding: 0.65rem max(env(safe-area-inset-right, 0px), clamp(1rem, 4.5vw, 1.85rem)) 0.75rem max(env(safe-area-inset-left, 0px), clamp(1rem, 4.5vw, 1.85rem));
        background: rgba(10, 10, 10, 0.88);
        backdrop-filter: blur(6px) saturate(140%);
        -webkit-backdrop-filter: blur(6px) saturate(140%);
        border-bottom: 1px solid #2a2a2a;
        box-shadow: 0 12px 28px -16px rgba(0, 0, 0, 0.7);
        opacity: 0;
        visibility: hidden;
        transform: translateY(-6px);
        pointer-events: none;
        transition: opacity 0.2s ease,
                    transform 0.2s ease,
                    visibility 0s linear 0.2s;
    }

    #site-ribbon.ribbon--socials-open .ribbon-socials {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        pointer-events: auto;
        transition: opacity 0.2s ease,
                    transform 0.2s ease,
                    visibility 0s linear 0s;
    }
}

@media (max-width: 380px) {
    .ribbon-brand__name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .ribbon-toggle__icon,
    .ribbon-socials {
        transition: opacity 0s, visibility 0s, transform 0s !important;
    }
}
