/* ============================================================================
 * components.css — the shared shell vocabulary.
 *
 * These class names are the house standard: .topbar, .view/.active, .tabbar,
 * .overlay/.sheet, .btn, .chip, .card, .panel, .empty-state, .toast. Reuse
 * them rather than inventing new ones — every app in the set already reads
 * this way, so a component moved between apps mostly just works.
 *
 * Naming is flat kebab-case with a component prefix: `detail-sheet`,
 * `seed-toolbar`, `fav-item-title`. Prefix-noun-modifier. Not BEM, no CSS
 * modules, no utility framework.
 *
 * ---------------------------------------------------------------------------
 * THE SHELL IS A GAME'S SHELL
 *
 * The first version of this file was the kit's default: a bordered top bar, a
 * bordered tab bar, bordered buttons, bordered cards. Correct and anonymous.
 * A game is allowed a little more presence than a utility, so the shell now
 * does three things the kit's does not:
 *
 *   THE WORDMARK IS GOLD. The brand name is set in the accent with a faint
 *   glow, which is the one place the app is allowed to be a little vain.
 *
 *   THE ACTIVE TAB SITS ON A LIT PILL. A colour change alone is easy to miss
 *   on a phone; a pill behind the glyph is not.
 *
 *   PRIMARY BUTTONS ARE LIT FROM ABOVE. A flat gold rectangle is a form
 *   button; a gold button with a highlight along its top edge is a thing you
 *   press in a game. The gradient is subtle and it is the whole difference.
 * ========================================================================= */

/* ---------- app shell ----------------------------------------------------
 * Fixed topbar, scrolling content between, fixed tabbar. The content column
 * pads itself clear of both so nothing hides under the chrome. */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--bg) 96%, transparent) 0%,
    color-mix(in srgb, var(--bg) 82%, transparent) 100%);
  backdrop-filter: saturate(1.4) blur(14px);
  /* A hairline of light rather than a ruled line: the bar is a lit edge
   * over the page, not a table header. */
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.05);
}

/* min-width:0 lets the brand name truncate instead of shoving the topbar
 * actions off the right edge on a narrow phone. A flex child's default
 * min-width is `auto`, which refuses to shrink below its content. */
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 800; min-width: 0;
}
.brand-icon {
  font-size: 1.2rem; line-height: 1;
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 55%, transparent));
}
.brand-name {
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 14px color-mix(in srgb, var(--accent) 35%, transparent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* The install offer is a top-bar affordance, so it has to stay small enough
 * that it never competes with the brand. Compact by default; the label drops
 * away entirely on a narrow phone, leaving the glyph. */
.install-btn { padding: 8px 12px; font-size: 0.8rem; min-height: 38px; }
.install-btn-icon { font-size: 0.9rem; line-height: 1; }

@media (max-width: 380px) {
  .install-btn-label { display: none; }
  .install-btn { padding: 8px 10px; }
}

.container {
  max-width: 640px;          /* phone-first; a wide screen gets margins, not a redesign */
  margin: 0 auto;
  padding:
    calc(var(--topbar-h) + var(--safe-t) + 12px)
    14px
    calc(var(--tabbar-h) + var(--safe-b) + 24px);
}

/* Exactly one .view carries .active at a time. Switching is driven by the
 * `data-view` attribute on a .tab button, resolved to #view-<name> — see
 * js/ui.js. */
.view { display: none; }
.view.active { display: block; animation: view-in 200ms ease-out; }

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- bottom tab bar ---------------------------------------------- */

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 20;
  padding-bottom: var(--safe-b);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--bg) 86%, transparent) 0%,
    color-mix(in srgb, var(--bg) 97%, transparent) 100%);
  backdrop-filter: saturate(1.4) blur(14px);
  box-shadow: 0 -1px 0 rgb(255 255 255 / 0.05);
}

.tabbar-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  padding: 4px 8px 0;
}

.tab {
  flex: 1;
  min-height: 44px;              /* thumbs, not cursors */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px 8px;
  background: none;
  border: 0;
  color: var(--ink-faint);
  cursor: pointer;
  transition: color 150ms ease;
}

/* The lit pill. Sized to the glyph, not the whole tab, so the four tabs read
 * as four icons with one of them switched on. */
.tab-icon {
  font-size: 1.15rem; line-height: 1;
  padding: 4px 16px;
  border-radius: var(--radius-pill);
  transition: background-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}
.tab.active { color: var(--accent); }
.tab.active .tab-icon {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  box-shadow: 0 0 16px -4px color-mix(in srgb, var(--accent) 60%, transparent);
  transform: translateY(-1px);
}
.tab-label { font-size: 0.68rem; font-weight: 800; letter-spacing: 0.02em; }

/* ---------- buttons ------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 0;
  background: linear-gradient(180deg, var(--bg-lift) 0%, var(--bg-raised) 100%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.07), 0 1px 2px rgb(0 0 0 / 0.3);
  color: var(--ink);
  font-weight: 800;
  font-size: 0.925rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: filter 150ms ease, transform 90ms ease, box-shadow 150ms ease;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Lit from above. See the header. */
.btn-primary {
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--accent) 60%, color-mix(in srgb, var(--accent) 88%, black) 100%);
  color: var(--accent-contrast);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.35),
    0 6px 18px -8px color-mix(in srgb, var(--accent) 80%, transparent);
}
.btn-ghost  { background: transparent; box-shadow: none; color: var(--ink-soft); }
.btn-danger { background: transparent; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bad) 40%, transparent); color: var(--bad); }
.btn-block  { display: flex; width: 100%; }
.btn-lg     { min-height: 54px; font-size: 1.05rem; border-radius: var(--radius); letter-spacing: 0.04em; text-transform: uppercase; }

.icon-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: var(--radius-pill);
  border: 0;
  background: color-mix(in srgb, var(--bg-lift) 70%, transparent);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.06);
  color: var(--ink-soft);
  font-weight: 800;
  cursor: pointer;
}

/* ---------- surfaces ----------------------------------------------------- */

.card, .panel {
  background: var(--bg-raised);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.05), var(--shadow-sm);
}

.card  { padding: 14px; }
.panel { padding: 16px; }
.panel-head { margin: 0 0 4px; font-size: 1rem; font-weight: 800; }
.panel-sub  { margin: 0 0 12px; color: var(--ink-soft); font-size: 0.85rem; }

/* ---------- chips -------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  min-height: 36px;
  border-radius: var(--radius-pill);
  border: 0;
  background: color-mix(in srgb, var(--bg-lift) 80%, transparent);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.05);
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.chip.active {
  background: var(--accent); color: var(--accent-contrast);
  box-shadow: 0 4px 14px -6px color-mix(in srgb, var(--accent) 80%, transparent);
}
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* A chip row used as the page's own tab strip — the codex — sits in a sunken
 * track so the four choices read as one control rather than four buttons. */
.chip-row.segmented {
  display: inline-flex; flex-wrap: nowrap; gap: 4px;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: rgb(0 0 0 / 0.28);
}
.chip-row.segmented .chip { box-shadow: none; background: transparent; }
.chip-row.segmented .chip.active { background: var(--accent); }

/* ---------- badges ------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: rgb(0 0 0 / 0.3);
  color: var(--ink-soft);
  font-size: 0.7rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.04em;
}

.badge-good { background: var(--good-bg); color: var(--good); }
.badge-bad  { background: var(--bad-bg);  color: var(--bad); }

/* ---------- empty state -------------------------------------------------- */

.empty-state { padding: 40px 20px; text-align: center; color: var(--ink-soft); }
.empty-title { margin: 0 0 6px; font-size: 1rem; font-weight: 800; color: var(--ink); }
.empty-sub   { margin: 0; font-size: 0.875rem; }

/* ---------- overlay + bottom sheet --------------------------------------- */

.overlay {
  position: fixed; inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.overlay[hidden] { display: none; }

.overlay-backdrop {
  position: absolute; inset: 0;
  background: rgb(8 6 14 / 0.55);
  backdrop-filter: blur(2px);
  animation: fade-in 180ms ease-out;
}

.sheet {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--bg-lift) 0%, var(--bg-raised) 80px);
  border-radius: 24px 24px 0 0;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.08), var(--shadow-lg);
  padding-bottom: var(--safe-b);
  animation: sheet-up 260ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

/* The grabber. It does nothing — the sheet is closed by the button, the
 * backdrop or Escape — but a sheet without one reads as a page that has
 * slid up by mistake. */
.sheet::before {
  content: "";
  position: absolute; top: 8px; left: 50%;
  width: 36px; height: 4px;
  transform: translateX(-50%);
  border-radius: 2px;
  background: rgb(255 255 255 / 0.18);
}

.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 20px 16px 8px;
}

.sheet-title { margin: 0; font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; }
.sheet-body  { padding: 0 16px 20px; overflow-y: auto; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }

/* ---------- toast -------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  transform: translateX(-50%) translateY(8px);
  z-index: 80;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: var(--bg);
  font-size: 0.875rem;
  font-weight: 800;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- install sheet ------------------------------------------------ */

.install-steps { margin: 12px 0 0; padding-left: 20px; line-height: 1.7; }
.install-steps li { margin-bottom: 8px; }
.install-sub { margin: 0; color: var(--ink-soft); font-size: 0.875rem; }
.install-glyph { width: 1em; height: 1em; vertical-align: -0.15em; }

/* ---------- pointer-only affordances -------------------------------------
 * EVERY :hover rule in the app lives in this block, and that is deliberate.
 * On a touch screen Safari applies :hover to whatever sits under the last tap
 * and KEEPS it there — so the next element rendered into that same slot
 * inherits a highlight it never earned, which reads as a rendering bug.
 * Gating hover on an actual pointer makes the problem structurally
 * impossible rather than something to remember. */
@media (hover: hover) {
  .btn:hover:not(:disabled)  { filter: brightness(1.12); }
  .btn-ghost:hover  { background: color-mix(in srgb, var(--bg-lift) 70%, transparent); color: var(--ink); }
  .btn-danger:hover { background: var(--bad-bg); }
  .icon-btn:hover   { color: var(--ink); filter: brightness(1.15); }
  .chip:hover:not(.active) { color: var(--ink); }
  .tab:hover        { color: var(--ink-soft); }
  .tab.active:hover { color: var(--accent); }
}
