:root {
  --ink: #092f3c;
  --ink-soft: #174958;
  --paper: #f7f3e8;
  --paper-deep: #eee5d0;
  --gold: #c49a43;
  --gold-dark: #8d6b29;
  --line: rgba(12, 53, 66, 0.18);
  --muted: #61737a;
  --success: #2e7d5b;
  --danger: #a8322d;
  --warning: #b5651d;
  --white: #fff;
  --shadow: 0 24px 70px rgba(3, 28, 36, 0.23);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--ink);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--ink); }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 15% 18%, rgba(31, 110, 140, 0.34), transparent 31rem),
    linear-gradient(145deg, #0c3542, #082a36 72%);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.58; }

a { color: var(--ink); }

.loading-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--paper);
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 18px;
}

.passport-card {
  position: relative;
  width: min(100%, 530px);
  padding: 34px 30px 28px;
  overflow: hidden;
  border: 1px solid rgba(196, 154, 67, 0.5);
  border-radius: 5px;
  background:
    linear-gradient(rgba(247, 243, 232, 0.96), rgba(247, 243, 232, 0.96)),
    repeating-radial-gradient(circle at 30% 20%, transparent 0 27px, rgba(31, 110, 140, 0.14) 28px 29px);
  box-shadow: var(--shadow);
}

.passport-card::after,
.passport-sheet::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.45;
  background-image:
    linear-gradient(32deg, transparent 47%, rgba(31, 110, 140, 0.08) 48% 49%, transparent 50%),
    linear-gradient(148deg, transparent 47%, rgba(196, 154, 67, 0.08) 48% 49%, transparent 50%);
  background-size: 78px 78px;
}

.card-content { position: relative; z-index: 1; }

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  color: var(--gold-dark);
  font-size: 27px;
  font-weight: 900;
  box-shadow: inset 0 0 0 5px rgba(196, 154, 67, 0.1);
}

.brand-kicker {
  margin: 13px 0 5px;
  color: var(--gold-dark);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.32em;
}

.brand h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.75rem, 6vw, 2.2rem);
}

.gold-rule {
  width: 58px;
  height: 4px;
  margin-top: 15px;
  border-radius: 99px;
  background: var(--gold);
}

.field { margin-bottom: 17px; }
.field label, .field-label {
  display: block;
  margin-bottom: 7px;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
}

.field input,
.field textarea,
.field select,
.search-row input {
  width: 100%;
  border: 1px solid rgba(12, 53, 66, 0.25);
  border-radius: 8px;
  padding: 13px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.field textarea { min-height: 105px; resize: vertical; }

.field input:focus,
.field textarea:focus,
.field select:focus,
.search-row input:focus {
  border-color: var(--gold-dark);
  box-shadow: 0 0 0 3px rgba(196, 154, 67, 0.18);
}

.hint, .muted { color: var(--muted); font-size: 0.9rem; }
.hint { margin: -8px 0 15px; line-height: 1.5; }

.primary,
.secondary,
.danger-button,
.ghost-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  padding: 12px 18px;
  font-weight: 750;
}

.primary { color: #f6e9bd; background: var(--ink); }
.primary:hover { background: var(--ink-soft); }
.primary.wide { width: 100%; padding: 15px; font-size: 1.05rem; }
.secondary { color: var(--ink); background: #e8ddc4; }
.danger-button { color: white; background: var(--danger); }
.ghost-button { color: var(--ink); background: transparent; border: 1px solid var(--line); }

.auth-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 20px;
}

.link-button {
  padding: 0;
  border: 0;
  color: var(--ink);
  background: transparent;
  text-decoration: underline;
}

.notice, .error-box, .success-box {
  margin: 14px 0;
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.45;
  font-size: 0.92rem;
}

.notice { border: 1px solid rgba(196, 154, 67, 0.38); background: rgba(196, 154, 67, 0.09); }
.error-box { border: 1px solid rgba(168, 50, 45, 0.35); color: #78231f; background: #f9e8e6; }
.success-box { border: 1px solid rgba(46, 125, 91, 0.35); color: #215f45; background: #e4f1e9; }

.app-shell { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  min-height: 72px;
  padding: 10px clamp(16px, 4vw, 52px);
  color: var(--paper);
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
  background: rgba(8, 42, 54, 0.94);
  backdrop-filter: blur(14px);
}

.top-brand { display: flex; align-items: center; gap: 11px; font-family: Georgia, serif; font-weight: 700; }
.top-brand .brand-mark { width: 38px; height: 38px; font-size: 20px; }

.main-nav { display: flex; gap: 6px; }
.nav-button {
  padding: 9px 13px;
  color: rgba(255, 255, 255, 0.72);
  border: 0;
  border-radius: 7px;
  background: transparent;
}
.nav-button.active, .nav-button:hover { color: white; background: rgba(255, 255, 255, 0.11); }

.user-tools { position: relative; display: flex; justify-content: flex-end; align-items: center; gap: 9px; }
.user-copy { text-align: right; line-height: 1.2; }
.user-copy b { display: block; font-size: 0.9rem; }
.user-copy span { color: rgba(255, 255, 255, 0.64); font-size: 0.76rem; }

.icon-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  padding: 0;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  font-size: 1.15rem;
}

.notification-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 21px;
  height: 21px;
  padding: 2px 5px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 20px;
  color: white;
  background: var(--danger);
  font-size: 0.7rem;
}

.notification-panel {
  position: absolute;
  top: 54px;
  right: 0;
  width: min(420px, calc(100vw - 28px));
  max-height: min(620px, calc(100vh - 90px));
  overflow: auto;
  padding: 17px;
  color: var(--ink);
  border: 1px solid rgba(196, 154, 67, 0.45);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.notification-panel h2 { margin: 0 0 4px; font: 700 1.25rem Georgia, serif; }
.notification-list { display: grid; gap: 11px; margin-top: 15px; }
.notification-item { padding: 13px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.notification-item p { margin: 6px 0; line-height: 1.4; }
.notification-actions, .modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 9px; margin-top: 13px; }

.page { width: min(1220px, calc(100% - 28px)); margin: 28px auto 50px; }

.passport-sheet {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(196, 154, 67, 0.42);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.passport-sheet > * { position: relative; z-index: 1; }

.identity-band {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px;
  align-items: center;
  padding: 26px clamp(18px, 4vw, 42px);
  border-bottom: 1px solid var(--line);
}

.avatar {
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  overflow: hidden;
  color: var(--paper);
  border: 3px solid var(--gold);
  border-radius: 50%;
  background: var(--ink-soft);
  font-family: Georgia, serif;
  font-size: 1.5rem;
  font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.identity h1 { margin: 0 0 5px; font: 700 clamp(1.5rem, 4vw, 2.2rem) Georgia, serif; }
.identity p { margin: 2px 0; color: var(--muted); }
.folio { text-align: right; }
.folio span { display: block; color: var(--muted); font-size: 0.73rem; letter-spacing: 0.15em; text-transform: uppercase; }
.folio b { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.1rem; }

.progress-strip {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 18px clamp(18px, 4vw, 42px);
  background: rgba(196, 154, 67, 0.08);
}
.progress-track { height: 10px; overflow: hidden; border-radius: 20px; background: #ddd4c1; }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold-dark), var(--gold)); }
.progress-count { white-space: nowrap; font-family: Georgia, serif; font-weight: 700; }

.territories { display: grid; gap: 20px; padding: 26px clamp(18px, 4vw, 42px) 38px; }
.territory { border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, 0.62); }
.territory-head { display: grid; grid-template-columns: 7px 1fr auto; gap: 14px; align-items: stretch; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.territory-color { border-radius: 20px; background: var(--category-color); }
.territory-head h2 { margin: 0 0 3px; font: 700 1.25rem Georgia, serif; }
.territory-head p { margin: 0; color: var(--muted); font-size: 0.88rem; }
.visa { align-self: center; padding: 6px 10px; border: 1px dashed var(--gold-dark); border-radius: 5px; color: var(--gold-dark); font-weight: 800; transform: rotate(-2deg); }
.visa.earned { color: var(--success); border-color: var(--success); background: rgba(46, 125, 91, 0.08); }

.challenge-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); gap: 11px; padding: 15px; }
.challenge-card { position: relative; min-height: 142px; padding: 15px; text-align: left; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; background: white; }
.challenge-card:hover:not(:disabled) { border-color: var(--category-color); transform: translateY(-1px); box-shadow: 0 7px 18px rgba(9, 47, 60, 0.09); }
.challenge-card.done { background: #ecf5ef; border-color: rgba(46, 125, 91, 0.38); }
.challenge-card.pending { background: #fbf2e7; border-color: rgba(181, 101, 29, 0.42); }
.challenge-card.locked { background: #eeeae0; }
.challenge-number { color: var(--category-color); font: 800 0.78rem ui-monospace, monospace; }
.challenge-card h3 { margin: 8px 0 6px; font: 700 1.02rem Georgia, serif; }
.challenge-card p { margin: 0; color: var(--muted); font-size: 0.82rem; line-height: 1.35; }
.status-pill { display: inline-block; margin-top: 11px; padding: 3px 7px; border-radius: 20px; color: white; background: var(--muted); font-size: 0.7rem; font-weight: 800; }
.done .status-pill { background: var(--success); }
.pending .status-pill { background: var(--warning); }

.dashboard { padding: clamp(18px, 4vw, 38px); }
.section-heading { display: flex; justify-content: space-between; gap: 18px; align-items: center; margin-bottom: 20px; }
.section-heading h1 { margin: 0; font: 700 2rem Georgia, serif; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 13px; margin-bottom: 22px; }
.kpi { padding: 17px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.kpi b { display: block; font: 700 1.7rem Georgia, serif; }
.kpi span { color: var(--muted); font-size: 0.84rem; }
.management-tabs { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 17px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.management-tabs .nav-button { color: var(--ink-soft); border: 1px solid var(--line); }
.management-tabs .nav-button.active, .management-tabs .nav-button:hover { color: var(--ink); background: #e8ddc4; }
.reflection-list { display: grid; gap: 14px; }
.reflection-group { padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.reflection-group h3 { margin: 0 0 4px; font: 700 1.08rem Georgia, serif; }
.reflection-group blockquote { margin: 12px 0 0; padding: 12px 14px; border-left: 3px solid var(--gold); background: var(--paper); line-height: 1.5; }
.reflection-group blockquote small { display: block; margin-top: 7px; color: var(--muted); }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; background: white; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); background: #f0eadc; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em; }

.modal-backdrop { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: 18px; background: rgba(2, 22, 29, 0.72); }
.modal { width: min(620px, 100%); max-height: calc(100vh - 36px); overflow: auto; border: 1px solid rgba(196, 154, 67, 0.48); border-radius: 10px; background: var(--paper); box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; padding: 20px 22px 15px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 5px 0 0; font: 700 1.55rem Georgia, serif; }
.modal-body { padding: 20px 22px 22px; }
.close-button { width: 34px; height: 34px; border: 0; border-radius: 50%; color: var(--ink); background: rgba(9, 47, 60, 0.08); font-size: 1.2rem; }
.challenge-description { padding: 13px 14px; border-left: 4px solid var(--category-color, var(--gold)); background: white; line-height: 1.55; }
.validation-label { display: inline-block; margin: 12px 0; padding: 5px 9px; border-radius: 20px; color: var(--ink); background: #e9dfc8; font-size: 0.78rem; font-weight: 800; }
.search-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.person-results { display: grid; gap: 7px; margin-top: 9px; }
.person-option { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.person-option small { display: block; color: var(--muted); }

.toast-region { position: fixed; z-index: 100; right: 18px; bottom: 18px; display: grid; gap: 9px; }
.toast { width: min(390px, calc(100vw - 36px)); padding: 13px 15px; color: white; border-radius: 8px; background: var(--ink); box-shadow: 0 12px 32px rgba(0,0,0,.25); }
.toast.error { background: var(--danger); }

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr auto; gap: 10px; }
  .main-nav { grid-row: 2; grid-column: 1 / -1; justify-content: center; }
  .user-copy { display: none; }
  .identity-band { grid-template-columns: auto 1fr; }
  .folio { grid-column: 1 / -1; text-align: left; }
  .kpis { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .passport-card { padding: 28px 20px 22px; }
  .page { width: min(100% - 16px, 1220px); margin-top: 14px; }
  .identity-band { gap: 13px; padding: 20px 16px; }
  .avatar { width: 62px; height: 62px; }
  .progress-strip { grid-template-columns: 1fr; padding: 16px; }
  .territories { padding: 17px 10px 25px; }
  .territory-head { grid-template-columns: 6px 1fr; }
  .visa { grid-column: 2; justify-self: start; }
  .challenge-grid { grid-template-columns: 1fr; padding: 10px; }
  .notification-panel { position: fixed; top: 70px; right: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
