/* Fanflare shell: header, mobile top bar and tab bar, menus, footer, toasts, celebration. */

/* Header (desktop and tablet), compact top bar (mobile) */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  padding-top: var(--safe-top);
  border-bottom: 1px solid var(--line);
  background: var(--surface-glass);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  max-width: var(--page-max);
  height: var(--header-height);
  margin-inline: auto;
  padding-inline: max(var(--gutter), var(--safe-left)) max(var(--gutter), var(--safe-right));
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  font-size: 25px;
  font-weight: var(--weight-strong);
  letter-spacing: -1.1px;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  color: var(--ink);
}
.brand:hover {
  color: var(--ink);
}
.brand svg {
  width: 26px;
  height: 26px;
  color: var(--accent);
  transition: transform var(--duration-slow) var(--ease-spring);
}
.brand:hover svg {
  transform: rotate(30deg);
}

/* Search field and its results panel (the panel is driven by the search module) */
/* The search fills the space between the brand and the navigation, with equal visible
   gaps on both sides (the nav links' own padding is pulled back below). */
.header-search {
  position: relative;
  flex: 1 1 auto;
  max-width: 600px;
  margin: 0 auto;
}
.search-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--tap);
  padding-inline: 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--surface-well);
  transition:
    background var(--duration) var(--ease-out),
    border-color var(--duration) var(--ease-out),
    box-shadow var(--duration) var(--ease-out);
}
.search-field:hover {
  background: var(--surface-well-hover);
}
.search-field:focus-within {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}
.search-field > svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
}
.search-field input {
  flex: 1;
  height: 100%;
  min-height: 0;
  padding: 0 4px;
  border: 0;
  background: transparent;
  font-size: var(--text-ui);
  box-shadow: none;
  outline: none;
}
.search-field input::-webkit-search-cancel-button {
  cursor: pointer;
}
.search-panel {
  position: absolute;
  z-index: var(--z-search-panel);
  top: calc(100% + var(--space-2));
  left: 0;
  right: 0;
  min-width: min(560px, 90vw);
  max-height: min(70vh, 620px);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

/* Primary navigation */
.header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.header-nav a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding-inline: 10px;
  border-radius: var(--radius);
  font-size: var(--text-ui);
  font-weight: var(--weight-strong);
  text-decoration: none;
  white-space: nowrap;
}
.header-nav a[aria-current] {
  color: var(--accent);
}
.header-nav svg {
  width: 20px;
  height: 20px;
}

/* Right-hand actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}
.header-actions form {
  display: contents;
}
/* Theme toggle: show the button for the other theme */
.theme-to-light,
:root[data-theme="dark"] .theme-to-dark {
  display: none;
}
:root[data-theme="dark"] .theme-to-light {
  display: inline-flex;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-to-dark {
    display: none;
  }
  :root:not([data-theme]) .theme-to-light {
    display: inline-flex;
  }
}
.spoiler-switch[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}
.spoiler-switch[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  top: 9px;
  right: 9px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--paper);
}
.spoiler-switch svg {
  transition: transform var(--duration) var(--ease-spring);
}
.spoiler-switch.is-busy svg {
  transform: scale(0.8);
}
.count-badge {
  position: absolute;
  top: 4px;
  right: 2px;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding-inline: 5px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--paper);
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  line-height: 1;
  box-shadow: 0 0 0 2px var(--paper);
}
.sparks-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  margin-inline: var(--space-1);
  padding-inline: 10px 12px;
  border-radius: var(--radius-pill);
  background: var(--spark-soft);
  color: var(--spark);
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background var(--duration-fast),
    transform var(--duration) var(--ease-spring);
}
.sparks-chip:hover {
  color: var(--spark);
  background: var(--spark-soft-hover);
}
.sparks-chip svg {
  width: 16px;
  height: 16px;
  color: var(--spark-icon);
}
.sparks-chip.is-bumped {
  animation: spark-bump var(--duration-slow) var(--ease-spring);
}
@keyframes spark-bump {
  40% {
    transform: scale(1.12);
  }
}
.sign-in {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  margin-left: var(--space-2);
  padding: 8px 15px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-size: var(--text-ui);
  font-weight: var(--weight-strong);
  text-decoration: none;
  white-space: nowrap;
}

/* Disclosure menus (details/summary; /js/menus.js adds outside-click and Escape) */
.menu {
  position: relative;
}
.menu > summary {
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.menu > summary::-webkit-details-marker {
  display: none;
}
.avatar-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: var(--tap);
  margin-left: var(--space-1);
  padding: 4px 6px 4px 4px;
  border-radius: var(--radius-pill);
  transition: background var(--duration-fast);
}
.avatar-btn:hover,
.menu[open] > .avatar-btn {
  background: var(--accent-soft);
}
.avatar-btn > svg {
  width: 16px;
  height: 16px;
  color: var(--muted);
  transition: transform var(--duration) var(--ease-out);
}
.menu[open] > .avatar-btn > svg {
  transform: rotate(180deg);
}
.menu-panel {
  position: absolute;
  z-index: var(--z-menu);
  top: calc(100% + var(--space-2));
  right: 0;
  width: 264px;
  padding: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform-origin: top right;
  animation: menu-in var(--duration) var(--ease-out);
}
@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.97);
  }
}
.menu-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  margin-bottom: var(--space-1);
  border-bottom: 1px solid var(--line);
}
.menu-head .avatar {
  --avatar-size: 44px;
}
.menu-head > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  flex: 1;
  min-width: 0;
  line-height: var(--leading-snug);
}
.menu-head > div > span {
  min-width: 0;
  overflow-wrap: anywhere;
}
.menu-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menu-head span {
  font-size: var(--text-xs);
  color: var(--muted);
}
.menu-head a {
  color: var(--accent);
  font-weight: var(--weight-strong);
  font-size: var(--text-sm);
  text-decoration: none;
}
.menu-list {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}
.menu-list li {
  margin: 0;
}
.menu-list a,
.menu-list button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font: var(--weight-regular) var(--text-ui) / 1.4 var(--font-sans);
  text-align: left;
  text-decoration: none;
  justify-content: flex-start;
  cursor: pointer;
}
.menu-list a:hover,
.menu-list button:hover {
  background: var(--surface-hover);
  color: var(--accent);
  transform: none;
}
.menu-list svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
}
.menu-list a:hover svg,
.menu-list button:hover svg {
  color: var(--accent);
}
.menu-list .divider {
  height: 1px;
  margin: var(--space-1) var(--space-2);
  background: var(--line);
}
.menu-list form {
  margin: 0;
}

/* Bottom tab bar (mobile) */
.tabbar {
  display: none;
}

/* Footer */
.site-footer {
  margin-top: var(--space-10);
}
.footer-inner {
  display: flex;
  align-items: center;
  gap: var(--space-7);
  max-width: var(--page-max);
  min-height: 115px;
  margin-inline: auto;
  padding-inline: var(--gutter);
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.footer-inner .brand {
  margin-right: auto;
  font-size: 22px;
}
.footer-inner .brand svg {
  width: 22px;
  height: 22px;
  color: var(--ink);
}
.footer-inner > a:not(.brand) {
  text-decoration: none;
}

/* Tablet: the desktop structure with icon navigation */
@media (max-width: 1179.98px) {
  .header-inner {
    gap: var(--space-4);
  }
  .header-nav .label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .header-nav a {
    width: var(--tap);
    justify-content: center;
    padding: 0;
    border-radius: var(--radius-pill);
  }
  .header-nav a:hover {
    background: var(--accent-soft);
  }
  .header-nav a[aria-current] {
    background: var(--accent-soft);
  }
}
@media (min-width: 1180px) {
  .header-nav {
    margin-inline-start: -10px;
  }
  .header-nav svg {
    display: none;
  }
}

/* Mobile: compact top bar and bottom tab bar */
@media (max-width: 767.98px) {
  body {
    padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom));
  }
  .site-header {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--surface-glass-strong);
  }
  .header-inner {
    gap: var(--space-2);
    padding-inline: max(16px, var(--safe-left)) max(10px, var(--safe-right));
  }
  .brand {
    font-size: 23px;
  }
  .brand svg {
    width: 24px;
    height: 24px;
  }
  .header-search,
  .header-nav,
  .sparks-chip,
  .header-actions .menu,
  .header-actions .sign-in {
    display: none;
  }
  .header-actions {
    margin-left: auto;
  }
  .header-actions .tooltip {
    left: auto;
    right: 0;
    translate: none;
  }
  .header-actions .tooltip::after {
    left: auto;
    right: calc(var(--tap) / 2 - 4px);
  }
  .tabbar {
    position: fixed;
    z-index: var(--z-tabbar);
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: calc(var(--tabbar-height) + var(--safe-bottom));
    padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    border-top: 1px solid var(--line);
    background: var(--surface-glass-strong);
    box-shadow: 0 -6px 18px -12px var(--shadow-edge);
  }
  .tabbar > a,
  .tabbar > .menu > summary {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: var(--tabbar-height);
    min-width: var(--tap);
    color: var(--muted);
    font-size: var(--text-2xs);
    font-weight: var(--weight-strong);
    letter-spacing: 0.01em;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: color var(--duration-fast);
  }
  .tabbar svg {
    width: 24px;
    height: 24px;
    transition: transform var(--duration) var(--ease-spring);
  }
  .tabbar > a:active svg,
  .tabbar > .menu > summary:active .avatar {
    transform: scale(0.88);
  }
  .tabbar > a[aria-current],
  .tabbar > .menu[open] > summary,
  .tabbar > .menu.is-current > summary {
    color: var(--accent);
  }
  .tabbar .avatar {
    --avatar-size: 26px;
    transition:
      transform var(--duration) var(--ease-spring),
      box-shadow var(--duration-fast);
  }
  .tabbar > .menu[open] .avatar,
  .tabbar > .menu.is-current .avatar,
  .tabbar > a[aria-current] .avatar {
    box-shadow:
      0 0 0 2px var(--paper),
      0 0 0 4px var(--accent);
  }
  .tabbar > .menu {
    position: static;
  }
  /* The Me menu opens as a bottom sheet above the tab bar, with a scrim behind it. */
  .tabbar > .menu[open] > summary::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: var(--scrim);
    animation: fade-in var(--duration) var(--ease-out);
  }
  .tabbar .menu-panel {
    position: fixed;
    top: auto;
    left: max(8px, var(--safe-left));
    right: max(8px, var(--safe-right));
    bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 8px);
    width: auto;
    max-height: calc(100dvh - var(--tabbar-height) - var(--safe-bottom) - var(--header-height) - 24px);
    overflow: auto;
    padding: var(--space-2) var(--space-2) var(--space-3);
    border-radius: var(--radius-xl);
    transform-origin: bottom center;
    animation: sheet-in var(--duration-slow) var(--ease-out);
  }
  .tabbar .menu-list a,
  .tabbar .menu-list button {
    min-height: var(--tap);
    font-size: var(--text-base);
  }
  .footer-inner {
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
    min-height: 0;
    padding-block: var(--space-6);
  }
  .footer-inner .brand {
    flex-basis: 100%;
  }
  .footer-inner > a:not(.brand) {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
  }
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
}

/* Toasts: a polite live region in the top layer (popover), stacked bottom centre */
.toasts {
  position: fixed;
  inset: auto 0 calc(var(--space-6) + var(--safe-bottom)) 0;
  width: min(420px, calc(100vw - 32px));
  height: auto;
  margin: 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  pointer-events: none;
}
.toasts:not(:popover-open) {
  display: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 100%;
  min-height: 48px;
  padding: 10px 18px 10px 14px;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: var(--paper);
  font-size: var(--text-ui);
  font-weight: var(--weight-strong);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in var(--duration-slow) var(--ease-spring);
}
.toast.is-leaving {
  animation: toast-out var(--duration) var(--ease-in-out) forwards;
}
.toast svg {
  width: 20px;
  height: 20px;
}
.toast.success svg {
  color: var(--toast-success);
}
.toast.error {
  background: var(--danger);
}
.toast.sparks {
  background: var(--gradient-brand);
  color: var(--on-brand);
}
.toast.sparks svg {
  color: var(--spark-glow);
  animation: spark-spin 900ms var(--ease-out);
}
.toast-amount {
  font-variant-numeric: tabular-nums;
  color: var(--brand-amount);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.92);
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
}
@keyframes spark-spin {
  from {
    transform: rotate(-120deg) scale(0.4);
  }
}
@media (max-width: 767.98px) {
  .toasts {
    bottom: calc(var(--tabbar-height) + var(--safe-bottom) + var(--space-3));
  }
}

/* Celebration: level-up or badge, a modal dialog with a spark burst */
.celebration {
  width: min(380px, calc(100vw - 32px));
  padding: var(--space-9) var(--space-7) var(--space-7);
  border: 0;
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--ink);
  text-align: center;
  overflow: visible;
  box-shadow: var(--shadow-lg);
}
.celebration[open] {
  animation: celebrate-in var(--duration-slow) var(--ease-spring);
}
.celebration::backdrop {
  background: var(--backdrop);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade-in var(--duration) var(--ease-out);
}
.celebration::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 120px;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background: var(--gradient-hero);
  opacity: 0.35;
  -webkit-mask: linear-gradient(#000, transparent);
  mask: linear-gradient(#000, transparent);
}
.celebration-medal {
  position: relative;
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  margin: 0 auto var(--space-5);
  border-radius: 50%;
  background: var(--gradient-medal);
  color: var(--on-brand);
  box-shadow:
    0 0 0 6px var(--surface),
    0 0 0 7px var(--accent-line),
    0 18px 40px -12px var(--brand-glow);
}
.celebration-medal .serif {
  font-size: 58px;
  line-height: 1;
  font-style: italic;
  margin-top: -4px;
}
.celebration-medal svg {
  width: 52px;
  height: 52px;
}
.celebration-burst {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}
.celebration-burst i {
  position: absolute;
  left: -4px;
  top: -4px;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--c, var(--spark-glow));
  opacity: 0;
  transform: rotate(var(--a)) translateY(0);
  animation: burst var(--duration-celebrate) var(--ease-out) var(--d, 0ms) forwards;
}
@keyframes burst {
  0% {
    opacity: 1;
    transform: rotate(var(--a)) translateY(-40px) scale(1);
  }
  100% {
    opacity: 0;
    transform: rotate(var(--a)) translateY(-150px) scale(0.3) rotate(160deg);
  }
}
.celebration-kicker {
  display: block;
  color: var(--accent);
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.celebration h2 {
  margin: var(--space-2) 0;
  font-size: 34px;
}
.celebration p {
  margin: 0 auto;
  max-width: 30ch;
  color: var(--muted);
}
.celebration form {
  margin-top: var(--space-6);
}
@keyframes celebrate-in {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.9);
  }
}
@media (prefers-reduced-motion: reduce) {
  .celebration-burst {
    display: none;
  }
}

@media (any-pointer: coarse) {
  .sign-in,
  .sparks-chip,
  .menu-list a,
  .menu-list button {
    min-height: var(--tap);
    min-width: var(--tap);
  }
}
