/* Top bar: brand, theme toggle, language menu */

.topbar {
    display: grid;
    grid-template-columns: 1fr minmax(0, 740px) 1fr;
    align-items: center;
    column-gap: 16px;
    /* Pinned at top:0 with viewport-fit=cover — reserve the top safe-area so the
       header clears the notch/Dynamic Island and feed content can't bleed above
       it (left/right insets matter in landscape). Height grows by the same inset
       so the 64px content row stays centred below the safe area. */
    padding: env(safe-area-inset-top) max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    position: sticky;
    top: 0;
    z-index: 10;
    height: calc(64px + env(safe-area-inset-top));
    min-height: calc(64px + env(safe-area-inset-top));
    flex-shrink: 0;
}

.topbar > .brand { justify-self: start; }
.topbar > .topbar-actions { justify-self: end; grid-column: 3; }

/* Left cluster: brand + scope button share the first topbar column. Lives here,
   not in switcher.css, because it's topbar layout — the feed and the map both
   use it and only the feed loads switcher.css. */
.topbar-lead {
    grid-column: 1;
    justify-self: stretch;
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}
.topbar-lead .brand { flex-shrink: 0; }

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: inherit;
    transition: opacity 0.15s ease;
}
.brand:hover { opacity: 0.7; }

.brand-mark {
    width: 28px;
    height: 28px;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}
.brand-mark svg { width: 100%; height: 100%; }

.brand-name {
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.15em;
    color: var(--text);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Theme toggle */

.theme-toggle {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0;
    flex-shrink: 0;
}
.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-subtle); }
.theme-toggle:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* Language menu */

.lang-menu {
    position: relative;
    display: inline-flex;
}

.lang-toggle {
    height: 36px;
    padding: 0 8px 0 10px;
    gap: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.lang-toggle:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-subtle); }
.lang-toggle:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.lang-toggle[aria-expanded="true"] {
    color: var(--text);
    border-color: var(--border-strong);
    background: var(--bg-subtle);
}

.lang-caret {
    color: var(--text-subtle);
    transition: transform .15s ease;
    flex-shrink: 0;
}
.lang-toggle[aria-expanded="true"] .lang-caret {
    transform: rotate(180deg);
}

.lang-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: var(--shadow-dropdown);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 50;
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    background: transparent;
    border: none;
    border-radius: 3px;
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: background .12s ease, color .12s ease;
}
.lang-option:hover,
.lang-option:focus-visible {
    background: var(--bg-subtle);
    outline: none;
}

.lang-option[aria-current="true"] {
    background: var(--bg-subtle);
}

.lang-option .lang-code {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    width: 22px;
    flex-shrink: 0;
}
.lang-option[aria-current="true"] .lang-code {
    color: var(--text);
}

.lang-option .lang-name {
    font-size: 13px;
    color: var(--text);
}

/* Phones: a deterministic row — the search is the only flexible element (grows
   from a 0 basis to fill the leftover), everything else is pinned to its
   intrinsic width. Higher specificity (.topbar > …) so these win over
   responsive.css regardless of load order.

   The brand goes entirely: the scope button takes the lead slot, and a lone
   icon button matches the other topbar controls (lang/theme/profile).
   responsive.css only hides .brand-name, which would leave the mark behind. */
@media (max-width: 640px) {
    .topbar > .topbar-lead { flex: 0 0 auto; }
    .topbar > .topbar-actions { flex: 0 0 auto; }
    .topbar > .topbar-search {
        flex: 1 1 0%;
        width: auto;
        min-width: 0;
    }
    .topbar-lead .brand { display: none; }
    .topbar-lead { gap: 0; }
}
