.topbar {
  position: sticky; top: 0;
  /* Above the cell stage (z:auto) and any tab-page content,
     so the tabs are always reachable on every page. */
  z-index: 150;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px;
  background: var(--paper);
  border-bottom: 1.5px solid var(--ink);
  overflow: hidden;
}
.topbar::after {
  /* Riso grain over the topbar itself, since the body grain is gone */
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background-image: url("/img/grain.svg");
  background-repeat: repeat;
  mix-blend-mode: multiply;
  opacity: 0.32;
}
.topbar > * { position: relative; z-index: 1; }

.brand {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

/* Mitosis easter egg: triggered from js/header.js. The original mark
   pinches and slides left, the cloned mark fades in and slides right,
   then both slide back together and fuse. */
.brand-mark.is-mitosing { animation: brand-mitosis-a 1.6s ease-in-out; }
.brand-mark-clone {
  position: absolute;
  top: 50%; left: 0;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 1;
  animation: brand-mitosis-b 1.6s ease-in-out;
}
/* Translate distances use percentages so the animation scales with
   the brand-mark size: ~10px at desktop's 30px mark, ~8px at mobile's
   24px mark. No need for separate keyframes per breakpoint. */
@keyframes brand-mitosis-a {
  0%   { transform: scale(1) translateX(0); }
  20%  { transform: scale(1.12, 1.18) translateX(0); }
  45%  { transform: scale(0.94, 0.88) translateX(-34%); }
  70%  { transform: scale(1) translateX(-20%); }
  100% { transform: scale(1) translateX(0); }
}
@keyframes brand-mitosis-b {
  0%   { opacity: 0; transform: translateY(-50%) scale(1) translateX(0); }
  19%  { opacity: 0; }
  20%  { opacity: 1; transform: translateY(-50%) scale(1.12, 1.18) translateX(0); }
  45%  { opacity: 1; transform: translateY(-50%) scale(0.94, 0.88) translateX(34%); }
  70%  { opacity: 1; transform: translateY(-50%) scale(1) translateX(20%); }
  99%  { opacity: 0.4; transform: translateY(-50%) scale(1) translateX(0); }
  100% { opacity: 0; transform: translateY(-50%) scale(1) translateX(0); }
}
.brand small {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}
.brand-mark {
  width: 30px; height: 30px;
  flex-shrink: 0;
}

.tabs {
  display: flex; gap: 2px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.tab {
  position: relative;
  padding: 8px 14px 10px;
  color: var(--ink-dim);
  border-radius: 999px;
  transition: color 0.18s;
}
.tab .num { color: var(--ink-faint); margin-right: 6px; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); }
.tab.active::after {
  content: "";
  position: absolute;
  left: 14px; right: 14px; bottom: 1px;
  height: 3px;
  background: var(--riso-pink);
  box-shadow: 1.5px 1.5px 0 var(--riso-green);
  border-radius: 2px;
}

@media (max-width: 760px) {
  .topbar { padding: 10px 14px; gap: 12px; }
  .brand { font-size: 14px; gap: 9px; flex-shrink: 0; }
  .brand-mark { width: 24px; height: 24px; }
  .brand small { display: none; }
  .tabs {
    /* Horizontal scroll when 6 tabs don't fit; hidden scrollbar */
    gap: 2px;
    font-size: 11px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    justify-content: flex-end;
    padding-bottom: 2px;
    mask-image: linear-gradient(to right, transparent 0, black 12px, black calc(100% - 12px), transparent 100%);
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    /* 38px min height for touch, meets WCAG target size on mobile. */
    padding: 10px 11px 12px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    white-space: nowrap;
  }
  .tab .num { display: none; }
}

@media (max-width: 420px) {
  .topbar { padding: 8px 10px; gap: 8px; }
  .brand { font-size: 13px; gap: 7px; }
  .brand-mark { width: 22px; height: 22px; }
  .tab { padding: 6px 8px 8px; }
}
