/* ============================================================================
   pistolsbros.com — theme.css
   THE single source of design tokens + shared component styling.

   - Color tokens are LOCKED (see CLAUDE.md) — do not invent new hex values.
   - Design tokens (spacing / radii / elevation / motion / type) follow
     UIUX-Polish-Spec.md.
   - Fonts (Anton display + Hanken Grotesk UI) are loaded via <link> in each
     page's <head>; this file only references the families.

   Pages link this file FIRST, then add a small page-specific <style> for
   layout that isn't shared. No tokens/colors should be redefined elsewhere.
   ========================================================================== */

:root {
  /* ── Locked color scheme (CLAUDE.md) ─────────────────────────────────── */
  --bg:            #1B0E2B; /* near-black violet — page background */
  --surface:       #2A1840; /* cards, list rows */
  --border:        #3D2459; /* dividers, card edges */
  --brand-purple:  #9D4EDD; /* wordmark/title, #2 rank badge */
  --orange:        #F97316; /* #1 spot, primary buttons, key highlights */
  --orange-bright: #FB923C; /* orange hover/pressed */
  --green:         #4ADE80; /* #3 spot, live dot, save confirmations */
  --green-deep:    #22C55E; /* green hover/pressed */
  --text:          #F5EFFA; /* names, body text */
  --text-muted:    #B9A8CC; /* sub-labels, timestamps */
  --danger:        #EF4444; /* delete only — the one sanctioned non-brand color */

  /* ── Spacing scale ───────────────────────────────────────────────────── */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;

  /* ── Radii ───────────────────────────────────────────────────────────── */
  --r-sm: 10px;   /* buttons, inputs */
  --r-md: 16px;   /* cards, rows */
  --r-lg: 22px;   /* modals */
  --r-pill: 999px;

  /* ── Elevation ───────────────────────────────────────────────────────── */
  --shadow-card: 0 4px 16px -8px rgba(0,0,0,0.55);
  --shadow-pop:  0 24px 60px -24px rgba(0,0,0,0.7);
  --glow-orange: 0 0 28px rgba(249,115,22,0.32);

  /* ── Motion ──────────────────────────────────────────────────────────── */
  --t-fast: 140ms ease;
  --t-base: 200ms cubic-bezier(0.2, 0.7, 0.2, 1);

  /* ── Type scale ──────────────────────────────────────────────────────── */
  --fs-display:    clamp(2.4rem, 8vw, 3.4rem); /* wordmark */
  --fs-name-champ: clamp(1.4rem, 5vw, 1.9rem);
  --fs-name:       1.0625rem;  /* 17px field/podium names */
  --fs-h2:         1.25rem;
  --fs-label:      0.75rem;    /* uppercase, letter-spaced section labels */
  --fs-meta:       0.8125rem;

  /* ── Font families ───────────────────────────────────────────────────── */
  --font-display: "Anton", Impact, "Arial Narrow Bold", sans-serif;
  --font-ui: "Hanken Grotesk", -apple-system, BlinkMacSystemFont,
             "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  /* Background depth: a soft purple glow top-center over the flat base so the
     page reads atmospheric instead of cheap. */
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(157,78,221,0.12), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  line-height: 1.4;
  min-height: 100vh;
  /* mobile-first: safe-area aware */
  padding:
    env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Accessibility: a visible keyboard focus ring on everything interactive. */
:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

/* ── Wordmark / header type ──────────────────────────────────────────────── */
.wordmark {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;            /* Anton ships a single heavy weight */
  font-size: var(--fs-display);
  letter-spacing: 0.02em;
  line-height: 0.95;
  color: var(--brand-purple);
  text-transform: uppercase;
}
.subtitle {
  margin: var(--sp-2) 0 0;
  font-size: var(--fs-label);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Section label (letter-spaced caps; supports a live count) ───────────── */
.section-title {
  margin: var(--sp-5) var(--sp-1) var(--sp-3);
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.section-title .count { color: var(--brand-purple); }

/* ── Card surface (elevation + hairline, never a flat fill) ──────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-card);
  padding: var(--sp-5) var(--sp-4);
}

/* ── Form fields ─────────────────────────────────────────────────────────── */
label.field { display: block; margin: 0 0 var(--sp-4); }
label.field > span {
  display: block;
  margin: 0 0 var(--sp-2);
  font-size: var(--fs-label);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}
input[type="email"],
input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 13px 14px;
  font: inherit;
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
input:focus {
  border-color: var(--brand-purple);
  box-shadow: 0 0 0 3px rgba(157,78,221,0.18);
}
input.invalid { border-color: var(--danger); }
input.invalid:focus { box-shadow: 0 0 0 3px rgba(239,68,68,0.18); }

/* Inline validation message under a field. */
.field-error {
  margin: calc(-1 * var(--sp-2)) 0 var(--sp-3);
  font-size: var(--fs-meta);
  font-weight: 600;
  color: var(--danger);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 48px;            /* big tap target */
  padding: 12px 18px;
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast), border-color var(--t-fast),
              color var(--t-fast), transform var(--t-fast), filter var(--t-fast);
}
.btn:disabled { opacity: 0.5; cursor: default; }
/* Instant pressed feedback (<50ms): the button depresses on tap. */
.btn:not(:disabled):active { transform: translateY(1px); }

/* Primary (Sign in, Add, Save): orange fill, DARK text — white-on-orange fails
   contrast; dark-on-orange passes (accessibility rule, CLAUDE.md). */
.btn-primary { background: var(--orange); color: var(--bg); }
.btn-primary:not(:disabled):hover { background: var(--orange-bright); }

/* Secondary / neutral action. */
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:not(:disabled):hover {
  border-color: var(--brand-purple);
  background: rgba(157,78,221,0.10);
}

/* Destructive: filled --danger — reserved for the delete-confirm modal ONLY. */
.btn-danger { background: var(--danger); color: var(--text); }
.btn-danger:not(:disabled):hover { filter: brightness(1.08); }

.btn-block { width: 100%; }

/* Loading state: toggle .is-loading on the button to show a spinner + verb.
   currentColor inherits the button's text color (dark on orange, light on ghost). */
.btn.is-loading { pointer-events: none; }
.btn.is-loading::before {
  content: "";
  width: 1em; height: 1em;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin 0.6s linear infinite;
}

/* Square icon button — row up/down + the de-escalated trash control. */
.icon-btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast),
              color var(--t-fast), transform var(--t-fast);
}
.icon-btn svg { width: 20px; height: 20px; display: block; }
.icon-btn:not(:disabled):hover {
  color: var(--text);
  border-color: var(--brand-purple);
  background: rgba(157,78,221,0.10);
}
.icon-btn:not(:disabled):active { transform: translateY(1px); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
/* Quiet trash: --danger appears only on hover, never as a resting fill. */
.icon-btn.danger:not(:disabled):hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(239,68,68,0.10);
}

/* ── Status panel (empty / error / connecting) ───────────────────────────── */
.status {
  margin: var(--sp-4) auto 0;
  text-align: center;
  padding: var(--sp-6) var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-card);
  color: var(--text-muted);
}
.status h2 { margin: 0 0 var(--sp-2); color: var(--text); font-size: var(--fs-h2); font-weight: 700; }
.status p  { margin: 0; font-size: var(--fs-meta); }
/* Status glyph is a small inline SVG (same stroke style as the icon set),
   tinted via currentColor — muted normally, --danger on error cards. */
.status .glyph { color: var(--text-muted); line-height: 0; margin-bottom: var(--sp-3); }
.status .glyph svg { width: 34px; height: 34px; display: block; margin: 0 auto; }
.status.error h2 { color: var(--danger); }
.status.error .glyph { color: var(--danger); }
.status .btn { margin-top: var(--sp-4); }

/* ── Toast — pill that slides up, auto-dismisses (~2.5s) ──────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 24px);
  display: inline-flex; align-items: center; gap: var(--sp-2);
  max-width: calc(100vw - 32px);
  font-weight: 700;
  font-size: var(--fs-meta);
  padding: 12px 20px;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-pop);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base), transform var(--t-base);
  z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { background: var(--green);  color: var(--bg); }   /* dark on green */
.toast.error   { background: var(--danger); color: var(--text); }

/* ── Rank badge + photo atoms (shared by both pages) ─────────────────────── */
.rank {
  flex: 0 0 40px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-pill);
  font-family: var(--font-display);   /* Anton numerals */
  font-weight: 400;
  font-size: 1.25rem;
  color: var(--text-muted);           /* default look for ranks 4+ */
}
.photo {
  flex: 0 0 56px;
  width: 56px; height: 56px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg);
  border: 2px solid var(--border);
  display: block;
}
/* Avatar paint: fade in over the placeholder circle to avoid any flash. */
.photo.fade { opacity: 0; transition: opacity var(--t-base); }
.photo.fade.loaded { opacity: 1; }

/* Podium colorings — #1 orange, #2 purple, #3 green (subtle medal highlight). */
li.bro.r1 .rank { background: var(--orange);       color: var(--bg);   box-shadow: inset 0 1px 0 rgba(255,255,255,0.25); }
li.bro.r1 .photo { border-color: var(--orange); }
li.bro.r2 .rank { background: var(--brand-purple); color: var(--text); box-shadow: inset 0 1px 0 rgba(255,255,255,0.25); }
li.bro.r2 .photo { border-color: var(--brand-purple); }
li.bro.r3 .rank { background: var(--green);        color: var(--bg);   box-shadow: inset 0 1px 0 rgba(255,255,255,0.25); }
li.bro.r3 .photo { border-color: var(--green); }

/* ── Modal overlay + card ────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(10, 4, 18, 0.72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
  padding: var(--sp-4);
  z-index: 50;
  /* Entrance fades in each time the element goes display:none -> flex. */
  animation: overlayIn var(--t-fast) both;
}
@media (min-width: 480px) { .overlay { align-items: center; } }
.modal {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  box-shadow: var(--shadow-pop);
  animation: modalIn var(--t-base) both;   /* fade + slight scale */
}
.modal h2 {
  margin: 0 0 var(--sp-4);
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.01em;
  font-size: 1.6rem;
  color: var(--text);
}
.modal p { margin: 0 0 var(--sp-4); font-size: var(--fs-name); color: var(--text-muted); }
.modal .actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-2); }
.modal .actions .btn { flex: 1 1 0; }

/* ── Keyframes ───────────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

/* Calm motion: honor the OS reduced-motion preference. The progress spinner is
   hidden (the verb text — "Adding…" — still communicates) rather than frozen. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .btn.is-loading::before { display: none; }
}

.hidden { display: none !important; }
