: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;

  --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: 12px;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { font-size: 18px; }
.brand-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
}

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

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

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

.field {
  display: inline-flex;
  align-items: center;
}

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: 0 16px;
  line-height: 42px;
  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; }

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.ghost { background: transparent; border-color: transparent; color: var(--text-dim); height: auto; padding: 6px 8px; }
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: 10px;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 4px 6px 4px 16px;
  height: 42px;
}
.user-pill .name { font-weight: 700; color: var(--brand); font-family: var(--font-display); }
.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; }

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

.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);
  background: var(--bg-card);
  line-height: 1.5;
}
.status-banner.complete {
  border-color: var(--green);
  background: var(--green-dim);
  color: var(--green);
}
.status-banner.pending {
  border-color: var(--amber);
  background: var(--amber-dim);
  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-groups {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 640px) {
  .main-groups { grid-template-columns: 1fr; }
}

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

.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;
}

.tier-ladder {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tier-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  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; white-space: nowrap; }
.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); }

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

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

.map-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: center;
  gap: 12px;
  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;
  line-height: 38px;
  padding: 0 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 {
  border: none;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 15px;
  padding: 2px 6px;
  visibility: hidden;
  height: auto;
}
.map-row:hover .clear-btn { visibility: visible; }
.clear-btn:hover { color: var(--red); border-color: transparent; }

@media (max-width: 560px) {
  .map-row { grid-template-columns: auto 1fr; row-gap: 8px; }
  .map-row input, .delta-chip, .clear-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; }

/* ---------- 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); }

.toast {
  position: fixed;
  bottom: 20px;
  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; }

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