/* Walk to Mordor: parchment, ink and lamplight. No external fonts: iOS ships Iowan Old Style & Palatino. */
:root {
  --paper: #f2e4c4;
  --paper-2: #e8d5aa;
  --paper-3: #dcc592;
  --ink: #2a1c0d;
  --ink-soft: #5d4a32;
  --ink-faint: #8a7556;
  --rule: rgba(60, 40, 15, .22);
  --accent: #8e2d17;     /* sealing wax */
  --accent-ink: #fff4e0;
  --gold: #a87a1f;
  --green: #48683a;
  --danger: #9b2414;
  --shadow: 0 1px 0 rgba(255,255,255,.35) inset, 0 6px 18px rgba(60, 35, 10, .18);
  --card: rgba(255, 248, 230, .55);
  --map-bg: #efdfb9;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --display: "Baskerville", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1b150f; --paper-2: #261d14; --paper-3: #33271a;
    --ink: #efe0bf; --ink-soft: #c7b28a; --ink-faint: #8f7c5c;
    --rule: rgba(240, 220, 180, .16);
    --accent: #e0724c; --accent-ink: #1b120a; --gold: #dcae4a; --green: #8db36f; --danger: #ff7a5c;
    --shadow: 0 8px 22px rgba(0,0,0,.45);
    --card: rgba(60, 45, 28, .45);
    --map-bg: #2b2217;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1b150f; --paper-2: #261d14; --paper-3: #33271a;
  --ink: #efe0bf; --ink-soft: #c7b28a; --ink-faint: #8f7c5c;
  --rule: rgba(240, 220, 180, .16);
  --accent: #e0724c; --accent-ink: #1b120a; --gold: #dcae4a; --green: #8db36f; --danger: #ff7a5c;
  --shadow: 0 8px 22px rgba(0,0,0,.45);
  --card: rgba(60, 45, 28, .45);
  --map-bg: #2b2217;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(255,255,255,.18), transparent 60%),
    radial-gradient(ellipse at 100% 100%, rgba(120,70,20,.16), transparent 55%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .35  0 0 0 0 .22  0 0 0 0 .08  0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  color: var(--ink);
  font: 17px/1.5 var(--serif);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.15; margin: 0 0 .4em; letter-spacing: .01em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
.smallcaps { font-variant: small-caps; letter-spacing: .08em; }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.tiny { font-size: .8rem; }
.center { text-align: center; }
.hidden { display: none !important; }
code, .mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .86em; }

/* ---------- shell ---------- */
#app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: linear-gradient(var(--paper), color-mix(in srgb, var(--paper) 88%, transparent));
  border-bottom: 1px solid var(--rule);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.brand { font-family: var(--display); font-size: 1.05rem; letter-spacing: .14em; text-transform: uppercase; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand svg { width: 26px; height: 26px; }
.group-switch { margin-left: auto; max-width: 52vw; }
.group-switch select {
  appearance: none; -webkit-appearance: none;
  font: inherit; font-size: .9rem; color: var(--ink);
  background: var(--card); border: 1px solid var(--rule); border-radius: 999px;
  padding: 6px 28px 6px 12px; max-width: 100%;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%; background-size: 5px 5px; background-repeat: no-repeat;
}
main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); }
main.full { max-width: none; padding: 0; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 4px 6px calc(env(safe-area-inset-bottom) + 4px);
  background: color-mix(in srgb, var(--paper-2) 94%, transparent);
  border-top: 1px solid var(--rule);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0 4px; text-decoration: none; color: var(--ink-soft); font-size: .72rem; letter-spacing: .04em;
}
.tabbar a svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { filter: drop-shadow(0 1px 0 rgba(0,0,0,.08)); }

/* ---------- cards, forms ---------- */
.card {
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 16px; margin: 0 0 16px; box-shadow: var(--shadow);
}
.card.plain { box-shadow: none; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.ornament { display: block; text-align: center; color: var(--ink-faint); letter-spacing: .6em; margin: 6px 0 14px; font-size: .9rem; }
.ornament::before { content: "❦  ✦  ❦"; }

label { display: block; font-size: .85rem; color: var(--ink-soft); margin: 10px 0 4px; letter-spacing: .03em; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink);
  background: color-mix(in srgb, var(--paper) 70%, white 10%);
  border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) input, :root:not([data-theme="light"]) select, :root:not([data-theme="light"]) textarea { background: var(--paper-2); } }
:root[data-theme="dark"] input, :root[data-theme="dark"] select, :root[data-theme="dark"] textarea { background: var(--paper-2); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
textarea { min-height: 84px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row > * { flex: 1; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 1rem; letter-spacing: .03em;
  padding: 11px 18px; border-radius: 999px; border: 1px solid transparent; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); text-decoration: none;
  box-shadow: 0 2px 0 rgba(0,0,0,.18), inset 0 1px 0 rgba(255,255,255,.18);
}
.btn:active { transform: translateY(1px); }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--rule); box-shadow: none; }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; margin-top: 14px; }
.btn[disabled] { opacity: .5; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 999px; overflow: hidden; }
.seg button { font: inherit; font-size: .88rem; padding: 7px 14px; border: 0; background: transparent; color: var(--ink-soft); cursor: pointer; }
.seg button.on { background: var(--ink); color: var(--paper); }
.seg.wide { display: flex; } .seg.wide button { flex: 1; }

.race-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.race-grid button {
  font: inherit; font-size: .74rem; color: var(--ink); cursor: pointer;
  border: 1px solid var(--rule); border-radius: 12px; background: transparent; padding: 8px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.race-grid button span { font-size: 1.5rem; }
.race-grid button.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

.keybox {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .95rem; word-break: break-all;
  background: var(--paper-2); border: 1px dashed var(--ink-faint); border-radius: 10px; padding: 12px; user-select: all; -webkit-user-select: all;
}
.copyline { display: flex; gap: 8px; align-items: stretch; margin: 6px 0 10px; }
.copyline .keybox { flex: 1; min-width: 0; padding: 8px 10px; font-size: .85rem; }
.copyline .btn { flex: 0 0 auto; align-self: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px); transform: translateX(-50%);
  z-index: 100; background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: .92rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: toast .25s ease-out; max-width: calc(100vw - 32px);
}
@keyframes toast { from { opacity: 0; transform: translate(-50%, 10px); } }
.error { color: var(--danger); font-size: .9rem; margin-top: 8px; }

/* ---------- welcome ---------- */
.hero { position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; box-shadow: var(--shadow); }
.hero .scene { display: block; width: 100%; height: auto; }
.hero .title {
  position: absolute; inset: auto 0 0 0; padding: 40px 16px 14px;
  background: linear-gradient(transparent, rgba(20,12,4,.72)); color: #fbeed3;
}
.hero .title h1 { font-size: 2rem; margin: 0; letter-spacing: .06em; }
.hero .title p { margin: 2px 0 0; opacity: .9; font-style: italic; }

/* ---------- map ---------- */
.map-wrap { position: relative; height: calc(100dvh - 56px - var(--nav-h) - env(safe-area-inset-bottom) - env(safe-area-inset-top)); min-height: 360px; background: var(--map-bg); overflow: hidden; touch-action: none; }
.map-wrap svg.map { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; -webkit-user-select: none; }
.map-wrap svg.map.dragging { cursor: grabbing; }
.map-controls { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 8px; }
.map-controls button {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--rule); background: var(--card); color: var(--ink);
  font: 600 1.25rem/1 var(--serif); box-shadow: var(--shadow); cursor: pointer; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.map-legend { position: absolute; left: 12px; top: 12px; font-size: .78rem; background: var(--card); border: 1px solid var(--rule); border-radius: 10px; padding: 6px 10px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); max-width: 60%; }
.map .wp-minor-label, .map .label-minor { opacity: 0; transition: opacity .2s; pointer-events: none; }
.map.zoomed .wp-minor-label, .map.zoomed .label-minor { opacity: 1; }
.map .token { cursor: pointer; }
.map .token .ring { transition: r .2s; }
.map .token:hover .ring { stroke-width: 3; }
.map .wp { cursor: pointer; }
.map .rider { cursor: pointer; }
@keyframes pulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }
.map .doom-glow { animation: pulse 3s ease-in-out infinite; }
.map .me-pulse { animation: mepulse 2.2s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes mepulse { 0% { transform: scale(.6); opacity: .8; } 100% { transform: scale(1.9); opacity: 0; } }

/* bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15,8,2,.35); z-index: 60; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; max-height: 82dvh; overflow: auto;
  background: var(--paper); border-top-left-radius: 20px; border-top-right-radius: 20px;
  border-top: 1px solid var(--rule); box-shadow: 0 -10px 30px rgba(0,0,0,.25);
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 20px); animation: rise .25s ease-out;
  max-width: 760px; margin: 0 auto;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--rule); margin: 0 auto 10px; }
.sheet .scene { width: 100%; border-radius: 12px; display: block; margin-bottom: 10px; }

/* ---------- journey ---------- */
.scene-frame { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 14px; border: 1px solid var(--rule); }
.scene-frame .scene { display: block; width: 100%; height: auto; }
.scene-caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 30px 14px 10px; color: #fbeed3; background: linear-gradient(transparent, rgba(15,8,2,.75)); }
.scene-caption .where { font-family: var(--display); font-size: 1.35rem; line-height: 1.1; }
.scene-caption .sub { font-size: .85rem; opacity: .9; font-style: italic; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--rule); border-radius: 12px; padding: 10px; text-align: center; }
.stat .v { font-family: var(--display); font-size: 1.35rem; line-height: 1.1; }
.stat .k { font-size: .72rem; color: var(--ink-soft); letter-spacing: .06em; text-transform: uppercase; margin-top: 2px; }
.progress { position: relative; height: 12px; border-radius: 6px; background: var(--paper-3); overflow: visible; margin: 18px 0 26px; }
.progress .fill { position: absolute; inset: 0 auto 0 0; border-radius: 6px; background: linear-gradient(90deg, var(--green), var(--gold) 60%, var(--accent)); }
.progress .tick { position: absolute; top: -4px; width: 2px; height: 20px; background: var(--ink-soft); }
.progress .tick span { position: absolute; top: 22px; transform: translateX(-50%); font-size: .66rem; color: var(--ink-soft); white-space: nowrap; }
.progress .rider-mark { position: absolute; top: -18px; transform: translateX(-50%); font-size: 1rem; }
.neighbours { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.neighbours a { text-decoration: none; color: inherit; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .76rem; border: 1px solid var(--rule); background: var(--card); white-space: nowrap; }
.chip.caught { background: #2a2a2a; color: #f2e0c0; border-color: #000; }
.chip.flag { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.chip.done { background: color-mix(in srgb, var(--gold) 25%, transparent); }
.daylist { list-style: none; padding: 0; margin: 0; }
.daylist li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dotted var(--rule); }
.daylist li:last-child { border-bottom: 0; }
.daylist .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--paper-3); overflow: hidden; }
.daylist .bar i { display: block; height: 100%; background: var(--green); }
.chart svg { width: 100%; height: auto; display: block; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.badge {
  text-align: center; padding: 10px 6px; border-radius: 12px; border: 1px solid var(--rule); background: var(--card); font-size: .75rem; line-height: 1.2;
}
.badge .seal {
  width: 52px; height: 52px; margin: 0 auto 6px; border-radius: 50%; display: grid; place-items: center; font-size: 1.5rem;
  background: radial-gradient(circle at 35% 30%, #c4553a, #7d200f 70%); box-shadow: inset 0 -3px 6px rgba(0,0,0,.35), 0 2px 4px rgba(0,0,0,.25);
}
.badge.locked { opacity: .38; filter: grayscale(1); }

/* ---------- leaderboard ---------- */
.board { list-style: none; padding: 0; margin: 0; }
.board li { display: grid; grid-template-columns: 30px 40px 1fr auto; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px dotted var(--rule); }
.board li.me { background: color-mix(in srgb, var(--gold) 14%, transparent); border-radius: 10px; }
.board .rank { font-family: var(--display); font-size: 1.2rem; text-align: center; color: var(--ink-soft); }
.board li:nth-child(1) .rank { color: var(--gold); font-size: 1.45rem; }
.board .tok { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 1.25rem; border: 2px solid var(--ink-soft); background: var(--paper-2); }
.board .nm { min-width: 0; }
.board .nm b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .nm small { color: var(--ink-soft); }
.board .val { font-family: var(--display); font-size: 1.1rem; text-align: right; }
.board a { color: inherit; text-decoration: none; display: contents; }

/* ---------- journal ---------- */
.entry { position: relative; }
.entry h3 { font-style: italic; font-weight: 500; font-size: 1.3rem; margin-top: 4px; }
.entry .when { font-size: .78rem; color: var(--ink-soft); letter-spacing: .08em; text-transform: uppercase; }
.entry p { margin: .45em 0; }
.entry p:first-of-type::first-letter { float: left; font-family: var(--display); font-size: 2.9em; line-height: .85; padding: 4px 6px 0 0; color: var(--accent); }

/* ---------- more / lists ---------- */
.menu { list-style: none; padding: 0; margin: 0; }
.menu a { display: flex; align-items: center; gap: 14px; padding: 14px 4px; border-bottom: 1px dotted var(--rule); color: inherit; text-decoration: none; }
.menu a .ic { font-size: 1.4rem; width: 32px; text-align: center; }
.menu a small { display: block; color: var(--ink-soft); }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps > li { counter-increment: s; position: relative; padding: 10px 0 10px 44px; border-bottom: 1px dotted var(--rule); }
.steps > li::before {
  content: counter(s); position: absolute; left: 0; top: 10px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; background: var(--ink); color: var(--paper); font-family: var(--display); font-size: .95rem;
}
.steps ul { padding-left: 18px; margin: 4px 0; }
.act { font-weight: 600; background: var(--paper-2); border: 1px solid var(--rule); border-radius: 6px; padding: 0 6px; white-space: nowrap; }
.note { border-left: 3px solid var(--gold); padding: 6px 12px; background: color-mix(in srgb, var(--gold) 10%, transparent); border-radius: 0 10px 10px 0; font-size: .92rem; margin: 10px 0; }
.warn { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }
table.simple { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.simple th, table.simple td { text-align: left; padding: 6px 4px; border-bottom: 1px dotted var(--rule); vertical-align: middle; }
table.simple th { font-weight: 600; color: var(--ink-soft); font-size: .78rem; letter-spacing: .05em; text-transform: uppercase; }
.guide-item { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px dotted var(--rule); }
.guide-item .scene { width: 110px; height: auto; border-radius: 10px; display: block; }
.guide-item .mile { font-size: .78rem; color: var(--ink-soft); letter-spacing: .05em; }

/* ---------- finale ---------- */
.finale { position: fixed; inset: 0; z-index: 200; background: #120604; color: #ffe9c2; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; overflow: hidden; animation: fade .6s; }
.finale canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.finale .scene { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .9; }
.finale .msg { position: relative; z-index: 2; padding: 28px 22px; max-width: 520px; animation: msg 1.6s ease-out .6s both; background: radial-gradient(ellipse at center, rgba(12,4,2,.78) 30%, rgba(12,4,2,0) 72%); }
@keyframes msg { from { opacity: 0; transform: translateY(30px) scale(.96); } }
.finale h1 { font-size: 2.3rem; letter-spacing: .06em; text-shadow: 0 0 22px #ff7a1a, 0 2px 0 #000; }
.finale p { font-size: 1.1rem; text-shadow: 0 1px 2px #000; }
.finale .btn { position: relative; z-index: 2; }
@keyframes quake { 0%,100% { transform: translate(0,0); } 20% { transform: translate(-3px,2px); } 40% { transform: translate(3px,-2px); } 60% { transform: translate(-2px,-1px); } 80% { transform: translate(2px,1px); } }
.finale.quake { animation: quake .5s linear 3; }

@media (min-width: 720px) {
  .stat-grid { grid-template-columns: repeat(6, 1fr); }
  .race-grid { grid-template-columns: repeat(8, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
