:root {
  --bg: #0e1220;
  --bg-elev: #171d33;
  --bg-elev-2: #202844;
  --border: #2c3556;
  --text: #e9edf8;
  --text-muted: #8f9ab8;
  --gold: #f2b632;
  --gold-dim: #a8802020;
  --green: #3ddc97;
  --red: #ff6b6b;
  --blue: #5aa9ff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
}

* { box-sizing: border-box; }

html, body, #root { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ---------- layout ---------- */

.app-shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.page {
  flex: 1;
  padding: 16px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.page.wide { max-width: 1200px; }

/* centered card layout for onboarding screens */
.center-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

/* ---------- header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(14, 18, 32, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-title .team-chip {
  color: var(--gold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ---------- bottom nav ---------- */

.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: rgba(14, 18, 32, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 11px 4px 13px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: color 0.15s;
}

.bottom-nav a.active { color: var(--gold); }
.bottom-nav .nav-icon { font-size: 19px; line-height: 1; }

/* ---------- typography ---------- */

h1 { font-size: 25px; margin: 0 0 6px; letter-spacing: -0.4px; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 6px; }

.subtitle { color: var(--text-muted); font-size: 14px; margin: 0 0 22px; line-height: 1.5; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }

.brand-mark {
  font-size: 40px;
  text-align: center;
  margin-bottom: 10px;
}

/* ---------- forms ---------- */

.field { margin-bottom: 14px; }

.label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input, .textarea, .select {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px; /* >=16px prevents iOS zoom-on-focus */
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.input:focus, .textarea:focus, .select:focus { border-color: var(--gold); }
.textarea { resize: vertical; min-height: 84px; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 650;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--gold);
  color: #24190a;
  transition: filter 0.15s, opacity 0.15s;
}

.btn:active { filter: brightness(0.9); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.secondary { background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn.danger { background: var(--red); color: #2a0d0d; }
.btn.success { background: var(--green); color: #06281a; }
.btn.auto { width: auto; }
.btn.sm { padding: 8px 13px; font-size: 13px; }

.btn-row { display: flex; gap: 9px; }
.btn-row .btn { flex: 1; }

/* ---------- cards ---------- */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card.flat { background: transparent; }

/* ---------- task cards ---------- */

.category { margin-bottom: 26px; }

.category-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 11px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.category-name {
  font-size: 12.5px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  color: var(--gold);
}

.category-progress { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.task-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
}

.task-card.is-accepted { border-color: #2a5c46; background: #14251f; }
.task-card.is-reviewed { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold-dim); }
.task-card.is-refused { border-color: #5c2a2a; }

.task-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 15px;
}

.task-title { font-weight: 650; font-size: 15.5px; line-height: 1.3; }

.task-points {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid #6d551a;
  padding: 4px 9px;
  border-radius: 20px;
  white-space: nowrap;
}

.task-body { padding: 0 15px 15px; }

.task-prompt {
  font-size: 14.5px;
  line-height: 1.55;
  color: #cdd5e8;
  margin: 0 0 13px;
  white-space: pre-wrap;
}

.task-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  display: block;
  margin-bottom: 13px;
  background: var(--bg-elev-2);
}

/* status pill */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 650;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 0.2px;
}

.pill.todo { background: #232b47; color: var(--text-muted); }
.pill.under_review { background: #2a2547; color: #b39ddb; }
.pill.reviewed { background: var(--gold); color: #24190a; }
.pill.accepted { background: #16382a; color: var(--green); }
.pill.refused { background: #3a1e1e; color: var(--red); }

/* upload / answer controls */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px 16px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 11px;
  transition: border-color 0.15s, color 0.15s;
}

.upload-zone:active { border-color: var(--gold); color: var(--gold); }
.upload-zone .zone-icon { font-size: 28px; }

.preview-wrap { position: relative; margin-bottom: 11px; }

.preview-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  display: block;
}

.preview-clear {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
}

/* the "you have mail" reveal button */
.reveal-btn {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #f2b632, #e08b1e);
  color: #24190a;
  font-size: 15px;
  font-weight: 750;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  animation: pulse-glow 2.2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(242, 182, 50, 0.45); }
  50% { box-shadow: 0 0 0 9px rgba(242, 182, 50, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .reveal-btn { animation: none; }
}

/* ---------- modal / letter ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 18, 0.82);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
  animation: fade-in 0.2s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.letter {
  background: #f6f1e4;
  color: #2b2415;
  border-radius: var(--radius);
  padding: 26px 22px 20px;
  max-width: 460px;
  width: 100%;
  max-height: 84dvh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: letter-in 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

@keyframes letter-in {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.letter-seal { font-size: 34px; text-align: center; margin-bottom: 8px; }

.letter-verdict {
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2.2px;
  text-transform: uppercase;
  margin-bottom: 16px;
}

.letter-verdict.accepted { color: #1e7a52; }
.letter-verdict.refused { color: #a33; }

.letter-body {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.68;
  white-space: pre-wrap;
  margin-bottom: 20px;
}

.letter-score {
  text-align: center;
  font-weight: 750;
  font-size: 15px;
  padding: 11px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.letter-score.accepted { background: #d8ecdf; color: #1e7a52; }
.letter-score.refused { background: #f3dcdc; color: #a33; }

.letter .btn { background: #2b2415; color: #f6f1e4; }

/* ---------- leaderboard ---------- */

.lb-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 15px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.lb-row.me { border-color: var(--gold); background: #1e1c2c; }

.lb-rank {
  font-size: 16px;
  font-weight: 750;
  width: 30px;
  text-align: center;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.lb-rank.top { color: var(--gold); font-size: 20px; }

.lb-name { flex: 1; font-weight: 620; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-meta { font-size: 11.5px; color: var(--text-muted); font-weight: 500; }

.lb-points {
  font-weight: 750;
  font-size: 16px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ---------- misc ---------- */

.alert {
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 13px;
  line-height: 1.45;
}

.alert.error { background: #3a1e1e; color: #ffb3b3; border: 1px solid #5c2a2a; }
.alert.info { background: #1c2c42; color: #a9cdf5; border: 1px solid #2f4a6b; }
.alert.success { background: #16382a; color: #8fe6bd; border: 1px solid #2a5c46; }

.empty-state {
  text-align: center;
  padding: 46px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 42px; margin-bottom: 12px; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.team-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px 15px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  margin-bottom: 8px;
  text-align: left;
  transition: border-color 0.15s;
}

.team-option:active { border-color: var(--gold); }
.team-option .to-name { font-weight: 650; font-size: 15px; }

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.name-badge {
  display: inline-block;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 13px;
  font-weight: 700;
  font-size: 16px;
  color: var(--gold);
  letter-spacing: 0.3px;
}

/* ---------- admin (desktop-first) ---------- */

.admin-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}

.admin-tab {
  padding: 11px 17px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 620;
  white-space: nowrap;
}

.admin-tab.active { color: var(--gold); border-bottom-color: var(--gold); }

.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 15px;
}

.review-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.review-card-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.review-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--bg-elev-2);
  cursor: zoom-in;
}

.review-answer {
  padding: 20px 16px;
  font-size: 18px;
  font-weight: 620;
  text-align: center;
  background: var(--bg-elev-2);
  word-break: break-word;
}

.review-actions { padding: 12px 14px; margin-top: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left;
  padding: 9px 11px;
  color: var(--text-muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 11px; border-bottom: 1px solid var(--border); vertical-align: top; }

.chip {
  display: inline-block;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 9px;
  font-size: 12px;
  margin: 0 5px 5px 0;
}

.chip button {
  background: none;
  border: none;
  color: var(--red);
  font-size: 13px;
  padding: 0 0 0 5px;
  line-height: 1;
}

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

@media (max-width: 560px) {
  .row-2 { grid-template-columns: 1fr; }
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  cursor: zoom-out;
}

.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- post-competition: archive, replay, adjustments ---------- */

.replay-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.replay-clock {
  font-size: 27px;
  font-weight: 750;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

.replay-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.speed-group {
  display: flex;
  gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.speed-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 650;
  padding: 6px 11px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

.speed-btn.active { background: var(--gold); color: #24190a; }

.replay-scrub {
  width: 100%;
  margin: 6px 0 12px;
  accent-color: var(--gold);
  cursor: pointer;
}

.replay-event {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 30px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.replay-track { position: relative; }

.replay-row {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 13px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: transform 0.55s cubic-bezier(0.34, 1.2, 0.42, 1);
  will-change: transform;
}

.replay-row.bump { border-color: var(--gold); }

.replay-rank {
  width: 26px;
  text-align: center;
  font-weight: 750;
  font-size: 14px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.replay-rank.top { color: var(--gold); }

.replay-name {
  width: 190px;
  font-weight: 620;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.replay-bar-wrap { flex: 1; min-width: 40px; }

.replay-bar {
  height: 16px;
  border-radius: 4px;
  background: linear-gradient(90deg, #8a6a18, var(--gold));
  transition: width 0.55s cubic-bezier(0.34, 1.2, 0.42, 1);
  min-width: 2px;
}

.replay-points {
  width: 66px;
  text-align: right;
  font-weight: 750;
  font-size: 15px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

@media (prefers-reduced-motion: reduce) {
  .replay-row, .replay-bar { transition: none; }
}

@media (max-width: 620px) {
  .replay-name { width: 110px; font-size: 13px; }
  .replay-points { width: 52px; font-size: 14px; }
}

/* filters */
.filter-bar {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.filter-bar .select { width: auto; min-width: 150px; padding: 9px 12px; font-size: 14px; }

.arch-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* adjustments */
.adj-layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 860px) {
  .adj-layout { grid-template-columns: 1fr; }
}

.adj-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.adj-delta {
  font-weight: 750;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  min-width: 54px;
}

.adj-delta.plus { color: var(--green); }
.adj-delta.minus { color: var(--red); }

/* Archive mixes short text answers with tall photos; let each card size to its
   own content instead of stretching to the tallest in the row. */
.review-grid.archive { align-items: start; }
.review-grid.archive .review-actions { margin-top: 0; }
