/* =============================================================================
   BLACK SIGNAL — css/components/topbar.css
   THE NAVIGATION FRAME — the top bar (≥ 600px) and the phone bottom bar,
   rendered by app/18-chrome.js on every in-app screen.

   Top bar: black, one hairline under it, 56px. Left: wordmark + breadcrumb
   (each segment a sweep key; the leading ‹ is Back).
   Right: ANALYTICS · XP cluster · TIMER · MENU, MENU last at the far edge.
   Bottom bar (< 600px): equal ruled cells in the thumb zone: BACK · <screen
   actions> · ANALYTICS · MENU. Content is padded so nothing sits under it.
   Keys: `.bs-topbar-key` / `.bs-key` — 36px, condensed, tracked, a 6px notch.
   ============================================================================= */
@layer components {

/* ── Page offsets while the frame is shown ─────────────────────────────── */
/* The bar is fixed (body carries overflow rules that would pin a sticky bar
   to the wrong scroller), so the page starts under it. */
body.bs-has-chrome { padding-top: calc(var(--bs-topbar-h) + env(safe-area-inset-top, 0px)); }
/* Under the frame a screen fills the viewport minus the bar — never a full
   100vh, which would overflow by the bar's height and let a focused field
   scroll the band out of view. */
body.bs-has-chrome #app,
body.bs-has-chrome #app > .bs-shell,
body.bs-has-chrome .bs-linux-shell,
body.bs-has-chrome .bs-linux-view,
body.bs-has-chrome .bs-python-view,
body.bs-has-chrome .bs-c-view,
body.bs-has-chrome .bs-course-screen,
body.bs-has-chrome .linux-category-screen,
body.bs-has-chrome .secplus-module-shell {
  height: auto;
  max-height: none;
  min-height: calc(100vh - var(--bs-topbar-h));
  min-height: calc(100dvh - var(--bs-topbar-h));
}
@media (max-width: 599px) {
  body.bs-has-bottombar { padding-bottom: calc(var(--bs-bottombar-h) + env(safe-area-inset-bottom, 0px)); }
  body.bs-has-chrome #app,
  body.bs-has-chrome #app > .bs-shell,
  body.bs-has-chrome .bs-linux-shell,
  body.bs-has-chrome .bs-linux-view,
  body.bs-has-chrome .bs-python-view,
  body.bs-has-chrome .bs-c-view,
  body.bs-has-chrome .bs-course-screen,
  body.bs-has-chrome .linux-category-screen,
  body.bs-has-chrome .secplus-module-shell {
    min-height: calc(100vh - var(--bs-topbar-h) - var(--bs-bottombar-h));
    min-height: calc(100dvh - var(--bs-topbar-h) - var(--bs-bottombar-h));
  }
}

/* ── Top bar ───────────────────────────────────────────────────────────── */
.bs-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: var(--z-chrome);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  /* Grow into the notch: the bar's visual height stays --bs-topbar-h, plus the
     status-bar inset on devices that have one (0 elsewhere). */
  box-sizing: border-box;
  height: calc(var(--bs-topbar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) calc(24px + env(safe-area-inset-right, 0px)) 0 calc(24px + env(safe-area-inset-left, 0px));
  background: var(--sig-black);
  border-bottom: 1px solid var(--sig-rule);
  color: var(--sig-ink);
}
.bs-topbar[hidden] { display: none; }
.bs-topbar-left  { display: flex; align-items: center; gap: 14px; min-width: 0; }
.bs-topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }

.bs-topbar-brand {
  display: inline-flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 10px 0 6px;
  font-family: var(--font-display); font-weight: 700; font-size: 14px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--orange);
  white-space: nowrap;
  background: none; border: 0; margin: 0; cursor: pointer; /* the wordmark is a plain link home: no hover fill */
}
.bs-topbar-dot { width: 7px; height: 7px; background: currentColor; flex: 0 0 auto; }
/* The kunda glyph, small, turning at the title screen's rate (30s a turn). */
.bs-topbar-glyph {
  display: block; flex: 0 0 auto;
  width: 22px; height: 22px;
  background-color: currentColor;
  -webkit-mask: url('../../kunda-glyph-96.png') center / contain no-repeat;
  mask: url('../../kunda-glyph-96.png') center / contain no-repeat;
  animation: bsGlyphSpin 30s linear infinite;
}
@keyframes bsGlyphSpin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .bs-topbar-glyph { animation: none; } }

.bs-crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; overflow: hidden; }
.bs-crumb {
  display: inline-flex; align-items: center;
  height: 32px; padding: 0 10px;
  font-family: var(--font-display); font-weight: 700; font-size: var(--sig-key-size); letter-spacing: var(--sig-key-track); text-transform: uppercase;
  color: var(--white-dim);
  white-space: nowrap;
}
.bs-crumb.is-current { color: var(--sig-ink); }
/* Crumb keys lean like the "/" between them: the sweep fills a slanted
   parallelogram, not a box. */
.bs-crumbs { --crumb-slant: 10px; }
button.bs-crumb {
  padding: 0 calc(10px + var(--crumb-slant) / 2);
  clip-path: polygon(var(--crumb-slant) 0, 100% 0, calc(100% - var(--crumb-slant)) 100%, 0 100%);
}
.bs-crumb-back { padding: 0 15px; font-size: 20px; line-height: 1; font-weight: 500; }
.bs-crumb-back[hidden] { display: none; }
.bs-crumb-sep { font-family: var(--sig-mono); font-size: 12px; color: var(--sig-ink-mute); padding: 0 2px; }

.bs-clock {
  font-family: var(--sig-mono); font-weight: 500; font-size: 13px; letter-spacing: 0.08em;
  color: var(--sig-ink); font-variant-numeric: tabular-nums;
  opacity: 0; transition: opacity var(--dur) var(--ease);
}
.bs-clock.is-live { opacity: 1; }

/* The keys */
.bs-topbar-key, .bs-key {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: auto; min-width: 0;
  height: 36px; padding: 0 14px;
  margin: 0;
  font: inherit;
  font-family: var(--font-display); font-weight: 700; font-size: 11.5px; letter-spacing: var(--sig-key-track); text-transform: uppercase;
  color: var(--orange);
  clip-path: polygon(var(--sig-notch) 0, 100% 0, 100% calc(100% - var(--sig-notch)), calc(100% - var(--sig-notch)) 100%, 0 100%, 0 var(--sig-notch));
  white-space: nowrap;
}
.bs-key--lg { height: 44px; padding: 0 22px; font-size: 13px; }
.bs-key--block { width: 100%; }
/* .bs-key--filled is defined in css/components/sweep.css (it needs !important to
   beat the varied per-screen button component styles it is applied over). */

/* XP cluster inside the bar: mono numbers, hairline track, rank eyebrow */
.bs-topbar-xp { display: flex; align-items: center; min-width: 0; }
.bs-topbar .xp-cluster { display: flex; flex-direction: column; gap: 4px; min-width: 150px; padding: 0 8px; }
.bs-topbar .xp-row { display: flex; justify-content: space-between; gap: 12px; }
.bs-topbar .xp-lvl, .bs-topbar .xp-nums { font-family: var(--sig-mono); font-size: 11px; letter-spacing: 0.04em; color: var(--sig-ink); }
.bs-topbar .xp-bar-wrap { height: 2px; background: var(--sig-rule); overflow: hidden; }
.bs-topbar .xp-bar-fill { height: 100%; background: var(--orange); transition: width var(--dur-slow) var(--ease); }
.bs-topbar .xp-rank { font-family: var(--font-display); font-weight: 600; font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--orange); text-align: right; }

/* The timer key */
/* The timer wears the filled "hovered" look constantly: accent cell, dark glyph
   and text (overrides .bs-topbar-key's accent text, which would vanish on the fill). */
.pomo-icon { gap: 8px; padding: 0 12px 0 10px; color: var(--accent-on-accent); }
.pomo-icon-svg { width: 20px; height: 20px; flex: 0 0 auto; }
.pomo-icon-arc { transition: stroke-dashoffset 1s linear; }
.pomo-key-label { font-variant-numeric: tabular-nums; min-width: 42px; text-align: left; }
.pomo-icon--active { border-color: var(--orange); }

/* ── Status (timer while running, level + XP) and the MENU key ────────── */
.bs-topbar-status { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bs-topbar .pomo-icon:not(.is-running) { display: none; }
.bs-menu-btn {
  display: inline-flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 14px 0 12px; margin: 0;
  font-family: var(--font-display); font-weight: 700; font-size: 11.5px; letter-spacing: var(--sig-key-track); text-transform: uppercase;
  color: var(--orange);
  clip-path: polygon(var(--sig-notch) 0, 100% 0, 100% calc(100% - var(--sig-notch)), calc(100% - var(--sig-notch)) 100%, 0 100%, 0 var(--sig-notch));
}
.bs-menu-icon { width: 20px; height: 20px; flex: 0 0 auto; fill: currentColor; overflow: visible; }
.bs-menu-line { transform-box: fill-box; transform-origin: center; transition: transform var(--dur) var(--ease-sharp), opacity var(--dur-fast) var(--ease-sharp); }
/* Open: the three lines become a close mark — it answers the click, so it may move. */
.bs-menu-btn.is-open .bs-menu-line--1 { transform: translateY(6px) rotate(45deg); }
.bs-menu-btn.is-open .bs-menu-line--2 { transform: scaleX(0); } /* not opacity: the sweep flip forces descendants to opacity 1 */
.bs-menu-btn.is-open .bs-menu-line--3 { transform: translateY(-6px) rotate(-45deg); }

/* ── The menu: a ruled list under the MENU key ─────────────────────────── */
.bs-navmenu {
  position: fixed;
  top: calc(var(--bs-topbar-h) - 1px);
  right: 24px;
  z-index: var(--z-menu);
  width: 320px;
  background: var(--sig-black);
  border: 1px solid var(--sig-rule-strong);
  border-top: 2px solid var(--orange);
}
.bs-navmenu[hidden] { display: none; }
.bs-navmenu.is-open { animation: bsNavIn var(--dur) var(--ease-sharp) both; }
@keyframes bsNavIn { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
.bs-navmenu-head {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--sig-rule);
  font-family: var(--sig-mono); font-weight: 500; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--sig-ink-dim);
}
.bs-navmenu-list { list-style: none; margin: 0; padding: 0; }
.bs-navmenu-sep { height: 0; border-top: 1px solid var(--sig-rule-strong); margin: 0; }
/* Label and subtitle are stacked in the second column (not a third column
   competing for width), so a longer translation can never collide with the
   note — it just wraps under the label. The number sits on the label's row. */
.bs-navmenu-item {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: baseline;
  gap: 3px 10px;
  width: 100%; min-height: 52px; padding: 14px 16px;
  border-width: 0 0 1px 0; border-color: var(--sig-rule);
  text-align: left;
}
.bs-navmenu-list li:last-child .bs-navmenu-item { border-bottom-width: 0; }
.bs-navmenu-num { grid-column: 1; grid-row: 1; font-family: var(--sig-mono); font-size: 11px; color: var(--orange); }
.bs-navmenu-label { grid-column: 2; grid-row: 1; font-family: var(--font-display); font-weight: 800; font-size: 20px; line-height: 1; letter-spacing: 0.02em; text-transform: uppercase; color: var(--sig-ink); }
.bs-navmenu-note { grid-column: 2; grid-row: 2; font-family: var(--sig-mono); font-size: 11px; letter-spacing: 0.04em; color: var(--sig-ink-mute); white-space: normal; overflow-wrap: anywhere; }
.bs-navmenu-note.is-live { color: var(--orange); }
.bs-navmenu-item.bs-sweep--alert .bs-navmenu-label, .bs-navmenu-item.bs-sweep--alert .bs-navmenu-num { color: var(--sig-alert-ink); }
@media (prefers-reduced-motion: reduce) {
  .bs-navmenu.is-open { animation: none; }
  .bs-menu-line { transition: none; }
}

/* ── Phone bottom bar ──────────────────────────────────────────────────── */
.bs-bottombar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: var(--z-chrome);
  display: none;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  height: calc(var(--bs-bottombar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--sig-black);
  border-top: 1px solid var(--sig-rule);
}
.bs-bottombar[hidden] { display: none; }
.bs-bottombar-key {
  display: flex; align-items: center; justify-content: center;
  height: 100%;
  padding: 0 6px;
  border-width: 0 1px 0 0;
  font-family: var(--font-display); font-weight: 700; font-size: 12px; letter-spacing: var(--sig-key-track); text-transform: uppercase;
  color: var(--orange);
  white-space: nowrap;
}
.bs-bottombar-key:last-child { border-right-width: 0; }
.bs-bottombar-back[hidden] { display: none; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .bs-topbar { gap: 10px; padding: 0 16px; }
  .bs-topbar .xp-cluster { min-width: 120px; }
  .bs-topbar .xp-rank { display: none; }
}
@media (max-width: 860px) {
  .bs-topbar { grid-template-columns: minmax(0, 1fr) auto; }
  .bs-topbar-xp { display: none; }
  .bs-crumb { padding: 0 8px; font-size: 11px; }
  button.bs-crumb { padding: 0 calc(8px + var(--crumb-slant) / 2); }
}
@media (max-width: 599px) {
  .bs-topbar { padding: 0 12px; height: 48px; grid-template-columns: auto minmax(0, 1fr); }
  .bs-menu-btn-label { display: none; }
  .bs-menu-btn { padding: 0 10px; height: 36px; }
  .bs-topbar .pomo-key-label { display: none; }
  .bs-navmenu { left: 0; right: 0; width: auto; border-left: 0; border-right: 0; }
  /* The crumb trail doesn't fit a phone, but its ‹ back key does: show only
     that, ahead of the wordmark, exactly where the desktop puts it. */
  .bs-crumbs { display: flex; order: -1; overflow: visible; }
  .bs-crumbs > :not(.bs-crumb-back) { display: none; }
  .bs-topbar-left { gap: 4px; }
  .bs-crumb-back { width: 40px; height: 40px; padding: 0; justify-content: center; font-size: 24px; clip-path: none; }
  .bs-topbar-brand { padding-left: 4px; }
  /* Back lives in the topbar now, so the bottom bar only appears for real
     screen actions (e.g. an exam's Submit). */
  .bs-bottombar-back { display: none !important; }
  .bs-bottombar:not([hidden]) { display: grid; }
  /* No bar on screen → reserve no space for one. */
  body:not(.bs-has-bottombar) { --bs-bottombar-h: 0px; }
}

}
