/* ───────────────── Front of Heroes · Navigation ─────────────────
   The top bar (desktop), the bottom tab bar with slide-up sheets (phones), the account menu.
   Tokens and shared components only. */

@layer components {

/* ══ Top bar ═════════════════════════════════════════════════════════════════════════════════ */
.topnav { position: sticky; top: 0; z-index: var(--z-nav); background: var(--surface-nav); border-bottom: 1px solid var(--border-subtle);
  -webkit-backdrop-filter: blur(18px) saturate(1.3); backdrop-filter: blur(18px) saturate(1.3); }
/* The front line: your blue, the brand, the enemy's red. */
.topnav::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none;
  background: linear-gradient(90deg, var(--blue), var(--brand) 50%, var(--red)); opacity: .55; }
.topnav-in { max-width: calc(var(--nav-max) + 2 * var(--page-pad)); margin: 0 auto; padding: 0 var(--page-pad); height: 60px; display: flex; align-items: center; gap: var(--sp-4); }

.topnav .brand { display: flex; align-items: center; gap: var(--sp-3); flex: none; color: var(--text); border-radius: var(--r-md); }
.topnav .brand .brand-mark { height: 34px; }
.topnav .brand .brand-word { height: 17px; }

.links { display: flex; align-items: center; gap: 0; flex: 1; min-width: 0; }
.nav-link { position: relative; display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 10px; border-radius: var(--r-md);
  color: var(--text-2); font: var(--fw-semibold) var(--fs-ui) / 1 var(--font-ui); white-space: nowrap; transition: background-color var(--t-fast), color var(--t-fast); }
.nav-link .icon { color: var(--text-3); transition: color var(--t-fast); }
.nav-link .caret { color: var(--text-3); transition: transform var(--t-base) var(--ease); }
.nav-link:hover { color: var(--text); background: var(--surface-3); }
.nav-link:hover .icon { color: var(--text); }
.nav-link.active { color: var(--text); }
.nav-link.active > .icon:first-child { color: var(--brand-text); }
/* The selected section sits on the front line: a short brand bar on the bar's bottom edge. */
.nav-link.active::after { content: ""; position: absolute; left: var(--sp-3); right: var(--sp-3); bottom: -11px; height: 2px; border-radius: 2px; background: var(--brand); box-shadow: 0 0 10px var(--brand-glow); }

/* Section menus: open on hover (desktop) or click, with each page's purpose under its name. */
.nav-group { position: relative; }
.nav-group:hover .caret, .nav-group.open .caret { transform: rotate(180deg); }
.nav-menu { display: none; position: absolute; left: 0; top: calc(100% + 10px); z-index: var(--z-dropdown); width: 300px; }
.nav-menu::before { content: ""; position: absolute; left: 0; right: 0; top: -12px; height: 12px; } /* hover bridge */
.nav-group:hover .nav-menu, .nav-group.open .nav-menu { display: block; animation: menu-in var(--t-base) var(--ease); }
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } }
.nav-item { display: flex; align-items: center; gap: var(--sp-3); width: 100%; padding: var(--sp-2); border-radius: var(--r-md); text-align: left; transition: background-color var(--t-fast); }
.nav-item-ico { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: var(--r-md); color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border-subtle); transition: color var(--t-fast), background-color var(--t-fast), border-color var(--t-fast); }
.nav-item-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.nav-item-text b { font: var(--fw-semibold) var(--fs-ui) / 1.3 var(--font-ui); color: var(--text); }
.nav-item-text small { font-size: var(--fs-xs); line-height: 1.35; color: var(--text-3); }
.nav-item:hover { background: var(--surface-3); }
.nav-item:hover .nav-item-ico { color: var(--text); border-color: var(--border); }
.nav-item.active .nav-item-ico { color: var(--on-brand); background: var(--brand); border-color: var(--brand-edge); }
.nav-item.active .nav-item-text b { color: var(--brand-text); }
.nav-menu .menu-head:not(:first-child) { margin-top: var(--sp-1); padding-top: var(--sp-3); border-top: 1px solid var(--border-subtle); }

/* ══ Resources: gold and energy ═══════════════════════════════════════════════════════════════ */
.resources { display: flex; align-items: center; gap: var(--sp-2); flex: none; }
.chip.res { min-height: 34px; padding: 0 6px 0 var(--sp-2); gap: var(--sp-2); font-size: var(--fs-ui); background: var(--surface-2); border-color: var(--border);
  transition: border-color var(--t-fast), background-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-base); cursor: pointer; }
.chip.res img { width: 20px; height: 20px; }
.chip.res b { font-weight: var(--fw-semibold); min-width: 2ch; }
.chip.res .plus { display: grid; place-items: center; width: 20px; height: 20px; border-radius: var(--r-pill); background: var(--brand); color: var(--on-brand); transition: transform var(--t-fast); }
.chip.res:hover { border-color: var(--brand-border); background: var(--brand-soft); }
.chip.res:hover .plus { transform: scale(1.12); }
.chip.res:active { transform: translateY(1px); }
.chip.res:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.chip .mini-bar { width: 52px; height: 6px; border-radius: var(--r-pill); background: var(--surface-sunken); overflow: hidden; box-shadow: inset 0 1px 1px rgba(0, 0, 0, .25); }
.chip .mini-bar i { display: block; height: 100%; border-radius: var(--r-pill); background: linear-gradient(90deg, #5f9e10, var(--lime) 70%, #bef264); transition: width .6s var(--ease); }
.chip .mini-bar i.low { background: linear-gradient(90deg, #c2410c, var(--amber)); }
.chip.nrg { position: relative; }
.chip.nrg.eat:hover img { filter: drop-shadow(0 0 5px var(--lime)); }

/* The energy card under the chip: exact numbers, the pool and the countdown to the next refill. */
.xp-tip { position: absolute; top: calc(100% + 12px); right: 0; z-index: var(--z-dropdown); min-width: 240px; padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2);
  border-radius: var(--r-lg); background: var(--surface-overlay); border: 1px solid var(--border); box-shadow: var(--shadow-3); text-align: left; cursor: default;
  opacity: 0; transform: translateY(-4px); pointer-events: none; transition: opacity var(--t-fast), transform var(--t-fast); }
.chip.nrg:hover .xp-tip, .chip.nrg:focus-visible .xp-tip { opacity: 1; transform: none; }
.xp-tip small { font: var(--fw-semibold) var(--fs-xs) / 1.3 var(--font-ui); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--text-3); }
.xp-tip .xp-amt { font: var(--fw-semibold) 1.625rem / 1.1 var(--font-display); color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.xp-tip .xp-amt span { margin-left: var(--sp-2); font: var(--fw-semibold) var(--fs-xs) / 1 var(--font-ui); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--lime-text); }
.xp-bar { height: 6px; border-radius: var(--r-pill); background: var(--surface-sunken); overflow: hidden; }
.xp-bar i { display: block; height: 100%; border-radius: var(--r-pill); background: linear-gradient(90deg, var(--blue), color-mix(in srgb, var(--blue) 55%, #fff)); transition: width .6s var(--ease); }
.nrg-tip .xp-bar i { background: linear-gradient(90deg, #5f9e10, var(--lime)); }
.nrg-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-4); font-size: var(--fs-sm); color: var(--text-2); }
.nrg-row b { color: var(--text); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.nrg-row .nrg-timer { color: var(--lime-text); }
.nrg-tip .nrg-hint { text-transform: none; letter-spacing: 0; font-weight: var(--fw-regular); font-size: var(--fs-xs); color: var(--text-3); }

/* ══ Messages button ═════════════════════════════════════════════════════════════════════════ */
.top-btn { position: relative; flex: none; width: 38px; height: 38px; display: grid; place-items: center; border-radius: var(--r-md); color: var(--text-2);
  border: 1px solid var(--border); background: var(--surface-2); transition: color var(--t-fast), background-color var(--t-fast), border-color var(--t-fast); }
.top-btn:hover { color: var(--text); background: var(--surface-3); border-color: var(--border-strong); }
.top-btn.active { color: var(--brand-text); border-color: var(--brand-border); }
.top-btn.unread { color: var(--text); }
.mail-badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; display: grid; place-items: center; border-radius: var(--r-pill);
  font: var(--fw-bold) var(--fs-xs) / 1 var(--font-ui); font-variant-numeric: tabular-nums; color: var(--on-brand); background: var(--brand);
  box-shadow: 0 0 0 2px var(--bg); animation: pop .4s cubic-bezier(.2, 1.6, .3, 1); }
@keyframes pop { from { transform: scale(.4); } }

/* ══ Account ═════════════════════════════════════════════════════════════════════════════════ */
.me { position: relative; flex: none; }
.me-btn { display: flex; align-items: center; gap: var(--sp-2); height: 40px; padding: 0 var(--sp-2) 0 4px; border-radius: var(--r-pill);
  border: 1px solid var(--border); background: var(--surface-2); transition: background-color var(--t-fast), border-color var(--t-fast); }
.me-btn:hover, .me.open .me-btn { background: var(--surface-3); border-color: var(--border-strong); }
.me-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.me .avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center; overflow: hidden; background: var(--surface-3); box-shadow: 0 0 0 1px var(--border); }
.me .avatar .flag { width: 46px; height: 32px; max-width: none; border-radius: 0; box-shadow: none; }
.me .avatar.lg { width: 44px; height: 44px; } .me .avatar.lg .flag { width: 64px; height: 44px; }
/* A fixed width, so the length of a citizen's name never moves the rest of the top bar; a long name
   ends in an ellipsis (the full name is in the tooltip and the menu). */
.me-name { display: flex; flex-direction: column; flex: none; width: 112px; min-width: 0; line-height: 1.15; text-align: left; }
.me-name b { font: var(--fw-semibold) var(--fs-ui) / 1.2 var(--font-ui); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-name small { font-size: var(--fs-xs); color: var(--text-3); }
.me .caret { color: var(--text-3); transition: transform var(--t-base) var(--ease); }
.me.open .caret { transform: rotate(180deg); }
.me .menu { display: none; position: absolute; right: 0; top: calc(100% + 8px); z-index: var(--z-dropdown); width: 280px; }
.me .menu::before { content: ""; position: absolute; left: 0; right: 0; top: -10px; height: 10px; }
.me.open .menu { display: block; animation: menu-in var(--t-base) var(--ease); }
.me .who { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3); }
.me .who > div { display: flex; flex-direction: column; min-width: 0; }
.me .who b { font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .who span { color: var(--text-3); font-size: var(--fs-sm); }
.menu-stats { display: flex; flex-direction: column; gap: var(--sp-3); margin: 0 var(--sp-1) var(--sp-1); padding: var(--sp-3); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border-subtle); }
.menu-stat { display: flex; flex-direction: column; gap: 6px; }
.menu-stat.row { flex-direction: row; justify-content: space-between; align-items: baseline; }
.menu-stat span { font: var(--fw-semibold) var(--fs-xs) / 1.3 var(--font-ui); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--text-3); }
.menu-stat b { font-size: var(--fs-ui); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.menu-stat b small { font-size: var(--fs-xs); color: var(--text-3); }
.menu-stat > small { font-size: var(--fs-xs); color: var(--text-3); }
.theme-toggle .theme-lbl { flex: 1; }
.theme-toggle .toggle-track { width: 34px; height: 20px; }
.theme-toggle .toggle-thumb { width: 14px; height: 14px; }
.theme-toggle .toggle-track.on .toggle-thumb { transform: translateX(14px); }

/* ══ Narrower desktops: labels give way first, then the wordmark. ══ */
@media (max-width: 1400px) { .topnav .brand .brand-word { display: none; } }
@media (max-width: 1220px) { .me-name { display: none; } .me-btn { padding: 0 6px 0 4px; } .chip .mini-bar { width: 36px; } }
@media (max-width: 1040px) { .nav-link .lbl, .nav-link .caret { display: none; } .nav-link.active .lbl { display: inline; } }

/* ══ Phones: a native-style bottom tab bar with slide-up sheets instead of the top menus ══ */
.tabbar, .nav-sheet, .nav-sheet-backdrop { display: none; }
@media (max-width: 720px) {
  .topnav .links, .topnav .top-btn.phone-hidden { display: none; }
  :root { --nav-h: 57px; }
  .topnav-in { height: 56px; justify-content: space-between; gap: var(--sp-2); }
  .topnav .brand .brand-mark { height: 30px; }
  .me .caret { display: none; }
  .me-btn { padding: 0 4px; }
  .resources { gap: 6px; }
  .chip.res { padding: 0 var(--sp-2); }
  .chip .mini-bar, .chip.res.buy .plus { display: none; }
  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-nav); display: grid; grid-template-columns: repeat(5, 1fr); min-height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: var(--surface-nav); border-top: 1px solid var(--border);
    -webkit-backdrop-filter: blur(18px) saturate(1.3); backdrop-filter: blur(18px) saturate(1.3); box-shadow: 0 -10px 30px rgba(0, 0, 0, .25); }
  .tab-item { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px; border-radius: var(--r-md); color: var(--text-3); transition: color var(--t-fast); }
  .tab-ico { display: grid; place-items: center; height: 24px; transition: transform var(--t-base) var(--ease); }
  .tab-lbl { font: var(--fw-semibold) var(--fs-xs) / 1 var(--font-ui); letter-spacing: .01em; }
  .tab-item.active { color: var(--text); }
  .tab-item.active .tab-ico { color: var(--brand-text); transform: translateY(-1px); }
  .tab-item.active::before { content: ""; position: absolute; top: -6px; left: 32%; right: 32%; height: 2px; border-radius: 0 0 2px 2px; background: var(--brand); box-shadow: 0 0 10px var(--brand-glow); }
  .tab-ico.mail-ico { position: relative; }
  .tab-ico.mail-ico .mail-badge { top: -6px; right: -12px; }
  .page { padding-bottom: calc(var(--tabbar-h) + var(--sp-8) + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(var(--tabbar-h) + var(--sp-5) + env(safe-area-inset-bottom)); }
  .scroll-top { right: var(--sp-4); bottom: calc(var(--tabbar-h) + var(--sp-4) + env(safe-area-inset-bottom)); }
  .contest-strip { left: var(--sp-4); bottom: calc(var(--tabbar-h) + var(--sp-4) + env(safe-area-inset-bottom)); width: calc(100vw - 2 * var(--sp-4) - 56px); }

  .nav-sheet-backdrop { display: block; position: fixed; inset: 0; z-index: calc(var(--z-nav) - 2); background: var(--scrim); animation: fade-in var(--t-base) ease-out; }
  .nav-sheet { display: flex; flex-direction: column; position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: calc(var(--z-nav) - 1); max-height: 72vh; overflow-y: auto;
    padding: var(--sp-2) var(--sp-3) var(--sp-4); border-radius: var(--r-xl) var(--r-xl) 0 0; background: var(--surface-overlay); border: 1px solid var(--border); border-bottom: 0;
    box-shadow: var(--shadow-3); animation: sheet-up var(--t-slow) var(--ease); overscroll-behavior: contain; }
  .nav-sheet-grab { align-self: center; width: 40px; height: 4px; margin: 2px 0 var(--sp-3); border-radius: 4px; background: var(--border-strong); }
  .nav-sheet h3 { margin: 0 var(--sp-2) var(--sp-2); font: var(--fw-bold) var(--fs-h2) / 1.1 var(--font-display); letter-spacing: var(--ls-display); text-transform: uppercase; }
  .nav-sheet-head { margin: var(--sp-3) var(--sp-2) var(--sp-1); font: var(--fw-semibold) var(--fs-xs) / 1.3 var(--font-ui); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--text-3); }
  .nav-sheet-item { display: flex; align-items: center; gap: var(--sp-3); min-height: 60px; padding: 0 var(--sp-2); border-radius: var(--r-md); text-align: left; color: var(--text); }
  .nav-sheet-item .ico { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: var(--r-md); color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border-subtle); }
  .nav-sheet-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .nav-sheet-text b { font: var(--fw-semibold) var(--fs-md) / 1.25 var(--font-ui); }
  .nav-sheet-text small { font-size: var(--fs-xs); color: var(--text-3); }
  .nav-sheet-go { color: var(--text-3); }
  .nav-sheet-item.active .ico { color: var(--on-brand); background: var(--brand); border-color: var(--brand-edge); }
  .nav-sheet-item.active .nav-sheet-text b { color: var(--brand-text); }
  .nav-sheet-item:active { background: var(--surface-3); }
}
@keyframes sheet-up { from { transform: translateY(100%); } }

/* A section a new player has not opened yet (src/nav.rs `is_new_page`). */
.new-dot { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: var(--r-pill); vertical-align: 1px;
  font: var(--fw-bold) 10px / 1.4 var(--font-ui); letter-spacing: .06em; text-transform: uppercase; color: var(--on-brand); background: var(--brand); }
}
