/* ========== Globals ==========
   Reserve space for bottom-docked bar on mobile */
:root {
  --bottom-bar-space: 0px;
}
body { padding-bottom: var(--bottom-bar-space); }

/* ========== TopBar shell ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  background: #f6f6f7; /* off-grey */
  border-bottom: 1px solid #e7e7ea;
}
.topbar__inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* center truly centered */
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
}
.topbar__slot { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.topbar__slot--left   { justify-content: flex-start; }
.topbar__slot--center { justify-content: center; text-align: center; }
.topbar__slot--right  { justify-content: flex-end; }

.topbar__home { font-weight: 600; text-decoration: none; color: #222; }
.topbar__nav  { color: #444; text-decoration: none; white-space: nowrap; }
.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__search-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border: 0; background: transparent; cursor: pointer;
  border-radius: .5rem;
}
.topbar__search-btn:focus-visible { outline: 2px solid #8aa1ff; outline-offset: 2px; }
.topbar__icon { fill: currentColor; color: #333; }

/* ========== Chips row (year view) ========== */
.topbar__row--chips { border-top: 1px solid #e7e7ea; padding: 4px .5rem; }
.topbar__chips {
  max-width: 980px; margin: 0 auto;
  display: flex; gap: 8px; overflow: auto; -webkit-overflow-scrolling: touch;
  padding: 4px 0;
}
.topbar__chip {
  --chip-color: #0b57d0;
  border: 1px solid var(--chip-color);
  background: color-mix(in srgb, var(--chip-color) 7%, white);
  color: color-mix(in srgb, var(--chip-color) 92%, black);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 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; }
@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) ========== */
/* Rely on the [hidden] attribute so JS can toggle; ensure it actually hides */
.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; }

/* Suggestions dropdown */
.topbar__suggest { position: relative; max-width: 980px; 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: sticky; top: 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; /* above page content */
  }

  /* keep inner visible while searching on desktop, but dim */
  .topbar--open .topbar__inner { opacity: .25; }
  .topbar__suggest { padding: 0; }
  .topbar__panel { max-height: 320px; overflow: auto; }
}

/* ========== Mobile (<= 700px): bar docked at bottom, panel from bottom ========== */
@media (max-width: 700px) {
  /* Dock the whole bar to bottom */
  .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: #f6f6f7;
    display: flex; flex-direction: column-reverse; /* chips row above main row */
    z-index: 90;
  }

  /* Search overlay from bottom */
  .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;
  }

  /* hide main row while the search is open (keeps layout simple) */
  .topbar--open .topbar__inner { visibility: hidden; }

  /* tighter spacing on mobile */
  .topbar__inner { gap: .25rem; padding: .4rem .5rem; }
  .topbar__title { font-size: 1rem; }
  .topbar__metric { font-size: .9rem; }

  /* Suggest panel should be tall enough to scroll */
  .topbar__panel { max-height: 45vh; overflow: auto; }
  .topbar.is-auth .tb-username { display: none; }
  
}

/* ========== Tiny tweaks ==========
   Hide year text on the flanks for very narrow screens */
@media (max-width: 420px) {
  .topbar__nav--inline .topbar__nav-text { display: none; }
}

/* When search is open, hide chips row (saves space) */
.topbar--open .topbar__row--chips { display: none; }


/* --- TopBar auth controls --- */
.tb-right{ display:flex; align-items:center; gap:8px }

/* Small pill button (reuses your chip look) */
.tb-chip{
  display:inline-flex; align-items:center; gap:8px;
  background: var(--chip); border:1px solid var(--line);
  border-radius:999px; padding:4px 10px; font-size:12px; cursor:pointer;
}

/* Avatar circle for signed-in state */
.tb-avatar{
  width:20px; height:20px; border-radius:999px; border:1px solid var(--line);
  background:#f6f7f9; display:grid; place-items:center; font-weight:700;
}

/* Panel shell (positioned under button on desktop; bottom-up on mobile like search) */
.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;
}

/* Panel contents */
.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 }

/* Mobile: make auth panel behave like your search overlay (bottom-docked) */
@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);
  }
}

/* Mobile: show only avatar (hide username text) */
@media (max-width: 700px){
  .tb-username { display: none !important; }
  .tb-chip { padding: 6px 10px; }
  .tb-avatar { width: 22px; height: 22px; }
}

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