/* ===== Root & Reset ===== */

:root {
  --years-width: 50px;
  --decades-width: 46px;
  --events-width: 140px;
  --places-width: 180px;
  --horiz-edge-offset: 3rem;
  --vert-edge-offset: 1.5rem;
  /* quick-actions sits at vert-edge-offset, lifted by translateY(-25%) of its
     own height (icon + vertical padding); this lands search-options 1rem
     below its actual bottom edge. */
  --search-options-top: calc(var(--vert-edge-offset) + 0.75 * (34px + 1rem) + 1rem);
  --search-options-max-height: 600px;
  --sidebar-list-max-height: calc(var(--search-options-max-height) - 2rem);
  --item-img-max-size: 70%;

  --color-text: #332b22;
  --color-bg: #fff;
  --color-muted: #666;
  --color-faint: #999;
  --color-border: #ccc;
  --color-hover: #f0f0f0;
  --color-accent: #ff8c00;
  --color-accent-border: #e67300;

  --nav-active-bg: var(--color-hover);
  --nav-active-fg: var(--color-text);
  --nav-active-hover-bg: var(--color-border);

  --font-family-sans-serif: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --font-size-big-label: 2.1rem;

  --shadow-card: rgba(0, 0, 0, 0.24) 0px 3px 8px;
}

* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

button {
  outline: none;
  user-select: none;
  touch-action: manipulation;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 400;
}

img,
svg {
  user-select: none;
  -webkit-user-drag: none;
}

html,
body {
  overscroll-behavior: none;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family-sans-serif);
  color: var(--color-text);
  background: var(--color-bg);
  height: 100dvh;
  overflow: hidden;
}

/* ===== App Shell ===== */

#app {
  position: relative;
  height: 100dvh;
  min-width: 1200px;
  margin: 0 auto;
  transform: translateZ(0);
}

#page-content {
  --pc-margin: 1rem;
  --pc-height: calc(100dvh - (2 * var(--vert-edge-offset)));

  position: relative;
  margin: var(--pc-margin);
  height: var(--pc-height);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background-color: var(--color-bg);

  &::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 10%;
    background: linear-gradient(to top, var(--color-bg), transparent);
    pointer-events: none;
  }
}

/* ===== Site Title ===== */

#logo {
  position: fixed;
  top: var(--vert-edge-offset);
  left: 50%;
  transform: translateX(-50%);
  text-align: left;
  text-transform: uppercase;
  cursor: pointer;
  font-size: 1.4rem;
  font-family: 'Bungee', sans-serif;
  z-index: 10;

  &::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 65%;
    height: 70%;
    border-radius: 50%;
    border-style: solid;
    border-color: var(--color-text);
    border-width: 0 4px;
    transform: translate(-50%, -50%) rotate(-20deg);
    z-index: -1;
    pointer-events: none;
  }
}

/* ===== Quick Actions (favorite + randomize) ===== */

#quick-actions {
  position: fixed;
  top: var(--vert-edge-offset);
  left: var(--horiz-edge-offset);
  transform: translateY(-25%);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background-color: var(--color-bg);
  box-shadow: var(--shadow-card);
  z-index: 10;
}

#search-close {
  display: none;
}

/* ===== Icon Buttons (misc controls) ===== */

.icon-shortcut {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--color-text);
  cursor: pointer;
  padding: 0;
  transition: transform 0.5s cubic-bezier(0.34, 2.6, 0.64, 1);

  & svg {
    width: 34px;
    height: 34px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
  }

  &.active {
    color: var(--color-accent);

    & svg {
      fill: currentColor;
      stroke: var(--color-accent-border);
    }
  }

  &.bounce {
    animation: icon-shortcut-bounce 0.32s;
  }

  &.pop {
    animation: icon-shortcut-pop 0.32s;
  }
}

#favorites-toggle svg {
  stroke-linejoin: round;
}

#sort-order-btn {
  &.hidden {
    display: none;
  }

  & svg {
    transition: transform 0.2s ease;
  }

  &.asc svg {
    transform: rotate(180deg);
  }
}

#randomize-btn {
  transform: translateY(1px) rotate(-8deg);

  &.rolling {
    animation: dice-roll 0.45s ease-out;
  }
}

.spark {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--size, 10px);
  height: var(--size, 10px);
  margin: calc(var(--size, 10px) / -2);
  color: var(--color-accent);
  pointer-events: none;
  z-index: 20;
  animation: spark-burst var(--duration, 0.5s) ease-out forwards;
  animation-delay: var(--delay, 0s);

  & svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
  }
}

/* ===== Filter Title Bar ===== */

#filter-title-bar {
  position: fixed;
  top: var(--vert-edge-offset);
  right: var(--horiz-edge-offset);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 10;
}

#filter-title-group {
  position: relative;
}

#filter-title {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.025rem;
  margin: 0;
}

#filter-title-bar:has(#item-favorite.visible) #filter-title {
  cursor: pointer;
}

#item-meta {
  position: absolute;
  top: calc(100% + 0.3rem);
  right: 0;
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--color-muted);
  display: none;

  &.visible {
    display: block;
  }
}

#item-favorite {
  position: relative;
  top: auto;
  right: auto;
  width: 28px;
  height: 28px;
  opacity: 1;
  display: none;

  &.visible {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* ===== Attribution ===== */

#attribution {
  position: fixed;
  bottom: var(--vert-edge-offset);
  right: var(--horiz-edge-offset);
  font-size: 0.75rem;
  color: var(--color-text);
  letter-spacing: -0.01rem;
  background-color: var(--color-bg);
  z-index: 10;
  transform: translateY(-100%);

  & a {
    color: inherit;
    text-decoration: underline;
  }
}

/* ===== Hotkey Legend ===== */

#hotkey-legend {
  position: fixed;
  bottom: var(--vert-edge-offset);
  left: var(--horiz-edge-offset);
  transform: translateY(-100%);
  display: flex;
  align-items: center;
  gap: 0.9rem;
  font-size: 0.75rem;
  color: var(--color-text);
  letter-spacing: -0.01rem;
  background-color: var(--color-bg);
  z-index: 10;
}

.hotkey {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.hotkey kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--color-hover);
  border: 1px solid var(--color-border);
  font-family: inherit;
  font-size: inherit;
  color: var(--color-text);
}

/* ===== Search Options ===== */

#search-options {
  position: fixed;
  top: var(--search-options-top);
  left: var(--horiz-edge-offset);
  display: flex;
  align-items: stretch;
  gap: 0.3rem;
  max-height: var(--search-options-max-height);
  z-index: 15;
  transition: opacity 0.15s ease-in, transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: top left;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);

  &.open {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
  }

  &.open.disabled {
    opacity: 0.25;
    cursor: pointer;
    transform: translateX(10%) rotate(-2deg) scale(0.88);

    & .nav-item {
      pointer-events: none;
    }
  }
}

.nav-filter {
  max-height: var(--sidebar-list-max-height);
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--color-bg);
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-behavior: smooth;
  transition: transform 0.2s ease;

  &::-webkit-scrollbar {
    display: none;
  }
}

/* ===== Shared Nav Item =====
   Base look for every clickable row in the search panel (years, decades,
   events, places). .year-item/.event-item/.decade-item carry no styling of
   their own -- they're query hooks for script.js. .event-group-label and
   .all-nav-item are modifiers layered on top. */

.nav-item {
  flex: 0 0 auto;
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  border: solid 1px transparent;
  border-radius: 0.25rem;
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  &.active {
    background: var(--color-text);
    color: var(--color-bg);
  }
}

#time-events-group {
  display: flex;
  align-items: flex-start;
  gap: 0.3rem;
  padding: 1rem;
  border: solid 1px transparent;
  border-radius: 0.5rem;
  background-color: var(--color-bg);
  box-shadow: var(--shadow-card);
  transform: scale(0.98);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.15s ease, border-color 0.15s ease;
}

/* ===== Timeline Nav ===== */

#timeline-filters {
  width: calc(var(--years-width) + var(--decades-width));
}

#timeline-list {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.decade-group {
  display: flex;

  &:has(.decade-item.active) .year-item {
    background-color: var(--color-text);
    color: var(--color-bg);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;

    &:not(:first-child) {
      border-top-right-radius: 0;
    }

    &:not(:last-child) {
      border-bottom-right-radius: 0;
    }
  }
}

.years-col {
  width: var(--years-width);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
}

.decade-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.4rem;
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.08);
  z-index: 2;

  &.active {
    background: var(--color-text);
    color: var(--color-bg);
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  & .decade-label {
    display: inline-block;
    transform: rotate(-90deg);
    white-space: nowrap;
  }
}

/* ===== Event Nav ===== */

#events-filter {
  width: var(--events-width);
}

#events-list {
  display: flex;
  flex-direction: column;
}

/* ===== Places Nav ===== */

#places-filter {
  width: var(--places-width);
  padding: 1rem;
  border: solid 1px transparent;
  border-radius: 0.5rem;
  background-color: var(--color-bg);
  box-shadow: var(--shadow-card);
  transform: scale(0.98);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.15s ease, border-color 0.15s ease;
}

#places-list {
  display: flex;
  flex-direction: column;
}

.event-item {
  text-align: left;

  &.active:not(.event-group-label):not(.all-nav-item) {
    &:has(+ .event-item.active) {
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
    }
  }

  &.event-group-label {
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    margin-top: 0.1rem;
    padding-left: 0.25rem;

    &.active {
      background: var(--color-text);
      color: var(--color-bg);

      &:has(+ .event-item.active) {
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
      }
    }
  }
}

/* An active child that comes right after an active group-label or another
   active child (i.e. it's not the first item in an active group) squares
   off its top corners so the group reads as one continuous block. */
.event-group-label.active + .event-item.active:not(.event-group-label):not(.all-nav-item),
.event-item.active:not(.event-group-label):not(.all-nav-item) + .event-item.active:not(.event-group-label):not(.all-nav-item) {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

/* Same "part of an active group" check as above, but also requires no
   active sibling after it -- i.e. this is the last child in the group.
   Gets extra bottom padding to give the block some breathing room at its end. */
.event-group-label.active + .event-item.active:not(.event-group-label):not(.all-nav-item):not(:has(+ .event-item.active)),
.event-item.active:not(.event-group-label):not(.all-nav-item) + .event-item.active:not(.event-group-label):not(.all-nav-item):not(:has(+ .event-item.active)) {
  padding-bottom: 0.5rem;
}

.event-group-icon {
  height: 20px;
  width: auto;
  max-width: 36px;
  object-fit: contain;
  flex: 0 0 auto;

  &.event-group-icon--mlb {
    height: 16px;
  }
}

.all-nav-item {
  position: sticky;
  top: 0;
  z-index: 5;
  text-align: left;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: -0.04rem;
  padding-left: 0.25rem;

  &.active {
    background: var(--color-text);
    color: var(--color-bg);
  }
}

/* Time and events are treated as one linked pair against places: filtering
   by either one recesses the places column, and filtering by a place
   recesses time and events instead. With everything at "All", nothing
   recesses. Pure state re-eval off the .active class updateActiveButtons()
   already maintains -- no click-time bookkeeping needed. */
#search-options:has(#timeline-list .active:not(.all-nav-item)) #places-filter,
#search-options:has(#events-list .active:not(.all-nav-item)) #places-filter {
  transform: scale(0.95) rotate(1deg) translateX(-10%);
  opacity: 0.9;
  z-index: 0;
}

#search-options:has(#timeline-list .active:not(.all-nav-item)) #time-events-group,
#search-options:has(#events-list .active:not(.all-nav-item)) #time-events-group {
  transform: scale(1);
  border-color: var(--color-border);
  z-index: 1;
}

#search-options:has(#places-list .active:not(.all-nav-item)) #time-events-group {
  transform: scale(0.95) rotate(-1deg) translateX(10%);
  opacity: 0.9;
  z-index: 0;
}

#search-options:has(#places-list .active:not(.all-nav-item)) #places-filter {
  transform: scale(1);
  border-color: var(--color-border);
  z-index: 1;
}

/* ===== Grid & Cards ===== */

main#grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, 160px);
  gap: 0.5rem;
  align-content: safe center;
  justify-content: safe center;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 0 calc(0.1 * var(--horiz-edge-offset));
  padding-top: calc((1.5 * var(--font-size-big-label)) + var(--vert-edge-offset));
  padding-bottom: calc(0.1 * var(--pc-height));

  &::-webkit-scrollbar {
    display: none;
  }

  &.favorites-view {
    cursor: pointer;
  }

  &.hidden {
    display: none;
  }

  &:has(.empty-state) {
    padding-top: 0;
    padding-bottom: 0;
  }
}

.card {
  position: relative;
  padding: 1.6rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.6rem;
  border-radius: 0.2rem;
  border: solid 2px transparent;
  cursor: zoom-in;

  &:has(.favorite-btn.favorited) {
    border-color: var(--color-accent-border);
  }

  &.active {
    border-color: var(--color-text);
    box-shadow: var(--shadow-card);

    &:has(.favorite-btn.favorited) {
      border-color: var(--color-accent-border);
    }

    & .meta {
      visibility: visible;
    }

    & .favorite-btn {
      opacity: 1;
    }
  }

  & img {
    width: 100%;
    height: 110px;
    object-fit: contain;
  }

  & .meta {
    position: absolute;
    bottom: 0.8rem;
    text-align: center;
    font-size: 0.7rem;
    font-family: var(--font-family-sans-serif);
    font-weight: 600;
    letter-spacing: -0.03rem;
    color: var(--color-muted);
    transform: translateY(50%);
  }
}

.favorite-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 27.5px;
  height: 27.5px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--color-faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, transform 0.25s cubic-bezier(0.34, 2.6, 0.64, 1);

  & svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linejoin: round;
  }

  &.favorited {
    opacity: 1;
    color: var(--color-accent);

    & svg {
      fill: currentColor;
      stroke: var(--color-accent-border);
    }
  }

  &.pop {
    animation: icon-shortcut-pop 0.32s;
  }
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--color-text);
  padding: 3rem 0;
  font-size: 1.2rem;
  letter-spacing: -0.025rem;
}

/* ===== Item Display (Lightbox) ===== */

#item-display {
  position: relative;
  display: none;
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
  cursor: pointer;

  &.visible {
    display: flex;
  }
}

#item-img {
  max-width: var(--item-img-max-size);
  max-height: var(--item-img-max-size);
  object-fit: contain;
}

.logo-detail-nav {
  position: absolute;
  bottom: var(--vert-edge-offset);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--color-text);
  cursor: pointer;
  padding: 0;
  transition: transform 0.25s cubic-bezier(0.34, 2.6, 0.64, 1);

  & svg {
    width: 64px;
    height: 64px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
  }

  &:disabled {
    opacity: 0.2;
    cursor: default;
  }

  &.hidden {
    display: none;
  }
}

#item-prev {
  right: calc(var(--horiz-edge-offset) + 72px);
}

#item-next {
  right: var(--horiz-edge-offset);
}

/* ===== Share ===== */

#share-favorites {
  position: relative;
  display: none;
  align-items: center;

  &.visible {
    display: flex;
  }
}

#share-feedback {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.3rem);
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--color-muted);
  opacity: 0;
  transition: opacity 0.15s ease;

  &.visible {
    opacity: 1;
  }
}

/* Only apply hover effects on devices with a real mouse/trackpad, so a tap
   on a touchscreen laptop or hybrid device can't leave a hover state stuck. */
@media (hover: hover) and (pointer: fine) {
  .icon-shortcut:hover {
    transform: scale(1.2);
  }

  #randomize-btn:hover {
    transform: translateY(1px) rotate(-8deg) scale(1.2);
  }

  .nav-item:hover {
    border: solid 1px var(--color-text);
  }

  .nav-item.active:hover {
    background: var(--color-text);
    color: var(--color-bg);
  }

  .decade-item.active:hover,
  .event-group-label.active:hover,
  .all-nav-item.active:hover {
    background: var(--color-text);
  }

  .logo-detail-nav:hover:not(:disabled) {
    transform: scale(1.2);
  }

  .favorite-btn:hover {
    transform: scale(1.2);
    color: var(--color-accent);
  }

  #filter-title-bar:has(#filter-title:hover) #item-favorite {
    transform: scale(1.2);
    color: var(--color-accent);
  }

  .card:hover {
    border-color: var(--color-text);
    box-shadow: var(--shadow-card);

    &:has(.favorite-btn.favorited) {
      border-color: var(--color-accent-border);
    }

    & .meta {
      visibility: visible;
    }

    & .favorite-btn {
      opacity: 1;
    }
  }
}

/* ===== Animations ===== */

@keyframes dice-roll {
  0% {
    transform: translateY(1px) rotate(-8deg);
  }
  40% {
    transform: translateY(-16px) rotate(420deg);
  }
  100% {
    transform: translateY(1px) rotate(712deg);
  }
}

@keyframes spark-burst {
  0% {
    transform: rotate(var(--angle)) translateY(calc(-1 * var(--start, 18px))) scale(1);
    opacity: 1;
  }
  100% {
    transform: rotate(var(--angle)) translateY(calc(-1 * var(--distance, 58px))) scale(0.3);
    opacity: 0;
  }
}

@keyframes icon-shortcut-bounce {
  0% {
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0.34, 2.6, 0.64, 1);
  }
  40% {
    transform: translateY(-16px);
    animation-timing-function: ease-out;
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes icon-shortcut-pop {
  0% {
    transform: scale(1);
    animation-timing-function: cubic-bezier(0.34, 2.6, 0.64, 1);
  }
  50% {
    transform: scale(1.25);
    animation-timing-function: ease-out;
  }
  100% {
    transform: scale(1);
  }
}

/* ===== Mobile (Responsive) =====
   Gated on pointer: coarse, not viewport width, so a narrow desktop
   browser window still gets the desktop layout -- only true touch
   devices get these overrides. */

@media (pointer: coarse) {
  #app {
    min-width: 0;
    width: 100dvw;
    height: 100dvh;
    /* Shared by #filter-title-bar's position and main#grid's padding-top
       below, so the two stay in lockstep. */
    --mobile-title-top: calc(var(--vert-edge-offset) + 2.4rem);
    /* Shared by #quick-actions/#search-close's own bottom offset and the
       detail nav arrows below, which stack above that pill. */
    --mobile-quick-actions-bottom: calc(var(--vert-edge-offset) + env(safe-area-inset-bottom) + 2rem);
    --mobile-quick-actions-height: 3.125rem;
  }

  #page-content {
    margin: 0;
    height: 100dvh;
  }

  /* Filter title moves out from desktop's top-right corner to sit
     centered directly under the logo, since mobile has no room to spare
     on the sides. Centered via a plain left offset (95vw wide, so 2.5vw
     of margin on each side) rather than transform: translateX(-50%) --
     a transform here would make this the containing block for its
     position: fixed descendants (#item-favorite, #sort-order-btn),
     pinning them to this box instead of the viewport. */
  #filter-title-bar {
    top: var(--mobile-title-top);
    left: 2.5vw;
    right: auto;
    width: 95vw;
    justify-content: center;
  }

  /* Sort + item-favorite move out of the centered title bar into their
     own fixed spot in the top-right corner -- the corner the whole title
     bar occupied on desktop before it recentered under the logo. They
     never show at the same time, so both land in the exact same spot.
     --horiz-edge-offset (3rem) was sized for desktop's 1200px layout and
     reads as a lopsided, oversized inset here against the 1.5rem
     vert-edge-offset -- use a smaller, symmetric inset instead. */
  #sort-order-btn,
  #item-favorite {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    z-index: 10;
  }

  #filter-title {
    font-size: 1.05rem;
  }

  /* #item-meta only ever shows in the detail/lightbox view, right-aligned
     under the title bar to match its desktop corner position -- now that
     the title bar is centered on mobile, center the meta text under it
     too instead of hugging a right edge that no longer means anything. */
  #item-meta {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }

  main#grid {
    --mobile-grid-gap: 0.3rem;
    --mobile-card-width: calc((100dvw - 2 * var(--mobile-grid-gap)) / 3);

    padding: 0;
    /* Enough room above the first row of cards for the logo, the filter
       title bar sitting just under it, and a bit of breathing room below
       the title before items start. The room below the title (was 2.2rem +
       2rem) is trimmed 30% so the gap doesn't read as oversized. */
    padding-top: calc(var(--mobile-title-top) + 2.94rem);
    /* Balances padding-top so align-content: safe center (below) centers
       within the actual chrome-free area -- from under the title bar down
       to above the quick-actions pill -- instead of skewing toward the
       bottom when there's too little content to fill the screen. */
    padding-bottom: calc(var(--mobile-quick-actions-bottom) + var(--mobile-quick-actions-height) + 0.75rem);
    gap: var(--mobile-grid-gap);
    /* auto-fit (not a plain repeat(3, ...)) so that with fewer than 3
       items the unused trailing track(s) collapse to 0 width -- letting
       justify-content: safe center (inherited from the base rule) center
       the actual row instead of it hugging the left edge of 3 full-width
       tracks. --mobile-card-width is sized so exactly 3 tracks ever fit. */
    grid-template-columns: repeat(auto-fit, var(--mobile-card-width));
  }

  .card {
    padding: 0.6rem 0.4rem;
  }

  .card .meta {
    display: none;
  }

  /* The empty-state message lives inside a grid item, but on mobile the
     grid's column tracks are always card-width regardless of column count
     -- with zero items that's a single ~33vw track, cramming the text.
     Pull it out to a fixed width centered on the grid's own position. */
  .empty-state {
    position: relative;
    left: 50%;
    width: 95vw;
    transform: translateX(-50%);
  }

  #quick-actions {
    top: auto;
    left: 50%;
    bottom: var(--mobile-quick-actions-bottom);
    transform: translateX(-50%);
    transition: opacity 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  /* Stands in for #quick-actions at the exact same spot while the panel is
     open -- the two cross-fade/scale via the :has() toggles below, driven
     off the same "open" class the panel already gets. */
  #search-close {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    left: 50%;
    bottom: var(--mobile-quick-actions-bottom);
    width: 3.5rem;
    height: 3.5rem;
    border: none;
    border-radius: 50%;
    background-color: var(--color-bg);
    box-shadow: var(--shadow-card);
    color: var(--color-text);
    cursor: pointer;
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) scale(0.7);
    transition: opacity 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);

    & svg {
      width: 22px;
      height: 22px;
      fill: none;
      stroke: currentColor;
      stroke-width: 2;
      stroke-linecap: round;
    }
  }

  #app:has(#search-options.open) #quick-actions {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) scale(0.7);
  }

  #app:has(#search-options.open) #search-close {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) scale(1);
  }

  /* Search panel spans the viewport instead of the desktop's fixed
     column widths. #time-events-group and #places-filter get flex-grow
     ratios of 2:1 off a shared flex-basis of 0 -- flexbox distributes
     only the leftover width *after* the gap between them, so the 2/3 |
     1/3 split naturally compensates for it without any manual calc. */
  #search-options {
    left: 1vw;
    width: 98vw;
    /* 80% of whatever's left below the panel's own top offset, not 80% of
       the full viewport -- so the cap tracks where the panel actually
       starts instead of assuming it starts at the very top. */
    max-height: calc((100dvh - var(--search-options-top)) * 0.8);
    overflow: hidden;
    /* .nav-filter's own scroll cap is desktop's fixed 600px otherwise --
       shorter phones can end up with a panel cap well under that, and
       without overflow:hidden above, the list just renders past the
       panel's box instead of clipping/scrolling within it. */
    --sidebar-list-max-height: calc((100dvh - var(--search-options-top)) * 0.8 - 2rem);
  }

  #time-events-group {
    flex: 2 1 0;
    width: auto;
    min-width: 0;
  }

  #places-filter {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
  }

  #timeline-filters {
    width: auto;
    flex: 2 1 0;
    min-width: 0;
  }

  #events-filter {
    width: auto;
    flex: 3 1 0;
    min-width: 0;
  }

  /* Recessing an inactive column still scales it back and slides it
     behind the active one, just without the desktop's added tilt. */
  #search-options:has(#timeline-list .active:not(.all-nav-item)) #places-filter,
  #search-options:has(#events-list .active:not(.all-nav-item)) #places-filter {
    transform: scale(0.95) translateX(-10%);
  }

  #search-options:has(#places-list .active:not(.all-nav-item)) #time-events-group {
    transform: scale(0.95) translateX(10%);
  }

  /* Detail prev/next shrink down from desktop's large corner arrows and
     move up to sit right-aligned above the quick-actions pill instead,
     which would otherwise crowd right into it. */
  .logo-detail-nav {
    bottom: calc(var(--mobile-quick-actions-bottom) + var(--mobile-quick-actions-height) + 0.75rem);

    & svg {
      width: 40px;
      height: 40px;
    }
  }

  #item-prev {
    right: calc(1.25rem + 40px + 0.5rem);
  }

  #item-next {
    right: 1.25rem;
  }

  #item-img {
    max-height: 50vh;
  }

  #hotkey-legend {
    display: none;
  }

  #attribution {
    left: 0;
    right: 0;
    width: 100%;
    bottom: 0;
    transform: none;
    box-sizing: border-box;
    text-align: center;
    padding: 2rem 1.5rem calc(var(--vert-edge-offset) + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--color-bg), transparent);
  }
}
