:root {
  --bg: #0b090f;
  --bg-elevated: #161320;
  --bg-card: #1a1624;
  --border: #2c2438;
  --text: #f3eef9;
  --text-dim: #a99cc0;
  --text-faint: #6f6684;

  --brand: #8e00f0;
  --brand-soft: #2a1240;
  --brand-glow: rgba(142, 0, 240, 0.35);

  --accent: var(--brand);

  --green: #5fe0a5;
  --green-dim: #16332a;
  --amber: #ffc36b;
  --amber-dim: #3d2e14;
  --red: #ff7a95;
  --red-dim: #3a1a24;
  --blue: #6bc8ff;

  --radius: 18px;
  --radius-sm: 12px;
  --radius-pill: 999px;

  --font-display: 'Quicksand', sans-serif;
  --font-body: 'Nunito', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-image:
    radial-gradient(circle at 12% 8%, var(--brand-glow), transparent 32%),
    radial-gradient(circle at 88% 92%, rgba(142, 0, 240, 0.16), transparent 38%);
  background-attachment: fixed;
}

::selection { background: var(--brand); color: #fff; }

/* signature: a soft dotted ribbon instead of a hard racing stripe */
.dot-line {
  height: 6px;
  width: 100%;
  background-image: radial-gradient(circle, var(--brand) 2.2px, transparent 2.4px);
  background-size: 18px 6px;
  background-repeat: repeat-x;
  opacity: 0.85;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  flex-wrap: wrap;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  height: auto;
  padding: 4px 2px;
  cursor: pointer;
}
.brand:hover { border-color: transparent; }
.brand-mark { font-size: 18px; }
.brand-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
}
.brand:hover .brand-text { color: var(--brand); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------- auth box ---------- */

.auth-box { display: flex; align-items: center; gap: 8px; }

.auth-form {
  display: flex;
  gap: 10px;
  row-gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

/* Inputs are wrapped in a <label> in markup so the entire visual box is a
   guaranteed click/tap target — clicking anywhere focuses the input, no
   matter what the exact hit-box math works out to. */
.field-wrap {
  display: inline-flex;
}

input[type="text"], input[type="password"] {
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--radius-pill);
  height: 42px;
  min-width: 140px;
  padding: 10px 16px;
  line-height: 1.2;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-glow); }
input::placeholder { color: var(--text-faint); font-weight: 600; }
input[readonly] { opacity: 0.7; cursor: default; }

button {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  border-radius: var(--radius-pill);
  border: 2px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  height: 42px;
  padding: 0 18px;
  cursor: pointer;
  transition: all 0.15s ease;
}
button:hover { border-color: var(--brand); color: var(--brand); }
button:active { transform: translateY(1px) scale(0.98); }
button.primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  box-shadow: 0 4px 14px var(--brand-glow);
}
button.primary:hover { filter: brightness(1.08); color: #fff; }
button.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
button.danger:hover { filter: brightness(1.08); color: #fff; }
button.ghost { background: transparent; border-color: transparent; color: var(--text-dim); height: auto; padding: 6px 10px; }
button.ghost:hover { color: var(--brand); }
button.small { height: 34px; padding: 0 14px; font-size: 13px; }

.auth-toggle-link {
  background: none;
  border: none;
  color: var(--text-dim);
  text-decoration: underline;
  padding: 4px;
  font-size: 13px;
  height: auto;
  font-family: var(--font-body);
  font-weight: 600;
}
.auth-toggle-link:hover { color: var(--brand); border-color: transparent; }

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 4px 6px 4px 16px;
  height: 42px;
  cursor: pointer;
}
.user-pill .name { font-weight: 700; color: var(--brand); font-family: var(--font-display); }
.user-pill:hover { border-color: var(--brand); }
.user-pill button { cursor: pointer; }
.user-pill .sync-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.auth-error { color: var(--red); font-size: 12px; margin-left: 4px; font-weight: 700; }

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

.app-main {
  flex: 1;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.hidden { display: none !important; }

/* ---------- goal select screen ---------- */

.goal-select {
  text-align: center;
  padding: 40px 10px 10px;
}
.goal-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 32px;
  margin: 0 0 6px;
}
.goal-title .kaomoji { color: var(--brand); }
.goal-sub {
  color: var(--text-dim);
  font-weight: 600;
  margin: 0 0 30px;
}

.goal-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  max-width: 560px;
  margin: 0 auto;
}

.goal-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 18px;
  cursor: pointer;
  transition: all 0.18s ease;
}
.goal-card:hover {
  transform: translateY(-3px);
  border-color: var(--card-color, var(--brand));
  box-shadow: 0 10px 24px rgba(0,0,0,0.35);
}
.goal-card .emoji { font-size: 26px; display: block; margin-bottom: 8px; }
.goal-card .name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  color: var(--card-color, var(--text));
  margin-bottom: 4px;
}
.goal-card .desc { color: var(--text-faint); font-size: 13px; font-weight: 600; }

/* ---------- search panel & profile editor ---------- */

.search-panel, .profile-editor {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 24px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel-head h2 {
  font-family: var(--font-display);
  font-size: 17px;
  margin: 0;
}
.search-field {
  position: relative;
  margin-bottom: 12px;
}
.search-panel .search-field input[type="text"] {
  width: 100%;
  margin-bottom: 0;
  padding-right: 44px;
}
.search-clear {
  position: absolute;
  top: 50%;
  right: 8px;
  width: 28px;
  height: 28px;
  min-width: 28px;
  padding: 0;
  transform: translateY(-50%);
  border-radius: var(--radius-pill);
  opacity: 1;
}
.search-clear.hidden {
  display: block;
  opacity: 0;
  pointer-events: none;
}
.search-results { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.search-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
}
.search-result-row:hover { border-color: var(--brand); color: var(--brand); }
.search-result-row .badge-chip { font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: var(--radius-pill); }
.search-racer-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-racer-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.search-pb {
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 800;
}

.editor-field {
  display: block;
  margin-bottom: 12px;
}
.editor-field span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.editor-field input { width: 100%; }

.viewing-banner {
  background: var(--brand-soft);
  border: 2px solid var(--brand);
  border-radius: var(--radius);
  padding: 12px 18px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
  flex-wrap: wrap;
}
.viewing-banner .profile-links { display: flex; gap: 14px; font-size: 13px; color: var(--text-dim); font-weight: 600; flex-wrap: wrap; }
.viewing-banner .profile-links a { color: var(--blue); text-decoration: none; }
.viewing-banner .profile-links a:hover { text-decoration: underline; }
.rank-points {
  color: var(--rank-color, var(--brand));
  font-size: 12px;
  font-weight: 900;
  margin-left: 8px;
  white-space: nowrap;
}
.admin-delete-player { flex: 0 0 auto; }
.social-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.social-icon {
  width: 1.2em;
  height: 1.2em;
  min-width: 1.2em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
}
.social-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

/* ---------- dashboard / rank pills ---------- */

.score-strip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  margin-bottom: 16px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 900;
}
.score-strip span {
  color: var(--rank-color, var(--brand));
  font-family: var(--font-display);
  font-size: 15px;
}

.rank-pills {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.rank-pill {
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  border: 2px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  color: var(--text-dim);
  transition: all 0.15s ease;
}
.rank-pill:hover { color: var(--text); }
.rank-pill.active {
  color: var(--pill-color, var(--brand));
  border-color: var(--pill-color, var(--brand));
  background: color-mix(in srgb, var(--pill-color, var(--brand)) 12%, var(--bg-card));
}

.change-goal-btn { margin-left: auto; font-size: 13px; }

.status-banner {
  border-radius: var(--radius);
  padding: 14px 20px;
  margin-bottom: 22px;
  font-weight: 700;
  border: 2px solid var(--border);
  border-left-width: 5px;
  background: var(--bg-card);
  line-height: 1.5;
  color: var(--text);
}
.status-banner.complete { border-left-color: var(--green); color: var(--green); }
.status-banner.pending { border-left-color: var(--amber); color: var(--amber); }

/* ---------- rank view ---------- */

.section-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  margin: 26px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 2px;
  border-radius: 2px;
  background: var(--border);
}
.section-title .count-pill {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 12px;
  color: #fff;
  background: var(--rank-color, var(--brand));
  border-radius: var(--radius-pill);
  padding: 3px 11px;
}

/* main map: small picker pills + single centered card */
.main-picker {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
}
.main-picker .rank-pill { font-size: 12px; padding: 6px 14px; }

.main-single-wrap {
  display: flex;
  justify-content: center;
}
.main-single-wrap.multi-main-wrap {
  align-items: stretch;
  gap: 14px;
  flex-wrap: wrap;
}
.main-single-wrap.multi-main-wrap .main-card {
  flex: 1 1 320px;
}

.main-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  width: 100%;
  max-width: 430px;
}
.main-card .map-name {
  font-weight: 800;
  font-family: var(--font-display);
  font-size: 15px;
  margin-bottom: 2px;
  text-align: center;
}
.main-card .map-cat {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 12px;
  display: block;
  font-weight: 600;
  text-align: center;
}

.pb-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.pb-input-row input { width: 100%; text-align: center; }
.pb-input-row .unit { color: var(--text-faint); font-size: 13px; font-weight: 700; }

.main-hint {
  font-size: 12px;
  color: var(--text-faint);
  font-weight: 600;
  margin-bottom: 12px;
  text-align: center;
}

.tier-ladder {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tier-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  border: 2px solid transparent;
  gap: 8px;
}
.tier-row .tier-label { display: flex; align-items: center; gap: 6px; min-width: 0; }
.tier-row .tier-label .rank-badge { min-width: 0; }
.tier-row .tier-label .rank-badge-name { white-space: normal; }
.tier-row.achieved {
  color: var(--rank-color, var(--brand));
  border-color: var(--rank-color, var(--brand));
  background: color-mix(in srgb, var(--rank-color, var(--brand)) 14%, var(--bg-elevated));
}
.tier-row .tier-req { color: var(--text-faint); font-size: 12px; }
.tier-row.achieved .tier-req { color: inherit; }
.tier-check { opacity: 0; width: 12px; }
.tier-row.achieved .tier-check { opacity: 1; }

.tier-chip {
  font-size: 11px;
  font-weight: 800;
  border-radius: var(--radius-pill);
  padding: 3px 9px;
  white-space: nowrap;
}
.tier-chip.met { background: var(--green-dim); color: var(--green); }
.tier-chip.close { background: var(--amber-dim); color: var(--amber); }
.tier-chip.far { background: var(--red-dim); color: var(--red); }

@media (max-width: 560px) {
  .tier-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .tier-chip {
    grid-column: 1 / -1;
    justify-self: start;
    white-space: normal;
  }
}

/* ---------- side maps ---------- */

.map-list { display: flex; flex-direction: column; gap: 8px; }

.map-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto auto;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  transition: border-color 0.15s ease;
}
.map-row.met { border-color: var(--green); }
.map-row.close { border-color: var(--amber); }

.map-cat-badge {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-faint);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  min-width: 20px;
  text-align: center;
}

.map-info .map-title { font-weight: 700; font-size: 14px; }
.map-info .map-req { font-size: 12px; color: var(--text-faint); font-weight: 600; }

.map-row input {
  width: 84px;
  min-width: 0;
  text-align: center;
  height: 38px;
  padding: 8px;
}

.delta-chip {
  font-size: 12px;
  font-weight: 800;
  border-radius: var(--radius-pill);
  padding: 5px 10px;
  white-space: nowrap;
  text-align: center;
  min-width: 84px;
}
.delta-chip.met { background: var(--green-dim); color: var(--green); }
.delta-chip.close { background: var(--amber-dim); color: var(--amber); }
.delta-chip.far { background: var(--red-dim); color: var(--red); }
.delta-chip.none { background: var(--bg-elevated); color: var(--text-faint); }

.clear-btn, .video-btn {
  border: none;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 15px;
  padding: 2px 6px;
  height: auto;
}
.clear-btn { visibility: hidden; }
.map-row:hover .clear-btn { visibility: visible; }
.clear-btn:hover { color: var(--red); border-color: transparent; }
.video-btn:hover { color: var(--brand); border-color: transparent; }
.video-btn.has-video { color: var(--blue); }

.video-time-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 800;
  text-shadow: 0 0 8px rgba(107, 200, 255, 0.65);
}
.video-time-link:hover { text-decoration: underline; }

.video-input-row {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.video-input-row input { flex: 1; }

@media (max-width: 560px) {
  .map-row { grid-template-columns: auto 1fr; row-gap: 8px; }
  .map-row input, .delta-chip, .clear-btn, .video-btn { grid-column: 2; justify-self: start; }
}

/* saved confirmation flash */
@keyframes savedFlash {
  0% { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-dim); }
  100% { border-color: var(--border); box-shadow: none; }
}
input.saved-flash { animation: savedFlash 0.9s ease; }

/* ---------- badges ---------- */

.badge-chip:has(.rank-badge) {
  background: color-mix(in srgb, var(--rank-badge-color, var(--brand)) 18%, var(--bg-elevated));
  color: var(--rank-badge-color, var(--brand));
}
.badge-chip.unranked { background: var(--bg-elevated); color: var(--text-faint); }

.rank-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  vertical-align: middle;
  line-height: 1;
  color: var(--rank-badge-color, currentColor);
}

.rank-badge-icon {
  width: 1.35em;
  height: 1.35em;
  min-width: 1.35em;
  object-fit: contain;
  flex: 0 0 auto;
}

.rank-badge-name {
  line-height: 1;
}

.goal-card .rank-badge {
  justify-content: center;
}

.rank-pill .rank-badge-icon,
.badge-chip .rank-badge-icon,
.tier-label .rank-badge-icon,
.status-banner .rank-badge-icon {
  width: 1.15em;
  height: 1.15em;
  min-width: 1.15em;
}

/* ---------- footer / toast ---------- */

.app-footer {
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: var(--text-faint);
  font-weight: 700;
}
.app-footer .vivi { color: var(--brand); font-weight: 800; }
.app-footer .heart { color: var(--brand); }
.app-footer a { color: var(--blue); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }
.footer-sep { color: var(--text-faint); margin: 0 8px; }

.toast {
  position: fixed;
  bottom: 82px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--bg-elevated);
  border: 2px solid var(--brand);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 13px;
  opacity: 1;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 50;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(10px); pointer-events: none; }

@media (max-width: 560px) {
  .rank-badge-icon,
  .social-icon {
    min-width: 18px;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 72px;
    transform: translateY(0);
    text-align: center;
  }

  .toast.hidden { transform: translateY(10px); }
}

.empty-note {
  color: var(--text-faint);
  font-size: 13px;
  padding: 10px 2px;
  font-weight: 600;
}
