:root {
  --bg: #0b1120;
  --bg-glow-1: rgba(56, 189, 248, 0.12);
  --bg-glow-2: rgba(129, 140, 248, 0.12);
  --card: #151e31;
  --card-2: #1e2a42;
  --border: #2a3a56;
  --text: #e6edf7;
  --muted: #8fa3bd;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --gold: #fbbf24;
  --silver: #cbd5e1;
  --bronze: #d97706;
  --green: #34d399;
  --red: #f87171;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over section display rules */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(900px 400px at 15% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(900px 400px at 85% -10%, var(--bg-glow-2), transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---------- Header ---------- */
header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.25rem;
  padding-top: calc(0.9rem + env(safe-area-inset-top));
  background: rgba(21, 30, 49, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-mark { display: inline-flex; }
.brand-mark svg {
  width: 1.9rem;
  height: 1.9rem;
  filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.45));
}
header h1 { margin: 0; font-size: 1.05rem; letter-spacing: 0.01em; }

nav { display: flex; align-items: center; gap: 0.75rem; }

.seg {
  display: flex;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.seg-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  min-height: 40px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #0b1120;
}
.seg-btn.active .live-dot { background: #0b1120; }
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem;
  /* Leave room for the sticky submit bar on the vote screen */
  padding-bottom: calc(6.5rem + env(safe-area-inset-bottom));
}

h2 { margin-top: 0; }

.hint { color: var(--muted); font-size: 0.9rem; }
.eyebrow {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ---------- Join ---------- */
#join-screen {
  display: flex;
  justify-content: center;
  padding-top: 3vh;
}

.join-card {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.join-card h2 { margin: 0 0 0.35rem; font-size: 1.5rem; }
.join-card .hint { margin: 0 0 1.4rem; }

#join-form { display: flex; flex-direction: column; gap: 0.85rem; }

#join-form label,
.pill-group legend {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0;
}

.pill-group { border: none; margin: 0; padding: 0; }

#group-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.pill {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.6rem 1rem;
  min-height: 44px;
  font-size: 0.92rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
}
.pill:hover { border-color: var(--accent); }
.pill:active { transform: scale(0.97); }
.pill.selected {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #0b1120;
  font-weight: 700;
}
.pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#join-form input {
  padding: 0.75rem 0.85rem;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font-size: 1rem; /* prevents iOS zoom-on-focus */
  transition: border-color 0.15s ease;
}
#join-form input:focus { outline: none; border-color: var(--accent); }

button.primary {
  padding: 0.85rem 1.2rem;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #0b1120;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.08s ease;
}
button.primary:hover { filter: brightness(1.1); }
button.primary:active { transform: scale(0.99); }
button.primary:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---------- Voted banner ---------- */
.voted-banner {
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.4);
  color: var(--green);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.banner-link {
  display: block;
  margin-top: 0.35rem;
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}
.banner-link:hover { text-decoration: underline; }

/* ---------- Thank you ---------- */
#thanks-screen {
  display: flex;
  justify-content: center;
  padding-top: 8vh;
}

.thanks-card {
  text-align: center;
  background: var(--card);
  border: 1px solid rgba(52, 211, 153, 0.45);
  border-radius: var(--radius);
  padding: 3rem 2.5rem;
  box-shadow: var(--shadow), 0 0 60px rgba(52, 211, 153, 0.08);
  max-width: 420px;
  width: 100%;
}

.thanks-emoji {
  line-height: 1;
  margin-bottom: 1rem;
  animation: thanks-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.thanks-emoji svg {
  width: 64px;
  height: 64px;
}
@keyframes thanks-pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.thanks-card h2 {
  margin: 0 0 0.5rem;
  font-size: 2.2rem;
  background: linear-gradient(90deg, var(--green), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.thanks-sub { color: var(--text); font-weight: 600; margin: 0 0 0.35rem; }

/* ---------- Voting: sticky progress ---------- */
.progress-sticky {
  position: sticky;
  top: calc(60px + env(safe-area-inset-top));
  z-index: 4;
  background: rgba(11, 17, 32, 0.92);
  backdrop-filter: blur(8px);
  padding: 0.6rem 0 0.8rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.progress-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.progress-head h2 { margin: 0; font-size: 1.15rem; }
.progress-text { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

.progress-track {
  margin-top: 0.55rem;
  height: 8px;
  background: var(--card-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--accent));
  transition: width 0.4s ease;
}

/* ---------- Team cards ---------- */
.team-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  transition: border-color 0.2s ease;
}
.team-card.voted { border-color: rgba(52, 211, 153, 0.45); }

.team-card h3 {
  margin: 0 0 1rem;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  position: relative;
  padding-bottom: 0.55rem;
}

/* Short gradient underline anchors the name */
.team-card h3::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 3.5rem;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
  border: 1px solid rgba(52, 211, 153, 0.4);
}

.criterion {
  padding: 0.7rem 0;
  border-top: 1px solid var(--border);
}
.criterion:first-of-type { border-top: none; }

.criterion-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.criterion-name { font-weight: 600; font-size: 0.95rem; }
.criterion-score {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  min-width: 3ch;
  text-align: right;
}
.criterion-score.empty { color: var(--muted); font-weight: 400; }

.criterion-desc { color: var(--muted); font-size: 0.8rem; margin: 0.2rem 0 0.45rem; }

/* Stars spread across the full row so thumbs land easily on mobile */
.stars {
  display: flex;
  gap: 0.25rem;
  max-width: 340px;
}

.star {
  flex: 1;
  background: none;
  border: none;
  font-size: 1.9rem;
  cursor: pointer;
  color: #3b4a63;
  padding: 0.25rem 0;
  min-height: 48px;
  line-height: 1;
  border-radius: 8px;
  text-align: center;
  transition: transform 0.08s ease, color 0.12s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.star.filled { color: var(--gold); }
.star:disabled { cursor: default; }
.star:not(:disabled):active { transform: scale(1.2); }
.star:focus-visible { outline: 2px solid var(--accent); }

@media (hover: hover) {
  .star:not(:disabled):hover { transform: scale(1.15); }
}

/* ---------- Sticky submit bar (single submission) ---------- */
.submit-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  background: rgba(21, 30, 49, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}

.submit-status {
  color: var(--muted);
  font-size: 0.85rem;
  min-width: 0;
}

.submit-bar .primary {
  flex-shrink: 0;
  min-width: 170px;
}

.submit-bar .primary.confirming {
  background: linear-gradient(90deg, var(--gold), #f59e0b);
  animation: nudge 0.3s ease;
}
@keyframes nudge {
  0% { transform: scale(1); }
  50% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

/* ---------- Results ---------- */
.results-head { margin-bottom: 1rem; }
.results-head h2 { margin-bottom: 0.25rem; }

.result-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.result-card.rank-1 { border-color: rgba(251, 191, 36, 0.5); }
.result-card.rank-2 { border-color: rgba(203, 213, 225, 0.4); }
.result-card.rank-3 { border-color: rgba(217, 119, 6, 0.45); }
.result-card.rank-1::before,
.result-card.rank-2::before,
.result-card.rank-3::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
}
.result-card.rank-1::before { background: var(--gold); }
.result-card.rank-2::before { background: var(--silver); }
.result-card.rank-3::before { background: var(--bronze); }

.result-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.result-head h3 { margin: 0; font-size: 1.15rem; display: flex; align-items: center; }

.rank { font-size: 1.4rem; margin-right: 0.5rem; }

.result-total {
  font-size: 1.3rem;
  font-weight: 800;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-variant-numeric: tabular-nums;
}
.result-total small { font-size: 0.8rem; font-weight: 600; color: var(--muted); -webkit-text-fill-color: var(--muted); }
.result-votes { color: var(--muted); font-size: 0.82rem; text-align: right; }

.bar-row {
  display: grid;
  grid-template-columns: 140px 1fr 46px;
  align-items: center;
  gap: 0.6rem;
  margin: 0.5rem 0;
}
.bar-label { font-size: 0.85rem; color: var(--muted); }
.bar-track { background: var(--card-2); border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.bar-value { font-size: 0.85rem; text-align: right; font-variant-numeric: tabular-nums; }

.live-dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: calc(5.5rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 2rem);
  background: var(--card-2);
  border: 1px solid var(--green);
  color: var(--text);
  border-radius: 10px;
  padding: 0.75rem 1.3rem;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  z-index: 10;
  animation: toast-in 0.2s ease;
}
#toast.error { border-color: var(--red); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Responsive & a11y ---------- */
@media (max-width: 560px) {
  main { padding: 1rem; padding-bottom: calc(7rem + env(safe-area-inset-bottom)); }
  .bar-row { grid-template-columns: 96px 1fr 42px; }
  header { padding: 0.7rem 1rem; padding-top: calc(0.7rem + env(safe-area-inset-top)); }
  header h1 { font-size: 1rem; }
  .join-card { padding: 1.3rem; }
  .stars { max-width: none; }        /* stars span the full card width */
  .star { font-size: 2.1rem; min-height: 52px; }
  .progress-sticky { top: calc(56px + env(safe-area-inset-top)); }
  .submit-bar { flex-direction: column; align-items: stretch; gap: 0.4rem; }
  .submit-status { text-align: center; }
  .submit-bar .primary { width: 100%; }
  .result-total { font-size: 1.15rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
