:root {
  --bg: #f4efe8;
  --ink: #121212;
  --accent: #df5f2d;
  --accent-dark: #b34720;
  --card: #fffaf4;
  --line: #2f2b28;
  --muted: #5f5751;
  --good: #1f8f4f;
  --warn: #8e3b22;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  background: radial-gradient(circle at top right, #ffe4c6, var(--bg));
  color: var(--ink);
  min-height: 100vh;
}

.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.2;
  background-image: radial-gradient(#000 0.4px, transparent 0.4px);
  background-size: 6px 6px;
}

.toast-stack {
  position: fixed;
  top: 14px;
  right: 14px;
  display: grid;
  gap: 0.5rem;
  z-index: 10;
}

.toast {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 10px;
  box-shadow: 2px 2px 0 var(--line);
  padding: 0.5rem 0.7rem;
  font-size: 0.88rem;
}

.toast.error { border-color: #a23b2a; }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1200px, 94vw);
  margin: 1.5rem auto 3rem;
  display: grid;
  gap: 1rem;
}

.hidden { display: none; }

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 18px;
  box-shadow: 4px 4px 0 var(--line);
  padding: 1rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-wrap {
  display: flex;
  align-items: center;
}

.brand-logo {
  width: min(420px, 58vw);
  min-width: 210px;
  height: auto;
  display: block;
  color: var(--line);
}

h1, h2, h3 { margin: 0.1rem 0; }

h1 {
  font-family: "Bebas Neue", sans-serif;
  letter-spacing: 1px;
  font-size: clamp(2rem, 5vw, 3rem);
}

.kicker {
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.tiny {
  font-size: 0.78rem;
  color: var(--muted);
}

.route-nav, .actions, .mode-switch, .scope-switch {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.auth {
  max-width: 480px;
}

.auth-form {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.8rem;
}

input, textarea, select {
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  font: inherit;
  width: 100%;
  background: #fff;
}

textarea { resize: vertical; }

.separator {
  border: 0;
  border-top: 1px dashed #c9bdb2;
  margin: 0.9rem 0;
}

.camera-preview {
  width: 100%;
  max-height: 280px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #111;
  margin-top: 0.55rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.7rem;
}

.stats div { display: grid; }

.avatar-cell {
  display: grid;
  gap: 0.35rem;
  align-content: start;
}

.avatar-img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: #fff;
  object-fit: cover;
}

#avatar-file {
  font-size: 0.78rem;
  padding: 0.35rem;
}

.profile-avatar {
  width: 88px;
  height: 88px;
  margin-bottom: 0.45rem;
}

.label {
  font-size: 0.77rem;
  color: var(--muted);
}

.arena-grid {
  display: grid;
  grid-template-columns: 1.7fr 1fr;
  gap: 1rem;
}

.season-card,
.mission-card {
  display: grid;
  gap: 0.5rem;
}

.progress-wrap {
  height: 12px;
  border-radius: 99px;
  border: 1px solid #d4c1b0;
  background: #fff4e8;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #df5f2d, #f1974f);
  transition: width 200ms ease;
}

.season-meta {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.challenge-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.timer {
  width: 54px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-weight: 700;
  background: #fff;
}

.constraint {
  background: #ffedda;
  padding: 0.7rem;
  border-radius: 10px;
  border: 1px dashed var(--line);
}

.btn {
  background: var(--accent);
  border: 2px solid var(--line);
  color: white;
  font-weight: 700;
  border-radius: 11px;
  padding: 0.62rem 0.9rem;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--line);
}

.btn.small {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

.btn:hover { background: var(--accent-dark); }

.btn.ghost {
  background: white;
  color: var(--ink);
}

.btn.active {
  background: #ffd6bb;
}

.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  box-shadow: none;
}

.feedback {
  min-height: 1.4rem;
  margin-top: 0.7rem;
  color: var(--good);
  font-weight: 500;
}

.breakdown ul {
  list-style: none;
  padding: 0;
  margin: 0.8rem 0;
  display: grid;
  gap: 0.4rem;
}

.breakdown li {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed #b7aea7;
  padding-bottom: 0.2rem;
}

.leaderboard-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.stats-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem;
  margin-top: 0.5rem;
}

.stats-kpis div {
  display: grid;
  background: #fff5ea;
  border: 1px solid #dbc8b8;
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
}

.chart-grid {
  margin-top: 0.85rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.chart-grid article {
  background: #fffdf9;
  border: 1px solid #dbc8b8;
  border-radius: 12px;
  padding: 0.6rem;
}

.chart-grid canvas {
  width: 100%;
  height: 190px;
  max-height: 190px;
  display: block;
  margin-top: 0.4rem;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #eadfd5;
}

.result-kpis {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.result-kpis div {
  display: grid;
  background: #fff5ea;
  border: 1px solid #dbc8b8;
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
}

#next-challenge {
  margin-top: 0.6rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.7rem;
}

th, td {
  text-align: left;
  border-bottom: 1px solid #ddd1c8;
  padding: 0.58rem 0.2rem;
  vertical-align: top;
}

.handle-link {
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font: inherit;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.handle-link:hover {
  color: var(--accent);
}

.me-row td {
  background: #fff0df;
  font-weight: 700;
}

.skeleton-row td {
  color: transparent;
  position: relative;
}

.skeleton-row td::after {
  content: "";
  position: absolute;
  inset: 8px 8px;
  border-radius: 8px;
  background: linear-gradient(90deg, #eee1d6, #f6ede6, #eee1d6);
  background-size: 200% 100%;
  animation: pulse 1.2s infinite linear;
}

@keyframes pulse {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (max-width: 980px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .arena-grid { grid-template-columns: 1fr; }
  .stats-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid { grid-template-columns: 1fr; }
  .chart-grid canvas {
    height: 170px;
    max-height: 170px;
  }
}

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr; display: grid; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .brand-logo { width: min(360px, 82vw); }
}
