/* ============================================
   DDD Shared Navigation
   ============================================ */

/* Skip link — first focusable element of every shared-chrome page. Visually hidden until it
   receives keyboard focus, then revealed at the top-left. Native anchor to #main-content; no
   JavaScript required. */
.skip-link {
  position: absolute;
  left: 8px;
  top: -64px;
  z-index: 10000;
  padding: 0.55rem 0.9rem;
  background: var(--theme-surface-overlay);
  color: var(--theme-ink-primary);
  border: 1px solid var(--theme-rule-focus);
  border-radius: 6px;
  font-family: var(--mono, var(--sans));
  font-size: var(--type-metadata-size);
  font-weight: 500;
  letter-spacing: var(--type-metadata-ls);
  text-decoration: none;
  transition: top 0.16s ease;
}
.skip-link:focus,
.skip-link:focus-visible {
  top: 8px;
  outline: 2px solid var(--theme-focus-ring);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--theme-focus-ring-outer);
}

.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: var(--theme-surface-page);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: inset 0 -1px 0 var(--theme-rule-subtle);
}
.nav-inner {
  /* The shared navigation is the top of the page spine, so it takes the primary page measure and
     the shared gutter rather than the private --nav-max-w, which was never defined anywhere and
     always fell through to its own 1200px. */
  width: 100%; max-width: var(--layout-box-page); margin: 0 auto;
  padding: 0 var(--layout-gutter); box-sizing: border-box;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 48px;
  gap: 1.25rem;
}
.nav-left { display: flex; align-items: center; gap: 1rem; }
.nav-brand { display: flex; align-items: center; text-decoration: none; gap: 0.4rem; }
.nav-brand { min-width: 44px; min-height: 44px; }
.nav-brand svg { width: 34px; height: 34px; display: block; flex-shrink: 0; transform: translateY(-1px); }
.nav-brand img {
  width: auto;
  height: 30px;
  display: block;
  flex-shrink: 0;
  transform: translateY(-1px);
  border-radius: 0;
}
.nav-brand span {
  font-family: var(--mono, var(--sans)); font-size: 0.72rem; font-weight: 500;
  color: var(--theme-ink-secondary); letter-spacing: 0.04em;
  white-space: nowrap;
}
.nav-back { font-size: 0.85rem; color: var(--theme-ink-secondary); transition: color 0.2s; }
.nav-back:hover { color: var(--theme-ink-link-hover); }

.nav-primary,
.dt-primary-nav {
  display: none;
  align-items: center;
  gap: 1.1rem;
  min-height: 48px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-primary > li,
.dt-primary-nav > li {
  display: flex;
  align-items: center;
  min-height: 48px;
}

.nav-primary a,
.dt-primary-nav a {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 48px;
  min-height: 44px;
  color: var(--theme-ink-secondary);
  font-family: var(--mono, var(--sans));
  font-size: var(--type-label-compact-size);
  font-weight: 500;
  letter-spacing: var(--type-label-compact-ls);
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.18s ease, opacity 0.18s ease;
}
.nav-primary > li > a::after,
.dt-primary-nav > li > a::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  height: 1px;
  background: var(--theme-rule-focus);
  opacity: 0;
  transform: scaleX(0.45);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.nav-primary a:hover,
.dt-primary-nav a:hover,
.nav-primary a[aria-current="page"],
.dt-primary-nav a[aria-current="page"] {
  color: var(--theme-ink-primary);
}
.nav-primary > li > a[aria-current="page"]::after,
.dt-primary-nav > li > a[aria-current="page"]::after {
  opacity: 0.75;
  transform: scaleX(1);
}

/* Language dropdown */
.lang-dropdown { position: relative; }
.lang-toggle {
  font-family: var(--sans); font-size: 1rem; font-weight: 500;
  color: var(--theme-ink-secondary); background: none;
  border: 1px solid var(--theme-rule-standard); cursor: pointer;
  padding: 0.3rem 0.6rem; border-radius: 4px; transition: all 0.2s;
  display: flex; align-items: center; gap: 0.3rem; letter-spacing: 0.04em;
}
.lang-toggle:hover { color: var(--theme-ink-primary); border-color: var(--theme-rule-interactive); }
.lang-toggle::after {
  content: ''; border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid currentColor; margin-top: 1px;
}
/* Language indicator — clean, minimal */
.nav-lang {
  font-family: var(--sans); font-size: 0.7rem; font-weight: 600;
  color: var(--theme-ink-muted); letter-spacing: 0.08em;
  min-height: 48px;
  padding: 0.25rem 0.5rem; cursor: default; user-select: none;
  white-space: nowrap;
}
.lang-menu {
  font-family: var(--sans); font-size: 0.72rem; font-weight: 500;
  background: var(--theme-surface-overlay); backdrop-filter: blur(8px);
  text-transform: uppercase; padding: 0.4rem 0;
  border-radius: 8px; padding: 0.35rem; min-width: 200px;
  z-index: 200; grid-template-columns: 1fr 1fr;
}
.lang-menu.open { display: grid; animation: fadeUp 0.15s ease; }
.lang-pick {
  font-family: var(--sans); font-size: 0.85rem; font-weight: 500;
  color: var(--theme-ink-muted); background: none; border: none;
  cursor: pointer; padding: 0.4rem 0.75rem; border-radius: 4px;
  transition: all 0.15s; display: block; width: 100%;
  text-align: left; min-height: 44px;
}
.lang-pick:hover { background: var(--theme-surface-hover); color: var(--theme-ink-primary); }
.lang-pick.active { color: var(--theme-ink-link); }

nav, section, footer { position: relative; z-index: 20; }

/* Scroll offset for anchors — accounts for fixed nav (48px) */
html { scroll-padding-top: 56px; }

body.nav-open { overflow: hidden; }

/* ---- Theme selection ----------------------------------------------------
   Native select keeps the three-state System / Light / Dark interaction keyboard- and
   touch-native. Desktop and mobile instances are synchronised by js/theme.js; only one is visible
   at a time. All colours resolve through semantic roles. */
.theme-control {
  min-height: 44px;
  align-items: center;
  gap: 0.4rem;
  color: var(--theme-ink-secondary);
  font-family: var(--mono, var(--sans));
  flex-shrink: 0;
}
.theme-control--desktop,
.theme-control--mobile {
  display: none;
}
.theme-control--standalone {
  display: inline-flex;
}
.theme-control__label {
  font-size: var(--type-label-compact-size);
  font-weight: 500;
  letter-spacing: var(--type-label-compact-ls);
  text-transform: uppercase;
  white-space: nowrap;
}
.theme-control__select {
  min-width: 78px;
  min-height: 44px;
  padding: 0.35rem 1.65rem 0.35rem 0.5rem;
  color: var(--theme-ink-primary);
  background-color: var(--theme-surface-raised);
  border: 1px solid var(--theme-rule-standard);
  border-radius: 4px;
  font: 500 0.7rem/1 var(--mono, var(--sans));
  letter-spacing: 0.02em;
  cursor: pointer;
}
.theme-control__select:hover {
  border-color: var(--theme-rule-interactive);
  background-color: var(--theme-surface-hover);
}
.theme-control__route-note {
  max-width: 7.5rem;
  color: var(--theme-ink-muted);
  font-size: 0.61rem;
  line-height: 1.2;
}
.theme-control__route-note[hidden] {
  display: none;
}
.theme-control__announcement {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Menu trigger ---- */
.menu-trigger {
  background: none; border: none; cursor: pointer;
  font-family: var(--sans); font-size: 0.72rem; font-weight: 500;
  color: var(--theme-ink-link); letter-spacing: 0.08em;
  text-transform: uppercase; padding: 0.4rem 0;
  min-height: 44px;
  min-width: 44px;
  transition: color 0.2s;
}
.menu-trigger:hover { color: var(--theme-ink-link-hover); }

/* ---- Full-screen nav overlay ---- */
.nav-overlay {
  position: fixed; top: 0; left: 0;
  width: 100vw; height: 100vh; height: 100dvh;
  z-index: 9999; background: var(--theme-surface-page);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 5rem 1rem 1.5rem;
  overflow-y: auto;
  opacity: 0; pointer-events: none;
  transition: opacity 200ms ease;
}
.nav-overlay.open {
  opacity: 1; pointer-events: auto;
}
/* Closed overlay is fully removed from layout, tab order and the accessibility tree. Shared here
   (not only in each page's inline <style>) so pages that lack the inline rule — e.g. the legacy
   in-practice page — do not leave a screen of focusable, screen-reader-browsable links behind the
   page. js/nav-overlay.js toggles the .open class and aria-hidden together. */
.nav-overlay:not(.open) { display: none; }
.nav-overlay-logo img {
  width: auto;
  height: 32px;
  display: block;
  border-radius: 0;
}
.nav-overlay-close {
  position: absolute; top: 0.9rem; right: 1rem;
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  background: var(--theme-surface-raised);
  border: 1px solid var(--theme-rule-standard); border-radius: 999px;
  cursor: pointer;
  font-size: 1.15rem; color: var(--theme-ink-secondary);
  line-height: 1; padding: 0; transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.nav-overlay-close:hover {
  color: var(--theme-ink-primary);
  border-color: var(--theme-rule-focus);
  background: var(--theme-surface-hover);
}
.nav-overlay-links {
  display: flex; flex-direction: column; align-items: center;
  gap: 0; text-align: center; width: 90%; max-width: 400px;
  margin-top: 0;
}
.nav-overlay-link {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; text-decoration: none; padding: 1.05rem 0;
  border-bottom: 1px solid var(--theme-rule-subtle);
  width: 100%;
  transition: background 0.15s ease;
}
.nav-overlay-link:first-child { border-top: 1px solid var(--theme-rule-subtle); }
.nav-overlay-link:hover,
.nav-overlay-link:focus-visible {
  background: var(--theme-surface-hover);
}
.nav-overlay-label {
  font-family: var(--sans); font-size: 1.05rem; font-weight: 500;
  color: var(--theme-ink-secondary); letter-spacing: 0.06em;
  text-transform: uppercase; transition: color 0.15s;
}
.nav-overlay-link:hover .nav-overlay-label,
.nav-overlay-link:focus-visible .nav-overlay-label { color: var(--theme-ink-primary); }
.nav-overlay-link[aria-current="page"] .nav-overlay-label {
  color: var(--theme-ink-link);
}
.nav-overlay-link[aria-current="page"] {
  border-color: var(--theme-rule-focus);
}
.nav-overlay-desc {
  font-family: var(--sans); font-size: 0.75rem; font-weight: 300;
  color: var(--theme-ink-secondary); line-height: 1.4;
}
/* Board sub-items (Currencies/Chains/Issuers) — indented, visually secondary */
.nav-overlay-link--board {
  padding: 0.65rem 0 0.65rem 1.25rem;
  border-bottom-color: var(--theme-rule-subtle);
}
.nav-overlay-link--board .nav-overlay-label {
  font-size: 0.9rem;
  color: var(--theme-ink-muted);
}
.nav-overlay-link--board .nav-overlay-desc {
  color: var(--theme-ink-secondary);
}

@media (max-width: 767px) {
  .nav-brand svg { width: 30px; height: 30px; }
  .nav-brand img { width: auto; height: 28px; border-radius: 0; }
  .nav-overlay-logo img { width: auto; height: 30px; border-radius: 0; }
  /* "Stable Tape" is short enough to keep visible on mobile. */

  .nav-overlay {
    align-items: stretch;
    justify-content: flex-start;
    padding: 3.5rem 1.15rem 1.6rem;
  }

  .nav-overlay-close {
    top: 0.7rem;
    right: 0.85rem;
  }

  .nav-overlay-links {
    width: 100%;
    max-width: none;
    align-items: stretch;
    text-align: left;
  }

  .nav-overlay-link {
    align-items: flex-start;
    gap: 0;
    padding: 0.62rem 0.15rem;
  }

  .nav-overlay-label {
    font-size: 0.86rem;
    letter-spacing: 0.05em;
  }

  .nav-overlay-link--board {
    padding: 0.52rem 0.15rem 0.52rem 1.1rem;
  }

  .nav-overlay-link--board .nav-overlay-label {
    font-size: 0.78rem;
  }

  .nav-overlay-desc {
    display: none;
  }

  .theme-control--mobile {
    display: flex;
    width: 100%;
    margin-top: 0.55rem;
    padding: 0.65rem 0.15rem 0;
    border-top: 1px solid var(--theme-rule-subtle);
  }

  .theme-control--mobile .theme-control__select {
    flex: 1;
  }

  .theme-control--standalone {
    margin-left: auto;
  }

  .theme-control--standalone .theme-control__label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

@media (min-width: 768px) {
  .nav-primary,
  .dt-primary-nav {
    display: flex;
  }

  .nav-primary {
    margin-left: auto;
  }

  .menu-trigger,
  .dt-menu {
    display: none;
  }

  .theme-control--desktop {
    display: inline-flex;
  }
}

@media (max-width: 767px) {
  .dt-live {
    display: none;
  }
}

@media (min-width: 768px) and (max-width: 1050px) {
  .nav-brand span,
  .dt-brand-tail {
    display: none;
  }

  .nav-primary,
  .dt-primary-nav {
    gap: 0.85rem;
  }

  /* Was 0.64rem (10.24px), below the constitution's 11px floor for essential text. The compact
     label role is the tightest size a meaningful nav label may take. */
  .nav-primary a,
  .dt-primary-nav a {
    font-size: var(--type-label-compact-size);
    letter-spacing: 0.08em;
  }
}

/* ---- Legacy hamburger (hidden) ---- */
.nav-hamburger { display: none; }

/* ═══════════════════════════════════════════════
   Metrics dropdown (desktop)
   ═══════════════════════════════════════════════ */

.nav-has-dropdown {
  position: relative;
  isolation: isolate;
}

.nav-dropdown-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.28em;
  height: 48px;
  min-height: 44px;
  line-height: 1;
  background: none; border: none; cursor: pointer; padding: 0;
  color: var(--theme-ink-secondary);
  font-family: var(--mono, var(--sans));
  font-size: var(--type-label-compact-size); font-weight: 500;
  letter-spacing: var(--type-label-compact-ls); text-transform: uppercase;
  white-space: nowrap;
  transition: color 0.18s ease;
}
.nav-dropdown-trigger:hover,
.nav-dropdown-trigger.is-current {
  color: var(--theme-ink-primary);
}
.nav-dropdown-trigger::after {
  content: '';
  position: absolute; left: 0; right: 1.15em; bottom: 8px;
  height: 1px; background: var(--theme-rule-focus);
  opacity: 0; transform: scaleX(0.45);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.nav-dropdown-trigger.is-current::after { opacity: 0.75; transform: scaleX(1); }

.nav-dropdown-caret {
  display: inline-block; font-size: 0.6em; color: var(--theme-ink-primary); opacity: 0.5; line-height: 1;
  margin-top: 1px;
  transform-origin: 50% 45%;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
/* Open state is driven only by the .open class (set by js/nav-overlay.js on click, keyboard and
   pointer-enter), never by :hover alone — a CSS-only hover reveal would show the panel while its
   aria-expanded stayed false and its descendants stayed inert. */
.nav-has-dropdown.open .nav-dropdown-caret { transform: rotate(180deg); opacity: 0.8; }

.nav-dropdown {
  position: absolute; top: 100%; right: 0;
  width: min(320px, calc(100vw - 32px));
  min-width: 234px; list-style: none; margin: 0; padding: 0.3rem;
  background: var(--theme-surface-overlay);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--theme-rule-standard); border-radius: 9px;
  box-shadow: none;
  opacity: 0; pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.17s ease, transform 0.17s ease;
  z-index: 200;
}
.nav-has-dropdown.open .nav-dropdown {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.nav-dropdown-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  gap: 2px;
  padding: 0.5rem 0.72rem; border-radius: 5px;
  text-decoration: none; outline-offset: -2px;
  text-align: center;
  transition: background 0.13s ease;
}
.nav-dropdown-item:hover { background: var(--theme-surface-hover); }
.nav-dropdown-item[aria-current="page"] { background: var(--theme-surface-active); }

.nav-dropdown-item-label {
  display: block;
  font-family: var(--mono, var(--sans)); font-size: var(--type-label-compact-size); font-weight: 500;
  letter-spacing: var(--type-label-compact-ls); text-transform: uppercase;
  color: var(--theme-ink-primary);
  transition: color 0.13s ease;
}
.nav-dropdown-item:hover .nav-dropdown-item-label,
.nav-dropdown-item[aria-current="page"] .nav-dropdown-item-label {
  color: var(--theme-ink-primary);
}
/* Weight 300 at this size read as faint rather than subordinate; the reference sets all
   interface prose at 400 and lets scale carry the hierarchy. Size is unchanged. */
.nav-dropdown-item-desc {
  display: block; font-family: var(--sans);
  font-size: 0.67rem; font-weight: 400;
  color: var(--theme-ink-secondary); letter-spacing: 0.01em;
}

/* Shared focus grammar: a semantic ring with a contrasting outer keyline. Inset offsets on
   edge-aligned rows keep the indicator inside the viewport and open panels without changing
   geometry or introducing overflow. */
:is(
  .nav-brand,
  .nav-back,
  .lang-toggle,
  .lang-pick,
  .menu-trigger,
  .nav-primary a,
  .dt-primary-nav a,
  .nav-dropdown-trigger,
  .nav-dropdown-item,
  .nav-overlay-close,
  .nav-overlay-link,
  .nav-overlay-accordion-trigger,
  .nav-overlay-link--sub,
  .theme-control__select
):focus-visible {
  outline: 2px solid var(--theme-focus-ring);
  outline-offset: -3px;
  box-shadow: inset 0 0 0 4px var(--theme-focus-ring-outer);
}

@media (min-width: 768px) and (max-width: 1050px) {
  .nav-dropdown-trigger { font-size: var(--type-label-compact-size); letter-spacing: 0.08em; }
  .nav-dropdown { min-width: 210px; }
}

/* ═══════════════════════════════════════════════
   Metrics accordion (mobile overlay)
   ═══════════════════════════════════════════════ */

.nav-overlay-accordion {
  width: 100%;
  border-bottom: 1px solid var(--theme-rule-subtle);
}

.nav-overlay-accordion-trigger {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; background: none; border: none; cursor: pointer;
  padding: 1.05rem 0; text-align: left; gap: 0.5rem;
}
.nav-overlay-accordion-trigger .nav-overlay-label { transition: color 0.15s; }
.nav-overlay-accordion-trigger.is-current .nav-overlay-label { color: var(--theme-ink-link); }

.nav-overlay-accordion-caret {
  font-size: 0.65rem; color: var(--theme-ink-muted); flex-shrink: 0; line-height: 1;
  transition: transform 0.2s ease, color 0.15s;
}
.nav-overlay-accordion.open .nav-overlay-accordion-caret {
  transform: rotate(180deg); color: var(--theme-ink-secondary);
}

.nav-overlay-accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}
.nav-overlay-accordion.open .nav-overlay-accordion-body { max-height: 320px; }
.nav-overlay-accordion-body-inner { padding-bottom: 0.45rem; }

.nav-overlay-link--sub {
  display: flex; flex-direction: column;
  align-items: flex-start; gap: 3px;
  padding: 0.68rem 0 0.68rem 1.1rem;
  border-top: 1px solid var(--theme-rule-subtle);
  text-decoration: none;
}
.nav-overlay-link--sub:first-child { border-top-color: var(--theme-rule-standard); }
.nav-overlay-link--sub .nav-overlay-label {
  font-size: 0.9rem; color: var(--theme-ink-muted);
  transition: color 0.15s;
}
.nav-overlay-link--sub:hover .nav-overlay-label,
.nav-overlay-link--sub[aria-current="page"] .nav-overlay-label { color: var(--theme-ink-link); }
.nav-overlay-link--sub .nav-overlay-desc { color: var(--theme-ink-secondary); font-size: 0.72rem; }

@media (max-width: 767px) {
  .nav-overlay-accordion-trigger { padding: 0.95rem 0; }
  .nav-overlay-link--sub .nav-overlay-desc { display: none; }
  .nav-overlay-link--sub { padding: 0.62rem 0 0.62rem 1rem; }
}

/* Respect reduced-motion for every shared navigation open/close transition, including the desktop
   dropdown panel, the full-screen overlay fade, the caret rotations and the skip-link reveal. */
@media (prefers-reduced-motion: reduce) {
  .nav-overlay,
  .nav-overlay-accordion-body,
  .nav-overlay-accordion-caret,
  .nav-dropdown,
  .nav-dropdown-caret,
  .skip-link { transition: none; }
}

@media (forced-colors: active) {
  .theme-control__select {
    border-color: CanvasText;
  }
}

/* ═══════════════════════════════════════════════
   Live snapshot sync — toast + value flash
   ═══════════════════════════════════════════════ */

.ddd-sync-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.25rem;
  z-index: 9000;
  padding: 0.45rem 0.85rem;
  background: var(--theme-surface-overlay);
  border: 1px solid var(--theme-rule-focus);
  border-radius: 6px;
  color: var(--theme-ink-link);
  font-size: 0.76rem;
  letter-spacing: 0.035em;
  font-family: var(--dt-mono, 'JetBrains Mono', 'Fira Mono', 'Courier New', monospace);
  backdrop-filter: blur(10px);
  box-shadow: none;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  user-select: none;
}
.ddd-sync-toast--visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes ddd-value-flash {
  0%   { background-color: transparent; }
  18%  { background-color: var(--theme-accent-surface); }
  100% { background-color: transparent; }
}
.ddd-value-flash {
  animation: ddd-value-flash 1.8s ease-out;
  border-radius: 3px;
}
