:root {
  --ink: #e9e1c8;
  --muted: #aaa88f;
  --night: #09100d;
  --forest: #13221b;
  --forest-2: #1b3025;
  --parchment: #d9c99f;
  --parchment-deep: #9d8254;
  --gold: #d7a642;
  --gold-pale: #eed79c;
  --sage: #7da184;
  --rust: #a55335;
  --line: rgba(235, 222, 181, .14);
  --shadow: 0 26px 80px rgba(0, 0, 0, .38);
  --radius: 24px;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; background: var(--night); }
body { margin: 0; min-width: 320px; background: var(--night); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button { color: inherit; }
::selection { background: var(--gold); color: #111; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.eyebrow { margin: 0 0 12px; color: var(--gold-pale); font-size: .73rem; font-weight: 750; letter-spacing: .22em; text-transform: uppercase; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
h1 { font-size: clamp(3.2rem, 7vw, 6.7rem); line-height: .92; letter-spacing: -.055em; }
h2 { margin: 0; font-size: clamp(2.15rem, 4.4vw, 4rem); letter-spacing: -.035em; }
h3 { font-size: 1.45rem; }

.topbar { position: sticky; top: 0; z-index: 40; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 76px; padding: 0 clamp(20px, 4vw, 72px); border-bottom: 1px solid var(--line); background: rgba(9, 16, 13, .87); backdrop-filter: blur(18px); }
.wordmark { display: inline-flex; align-items: center; gap: 12px; width: max-content; text-decoration: none; }
.wordmark-star { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid rgba(215,166,66,.55); border-radius: 50%; color: var(--gold); }
.wordmark b, .wordmark small { display: block; }
.wordmark b { font-family: Georgia, serif; font-size: 1.12rem; font-weight: 500; letter-spacing: .04em; }
.wordmark small { margin-top: 2px; color: var(--muted); font-size: .61rem; letter-spacing: .12em; text-transform: uppercase; }
.topbar nav { display: flex; gap: 32px; }
.topbar nav a { color: #c6c3af; font-size: .78rem; letter-spacing: .1em; text-decoration: none; text-transform: uppercase; }
.topbar nav a:hover, .topbar nav a:focus-visible { color: var(--gold-pale); }
.top-actions { display: flex; justify-content: flex-end; gap: 9px; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%; background: rgba(255,255,255,.025); cursor: pointer; }
.icon-button:hover { border-color: rgba(215,166,66,.5); background: rgba(215,166,66,.08); }

.hero-section { position: relative; display: flex; min-height: calc(100vh - 76px); align-items: center; overflow: hidden; padding: 72px clamp(24px, 8vw, 132px) 154px; isolation: isolate; }
.hero-art { position: absolute; inset: 0; z-index: -3; background-color: #16281e; background-image: linear-gradient(90deg, rgba(5,10,7,.94) 0%, rgba(8,15,11,.70) 40%, rgba(8,12,10,.15) 72%), linear-gradient(0deg, #09100d 0%, transparent 35%), url('art/hero-map.webp'); background-size: cover; background-position: center; transform: scale(1.02); }
.hero-vignette { position: absolute; inset: 0; z-index: -2; background: radial-gradient(circle at 72% 38%, transparent 0 18%, rgba(4,8,6,.2) 55%, rgba(4,8,6,.74) 100%), linear-gradient(180deg, transparent 70%, var(--night)); }
.hero-content { width: min(760px, 72vw); animation: rise .9s ease both; }
.hero-content h1 { margin: 0; text-shadow: 0 5px 40px rgba(0,0,0,.6); }
.hero-content h1 em { color: var(--gold-pale); font-weight: 400; }
.hero-summary { max-width: 650px; margin: 26px 0 30px; color: #cbc7b1; font-family: Georgia, serif; font-size: clamp(1.05rem, 1.6vw, 1.36rem); line-height: 1.65; }
.hero-actions { display: flex; align-items: center; gap: 18px; }
.sync-status { color: var(--muted); font-size: .78rem; }
.button { display: inline-flex; min-height: 48px; align-items: center; justify-content: center; gap: 9px; padding: 0 20px; border: 1px solid transparent; border-radius: 999px; font-size: .78rem; font-weight: 750; letter-spacing: .08em; text-decoration: none; text-transform: uppercase; cursor: pointer; transition: transform .2s ease, background .2s ease, border-color .2s ease; }
.button:hover { transform: translateY(-2px); }
.button.primary { background: var(--gold); color: #172018; box-shadow: 0 10px 35px rgba(215,166,66,.19); }
.button.primary:hover { background: #e2b653; }
.button.secondary { border-color: rgba(215,166,66,.4); background: rgba(215,166,66,.07); color: var(--gold-pale); }
.button:disabled { cursor: wait; opacity: .6; transform: none; }
.stat-ribbon { position: absolute; right: clamp(24px, 5vw, 80px); bottom: 55px; left: clamp(24px, 5vw, 80px); display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 20px; background: rgba(10,18,14,.82); box-shadow: var(--shadow); backdrop-filter: blur(16px); }
.stat-ribbon article { padding: 22px 30px; }
.stat-ribbon article + article { border-left: 1px solid var(--line); }
.stat-ribbon span, .stat-ribbon small { display: block; color: var(--muted); }
.stat-ribbon span { margin-bottom: 7px; font-size: .69rem; letter-spacing: .13em; text-transform: uppercase; }
.stat-ribbon strong { display: block; color: var(--gold-pale); font-family: Georgia, serif; font-size: clamp(1.8rem, 3vw, 2.6rem); font-weight: 400; }
.stat-ribbon small { margin-top: 4px; font-size: .72rem; }

.content-section { padding: 105px clamp(24px, 7vw, 112px); }
.map-section { background: radial-gradient(circle at 82% 10%, rgba(65,93,68,.13), transparent 32%), #0d1712; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 42px; }
.section-stat { margin: 0 0 8px; color: var(--muted); font-family: Georgia, serif; font-size: 1rem; font-style: italic; }
.segmented { display: flex; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.02); }
.segmented button { min-width: 92px; padding: 10px 18px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); cursor: pointer; }
.segmented button.active { background: rgba(215,166,66,.16); color: var(--gold-pale); }
.map-frame { position: relative; aspect-ratio: 16 / 7; min-height: 380px; overflow: hidden; border: 1px solid rgba(229,208,151,.18); border-radius: var(--radius); background-color: #c5ae77; box-shadow: var(--shadow), inset 0 0 80px rgba(46,31,12,.46); }
.map-texture { position: absolute; inset: 0; background-image: linear-gradient(rgba(67,50,22,.08), rgba(67,50,22,.08)), url('art/living-map.webp'); background-position: center; background-size: cover; filter: sepia(.18) saturate(.82) contrast(1.02); }
.map-frame::after { content: ''; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 70px rgba(40,24,8,.42); }
#journeyMap { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; cursor: crosshair; }
.map-legend { position: absolute; z-index: 4; right: 20px; bottom: 17px; display: flex; gap: 18px; padding: 9px 13px; border-radius: 999px; background: rgba(34,29,17,.72); color: #eee0b9; font-size: .68rem; backdrop-filter: blur(7px); }
.map-legend span { display: flex; align-items: center; gap: 7px; }
.map-legend i { width: 18px; height: 2px; background: var(--gold); }
.map-legend .legend-ahead { background: rgba(57,42,18,.65); }
.map-tooltip { position: absolute; z-index: 6; max-width: 190px; padding: 9px 12px; border: 1px solid rgba(77,54,20,.22); border-radius: 10px; background: rgba(25,22,14,.9); color: #f0e3bb; font-family: Georgia, serif; font-size: .8rem; pointer-events: none; transform: translate(-50%, calc(-100% - 14px)); }
.journey-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 18px; }
.journey-card { position: relative; overflow: hidden; padding: 26px; border: 1px solid var(--line); border-radius: 20px; background: linear-gradient(135deg, rgba(255,255,255,.035), rgba(255,255,255,.015)); }
.journey-card.selected { border-color: rgba(215,166,66,.38); }
.journey-card header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.journey-card h3 { margin: 0 0 4px; font-size: 1.55rem; }
.journey-card header p { margin: 0; color: var(--muted); font-size: .74rem; }
.journey-percent { color: var(--gold-pale); font-family: Georgia, serif; font-size: 2rem; }
.progress-track { height: 5px; margin: 21px 0 18px; overflow: hidden; border-radius: 9px; background: rgba(255,255,255,.07); }
.progress-track i { display: block; width: var(--progress); height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--sage), var(--gold)); }
.journey-details { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.journey-details span { display: block; color: var(--muted); font-size: .65rem; letter-spacing: .1em; text-transform: uppercase; }
.journey-details strong { display: block; margin-top: 5px; font-family: Georgia, serif; font-size: 1.06rem; font-weight: 500; }
.chapter-pill { display: inline-flex; margin-top: 18px; padding: 7px 10px; border: 1px solid rgba(215,166,66,.26); border-radius: 999px; color: var(--gold-pale); font-size: .62rem; letter-spacing: .11em; text-transform: uppercase; }
.distance-note { max-width: 880px; margin: 18px auto 0; color: #7f806f; font-family: Georgia, serif; font-size: .81rem; font-style: italic; line-height: 1.6; text-align: center; }

.chronicle-section { background: #101d17; }
.milestone-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.milestone-card { position: relative; min-height: 265px; overflow: hidden; padding: 0; border: 1px solid var(--line); border-radius: 18px; background: #172119; text-align: left; cursor: pointer; }
.milestone-card.locked { cursor: default; filter: saturate(.35); opacity: .58; }
.milestone-card:not(.locked):hover .milestone-art { transform: scale(1.055); }
.milestone-art { position: absolute; inset: 0; background-position: center; background-size: cover; transition: transform .6s ease; }
.milestone-card::after { content: ''; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(6,11,8,.98), rgba(6,11,8,.1) 74%); }
.milestone-copy { position: absolute; z-index: 2; right: 0; bottom: 0; left: 0; padding: 20px; }
.milestone-copy small { color: var(--gold-pale); font-size: .61rem; letter-spacing: .13em; text-transform: uppercase; }
.milestone-copy h3 { margin: 7px 0 5px; font-size: 1.25rem; }
.milestone-copy span { color: #a9aa98; font-size: .72rem; }
.milestone-lock { position: absolute; z-index: 3; top: 14px; right: 14px; display: grid; width: 32px; height: 32px; place-items: center; border: 1px solid rgba(255,255,255,.13); border-radius: 50%; background: rgba(6,10,8,.63); color: #b8b7a2; }

.insights-section { background: radial-gradient(circle at 9% 100%, rgba(215,166,66,.08), transparent 35%), #0b1410; }
.insights-grid { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(250px, .8fr); gap: 18px; }
.chart-card, .pace-card { border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,.025); }
.chart-card { min-width: 0; padding: 24px; }
#distanceChart { width: 100%; height: 310px; }
.chart-legend { display: flex; justify-content: space-between; margin-top: 14px; color: var(--muted); font-size: .72rem; }
.chart-legend span { display: flex; align-items: center; gap: 8px; }
.chart-legend i { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }
.chart-legend b { font-weight: 500; }
.insights-heading-tools { display: grid; justify-items: end; gap: 10px; }
.range-switcher { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.02); }
.range-switcher button { min-height: 34px; padding: 0 13px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-size: .7rem; cursor: pointer; }
.range-switcher button.active { background: rgba(215,166,66,.19); color: var(--gold-pale); }
.pace-card { display: flex; flex-direction: column; justify-content: center; padding: 34px; }
.pace-card > strong { color: var(--gold-pale); font-family: Georgia, serif; font-size: clamp(2.6rem, 5vw, 4.6rem); font-weight: 400; line-height: 1; }
.pace-card > span, .pace-card > p { color: var(--muted); }
.pace-card > span { margin-top: 8px; font-size: .78rem; }
.pace-card > p:not(.eyebrow) { margin: 0 0 5px; font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; }
.pace-card h3 { margin: 0 0 8px; color: var(--ink); }
.pace-card #nextEta { color: var(--muted); font-family: Georgia, serif; font-size: .85rem; letter-spacing: 0; line-height: 1.55; text-transform: none; }
.divider { height: 1px; margin: 28px 0; background: var(--line); }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 34px clamp(24px, 7vw, 112px); border-top: 1px solid var(--line); background: #080e0b; color: #666c62; font-size: .67rem; line-height: 1.5; }
footer p { max-width: 560px; margin: 0; }

.login-view, .setup-page { min-height: 100vh; background-color: #0f1c15; background-image: linear-gradient(90deg, rgba(6,11,8,.96), rgba(8,14,11,.5)), url('art/shire.webp'); background-position: center; background-size: cover; }
.login-view { display: grid; place-items: center; padding: 24px; }
.login-card, .setup-shell { width: min(100%, 530px); padding: clamp(32px, 6vw, 58px); border: 1px solid rgba(230,214,165,.2); border-radius: 28px; background: rgba(8,16,12,.87); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.login-card { text-align: center; }
.brand-mark { display: grid; width: 58px; height: 58px; place-items: center; margin: 0 auto 22px; border: 1px solid rgba(215,166,66,.5); border-radius: 50%; color: var(--gold); font-size: 1.4rem; }
.login-card h1 { margin: 0 0 14px; font-size: clamp(3rem, 10vw, 5rem); }
.login-card > p:not(.eyebrow):not(.legal-note), .setup-intro { color: var(--muted); font-family: Georgia, serif; }
.login-card form { display: grid; gap: 12px; margin-top: 28px; }
.login-card input { text-align: center; }
.form-error { min-height: 18px; margin: 0; color: #e8a98f; font-size: .76rem; }
.legal-note { margin: 27px 0 0; color: #656a61; font-size: .63rem; line-height: 1.5; }

.setup-page { display: grid; place-items: center; padding: 42px 20px; }
.setup-shell { width: min(100%, 650px); }
.setup-shell h1 { margin: 0; font-size: clamp(2.7rem, 8vw, 4.6rem); }
.setup-intro { margin-bottom: 30px; line-height: 1.6; }
.setup-form, .settings-copy form { display: grid; gap: 17px; }
label span { display: block; margin-bottom: 8px; color: #c9c6b4; font-size: .71rem; letter-spacing: .09em; text-transform: uppercase; }
label small { display: block; margin-top: 5px; color: #747a70; font-size: .68rem; }
input, select, textarea { width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid rgba(230,221,190,.16); border-radius: 12px; outline: none; background: rgba(255,255,255,.035); color: var(--ink); }
textarea { padding-block: 12px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: rgba(215,166,66,.65); box-shadow: 0 0 0 3px rgba(215,166,66,.09); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
details { padding: 15px; border: 1px solid var(--line); border-radius: 12px; }
details summary { cursor: pointer; color: var(--muted); font-size: .76rem; }
details label { display: block; margin-top: 15px; }
.notice { margin: 20px 0; padding: 12px 14px; border-radius: 10px; font-size: .78rem; }
.notice.error { border: 1px solid rgba(183,92,61,.4); background: rgba(183,92,61,.12); color: #f0b29b; }
.setup-success code { display: block; overflow-wrap: anywhere; margin: 18px 0; padding: 14px; border-radius: 10px; background: #08100c; color: var(--gold-pale); }

dialog { max-width: calc(100vw - 32px); padding: 0; border: 1px solid rgba(235,218,166,.2); border-radius: 24px; background: #111d17; color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(3,7,5,.78); backdrop-filter: blur(7px); }
.dialog-close { position: absolute; z-index: 5; top: 13px; right: 13px; display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid rgba(255,255,255,.2); border-radius: 50%; background: rgba(5,10,8,.6); color: #fff; font-size: 1.35rem; cursor: pointer; }
.milestone-dialog { width: min(900px, calc(100vw - 32px)); }
.dialog-art { min-height: 400px; background-position: center; background-size: cover; }
.dialog-copy { padding: 28px 34px 34px; }
.dialog-copy h2 { font-size: 2.5rem; }
.dialog-copy p:not(.eyebrow) { color: #b6b4a3; font-family: Georgia, serif; line-height: 1.65; }
.dialog-copy strong { color: var(--gold-pale); font-family: Georgia, serif; font-weight: 500; }
.settings-dialog { width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 36px); overflow: auto; }
.settings-copy { padding: 40px; }
.settings-copy h2 { margin-bottom: 27px; font-size: 2.65rem; }
.toggle-row { display: flex; align-items: center; gap: 12px; }
.toggle-row input { width: 20px; min-height: 20px; }
.toggle-row span { margin: 0; text-transform: none; letter-spacing: 0; }
.settings-divider { height: 1px; margin: 28px 0; background: var(--line); }
.manual-form { grid-template-columns: 1fr 1fr; }
.manual-form label:first-child { grid-column: 1 / -1; }
.manual-form .button { grid-column: 1 / -1; }
.text-button { margin-top: 30px; padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; text-decoration: underline; }
.text-button.danger { color: #d69078; }

.toast { position: fixed; z-index: 80; right: 20px; bottom: 20px; max-width: min(380px, calc(100vw - 40px)); padding: 13px 17px; border: 1px solid rgba(215,166,66,.3); border-radius: 12px; background: rgba(15,29,22,.96); box-shadow: var(--shadow); color: var(--ink); font-size: .78rem; transform: translateY(120px); opacity: 0; transition: .3s ease; }
.toast.show { transform: translateY(0); opacity: 1; }

@keyframes rise { from { transform: translateY(18px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr auto; }
  .topbar nav { display: none; }
  .hero-content { width: 85vw; }
  .milestone-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .insights-grid { grid-template-columns: 1fr; }
  .pace-card { min-height: 300px; }
}
@media (max-width: 700px) {
  .topbar { min-height: 66px; padding: 0 16px; }
  .wordmark small { display: none; }
  .hero-section { min-height: 780px; align-items: flex-start; padding: 90px 20px 220px; }
  .hero-art { background-position: 66% center; }
  .hero-content { width: 100%; }
  .hero-content h1 { font-size: clamp(3.1rem, 16vw, 4.6rem); }
  .hero-summary { font-size: 1rem; }
  .hero-actions { align-items: flex-start; flex-direction: column; }
  .stat-ribbon { right: 16px; bottom: 28px; left: 16px; grid-template-columns: 1fr 1fr; }
  .stat-ribbon article { padding: 16px; }
  .stat-ribbon article + article { border-left: 1px solid var(--line); }
  .stat-ribbon article:last-child { display: none; }
  .stat-ribbon strong { font-size: 1.7rem; }
  .content-section { padding: 75px 18px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .insights-heading-tools { justify-items: start; }
  .section-stat { display: none; }
  .map-frame { aspect-ratio: 4 / 5; min-height: 510px; }
  .map-texture { background-position: center; }
  .map-legend { right: 10px; bottom: 10px; left: 10px; justify-content: center; }
  .journey-cards { grid-template-columns: 1fr; }
  .journey-card { padding: 21px; }
  .milestone-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .milestone-card { min-height: 230px; }
  .milestone-copy { padding: 14px; }
  .milestone-copy h3 { font-size: 1.05rem; }
  .chart-card { padding: 15px 10px; }
  #distanceChart { height: 260px; }
  .form-grid, .manual-form { grid-template-columns: 1fr; }
  .manual-form label:first-child, .manual-form .button { grid-column: auto; }
  .settings-copy { padding: 32px 20px; }
  .dialog-art { min-height: 285px; }
  .dialog-copy { padding: 24px; }
  footer { flex-direction: column; }
}
@media (max-width: 410px) {
  .milestone-grid { grid-template-columns: 1fr; }
  .milestone-card { min-height: 250px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
