/* ===========================================================================
   Fun Points — "The Parlor Ledger" design system
   Warm game-night betting-parlor: espresso ink, cream paper, gold coins,
   emerald/coral for yes/no. Fraunces (display) · Hanken Grotesk (body) ·
   Space Mono (numbers). Self-hosted fonts; single stylesheet; no JS framework.
   =========================================================================== */

/* ---- Fonts (self-hosted woff2 under /static/fonts) ---------------------- */
@font-face {
  font-family: "Fraunces";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/fraunces-400.woff2") format("woff2");
}
@font-face {
  font-family: "Fraunces";
  font-style: normal; font-weight: 600; font-display: swap;
  src: url("/static/fonts/fraunces-600.woff2") format("woff2");
}
@font-face {
  font-family: "Fraunces";
  font-style: italic; font-weight: 500; font-display: swap;
  src: url("/static/fonts/fraunces-italic-500.woff2") format("woff2");
}
@font-face {
  font-family: "Hanken Grotesk";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/hanken-400.woff2") format("woff2");
}
@font-face {
  font-family: "Hanken Grotesk";
  font-style: normal; font-weight: 500; font-display: swap;
  src: url("/static/fonts/hanken-500.woff2") format("woff2");
}
@font-face {
  font-family: "Hanken Grotesk";
  font-style: normal; font-weight: 700; font-display: swap;
  src: url("/static/fonts/hanken-700.woff2") format("woff2");
}
@font-face {
  font-family: "Space Mono";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/space-mono-400.woff2") format("woff2");
}
@font-face {
  font-family: "Space Mono";
  font-style: normal; font-weight: 700; font-display: swap;
  src: url("/static/fonts/space-mono-700.woff2") format("woff2");
}

/* ---- Tokens ------------------------------------------------------------- */
:root {
  /* Warm ink surfaces */
  --ink-900: #141110;
  --ink-850: #1a1614;
  --ink-800: #1f1a17;
  --ink-700: #2a2320;
  --ink-600: #362d28;

  /* Paper (text) */
  --paper:       #f4efe7;
  --paper-dim:   #c7bcad;
  --paper-faint: #8d8273;

  /* Hairlines */
  --line:        rgba(244, 239, 231, 0.10);
  --line-strong: rgba(244, 239, 231, 0.18);

  /* Coins / primary */
  --gold:      #f2b340;
  --gold-soft: #ffd27a;
  --gold-deep: #c98a1e;
  --gold-ink:  #2a1c05;

  /* Outcomes */
  --emerald:      #34d399;
  --emerald-deep: #1f9c72;
  --emerald-ink:  #04231a;
  --coral:        #ff6f61;
  --coral-deep:   #d64a3e;
  --coral-ink:    #2a0c09;

  /* Status tints (low-chroma fills) */
  --tint-gold:    rgba(242, 179, 64, 0.14);
  --tint-emerald: rgba(52, 211, 153, 0.15);
  --tint-coral:   rgba(255, 111, 97, 0.15);
  --tint-paper:   rgba(244, 239, 231, 0.06);

  /* Type */
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "Space Mono", ui-monospace, "SFMono-Regular", monospace;

  --fs-display: clamp(2.1rem, 7vw, 3rem);
  --fs-h1: clamp(1.6rem, 5vw, 2.1rem);
  --fs-h2: 1.3rem;
  --fs-lg: 1.12rem;
  --fs-body: 1rem;
  --fs-sm: 0.875rem;
  --fs-xs: 0.75rem;

  /* Space */
  --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; --r-md: 16px; --r-lg: 22px; --r-xl: 28px; --r-pill: 999px;

  /* Shadows / glow */
  --shadow-1: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.28);
  --shadow-2: 0 6px 24px rgba(0,0,0,.42), 0 2px 6px rgba(0,0,0,.35);
  --glow-gold: 0 6px 22px rgba(242, 179, 64, 0.30);
  --inset-top: inset 0 1px 0 rgba(255,255,255,.05);

  /* Motion */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur: 220ms;

  --tap: 48px; /* min touch target */
  --maxw: 560px;
}

/* ---- Reset / base ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: 1.5;
  color: var(--paper);
  background-color: var(--ink-900);
  /* Felt-table atmosphere: warm vignette + faint top glow + grain */
  background-image:
    radial-gradient(120% 80% at 50% -10%, rgba(242,179,64,0.08), transparent 60%),
    radial-gradient(100% 70% at 50% 120%, rgba(52,211,153,0.05), transparent 55%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.025'/%3E%3C/svg%3E");
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, svg { display: block; max-width: 100%; }
a { color: var(--gold-soft); text-decoration: none; }
a:hover { color: var(--gold); }
button, input, select, textarea { font: inherit; color: inherit; }

::selection { background: var(--tint-gold); }

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.1; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
.display { font-family: var(--font-display); font-size: var(--fs-display); font-weight: 600; line-height: 1.04; letter-spacing: -0.02em; }
.muted { color: var(--paper-dim); }
.faint { color: var(--paper-faint); }
.serif-it { font-family: var(--font-display); font-style: italic; font-weight: 500; }

/* Numbers always feel like a ledger */
.num { font-family: var(--font-mono); font-feature-settings: "tnum" 1; letter-spacing: -0.02em; }

/* ---- Layout: app shell -------------------------------------------------- */
.app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: calc(var(--sp-3) + env(safe-area-inset-top, 0)) var(--sp-4) var(--sp-3);
  background: linear-gradient(var(--ink-900) 70%, transparent);
  backdrop-filter: blur(8px);
}
.topbar .brand {
  font-family: var(--font-display); font-weight: 600; font-size: 1.25rem;
  letter-spacing: -0.01em; color: var(--paper); display: inline-flex; align-items: center; gap: 8px;
}
.topbar .brand .pip { color: var(--gold); }
.topbar .spacer { flex: 1; }

/* The points purse in the top bar */
.purse {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px 7px 9px;
  background: var(--tint-gold);
  border: 1px solid rgba(242,179,64,.34);
  border-radius: var(--r-pill);
  box-shadow: var(--inset-top);
}
.purse .coin { width: 18px; height: 18px; flex: none; }
.purse .amount { font-family: var(--font-mono); font-weight: 700; color: var(--gold-soft); font-size: var(--fs-sm); }

.main { flex: 1; padding: var(--sp-4) var(--sp-4) var(--sp-8); display: flex; flex-direction: column; gap: var(--sp-4); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin: var(--sp-2) 2px 0; }
.section-head h2 { font-size: 1.05rem; letter-spacing: .01em; }
.section-head .eyebrow { font-family: var(--font-mono); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .14em; color: var(--paper-faint); }

/* ---- Cards -------------------------------------------------------------- */
.card {
  background: linear-gradient(var(--ink-800), var(--ink-850));
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-1), var(--inset-top);
}
.card-tight { padding: var(--sp-4); }
.card-link { display: block; color: inherit; transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.card-link:active { transform: scale(.985); }
.card-link:hover { border-color: var(--line-strong); }

.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  --bg: var(--ink-700); --fg: var(--paper); --bd: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 var(--sp-5);
  font-family: var(--font-body); font-weight: 700; font-size: var(--fs-body);
  color: var(--fg); background: var(--bg);
  border: 1px solid var(--bd); border-radius: var(--r-pill);
  box-shadow: var(--inset-top); cursor: pointer;
  transition: transform 120ms var(--ease), filter var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 2px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: var(--fs-lg); padding: 0 var(--sp-6); }
.btn-sm { min-height: 38px; padding: 0 var(--sp-4); font-size: var(--fs-sm); }

.btn-primary { --bg: linear-gradient(180deg, var(--gold-soft), var(--gold)); --fg: var(--gold-ink); --bd: var(--gold-deep); box-shadow: var(--glow-gold), var(--inset-top); }
.btn-yes { --bg: linear-gradient(180deg, #4be4ab, var(--emerald)); --fg: var(--emerald-ink); --bd: var(--emerald-deep); }
.btn-no  { --bg: linear-gradient(180deg, #ff8a7e, var(--coral)); --fg: var(--coral-ink); --bd: var(--coral-deep); }
.btn-ghost { --bg: transparent; --bd: var(--line-strong); box-shadow: none; }
.btn-danger { --bg: transparent; --fg: var(--coral); --bd: rgba(255,111,97,.4); box-shadow: none; }

/* ---- Forms -------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.label { font-weight: 700; font-size: var(--fs-sm); color: var(--paper); }
.hint { font-size: var(--fs-xs); color: var(--paper-faint); }
.input, .textarea, .select {
  width: 100%; min-height: var(--tap); padding: 12px 14px;
  background: var(--ink-900); color: var(--paper);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--paper-faint); }
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--tint-gold);
}
.input-coin { padding-left: 38px; font-family: var(--font-mono); }
.input-wrap { position: relative; }
.input-wrap .coin-prefix { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; pointer-events: none; opacity: .9; }

/* Segmented choice (e.g. pick your side) */
.segment { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; padding: 5px; background: var(--ink-900); border: 1px solid var(--line); border-radius: var(--r-pill); }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment label {
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: var(--r-pill); font-weight: 700; font-size: var(--fs-sm); color: var(--paper-dim);
  cursor: pointer; transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.segment input:checked + label { color: var(--paper); }
.segment input.s-yes:checked + label { background: var(--tint-emerald); color: var(--emerald); }
.segment input.s-no:checked + label  { background: var(--tint-coral); color: var(--coral); }
.segment input.s-plain:checked + label { background: var(--tint-paper); color: var(--paper); }

/* ---- Badges / pills ----------------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-pill);
  font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; line-height: 1;
  background: var(--tint-paper); color: var(--paper-dim); border: 1px solid var(--line);
}
.pill-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-open    { color: var(--gold-soft); background: var(--tint-gold); border-color: rgba(242,179,64,.3); }
.pill-pending { color: var(--paper-dim); }
.pill-resolved{ color: var(--paper-dim); }
.pill-won     { color: var(--emerald); background: var(--tint-emerald); border-color: rgba(52,211,153,.3); }
.pill-lost    { color: var(--coral); background: var(--tint-coral); border-color: rgba(255,111,97,.3); }
.pill-void    { color: var(--paper-faint); }

/* ---- Avatars / member rows --------------------------------------------- */
.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 600; font-size: 1rem; color: var(--gold-ink);
  background: linear-gradient(140deg, var(--gold-soft), var(--gold-deep));
  box-shadow: var(--inset-top); text-transform: uppercase;
}
.avatar-sm { width: 30px; height: 30px; font-size: .8rem; }
.avatar-emerald { background: linear-gradient(140deg, #6ff0c0, var(--emerald-deep)); color: var(--emerald-ink); }
.avatar-coral   { background: linear-gradient(140deg, #ffa99f, var(--coral-deep)); color: var(--coral-ink); }
.avatar-sky     { background: linear-gradient(140deg, #9bd0f0, #3f7fb0); color: #04161f; }

.member { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-top: 1px solid var(--line); }
.member:first-child { border-top: 0; }
.member .who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.member .who .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member .who .sub { font-size: var(--fs-xs); color: var(--paper-faint); }
.member .bal { margin-left: auto; }

/* Points display */
.points { display: inline-flex; align-items: baseline; gap: 4px; font-family: var(--font-mono); font-weight: 700; }
.points .v { color: var(--gold-soft); }
.points .u { font-size: .7em; color: var(--paper-faint); text-transform: uppercase; letter-spacing: .1em; }
.points-lg .v { font-size: 1.5rem; }
.points-pos .v { color: var(--emerald); }
.points-neg .v { color: var(--coral); }

/* ---- Leaderboard -------------------------------------------------------- */
.board { display: flex; flex-direction: column; }
.board .rank { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-top: 1px solid var(--line); }
.board .rank:first-child { border-top: 0; }
.board .rank .no { width: 26px; text-align: center; font-family: var(--font-mono); font-weight: 700; color: var(--paper-faint); }
.board .rank.top .no { color: var(--gold); }

/* ---- The wager (bet) widget -------------------------------------------- */
.wager {
  position: relative; overflow: hidden;
  border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  background:
    radial-gradient(120% 60% at 0% 0%, rgba(52,211,153,.10), transparent 55%),
    radial-gradient(120% 60% at 100% 100%, rgba(255,111,97,.10), transparent 55%),
    linear-gradient(var(--ink-800), var(--ink-850));
  box-shadow: var(--shadow-1), var(--inset-top);
}
.wager .q {
  font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600; line-height: 1.25;
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
}
.wager .sides { display: grid; grid-template-columns: 1fr 1fr; }
.wager .side { padding: var(--sp-4) var(--sp-5) var(--sp-5); border-top: 1px solid var(--line); }
.wager .side + .side { border-left: 1px solid var(--line); }
.wager .side .tag { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.wager .side.yes .tag { color: var(--emerald); }
.wager .side.no  .tag { color: var(--coral); }
.wager .side .line { margin-top: 8px; font-size: var(--fs-sm); color: var(--paper-dim); }
.wager .side .win { margin-top: 4px; font-family: var(--font-mono); font-weight: 700; font-size: 1.25rem; }
.wager .side.yes .win { color: var(--emerald); }
.wager .side.no  .win { color: var(--coral); }

/* Plain-language one-liner + odds chip */
.odds-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 700;
  border-radius: var(--r-pill); background: var(--tint-paper); color: var(--paper-dim); border: 1px solid var(--line);
}
.you-stake {
  margin: 0 var(--sp-5) var(--sp-5); padding: var(--sp-4);
  border-radius: var(--r-md); background: var(--tint-gold); border: 1px solid rgba(242,179,64,.28);
  font-size: var(--fs-sm); color: var(--paper);
}
.you-stake b { font-family: var(--font-mono); color: var(--gold-soft); }

/* Resolve control: two big outcome buttons + void */
.resolve { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.resolve .btn { width: 100%; }
.resolve .void { grid-column: 1 / -1; }

/* ---- Empty state -------------------------------------------------------- */
.empty { text-align: center; padding: var(--sp-7) var(--sp-5); }
.empty .glyph { font-size: 2.4rem; }
.empty h2 { font-size: var(--fs-h2); margin-top: var(--sp-3); }
.empty p { color: var(--paper-dim); margin-top: var(--sp-2); }
.empty .btn { margin-top: var(--sp-5); }

/* ---- Toast -------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0)); transform: translateX(-50%);
  z-index: 50; max-width: calc(var(--maxw) - 32px); width: max-content;
  padding: 12px 16px; border-radius: var(--r-pill);
  background: var(--ink-700); border: 1px solid var(--line-strong); box-shadow: var(--shadow-2);
  font-weight: 600; font-size: var(--fs-sm);
  animation: toast-in var(--dur) var(--ease);
}
.toast-good { border-color: rgba(52,211,153,.4); color: var(--emerald); }
.toast-bad  { border-color: rgba(255,111,97,.4); color: var(--coral); }

/* ---- Auth / centered narrow pages -------------------------------------- */
.centered { min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-5); }
.auth-card { width: 100%; max-width: 400px; }
.lede { color: var(--paper-dim); margin-top: var(--sp-2); }

/* ---- Coin glyph helper -------------------------------------------------- */
.coin-svg { display: inline-block; vertical-align: -0.18em; }

/* The shared <svg> gradient defs must take no space (an unstyled inline SVG
   otherwise renders at the default 300x150 and pushes content down). */
.hidden-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---- Motion: staggered reveal on load ---------------------------------- */
@media (prefers-reduced-motion: no-preference) {
  .reveal > * { animation: rise 460ms var(--ease) both; }
  .reveal > *:nth-child(1) { animation-delay: 40ms; }
  .reveal > *:nth-child(2) { animation-delay: 90ms; }
  .reveal > *:nth-child(3) { animation-delay: 140ms; }
  .reveal > *:nth-child(4) { animation-delay: 190ms; }
  .reveal > *:nth-child(5) { animation-delay: 240ms; }
  .reveal > *:nth-child(6) { animation-delay: 290ms; }
  .reveal > *:nth-child(n+7) { animation-delay: 330ms; }
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* HTMX swap fade */
.htmx-swapping { opacity: 0; transition: opacity 120ms var(--ease); }
.htmx-settling { opacity: 1; }

/* ---- Utilities ---------------------------------------------------------- */
.mt-2 { margin-top: var(--sp-2); } .mt-3 { margin-top: var(--sp-3); } .mt-4 { margin-top: var(--sp-4); }
.center { text-align: center; }
.divider { height: 1px; background: var(--line); border: 0; margin: var(--sp-2) 0; }
.link-quiet { color: var(--paper-dim); } .link-quiet:hover { color: var(--paper); }

/* Layout helpers (so markup stays inline-style-free under our strict CSP) */
.col { display: flex; flex-direction: column; }
.flex-1 { flex: 1; min-width: 0; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.strong { font-weight: 700; }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }

/* Name + subtitle stack used in member rows, cards, ranks */
.who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.who .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .sub { font-size: var(--fs-xs); color: var(--paper-faint); }

/* Italic serif question line in bet list cards */
.bet-q { font-family: var(--font-display); font-style: italic; font-weight: 500; font-size: 1.05rem; line-height: 1.3; }
/* Neutral variant of the stake callout */
.you-stake.quiet { background: var(--tint-paper); border-color: var(--line); }
