:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-card-hover: #1e3a5f;
    --border-color: #2d2d44;
    --text-primary: #ffffff;
    --text-secondary: #e2e8f0;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --accent: #4ade80;
    --accent-hover: #22c55e;
    --accent-dark: #0f0f1a;
    --warning: #f59e0b;
}

@media (prefers-color-scheme: light) {
    :root:not(.dark) {
        --bg-primary: #f8fafc;
        --bg-secondary: #ffffff;
        --bg-card: #f1f5f9;
        --bg-card-hover: #e2e8f0;
        --border-color: #e2e8f0;
        --text-primary: #0f172a;
        --text-secondary: #1e293b;
        --text-muted: #64748b;
        --text-dim: #94a3b8;
        --accent: #22c55e;
        --accent-hover: #16a34a;
        --accent-dark: #ffffff;
        --warning: #f59e0b;
    }
}

:root.dark {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-card-hover: #1e3a5f;
    --border-color: #2d2d44;
    --text-primary: #ffffff;
    --text-secondary: #e2e8f0;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --accent: #4ade80;
    --accent-hover: #22c55e;
    --accent-dark: #0f0f1a;
    --warning: #f59e0b;
}

:root.light {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #f1f5f9;
    --bg-card-hover: #e2e8f0;
    --border-color: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #1e293b;
    --text-muted: #64748b;
    --text-dim: #94a3b8;
    --accent: #22c55e;
    --accent-hover: #16a34a;
    --accent-dark: #ffffff;
    --warning: #f59e0b;
}

html {
    scrollbar-gutter: stable;
}

header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}

.logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
}

.logo-text {
    font-family: 'Archivo', 'Inter', -apple-system, sans-serif;
    font-weight: 800;
    font-size: 1.35rem;
    line-height: 1;
    letter-spacing: 0.005em;
    text-transform: uppercase;
    color: var(--text-primary);
}

.logo-text .logo-accent {
    color: var(--accent);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Below the narrowest current phone width (iPhone SE/mini and everything wider
   now fits without any scrolling — see the icon-only lang trigger below), give
   header-right a scrollable fallback instead of letting it force the whole page
   to scroll horizontally. Scoped to only this rare, narrow range: unconditional
   overflow-x:auto was found to make iOS Safari occasionally swallow a tap on the
   language button as the start of a scroll gesture, even with nothing to scroll,
   so it must not apply on device widths where nothing overflows in the first
   place (i.e. every current iPhone). */
@media (max-width: 374px) {
    .header-right {
        /* Flex items default to min-width:auto, which blocks shrinking below
           their content's natural width — that's what pushed this row past the
           viewport instead of it adapting. min-width:0 lets it shrink. */
        min-width: 0;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .header-right::-webkit-scrollbar {
        display: none;
    }
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 6px;
}

.header-nav a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 8px 15px;
    border-radius: 50px;
    white-space: nowrap;
    transition: color 0.2s ease, background 0.2s ease;
}

.header-nav a:hover {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.header-nav .nav-short { display: none; }

@media (max-width: 560px) {
    .header-right { gap: 6px; }
    .header-nav { margin-right: 0; gap: 4px; }
    .header-nav a { padding: 7px 8px; font-size: 0.84rem; }
    /* Icon-only brand + shorter WC label on mobile to fit the nav */
    .logo-text { display: none; }
    .header-nav .nav-full { display: none; }
    .header-nav .nav-short { display: inline; }
    /* Globe + current language code, no chevron (dropping the chevron is what
       actually buys back the room for the code: the button doesn't need an
       extra affordance icon to read as tappable, same as the plain-icon
       .theme-toggle next to it). The nav padding/gap trims above pay for
       showing the code without reintroducing the clipping this replaced. */
    .lang-dropdown-trigger { padding: 8px 10px; gap: 5px; }
    .lang-dropdown-trigger svg.chevron { display: none; }
}

/* Placed after the ≤560px block on purpose: a media block earlier in source
   order loses the cascade to an equal-specificity rule in a later block, even
   when its own range (≤374px) is narrower and "should" win logically — CSS
   doesn't know one range nests inside the other, it just applies in source
   order. Real 360px-device session recordings (Clarity) showed the language
   trigger still partly cut off despite the ≤560px trims above (content ~298px
   vs. ~272px available), because an earlier attempt at these overrides above
   the ≤560px block was silently losing the cascade. Trim further here so
   360px fits outright rather than relying on the overflow-x:auto fallback
   (invisible scrollbar — users don't discover it, it just reads as "cut off"). */
@media (max-width: 374px) {
    .header-right { gap: 4px; }
    .header-nav { gap: 3px; }
    .header-nav a { padding: 6px 5px; font-size: 0.8rem; }
    .theme-toggle { width: 34px; height: 34px; padding: 6px; }
    .lang-dropdown-trigger { padding: 7px 7px; }
}

.theme-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    height: 38px;
    box-sizing: border-box;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: var(--bg-card-hover);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

.theme-icon-sun,
.theme-icon-moon {
    display: none;
}

:root:not(.light) .theme-icon-sun,
:root.dark .theme-icon-sun {
    display: block;
}

:root.light .theme-icon-moon {
    display: block;
}

.lang-dropdown-container {
    position: relative;
    display: inline-block;
}

.lang-dropdown-trigger {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    height: 38px;
    box-sizing: border-box;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s ease;
    user-select: none;
}

.lang-dropdown-trigger:hover,
.lang-dropdown-container.active .lang-dropdown-trigger {
    background: var(--bg-card-hover);
    color: var(--accent);
    border-color: var(--accent);
}

.lang-dropdown-trigger svg.chevron {
    transition: transform 0.2s ease;
}

.lang-dropdown-container.active .lang-dropdown-trigger svg.chevron {
    transform: rotate(180deg);
}

.lang-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px;
    display: none;
    flex-direction: column;
    gap: 2px;
    min-width: 140px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    z-index: 101;
}

:root.light .lang-dropdown-menu {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.lang-dropdown-container.active .lang-dropdown-menu {
    display: flex;
}

.lang-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.15s ease;
    text-align: left;
}

.lang-dropdown-item:hover {
    background: var(--bg-card-hover);
    color: var(--accent);
}

.lang-dropdown-item.active {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

#lang-banner {
    background: #16162a;
    border-bottom: 1px solid var(--border-color);
    padding: 10px 0;
    font-size: 0.9rem;
    color: #ffffff;
}

:root.light #lang-banner {
    background: #f1f5f9;
    border-bottom: 1px solid var(--border-color);
    color: #0f172a;
}

.lang-banner-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.lang-banner-text {
    font-weight: 500;
}

.lang-banner-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.lang-banner-btn {
    background: var(--accent);
    color: var(--accent-dark);
    padding: 6px 14px;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.8rem;
    transition: transform 0.2s ease;
}

.lang-banner-btn:hover {
    transform: scale(1.03);
}

.lang-banner-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}

.lang-banner-close:hover {
    color: var(--text-primary);
}

/* RTL support (Arabic). direction:rtl on the root flips the flex main-axis
   automatically for header-content / header-right / header-nav / the
   lang-dropdown-trigger's own contents, so only the rules below — things
   authored with a physical (not logical) direction — need an explicit
   override. */
[dir="rtl"] {
    direction: rtl;
}

[dir="rtl"] .lang-dropdown-menu {
    right: auto;
    left: 0;
}

[dir="rtl"] .lang-dropdown-item {
    text-align: right;
}
