/* App chrome: header, stats, search, footer, floating button, shared controls. */

/* ---------- shared controls ---------- */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn--sm {
  width: 30px;
  height: 30px;
  border-color: transparent;
  background: transparent;
}

.icon-btn--sm:hover {
  background: var(--surface-2);
}

.icon-btn[aria-pressed='true'] {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
  background: var(--accent-soft);
}

.ghost-btn,
.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 13.5px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.ghost-btn:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.ghost-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.primary-btn {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 600;
}

.primary-btn:hover {
  filter: brightness(1.08);
  color: var(--accent-ink);
}

.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.segmented__btn {
  min-width: 28px;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.segmented__btn:hover {
  color: var(--text);
}

.segmented__btn[aria-pressed='true'] {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 93%, transparent);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.topbar.is-stuck {
  border-bottom-color: var(--line);
}

.topbar__inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px var(--pad-page) 12px;
  display: grid;
  gap: 10px;
}

.topbar__row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand__mark {
  width: 15px;
  height: 15px;
  border-radius: 4px;
  background: var(--today);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--today) 22%, transparent);
  flex: none;
}

.brand__title {
  font-size: clamp(17px, 2.6vw, 21px);
  font-weight: 650;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.motto {
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.5;
  max-width: 62ch;
}

/* Once you start scrolling the header shrinks to a title bar plus the
   progress line, so the grid gets the screen. */
.topbar.is-compact .motto,
.topbar.is-compact .stats {
  display: none;
}

.topbar.is-compact:not(.has-search) .searchbar {
  display: none;
}

/* Theme button shows exactly one glyph for the active mode. */
#theme-btn .icon {
  display: none;
}

:root[data-theme='light'] #theme-btn .icon--sun,
:root[data-theme='dark'] #theme-btn .icon--moon,
:root:not([data-theme]) #theme-btn .icon--auto {
  display: block;
}

/* ---------- life progress ---------- */

.lifebar {
  display: grid;
  gap: 9px;
}

.lifebar__track {
  position: relative;
  height: 7px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}

.lifebar__fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 60%, var(--today)), var(--accent));
  transition: width 1.1s cubic-bezier(0.22, 1, 0.36, 1);
}

.lifebar__ticks {
  position: absolute;
  inset: 0;
}

/* One tick per decade, placed by percentage. */
.lifebar__ticks span {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: color-mix(in srgb, var(--bg) 65%, transparent);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.stat__value {
  font-family: var(--font-num);
  font-size: 15px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.stat__label {
  color: var(--text-faint);
  font-size: 12px;
}

/* ---------- search ---------- */

.searchbar {
  flex: 1 1 200px;
  max-width: 400px;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.searchbar:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  box-shadow: var(--ring);
}

.searchbar__icon {
  color: var(--text-faint);
}

.searchbar__input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font-size: 14px;
}

.searchbar__input:focus {
  outline: none;
}

.searchbar__input::-webkit-search-cancel-button {
  filter: grayscale(1);
  opacity: 0.6;
}

.searchbar__count {
  color: var(--text-faint);
  font-family: var(--font-num);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.searchbar__nav {
  display: flex;
  gap: 2px;
}

/* ---------- footer ---------- */

.footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 6px var(--pad-page) calc(48px + env(safe-area-inset-bottom));
  color: var(--text-faint);
  font-size: 12.5px;
  display: grid;
  gap: 12px;
}

.footer__keys {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  color: var(--text-faint);
  font-size: 11.5px;
}

.footer__keys kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  font-family: var(--font-num);
  font-size: 10.5px;
  text-align: center;
}

@media (pointer: coarse) {
  .footer__keys {
    display: none;
  }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.legend__item:hover {
  color: var(--text);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.legend__now {
  padding: 1px 6px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--today) 16%, transparent);
  color: var(--today);
  font-size: 10.5px;
  font-weight: 600;
}

.legend__swatch {
  width: 11px;
  height: 11px;
  border-radius: 3.5px;
  background: hsl(
    var(--h) calc(var(--cell-sat0) + var(--swatch-i) * var(--cell-satk))
      calc(var(--cell-l0) - var(--swatch-i) * var(--cell-k))
  );
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 8%);
}

/* ---------- floating jump-to-today ---------- */

.fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 25;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-dim);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  transition: color 0.15s ease, transform 0.15s ease, opacity 0.2s ease;
}

.fab:hover {
  color: var(--today);
  transform: translateY(-2px);
}

.fab .icon {
  width: 21px;
  height: 21px;
}

body.panel-open .fab {
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 720px) {
  /* The search field drops to a line of its own under the title. */
  .topbar__row {
    flex-wrap: wrap;
  }

  .brand {
    margin-right: auto;
  }

  .searchbar {
    order: 3;
    flex-basis: 100%;
    max-width: none;
    margin-left: 0;
  }
}

@media (max-width: 640px) {
  .motto {
    display: none;
  }

  .topbar__inner {
    padding-top: 10px;
    gap: 8px;
  }

  .stats {
    gap: 4px 14px;
  }

  .stat__value {
    font-size: 14px;
  }
}
