/* ========== Globals ========== */
/* Reserve space for bottom-docked bar on mobile */
:root {
  --bottom-bar-space: 0px;
  --topbar-height: 64px;
  --topbar-edge-gutter: .75rem;
  --topbar-link-color: #4c4943;
  --topbar-link-active: #1c1a17;
  --mobile-info-bar-height: 38px;
}
body { padding-bottom: var(--bottom-bar-space); }

/* ========== TopBar shell ========== */
.topbar {
  position: sticky;
  top: 0;
  left: 0; right: 0;
  z-index: 60;
  --topbar-link-color: #f5f5f5;
  --topbar-link-active: #ffffff;
  background: rgba(21,21,21,.92); /* nearly-solid charcoal */
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.topbar__inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* center truly centered */
  align-items: center;
  gap: .5rem;
  padding: .5rem 0;
}
.topbar__slot { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.topbar__slot--left   { justify-content: flex-start; padding-left: var(--topbar-edge-gutter); }
.topbar__slot--center { justify-content: center; text-align: center; }
.topbar__slot--right  { justify-content: flex-end; padding-right: 0; align-items: center; }
/* Normalize vertical alignment of controls in the right slot */
.topbar__slot--right > * { align-self: center; }
.topbar__controls{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 0px;
}
.topbar__search-wrap{
  display: inline-flex;
  align-items: center;
  margin-left: 8px; /* slight separation from chips; no auto-push */
}
.topbar__slot--right .topbar__bench,
.topbar__slot--right .tb-auth,
.topbar__slot--right .topbar__search-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.topbar__home { font-weight: 600; text-decoration: none; color: #222; }
.topbar__nav  { color: #444; text-decoration: none; white-space: nowrap; }

@media (max-width: 700px) {
  .topbar__nav  { color: #444; text-decoration: none; white-space: nowrap; font-size: smaller;}
}

.topbar__nav:hover { text-decoration: underline; }
.topbar__title  { font-weight: 700; font-size: 1.125rem; line-height: 1.2; }
.topbar__metric { font-size: .95rem; color: #333; padding: .1rem .4rem; border-radius: .4rem; background: #ededf0; }

.topbar__inner .topbar__home,
.topbar__inner .topbar__nav,
.topbar__inner .topbar__title,
.topbar__inner .topbar__mobile-title {
  color: #f6f6f6;
}
.topbar__inner .topbar__nav:hover,
.topbar__inner .topbar__home:hover { color: #fff; }
.topbar__inner .topbar__metric {
  color: #f9fafb;
  background: rgba(255,255,255,.12);
}

.topbar__search-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border: 0; background: transparent; cursor: pointer;
  border-radius: .5rem;
  color: #f6f6f6;
  justify-content: center;
  padding-inline: 2px;
  padding-block: 0;
}
.topbar__search-btn:hover { background: rgba(255,255,255,.08); }
.topbar__search-btn:focus-visible { outline: 2px solid #8aa1ff; outline-offset: 2px; }
.topbar__icon { fill: currentColor; color: currentColor; width: 26px; height: 26px; }

/* Debug: visualize right slot layout */
@media (max-width: 700px){
  .topbar__search-wrap{ margin-left: 1px; }
}

/* ========== Chips row (year view) ========== */
.topbar__row--chips {
  border-top: 1px solid #e7e7ea;
  padding: 4px .5rem;
  background: #f6f6f7; /* keep chips bar light */
  color: var(--ink, #222);
}
.topbar__chips {
  max-width: var(--wrap); margin: 0 auto;
  display: flex; gap: 8px; overflow: auto; -webkit-overflow-scrolling: touch;
  padding: 4px 0;
}
.topbar__chip {
  /* Drive styling via the shared .chip tokens */
  --chip-color: #0b57d0;
  --chip-border: 1px solid var(--chip-color);
  --chip-bg: color-mix(in srgb, var(--chip-color) 7%, white);
  --chip-ink: color-mix(in srgb, var(--chip-color) 92%, black);
  --chip-radius: 999px;
  --chip-py: 6px;
  --chip-px: 10px;
  --chip-fz: 12px;

  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: 0 1px 0 rgba(0,0,0,.04), inset 0 0 0 1px color-mix(in srgb, var(--chip-color) 8%, transparent);
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
}
.topbar__chip:hover { background: color-mix(in srgb, var(--chip-color) 14%, white); }
.topbar__chip[aria-selected="true"] {
  background: var(--chip-color); color: #fff; border-color: var(--chip-color);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--chip-color) 25%, transparent);
}

.topbar__count{
  margin-left: 0px;
  opacity: .8;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 420px){
  .topbar__count{ margin-left: 0px; }
}

/* Centerline (year flanked by prev/next) */
.topbar__centerline { display: inline-flex; align-items: center; gap: .75rem; flex-wrap: nowrap; }
.topbar__nav--inline { font-weight: 500; font-size: .95rem; white-space: nowrap; }
.topbar__nav--inline.topbar__nav--prev,
.topbar__nav--inline.topbar__nav--next {
  color: #bebcbc;
}
@media (max-width: 420px) { .topbar__nav--inline .topbar__nav-text { display: none; } }

/* Small era pill next to year */
.topbar__era {
  display: inline-block; margin-left: .5rem; padding: .1rem .4rem;
  font-size: .75rem; line-height: 1.1;
  border: 1px solid var(--era-color, #d0d0d4); border-radius: .5rem;
  color: color-mix(in srgb, var(--era-color, #d0d0d4) 88%, black);
  background: color-mix(in srgb, var(--era-color, #d0d0d4) 12%, white);
}

/* ========== Search panel (shared rules) ========== */
.topbar__search[hidden] { display: none !important; }

.topbar__search-form {
  max-width: 960px; margin: 0 auto;
  display: grid; grid-template-columns: 18px 1fr auto; gap: .5rem; align-items: center;
}
.topbar__search-input {
  font: inherit; padding: .6rem .7rem; border: 1px solid #d7d7dc; border-radius: .5rem; background: #fff;
}
.topbar__search-input:focus { outline: 2px solid #8aa1ff; outline-offset: 1px; }
.topbar__search-cancel {
  border: 0; background: transparent; padding: .4rem .6rem; cursor: pointer; color: #666; border-radius: .4rem;
}
.topbar__search-cancel:hover { background: #ededf0; }

.topbar__suggest { position: relative; max-width: var(--wrap); margin: 0 auto; padding: 0 .5rem .5rem; }
.topbar__panel {
  border: 1px solid #e7e7ea; border-radius: 10px; background: #fff;
  box-shadow: 0 8px 24px rgba(0,0,0,.08); overflow: hidden;
}
.topbar__group { border-top: 1px solid #f1f1f3; }
.topbar__group:first-child { border-top: 0; }
.topbar__group-label { font-size: 12px; color: #6b7280; padding: 6px 10px; background: #fafafa; }
.topbar__item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; text-decoration: none; color: inherit; cursor: pointer;
}
.topbar__item:hover, .topbar__item.is-active { background: #f3f4f6; }
.topbar__item .k { margin-left: auto; font-size: 12px; color: #9ca3af; }

/* ========== Desktop (>= 701px): bar at top, panel under it ========== */
@media (min-width: 701px) {
  .topbar {
    position: fixed; /* keep bar fixed at top, always visible */
    top: 0; left: 0; right: 0;
    z-index: 70;
  }

  .topbar__search {
    position: absolute; /* under the bar */
    left: 0; right: 0; top: 100%;
    background: #fff;
    border-bottom: 1px solid #e7e7ea;
    box-shadow: 0 8px 24px rgba(0,0,0,.08);
    padding: .5rem;
    z-index: 80;
  }

  .topbar--open .topbar__inner { opacity: .25; } /* dim while searching */
  .topbar__suggest { padding: 0; }
  .topbar__panel { max-height: 320px; overflow: auto; }
}

/* ========== Mobile (<= 700px): bar docked at bottom, panel from bottom ========== */
@media (max-width: 700px) {
  .topbar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; width: 100%;
    border-top: 1px solid #e7e7ea; border-bottom: none;
    padding-bottom: max(0px, env(safe-area-inset-bottom));
    background: rgba(21,21,21,.92);
    display: flex; flex-direction: column-reverse; /* chips row above main row */
    z-index: 90;
  }

  .topbar__search {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    padding: .35rem .5rem calc(8px + env(safe-area-inset-bottom));
    background: #f6f6f7;
    border-top: 1px solid #e7e7ea; border-bottom: none;
    z-index: 95;
  }

  .topbar--open .topbar__inner { visibility: hidden; } /* hide main row while searching */

  .topbar__inner { gap: .25rem; padding: .4rem 0; }
  .topbar__title { font-size: 1rem; }
  .topbar__metric { font-size: .9rem; }
  .topbar__centerline { gap: .4rem; } /* tighter spacing on mobile */
  .topbar__nav--inline span[aria-hidden="true"] { font-weight: 700; } /* thicker arrows on mobile */

  .topbar__panel { max-height: 45vh; overflow: auto; }
}

/* ========== Tiny tweaks ========== */
@media (max-width: 420px) {
  .topbar__nav--inline .topbar__nav-text { display: none; }
}
.topbar--open .topbar__row--chips { display: none; }

/* --- TopBar auth controls --- */
.tb-right{ display:flex; align-items:center; gap:8px }
.tb-auth .chip{ gap: 6px; }
.tb-initial{
  display: inline-flex;
  align-items: center;
}
.tb-username{
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  font-weight: 600;
}
.tb-auth{ position:relative }
.tb-auth-panel{
  position:absolute; right:0; top:calc(100% + 6px);
  border:1px solid var(--line); border-radius:12px; background:#fff;
  box-shadow:0 6px 24px rgba(0,0,0,.08); min-width:260px; z-index:60;
}
.tb-auth-inner{ padding:12px; display:grid; gap:10px; }
.tb-field{ display:grid; gap:4px; }
.tb-label{ font-size:12px; color:var(--muted) }
.tb-field input{
  width:100%; padding:8px 10px; border:1px solid var(--line); border-radius:8px; font:inherit;
}
.tb-actions{ display:flex; gap:8px; align-items:center; flex-wrap:wrap }
.tb-auth-link{ text-decoration:none; }
.tb-auth-link:hover{ text-decoration:underline }

@media (max-width: 700px){
  .tb-auth{ position:static }
  .tb-auth-panel{
    position:fixed; left:0; right:0; bottom:0; top:auto;
    border-radius:16px 16px 0 0; border-left:0; border-right:0; border-bottom:0;
    box-shadow:0 -8px 24px rgba(0,0,0,.12);
  }
  .tb-username { display: none !important; }
  .tb-avatar { width: 22px; height: 22px; border-radius:6px; }
}

@media (min-width: 701px){
  .tb-initial { display: none !important; } /* desktop: hide initial, show truncated name */
  .tb-auth .topbar__bench-toggle{
    justify-content: center;
    gap: 0;
  }
  .tb-username{
    margin-left: 0;
    text-align: center;
  }
}

/* --- Bench dropdown (topbar) --- */
.topbar__bench{
  position: relative;
  display:flex;
  align-items:center;
}
.topbar__bench-toggle{
  gap:2px;
  border-radius: 999px;
  padding: 8px 12px;  /* taller, slightly narrower pill */
}
.tb-auth .topbar__bench-toggle{
  padding: 4px 12px;  /* match bench height/line exactly */
  border-radius: 999px;
  min-width: unset;
  justify-content: center;
}
.topbar__bench-count{
  margin-left:1px;
  font-weight:400;
  color:var(--muted);
}
.topbar__bench-toggle--flash{
  box-shadow:0 0 0 2px color-mix(in srgb, #0b57d0 60%, transparent);
  animation: benchPulse .9s ease-out 1;
}
@keyframes benchPulse{
  0%{ box-shadow:0 0 0 0 color-mix(in srgb, #0b57d0 60%, transparent); }
  70%{ box-shadow:0 0 0 6px color-mix(in srgb, #0b57d0 20%, transparent); }
  100%{ box-shadow:0 0 0 0 color-mix(in srgb, #0b57d0 0%, transparent); }
}
.year-bench[hidden]{ display:none !important; }
.topbar__bench .year-bench{
  right:0;
  top:calc(100% + 6px);
  padding:12px;
  min-width:320px;
  max-width:360px;
  z-index:80;
}
.year-bench__box{
  display:flex;
  flex-direction:column;
  gap:8px;
  font-size: var(--fs-small);
}
.year-bench__row{
  display:grid;
  grid-template-columns: auto minmax(0,1fr) auto auto;
  align-items:center;
  gap:8px;
  cursor: grab;
}
.year-bench__drag{
  font-size:14px;
  color:var(--muted);
  user-select:none;
  line-height:1;
  padding-inline:4px;
  cursor: grab;
  touch-action: none;
}
.year-bench__row.is-dragging{
  opacity:.7;
}
.year-bench__actions{
  display:flex;
  align-items:center;
  gap:6px;
}
.year-bench__heading{
  grid-column: 1 / -1;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  margin-bottom:2px;
}
.year-bench__title{
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:.08em;
  color:var(--muted);
}
.year-bench__heading-actions{
  display:flex;
  align-items:center;
}
.year-bench__hide{
  border:0;
  background:transparent;
  padding:2px 6px;
  margin:0;
  font-size:11px;
  letter-spacing:.06em;
  text-transform:uppercase;
  color:var(--muted);
  border-radius:999px;
  cursor:pointer;
  transition: color .15s ease, background-color .15s ease;
}
.year-bench__hide:hover,
.year-bench__hide:focus-visible{
  outline:none;
  color:var(--ink);
  background:color-mix(in srgb, var(--color, #9ca3af) 8%, #f3f4f6);
}
.year-bench__name{
  min-width:0;
  font-size:13px;
  line-height:1.3;
  color:var(--ink);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  align-self:center;
}
.year-bench__name--empty{
  color:var(--muted);
  font-style:italic;
}
.year-bench__label{ display:inline; }
.year-bench__inspect,
.year-bench__remove{
  border:0;
  background:transparent;
  padding:0;
  margin:0;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:22px;
  height:22px;
  border-radius:999px;
  color:var(--muted);
  cursor:pointer;
  transition: color .15s ease, background-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.year-bench__inspect svg{ width:16px; height:16px; }
.year-bench__inspect:hover,
.year-bench__inspect:focus-visible{
  outline:none;
  color:var(--ink);
  background:color-mix(in srgb, var(--color, #9ca3af) 10%, #f3f4f6);
  box-shadow:0 0 0 1px color-mix(in srgb, var(--color, #9ca3af) 35%, var(--line));
  transform: translateY(-0.5px);
}
.year-bench__remove span{ font-size:16px; line-height:1; }
.year-bench__remove:hover:not(:disabled),
.year-bench__remove:focus-visible:not(:disabled){
  outline:none;
  color:var(--danger);
  background:color-mix(in srgb, var(--danger) 5%, #fef2f2);
  box-shadow:0 0 0 1px color-mix(in srgb, var(--danger) 35%, transparent);
  transform: translateY(-0.5px);
}
.year-bench__remove:disabled{
  opacity:.3;
  cursor:default;
}
.year-bench__compare{
  margin-top:4px;
  display:flex;
  justify-content:space-between;
  gap:8px;
  width:100%;
  flex-wrap:wrap;
}
.year-bench__compare-btn{ width:100%; }
.year-bench__note{
  font-size: var(--fs-small);
  color: var(--muted);
  flex:1 1 auto;
  text-align:left;
}
.year-bench__message{
  margin-top:6px;
  padding:6px 8px;
  font-size:12px;
  line-height:1.3;
  color:#92400e;
  background:#fffbeb;
  border-radius:10px;
  border:1px solid color-mix(in srgb,#fbbf24 45%, white);
  box-shadow:0 1px 4px rgba(0,0,0,.04);
  opacity:0;
  transform:translateY(2px);
  transition:opacity .25s ease, transform .25s ease;
}
.year-bench__message.is-visible{
  opacity:1;
  transform:translateY(0);
}
.year-bench__search-input{ width:100%; }
.year-bench__suggest{ margin-top:6px; }
.year-bench__suggest-panel{
  border-radius:10px;
  overflow:hidden;
}
.year-bench__suggest-panel .year-bench__suggest-item{
  border:0;
  background:transparent;
  width:100%;
  text-align:left;
  padding:6px 8px; /* a bit more compact than topbar */
  font-size: var(--fs-small);
}
.year-bench__suggest-panel .year-bench__suggest-item span{
  pointer-events:none;
}
.year-bench__suggest-panel .year-bench__suggest-item:hover,
.year-bench__suggest-panel .year-bench__suggest-item:focus-visible{
  background:#f3f4f6;
}
.year-bench.year-bench--highlight{
  box-shadow:0 0 0 2px color-mix(in srgb, var(--ink) 40%, transparent), 0 12px 30px rgba(0,0,0,.16);
}
@media (max-width: 700px){
  .topbar__bench .year-bench{
    position:fixed;
    left:10px;
    right:10px;
    bottom:calc(var(--bottom-bar-space, 0px) + 12px);
    top:auto;
  }
}

/* ========== Main nav links (Home / Sources / About) ========== */
/* One class for all three anchors. Keep using <span class="home-text"> for labels. */
.topbar__home,
.topbar__mobile-title .mobile-only {
  display:inline-flex;
  align-items:center;
  gap:.35rem;
  font-weight:600;
  text-decoration:none;
  color: var(--ink, #222);
  font-family: var(--font-ui, Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif);
  transition: color .2s ease, opacity .2s ease;
}
.topbar__home .icon{
  line-height:1;
  font-size:1.05rem; /* unify icon size */
  display:inline-block;
  vertical-align:middle;
}
.topbar__home:hover{ text-decoration:none; opacity:.9 }

/* Inactive vs active colours (simple, elegant) */
.topbar__home { color: var(--topbar-link-color); }                 
.topbar__home.is-active { color: var(--topbar-link-active); font-weight:700; } /* active deep charcoal */

/* Subtle hover only on inactive */
@media (hover: hover){
  .topbar__home:not(.is-active):hover { color:#555; }
}

/* Separator between links */
.topbar__sep { display:inline-block; margin:0 .5rem; color:#b5b0a8; opacity:.9; }

/* Desktop: always show labels + separators */
@media (min-width: 701px){
  .topbar .home-text,
  .topbar__sep { display:inline !important; }
  .topbar__mobile-title .mobile-only { display:none !important; }
}

/* Mobile: icons only (hide labels + separators, tighten gaps) */
@media (max-width: 700px){
  .topbar .home-text,
  .topbar__sep { display:none !important; }
  .topbar__home { gap:.05rem; }
  .topbar__home .home-text { display:none !important; }   /* mobile icons-only */
  .topbar__slot--left .home-text { display:inline !important; }
}
