/* ============================================================================
   Beer Pong — "Championship" theme
   Deep navy + metallic gold, varsity serif display (Fraunces) over a clean
   grotesque body (Hanken Grotesk). Mobile-first, one-handed, party-proof.
   ============================================================================ */

@font-face {
  font-family: "Fraunces";
  src: url("/static/fonts/fraunces-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("/static/fonts/fraunces-900.woff2") format("woff2");
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Hanken Grotesk";
  src: url("/static/fonts/hanken-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Hanken Grotesk";
  src: url("/static/fonts/hanken-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Hanken Grotesk";
  src: url("/static/fonts/hanken-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0a1521;
  --bg-2: #0d1b2a;
  --panel: #112236;
  --panel-2: #16304a;
  --line: rgba(201, 162, 39, 0.20);
  --line-soft: rgba(236, 230, 214, 0.09);
  --gold: #c9a227;
  --gold-bright: #e7c85a;
  --gold-deep: #9c7d1a;
  --text: #f1ead9;
  --muted: #8fa1b4;
  --danger: #e5694f;
  --green: #5bbf93;
  --radius: 16px;
  --gap: 16px;
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --body: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--body);
  color: var(--text);
  line-height: 1.55;
  background-color: var(--bg);
  /* atmosphere: warm gold glow up top, fading into deep navy + faint grain */
  background-image:
    radial-gradient(120% 70% at 50% -10%, rgba(201, 162, 39, 0.16), rgba(201, 162, 39, 0) 60%),
    radial-gradient(90% 60% at 100% 0%, rgba(86, 124, 168, 0.10), rgba(0, 0, 0, 0) 55%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 60%);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
}

/* faint film-grain overlay for depth */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: 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.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ----- top bar ----- */
header.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) clamp(16px, 5vw, 28px) 14px;
  background: linear-gradient(180deg, rgba(11, 22, 34, 0.92), rgba(11, 22, 34, 0.62));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
header.topbar .brand {
  font-family: var(--display);
  font-weight: 900;
  font-size: 1.2rem;
  letter-spacing: 0.2px;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}
header.topbar .brand span { color: var(--gold); }
header.topbar nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  font-size: 0.9rem;
}
header.topbar nav a { color: var(--muted); text-decoration: none; }
header.topbar nav a:hover { color: var(--text); }

/* nav action pills */
header.topbar nav a.navbtn {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}
header.topbar nav a.navbtn:hover {
  text-decoration: none;
  color: var(--gold-bright);
  border-color: var(--gold);
}
header.topbar nav a.navbtn.gold {
  color: #1a1205;
  border-color: transparent;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  box-shadow: 0 6px 16px -9px rgba(201, 162, 39, 0.8);
}
header.topbar nav a.navbtn.gold:hover { color: #1a1205; filter: brightness(1.04); }
header.topbar nav a.navlink { color: var(--muted); font-size: 0.85rem; }
header.topbar nav a.navlink:hover { color: var(--text); }

/* language toggle */
.langpick {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.2);
}
.langpick button {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 1.05rem;
  line-height: 1;
  padding: 5px 9px;
  cursor: pointer;
  /* inactive flags are dimmed/desaturated so the active one reads clearly */
  filter: grayscale(0.8);
  opacity: 0.5;
  transition: filter 0.15s ease, opacity 0.15s ease;
}
.langpick button:hover { opacity: 0.85; filter: grayscale(0.3); }
.langpick button.on {
  filter: none;
  opacity: 1;
  background: rgba(201, 162, 39, 0.28);
}

/* ----- layout ----- */
.wrap {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 22px clamp(16px, 5vw, 28px) calc(40px + env(safe-area-inset-bottom));
}

h1, h2, h3 { font-family: var(--display); }
h1 {
  font-weight: 900;
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  line-height: 1.05;
  letter-spacing: -0.01em;
  margin: 0.1em 0 0.45em;
}
h2 { font-weight: 600; font-size: 1.3rem; margin: 1.4em 0 0.5em; }
h3 {
  font-family: var(--body);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 1.3em 0 0.5em;
}
a { color: var(--gold-bright); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ----- cards ----- */
.card {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(0, 0, 0, 0)),
    var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: var(--gap);
  box-shadow: 0 14px 40px -28px rgba(0, 0, 0, 0.9);
}

/* staggered entrance */
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.wrap > h1,
.wrap > h2,
.wrap > .card,
.wrap > .match,
.wrap > .btn {
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.wrap > *:nth-child(1) { animation-delay: 0.02s; }
.wrap > *:nth-child(2) { animation-delay: 0.07s; }
.wrap > *:nth-child(3) { animation-delay: 0.12s; }
.wrap > *:nth-child(4) { animation-delay: 0.17s; }
.wrap > *:nth-child(5) { animation-delay: 0.22s; }
.wrap > *:nth-child(n+6) { animation-delay: 0.26s; }
@media (prefers-reduced-motion: reduce) {
  .wrap > * { animation: none !important; }
}

/* ----- forms ----- */
label {
  display: block;
  margin: 14px 0 5px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}
input, select, textarea {
  width: 100%;
  padding: 14px;
  font-size: 1rem; /* >=16px: no iOS zoom */
  font-family: inherit;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.22);
}
textarea { resize: vertical; min-height: 120px; line-height: 1.6; }

/* ----- buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 18px;
  margin-top: 16px;
  font-family: var(--body);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  text-decoration: none;
  border: none;
  border-radius: 13px;
  cursor: pointer;
  color: #1a1205;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  box-shadow: 0 8px 22px -10px rgba(201, 162, 39, 0.7);
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:hover { text-decoration: none; filter: brightness(1.04); }
.btn:active { transform: translateY(1px) scale(0.995); }
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  filter: grayscale(0.3);
}
.btn.secondary {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn.success {
  background: linear-gradient(180deg, #6fd0a4, var(--green));
  color: #042018;
  box-shadow: 0 8px 22px -10px rgba(91, 191, 147, 0.7);
}
.btn.small { width: auto; padding: 10px 16px; margin-top: 0; font-size: 0.9rem; border-radius: 11px; }
.btn.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  box-shadow: none;
}
.btn.danger:hover { filter: none; background: rgba(229, 105, 79, 0.14); }

/* sticky primary action — always thumb-reachable */
.btn.sticky {
  position: sticky;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 6;
}

/* ----- flash ----- */
.flash {
  padding: 13px 15px;
  border-radius: 12px;
  margin-bottom: var(--gap);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.95rem;
}
.flash.error { background: rgba(229, 105, 79, 0.12); border-color: var(--danger); color: #ffd6cc; }
.flash.ok { background: rgba(91, 191, 147, 0.12); border-color: var(--green); color: #c8f3e1; }

/* ----- table ----- */
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line-soft); }
th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
td:first-child, th:first-child { color: var(--muted); }

/* ----- badges ----- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line-soft);
  vertical-align: middle;
}
.badge.live {
  background: rgba(201, 162, 39, 0.16);
  border-color: var(--gold);
  color: var(--gold-bright);
}
.badge.live::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--gold-bright);
  vertical-align: middle;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(231, 200, 90, 0.6); } 50% { opacity: 0.5; box-shadow: 0 0 0 5px rgba(231, 200, 90, 0); } }
.badge.done { background: rgba(91, 191, 147, 0.16); border-color: var(--green); color: #8fe3c0; }
.badge.pending { color: var(--muted); }

/* ----- match row (history, admin, generic) ----- */
.match {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 13px;
  margin-bottom: 10px;
  background: var(--panel);
}
.match .side { flex: 1; min-width: 0; }
.match .side.win { font-weight: 700; color: var(--gold-bright); }
.match .vs { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.1em; padding: 0 4px; }
.match .score { font-family: var(--display); font-weight: 900; font-variant-numeric: tabular-nums; font-size: 1.2rem; }

/* ----- hero "your match" card ----- */
.matchcard {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--gold);
  background:
    radial-gradient(120% 90% at 50% -20%, rgba(201, 162, 39, 0.18), rgba(0, 0, 0, 0) 60%),
    linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: 0 22px 60px -30px rgba(201, 162, 39, 0.5);
}
.matchcard .roundtag {
  font-family: var(--body);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 14px;
}
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.scoreboard .who {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(1.1rem, 5vw, 1.5rem);
  line-height: 1.1;
  word-break: break-word;
}
.scoreboard .who.me { color: var(--gold-bright); }
.scoreboard .who.right { text-align: right; }
.scoreboard .crossed {
  font-family: var(--display);
  font-weight: 900;
  font-size: 1.4rem;
  color: var(--muted);
  opacity: 0.7;
}

/* ----- score steppers ----- */
.steppers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}
.steppers .field { min-width: 0; }
.steppers .caption {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}
.stepper {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-2);
}
.stepper button {
  appearance: none;
  flex: 0 0 auto;
  width: 50px;
  border: none;
  background: rgba(255, 255, 255, 0.04);
  color: var(--gold-bright);
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.stepper button:active { background: rgba(201, 162, 39, 0.22); }
.stepper .val {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  font-size: 2rem;
  min-width: 2ch;
}
/* the real input — visible when JS is off, hidden when steppers are active */
.stepper input {
  width: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-family: var(--display);
  font-weight: 900;
  font-size: 1.8rem;
  padding: 10px 0;
}
.stepper input:focus { box-shadow: none; }
.js .stepper input { display: none; }
.js .stepper.nojs-only { display: none; }

/* ----- QR / join ----- */
.qr {
  display: block;
  margin: 16px auto;
  width: 230px;
  height: 230px;
  image-rendering: pixelated;
  background: #fff;
  padding: 12px;
  border-radius: 14px;
  box-shadow: 0 16px 40px -20px rgba(0, 0, 0, 0.8);
}
.joinlink {
  word-break: break-all;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--bg-2);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-soft);
}

/* ----- bracket ----- */
.bracket-wrap { position: relative; }
.bracket-wrap::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 14px;
  width: 38px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(10, 21, 33, 0), var(--bg));
}
.bracket-wrap .hint {
  position: absolute;
  top: -26px; right: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.bracket { display: flex; gap: 22px; overflow-x: auto; padding: 6px 2px 14px; scroll-snap-type: x proximity; }
.bracket .round { display: flex; flex-direction: column; justify-content: space-around; gap: 14px; min-width: 172px; scroll-snap-align: start; }
.bracket .round h4 {
  margin: 0 0 2px;
  font-family: var(--body);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}
.bracket .bm {
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  background: var(--panel);
  font-size: 0.86rem;
  overflow: hidden;
}
.bracket .bm .row { display: flex; justify-content: space-between; gap: 8px; padding: 9px 11px; }
.bracket .bm .row + .row { border-top: 1px solid var(--line-soft); }
.bracket .bm .row.win { color: var(--gold-bright); font-weight: 700; background: rgba(201, 162, 39, 0.08); }
.bracket .bm .row .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 116px; }
.bracket .bm .row span:last-child { font-family: var(--display); font-weight: 900; font-variant-numeric: tabular-nums; }
.you { color: var(--gold); font-weight: 700; }

/* ----- grids ----- */
.grid2 { display: grid; grid-template-columns: 1fr; gap: var(--gap); }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* ----- champion screen ----- */
.champion {
  position: relative;
  overflow: hidden;
  text-align: center;
  border: 1px solid var(--gold);
  background:
    radial-gradient(120% 100% at 50% 0%, rgba(231, 200, 90, 0.28), rgba(0, 0, 0, 0) 62%),
    linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: 0 26px 70px -30px rgba(201, 162, 39, 0.6);
  padding: 30px 22px;
}
.champion .trophy {
  font-size: 3.6rem;
  line-height: 1;
  display: inline-block;
  animation: trophy 2.6s ease-in-out infinite;
  filter: drop-shadow(0 6px 18px rgba(201, 162, 39, 0.5));
}
@keyframes trophy {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-6px) rotate(3deg); }
}
.champion .crowned {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(2rem, 11vw, 3.4rem);
  line-height: 1.02;
  margin: 8px 0 4px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold-deep));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.champion h2 { margin: 0.2em 0; }

/* live-update wrapper: transparent to layout so cards stack as before */
#me-live { display: contents; }

/* confetti overlay */
#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

/* ----- footer ----- */
footer {
  position: relative;
  z-index: 1;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  padding: 30px 0 calc(30px + env(safe-area-inset-bottom));
}
.inline-form { display: inline; }

/* team generator */
.teamcard h3 {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 900;
  text-transform: none;
  letter-spacing: 0;
  color: var(--gold-bright);
  margin: 0 0 12px;
}
.teamlist { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-block;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  font-weight: 600;
  font-size: 0.92rem;
}

/* compact admin score entry */
.scoreinputs { display: flex; gap: 10px; align-items: end; margin-top: 12px; }
.scoreinputs > div { flex: 1; }
.scoreinputs > div:last-child { flex: 0 0 auto; }
.scoreinputs label { margin-top: 0; }
