:root {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6; /* blue */
  --series-2: #1baf7a; /* aqua */
  --series-3: #eda100; /* yellow */
  --series-4: #008300; /* green */
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);

    --series-1: #3987e5;
    --series-2: #199e70;
    --series-3: #c98500;
    --series-4: #008300;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  padding-bottom: 3rem;
}

.app-header {
  text-align: center;
  padding: 1.75rem 1rem 0.5rem;
}

.app-header h1 {
  margin: 0;
  font-size: 1.6rem;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--text-secondary);
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.dashboard-main {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-width: 0;
}

@media (min-width: 900px) {
  main {
    max-width: 1040px;
  }
  .dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    align-items: start;
  }
  .weekly-panel {
    position: sticky;
    top: 1rem;
  }
}

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.1rem;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

/* ---- Race track ---- */

.track-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1.1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.lane {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

.lane-name-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.lane-name {
  font-weight: 600;
  font-size: 0.95rem;
  border: none;
  background: transparent;
  color: var(--text-primary);
  padding: 0.1rem 0.2rem;
  border-radius: 6px;
  min-width: 0;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lane-name:focus {
  outline: 1px solid var(--baseline);
  background: var(--page);
}

.lane-amount {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.track {
  position: relative;
  height: 30px;
  background: var(--page);
  border: 1px solid var(--gridline);
  border-radius: 999px;
  overflow: visible;
}

.track-fill {
  position: absolute;
  inset: 2px auto 2px 2px;
  border-radius: 999px;
  transition: width 0.6s ease;
  width: 0%;
}

.track-ticks {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.track-ticks span {
  width: 1px;
  height: 100%;
  background: var(--gridline);
}
.track-ticks span:first-child,
.track-ticks span:last-child {
  background: transparent;
}

.track-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.15rem;
  transition: left 0.6s ease;
  left: 0%;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}

.lane-scale {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 0 1px;
}

/* ---- Rank ---- */

.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.rank-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
  background: var(--page);
  border: 1px solid var(--border);
}

.rank-pos {
  font-weight: 700;
  color: var(--text-secondary);
  width: 1.6rem;
  text-align: center;
  flex: none;
}

.rank-name {
  flex: 1;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-amount {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

/* ---- Add panel ---- */

.participant-select {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.participant-btn {
  border: 1px solid var(--gridline);
  background: var(--page);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.participant-btn.active {
  border-color: var(--text-primary);
  font-weight: 700;
}

.amount-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.amount-btn, .custom-amount button, .undo-btn, #reset-btn {
  border: 1px solid var(--gridline);
  background: var(--page);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 0.6rem 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.amount-btn:active, .custom-amount button:active {
  transform: scale(0.97);
}

.custom-amount {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.custom-amount input {
  flex: 1;
  border: 1px solid var(--gridline);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  background: var(--page);
  color: var(--text-primary);
  font-size: 0.95rem;
  min-width: 0;
}

.undo-btn {
  width: 100%;
  color: var(--text-secondary);
}

.danger-panel {
  text-align: center;
}

#reset-btn {
  color: #d03b3b;
  border-color: #d03b3b;
  width: 100%;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translate(-50%, 10px);
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---- Auth ---- */

.hidden {
  display: none !important;
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.auth-tab {
  flex: 1;
  border: 1px solid var(--gridline);
  background: var(--page);
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 0.6rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.auth-tab.active {
  color: var(--text-primary);
  border-color: var(--text-primary);
  font-weight: 700;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.auth-form input {
  border: 1px solid var(--gridline);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  background: var(--page);
  color: var(--text-primary);
  font-size: 0.95rem;
}

.auth-form button[type="submit"] {
  border: 1px solid var(--text-primary);
  background: var(--text-primary);
  color: var(--surface-1);
  border-radius: 10px;
  padding: 0.65rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.auth-error {
  min-height: 1.1em;
  margin: 0;
  color: #d03b3b;
  font-size: 0.85rem;
}

.session-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
}

#whoami {
  font-weight: 600;
}

.session-panel button {
  border: 1px solid var(--gridline);
  background: var(--page);
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}

#dashboard {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ---- Extras (bebidas & venenos) ---- */

.extra-subtitle {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.extra-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.extra-btn {
  border: 1px solid var(--gridline);
  background: var(--page);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font-size: 0.88rem;
  cursor: pointer;
}

.extra-btn.veneno {
  border-color: rgba(208, 59, 59, 0.35);
  background: rgba(208, 59, 59, 0.07);
}

.extra-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  background: var(--page);
  border: 1px solid var(--gridline);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.9rem;
}

.extra-entry span {
  font-weight: 600;
  font-size: 0.9rem;
}

.extra-entry input {
  border: 1px solid var(--gridline);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 0.9rem;
  flex: 1;
  min-width: 7rem;
}

.extra-entry-actions {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.extra-entry-actions button {
  flex: 1;
  border: 1px solid var(--text-primary);
  background: var(--text-primary);
  color: var(--surface-1);
  border-radius: 8px;
  padding: 0.5rem;
  font-size: 0.88rem;
  cursor: pointer;
}

#extra-cancel-btn {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--gridline);
}

.extra-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.15rem;
}

.extra-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--gridline);
  background: var(--page);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

.extra-chip.veneno {
  border-color: rgba(208, 59, 59, 0.35);
  background: rgba(208, 59, 59, 0.07);
}

/* ---- Weekly rank ---- */

.weekly-rank-content {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.day-rank {
  border-top: 1px solid var(--gridline);
  padding-top: 0.6rem;
}

.day-rank:first-child {
  border-top: none;
  padding-top: 0;
}

.day-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: capitalize;
  margin-bottom: 0.4rem;
}

.day-label.today {
  color: var(--text-primary);
}

.day-rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.day-rank-list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
}

.day-rank-pos {
  width: 1.3rem;
  text-align: center;
  flex: none;
  color: var(--text-secondary);
}

.day-rank-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-rank-amount {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.day-rank-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}
