:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --border: #e3e5e8;
  --accent: #4f6db8;
  --ok: #4f6db8;
  --down: #64748b;
  --radius: 8px;
}

:root[data-theme="dark"] {
  --bg: #121418;
  --surface: #1b1e24;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --border: #2c3038;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

h1 { margin: 0 0 0.25rem; }
h2 { margin-top: 0; font-size: 1.1rem; }

.status { color: var(--muted); margin: 0 0 1.5rem; }

.badge {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
}
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.down { color: var(--down); border-color: currentColor; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

form { display: flex; gap: 0.5rem; }

input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.25rem 0.75rem;
}

ul { list-style: none; padding: 0; margin: 1rem 0 0; }
li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
}

.error { color: var(--down); margin: 1rem 0 0; }

[hidden] { display: none !important; }

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

/* The auth and map pages share this blue-and-gray palette; css/theme.css swaps it
   for the dark theme. */
.auth, .map-page {
  --a-blue: #4f6db8;       /* buttons, slider, checks: white text stays readable */
  --a-blue-dark: #405a9a;
  --a-blue-fade: #a4b4dc;  /* large background shapes */
  --a-blue-soft: #c3cee9;
  --a-blue-tint: #eceff8;
  --a-gray: #c9ceda;
  --a-gray-light: #e6e9f0;
  --a-white: #ffffff;
  --a-ink: #14182b;
  --a-muted: #6b7184;
  --a-field: #f3f5fa;
  --a-line: #e4e7ef;
  --a-on-accent: #ffffff;  /* text on blue/teal buttons, in both themes */
}

.auth {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 2rem 1rem;
  overflow: hidden;
  background: #f6f7fa;
  color: var(--a-ink);
}

/* Background: faded campus map, tinted blue-gray, strongest behind the card and
   fading to the page color at the edges. */
.backdrop {
  position: absolute;
  inset: 0;
  pointer-events: none;
  -webkit-mask-image: radial-gradient(ellipse 75% 70% at 50% 50%, #000 25%, transparent 100%);
  mask-image: radial-gradient(ellipse 75% 70% at 50% 50%, #000 25%, transparent 100%);
}
.auth-map {
  position: absolute;
  inset: 0;
  background: #eef1f7;
  opacity: 0.55;
}
.auth-map .leaflet-tile-pane { filter: grayscale(1) contrast(1.05) brightness(1.04); }
/* Wash the gray map in the app's blue */
.backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--a-blue);
  mix-blend-mode: color;
  opacity: 0.45;
}
.auth-map .leaflet-control-container { display: none; } /* attribution shown on the card instead */

/* Card */
.auth-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 2.5rem 2.25rem 2.25rem;
  background: var(--a-white);
  border-radius: 20px;
  box-shadow:
    0 1px 2px rgba(20, 24, 43, 0.06),
    0 24px 60px -12px rgba(20, 24, 43, 0.22);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
}
.brand-wordmark {
  display: inline-flex;
  white-space: nowrap;
  font-family: ui-rounded, "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.065em;
}
.brand-peter { color: #cf3642; }
.brand-parker { color: #2455a7; }
.partner-logo { height: 22px; width: auto; display: block; }
.mascot-logo { height: 48px; width: 44px; object-fit: contain; display: block; }

.auth-card h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.subtitle { margin: 0.35rem 0 1.5rem; color: var(--a-muted); }

/* Sign in / Sign up slider: a blue thumb slides under the active label. */
.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  margin-bottom: 1.5rem;
  background: var(--a-field);
  border-radius: 999px;
}
.tab-thumb {
  position: absolute;
  top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 4px);
  background: var(--a-blue);
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(79, 109, 184, 0.25);
  transition: transform 0.3s cubic-bezier(0.65, 0, 0.35, 1);
}
.tabs[data-mode="signup"] .tab-thumb { transform: translateX(100%); }
.tab {
  position: relative; /* above the thumb */
  padding: 0.6rem 0;
  background: transparent;
  color: var(--a-muted);
  border-radius: 999px;
  font-weight: 500;
  transition: color 0.3s;
}
.tab:hover { color: var(--a-ink); }
.tab.active, .tab.active:hover { color: var(--a-on-accent); }
.tab:focus-visible { outline: 2px solid var(--a-blue-soft); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .tab-thumb, .tab { transition: none; }
}

/* Form */
#auth-form {
  flex-direction: column;
  gap: 1rem;
}
#auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
}
#auth-form input:not([type="checkbox"]) {
  padding: 0.75rem 0.9rem;
  background: var(--a-field);
  color: var(--a-ink);
  border: 1.5px solid transparent;
  border-radius: 10px;
  font-size: 0.95rem;
  transition: border-color 0.15s, background 0.15s;
}
#auth-form input:not([type="checkbox"]):focus {
  outline: none;
  background: var(--a-white);
  border-color: var(--a-blue);
}
/* Round icons inside the fields (person, email, lock) so the boxes line up */
.input-with-icon { position: relative; display: block; }
.input-with-icon input { width: 100%; box-sizing: border-box; padding-left: 2.6rem !important; }
.field-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  width: 1.25rem;
  height: 1.25rem;
  transform: translateY(-50%);
  pointer-events: none;
}
.field-icon circle:first-child { fill: var(--a-blue-tint); stroke: var(--a-blue-soft); stroke-width: 1; }
.field-icon .cut { fill: var(--a-blue); }
.field-icon .stroke { fill: none; stroke: var(--a-blue); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.input-with-icon:focus-within .field-icon circle:first-child { stroke: var(--a-blue); }

#auth-form label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  font-weight: 400;
  color: var(--a-muted);
  cursor: pointer;
}
#auth-form input[type="checkbox"] {
  flex: none;
  width: 1rem;
  height: 1rem;
  accent-color: var(--a-blue);
}
#auth-form .error {
  margin: 0;
  padding: 0.6rem 0.8rem;
  background: var(--a-blue-tint);
  color: var(--a-blue-dark);
  border-left: 3px solid var(--a-blue);
  border-radius: 6px;
  font-size: 0.88rem;
}

#auth-submit {
  margin-top: 0.25rem;
  padding: 0.8rem 1rem;
  background: var(--a-blue);
  border-radius: 10px;
  font-weight: 600;
  transition: background 0.15s;
}
#auth-submit:hover { background: var(--a-blue-dark); }
#auth-submit:focus-visible { outline: 3px solid var(--a-blue-soft); outline-offset: 2px; }

/* Password requirement checklist: each item gets a box that ticks when met. */
.rules {
  margin: -0.35rem 0 0;
  display: grid;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--a-muted);
}
.rules li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0;
  border: none;
  justify-content: flex-start;
  transition: color 0.15s;
}
.rules li::before {
  content: "";
  flex: none;
  width: 1rem;
  height: 1rem;
  border: 1.5px solid var(--a-gray);
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  line-height: 1;
  color: var(--a-on-accent);
  transition: background 0.15s, border-color 0.15s;
}
.rules li.met { color: var(--a-ink); }
.rules li.met::before {
  content: "\2713";
  background: var(--a-blue);
  border-color: var(--a-blue);
}

@media (max-width: 520px) {
  .auth-card { padding: 2rem 1.5rem 1.75rem; }
}

.map-credit {
  position: absolute;
  right: 0.75rem;
  bottom: 0.5rem;
  margin: 0;
  font-size: 0.7rem;
  color: var(--a-muted);
}
.map-credit a { color: inherit; }

button:disabled { opacity: 0.6; cursor: wait; }

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

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- Sign up, step 2: Terms of Service ---------- */

.auth-card[data-step="terms"] > h1,
.auth-card[data-step="terms"] > #auth-subtitle,
.auth-card[data-step="terms"] > .tabs { display: none; }

.terms-step { display: flex; flex-direction: column; gap: 0.75rem; }
.terms-step h2 { margin: 0; font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.terms-step .subtitle { margin: -0.4rem 0 0.1rem; font-size: 0.9rem; }

.terms-back {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: -0.5rem 0 0 -0.4rem;
  padding: 0.3rem 0.55rem 0.3rem 0.35rem;
  background: none;
  color: var(--a-muted);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}
.terms-back svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.terms-back:hover { background: var(--a-field); color: var(--a-ink); }

.terms-frame { position: relative; border-radius: 12px; background: var(--a-field); overflow: hidden; }
.terms-box {
  max-height: min(300px, 42vh);
  overflow-y: auto;
  padding: 0.9rem 1rem 1.2rem;
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--a-ink);
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.terms-box:focus-visible { outline: 2px solid var(--a-blue-soft); outline-offset: -2px; }
.terms-box h3 { margin: 0.9rem 0 0.25rem; font-size: 0.84rem; font-weight: 700; }
.terms-box p { margin: 0 0 0.5rem; color: #3a4054; }
.terms-box .terms-meta { color: var(--a-muted); font-size: 0.74rem; margin-bottom: 0.2rem; }
/* Reading progress: fills left to right as you scroll the terms */
.terms-progress { height: 3px; background: var(--a-line); }
.terms-progress span {
  display: block;
  height: 100%;
  background: var(--a-blue);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.12s linear;
}

.terms-hint { margin: -0.3rem 0 0; font-size: 0.78rem; color: var(--a-muted); transition: color 0.2s; }
.terms-hint.done { color: var(--a-blue-dark); font-weight: 600; animation: msg-in 0.3s ease both; }

/* The agreement checkbox: a custom box whose tick draws itself */
.terms-agree {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.7rem 0.8rem;
  border: 1.5px solid var(--a-line);
  border-radius: 12px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--a-muted);
  cursor: not-allowed;
  transition: border-color 0.2s, background-color 0.2s, color 0.2s;
}
.terms-agree input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.terms-check {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-top: 0.05rem;
  border: 2px solid var(--a-gray);
  border-radius: 7px;
  background: var(--a-white);
  transition: background-color 0.2s, border-color 0.2s, transform 0.3s cubic-bezier(0.34, 1.5, 0.64, 1);
}
.terms-check svg { width: 16px; height: 16px; fill: none; stroke: var(--a-white); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.terms-check path { stroke-dasharray: 16; stroke-dashoffset: 16; transition: stroke-dashoffset 0.32s cubic-bezier(0.65, 0, 0.35, 1) 0.06s; }
.terms-agree.unlocked { cursor: pointer; color: var(--a-ink); border-color: var(--a-blue-soft); }
.terms-agree.unlocked .terms-check { border-color: var(--a-blue); animation: check-nudge 0.6s ease 1; }
.terms-agree.unlocked:hover { background: var(--a-blue-tint); }
.terms-agree input:focus-visible + .terms-check { outline: 3px solid var(--a-blue-soft); outline-offset: 2px; }
.terms-agree:has(input:checked) { border-color: var(--a-blue); background: var(--a-blue-tint); }
.terms-agree input:checked + .terms-check { background: var(--a-blue); border-color: var(--a-blue); transform: scale(1.12); }
.terms-agree input:checked + .terms-check path { stroke-dashoffset: 0; }
.terms-agree:active input:not(:disabled) + .terms-check { transform: scale(0.88); }

#terms-submit {
  padding: 0.8rem 1rem;
  background: var(--a-blue);
  border-radius: 10px;
  font-weight: 600;
  transition: background-color 0.15s, opacity 0.2s, transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#terms-submit:disabled { opacity: 0.4; cursor: not-allowed; }
#terms-submit[aria-busy="true"] { opacity: 0.75; cursor: wait; }
#terms-submit:not(:disabled):hover { background: var(--a-blue-dark); }
#terms-submit:not(:disabled):active { transform: scale(0.96); }
#terms-submit.ready { animation: ready-pop 0.42s cubic-bezier(0.34, 1.5, 0.64, 1); }
#terms-submit.success, #terms-submit.success:disabled { background: #13806a; opacity: 1; cursor: default; animation: ready-pop 0.42s cubic-bezier(0.34, 1.5, 0.64, 1); }
#terms-submit.success::before { content: "\2713  "; }
#terms-step .error {
  margin: 0;
  padding: 0.6rem 0.8rem;
  background: var(--a-blue-tint);
  color: var(--a-blue-dark);
  border-left: 3px solid var(--a-blue);
  border-radius: 6px;
  font-size: 0.88rem;
}

.terms-step:not([hidden]) { animation: terms-in 0.42s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
#auth-form.returning { animation: form-back 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both; }

@keyframes terms-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes form-back { from { opacity: 0; transform: translateX(-16px); } }
@keyframes ready-pop { 0% { transform: scale(1); } 45% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes check-nudge { 30% { transform: scale(1.18); } 60% { transform: scale(0.95); } }

@media (prefers-reduced-motion: reduce) {
  .terms-step:not([hidden]), #auth-form.returning,
  #terms-submit.ready, #terms-submit.success, .terms-agree.unlocked .terms-check { animation: none; }
  .terms-check path, .terms-progress span { transition: none; }
}

/* Sign-up tip under the email field */
.uci-tip {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  margin: -0.35rem 0 0;
  padding: 0.5rem 0.65rem;
  background: var(--a-blue-tint);
  border-radius: 8px;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--a-blue-dark);
}
.uci-tip svg { flex: none; width: 15px; height: 15px; margin-top: 0.1rem; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.terms-hint.nudge { color: var(--a-blue-dark); font-weight: 600; animation: shake 0.4s cubic-bezier(0.2, 0.8, 0.2, 1); }
@media (prefers-reduced-motion: reduce) { .terms-hint.nudge { animation: none; } }

/* Live hint under the username field: too short / too long / taken / available */
.field-status { display: flex; align-items: center; gap: 0.3rem; font-size: 0.78rem; font-weight: 500; color: var(--a-muted); min-height: 0; }
.field-status:empty { display: none; }
.field-status::before { flex: none; font-weight: 700; }
.field-status[data-tone="error"] { color: #c2453d; }
.field-status[data-tone="error"]::before { content: "!"; display: grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; background: #c2453d; color: #fff; font-size: 0.65rem; }
.field-status[data-tone="ok"] { color: #13806a; }
.field-status[data-tone="ok"]::before { content: "\2713"; }
.field-status[data-tone="pending"]::before { content: ""; width: 10px; height: 10px; border: 2px solid var(--a-gray); border-top-color: var(--a-blue); border-radius: 50%; animation: spin 0.7s linear infinite; }
.field-status.pop { animation: msg-in 0.2s ease both; }
#auth-form label:has(.field-status[data-tone="error"]) .input-with-icon input { border-color: #e3a19c; }
#auth-form label:has(.field-status[data-tone="ok"]) .input-with-icon input { border-color: #8cc9b9; }
@media (prefers-reduced-motion: reduce) { .field-status.pop { animation: none; } }
