:root {
  --parch: #efe0bb;
  --parch-dark: #d6bf8c;
  --ink: #2e1d0f;
  --ink-soft: #5a4128;
  --crimson: #7d1418;
  --crimson-dark: #4f0b0e;
  --gold: #d6ab3e;
  --gold-light: #f0d27a;
  --wood: #2a1a0e;
  --wood-light: #4a3020;
  --iron: #2d2b28;
  --forest: #2f4a2a;
  --display: 'Cinzel Decorative', 'Cinzel', Georgia, serif;
  --heading: 'Cinzel', Georgia, serif;
  --body: 'IM Fell English', Georgia, 'Times New Roman', serif;
  --paper-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.24 0 0 0 0 0.1 0 0 0 0.28 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d0906; color: var(--ink); font-family: var(--body); }
body { -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, transparent 55%, rgba(10, 5, 2, 0.55) 100%); }
[hidden] { display: none !important; }

/* ---------- parchment surfaces ---------- */
.parchment, .modal-frame {
  position: relative;
  background: var(--paper-grain), radial-gradient(ellipse at 50% 40%, #f6ead0 0%, var(--parch) 55%, var(--parch-dark) 100%);
  color: var(--ink);
  box-shadow: inset 0 0 60px rgba(120, 80, 30, 0.45), inset 0 0 8px rgba(80, 50, 20, 0.5), 0 18px 50px rgba(0, 0, 0, 0.6);
}
.modal-frame::before, .parchment::before {
  content: ''; position: absolute; inset: 10px; pointer-events: none;
  border: 2px solid rgba(125, 20, 24, 0.55); outline: 1px solid rgba(214, 171, 62, 0.8); outline-offset: 3px;
}
.modal-frame::after, .parchment::after {
  content: ''; position: absolute; inset: 4px; pointer-events: none;
  background:
    radial-gradient(circle at 0 0, var(--gold) 0 5px, transparent 6px),
    radial-gradient(circle at 100% 0, var(--gold) 0 5px, transparent 6px),
    radial-gradient(circle at 0 100%, var(--gold) 0 5px, transparent 6px),
    radial-gradient(circle at 100% 100%, var(--gold) 0 5px, transparent 6px);
}

/* ---------- title screen ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; z-index: 20;
  background: radial-gradient(ellipse at center, rgba(20, 12, 6, 0.25), rgba(8, 4, 2, 0.8)); transition: opacity 0.9s ease; }
.screen.fade { opacity: 0; pointer-events: none; }
.scroll { width: min(640px, 94vw); display: flex; flex-direction: column; align-items: center; filter: drop-shadow(0 20px 40px rgba(0,0,0,0.7)); animation: unfurl 1.1s ease-out both; }
@keyframes unfurl { from { transform: scaleY(0.2); opacity: 0; } to { transform: scaleY(1); opacity: 1; } }
.scroll-rod { width: 106%; height: 22px; border-radius: 11px; position: relative; z-index: 2;
  background: linear-gradient(180deg, #6b4526, #3a2412 45%, #24160a 60%, #5a3a20); box-shadow: 0 4px 10px rgba(0,0,0,0.5); }
.scroll-rod::before, .scroll-rod::after { content: ''; position: absolute; top: -5px; width: 32px; height: 32px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--gold-light), var(--gold) 45%, #7a5a14); }
.scroll-rod::before { left: -14px; } .scroll-rod::after { right: -14px; }
.parchment { width: 100%; margin: -6px 0; padding: 38px clamp(20px, 6vw, 56px) 34px; text-align: center; max-height: calc(100vh - 110px); overflow: auto; }
.crest { width: 74px; height: 86px; margin: 0 auto 6px; display: block; filter: drop-shadow(0 3px 3px rgba(0,0,0,0.35)); }
.kicker { font-family: var(--heading); font-size: 0.78rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--crimson); margin: 0 0 6px; }
h1 { font-family: var(--display); font-weight: 900; font-size: clamp(2rem, 8vw, 3.6rem); line-height: 1.05; margin: 0; color: var(--crimson-dark);
  text-shadow: 0 1px 0 rgba(255,240,200,0.8), 0 2px 6px rgba(90, 20, 10, 0.25); }
.subtitle { font-style: italic; font-size: 1.2rem; color: var(--ink-soft); margin: 8px 0 0; }
.divider { display: flex; align-items: center; gap: 12px; margin: 16px auto; max-width: 360px; color: var(--crimson); }
.divider::before, .divider::after { content: ''; flex: 1; height: 2px; background: linear-gradient(90deg, transparent, var(--gold), var(--crimson), var(--gold), transparent); }
.divider span { font-size: 1.4rem; }
.lore { font-size: 1.1rem; line-height: 1.5; margin: 0 auto 20px; max-width: 460px; }
.progress { height: 20px; border-radius: 10px; margin: 8px auto 10px; max-width: 420px; padding: 3px;
  background: linear-gradient(180deg, #2a1a0e, #4a3020); border: 2px solid var(--gold); box-shadow: inset 0 2px 6px rgba(0,0,0,0.6); }
.progress-fill { height: 100%; width: 0%; border-radius: 7px; transition: width 0.25s ease;
  background: linear-gradient(180deg, #ffcf6a, #e07818 55%, #a3360a); box-shadow: 0 0 12px rgba(255, 150, 40, 0.8); }
.loading-text { font-style: italic; min-height: 1.5em; margin: 0; color: var(--ink-soft); }

/* ---------- buttons ---------- */
.btn { font-family: var(--heading); font-weight: 700; font-size: 1rem; letter-spacing: 0.06em; cursor: pointer; color: var(--gold-light);
  padding: 11px 22px; min-height: 44px; border-radius: 4px; border: 2px solid var(--gold);
  background: linear-gradient(180deg, var(--wood-light), var(--wood)); box-shadow: inset 0 1px 0 rgba(255,220,150,0.25), 0 3px 8px rgba(0,0,0,0.45);
  text-shadow: 0 1px 2px rgba(0,0,0,0.8); transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease; }
.btn:hover { filter: brightness(1.2); box-shadow: inset 0 1px 0 rgba(255,220,150,0.3), 0 0 16px rgba(214, 171, 62, 0.55); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus-visible, .hud-btn:focus-visible, .t-btn:focus-visible, select:focus-visible, input:focus-visible, .close-x:focus-visible, .wp:focus-visible {
  outline: 3px solid var(--gold-light); outline-offset: 3px; }
.btn-seal { font-size: 1.2rem; padding: 14px 34px; border-radius: 40px; color: #fff4d6; border-color: var(--gold-light);
  background: radial-gradient(circle at 40% 30%, #b3262b, var(--crimson) 45%, var(--crimson-dark)); box-shadow: 0 0 0 4px rgba(79, 11, 14, 0.5), 0 6px 16px rgba(0,0,0,0.5); }
.btn-seal.small { font-size: 1rem; padding: 10px 26px; }
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.btn-row .btn { font-size: 0.9rem; padding: 9px 16px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#compass { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(460px, 70vw); height: 38px;
  overflow: hidden; border: 2px solid var(--gold); border-radius: 4px;
  background: linear-gradient(180deg, rgba(42, 26, 14, 0.92), rgba(20, 12, 6, 0.92)); box-shadow: 0 4px 12px rgba(0,0,0,0.5), inset 0 0 12px rgba(0,0,0,0.6);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 15%, #000 85%, transparent); mask-image: linear-gradient(90deg, transparent, #000 15%, #000 85%, transparent); }
#compass-strip { position: absolute; top: 0; left: 0; height: 100%; white-space: nowrap; will-change: transform; }
.cmp { position: absolute; top: 0; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; transform: translateX(-50%);
  font-family: var(--heading); color: var(--gold-light); font-size: 0.72rem; }
.cmp.major { font-size: 1.05rem; font-weight: 700; color: #fff0c4; text-shadow: 0 0 6px rgba(214, 171, 62, 0.7); }
.cmp.major.n { color: #ff8a7a; }
.cmp.tick { font-size: 0.6rem; opacity: 0.7; }
.compass-mark { position: absolute; left: 50%; top: -2px; width: 0; height: 0; transform: translateX(-50%);
  border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 9px solid var(--crimson); filter: drop-shadow(0 0 2px #000); }

#location-banner { position: absolute; top: 72px; left: 50%; transform: translate(-50%, -12px); text-align: center; opacity: 0; transition: opacity 0.8s ease, transform 0.8s ease; width: min(720px, 92vw); }
#location-banner.show { opacity: 1; transform: translate(-50%, 0); }
.ribbon { display: inline-block; position: relative; padding: 8px 46px; color: #fff3d0;
  background: linear-gradient(180deg, #a01c21, var(--crimson) 50%, var(--crimson-dark)); border-top: 2px solid var(--gold); border-bottom: 2px solid var(--gold);
  box-shadow: 0 6px 18px rgba(0,0,0,0.55); }
.ribbon::before, .ribbon::after { content: ''; position: absolute; top: 8px; width: 30px; height: 100%; background: var(--crimson-dark); z-index: -1; }
.ribbon::before { left: -22px; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 30% 50%); }
.ribbon::after { right: -22px; clip-path: polygon(0 0, 100% 0, 70% 50%, 100% 100%, 0 100%); }
#location-name { margin: 0; font-family: var(--display); font-weight: 700; font-size: clamp(1.1rem, 3.6vw, 1.8rem); letter-spacing: 0.04em; text-shadow: 0 2px 4px rgba(0,0,0,0.6); }
#location-banner.secret .ribbon { background: linear-gradient(180deg, #e8c25a, #b8892a 50%, #7a5a14); color: #2a1a06; text-shadow: 0 1px 0 rgba(255,240,200,0.6); }
#location-banner.secret .ribbon::before, #location-banner.secret .ribbon::after { background: #6a4c10; }
#location-banner.secret #location-desc { color: #ffe9a8; }
.secret-count { text-align: center; font-family: var(--heading); color: var(--crimson-dark); margin: 0 0 14px; }
#location-desc { margin: 10px 0 0; font-style: italic; font-size: clamp(0.95rem, 2.4vw, 1.15rem); color: #f7e7c0; text-shadow: 0 1px 4px #000, 0 0 12px #000; }

#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%;
  background: rgba(255, 240, 200, 0.75); box-shadow: 0 0 0 1px rgba(0,0,0,0.6); }
#plaque { position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 2px;
  padding: 8px 16px; border: 2px solid var(--gold); border-radius: 3px; color: var(--gold-light);
  background: linear-gradient(180deg, rgba(42, 26, 14, 0.9), rgba(20, 12, 6, 0.9)); box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
#plaque-name { font-family: var(--heading); font-weight: 700; font-size: 0.95rem; }
#plaque-time { font-style: italic; font-size: 0.85rem; color: #e8d6a8; }
#hint { position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%); padding: 8px 18px; border-radius: 3px; opacity: 0; transition: opacity 0.6s;
  font-style: italic; font-size: 1.05rem; color: #fff1cc; background: rgba(20, 12, 6, 0.75); border: 1px solid rgba(214, 171, 62, 0.6); text-align: center; max-width: 90vw; }
#hint.show { opacity: 1; }
#fps { position: absolute; right: 14px; bottom: 14px; font-family: monospace; color: var(--gold-light); background: rgba(0,0,0,0.5); padding: 3px 8px; border-radius: 3px; }
.hud-buttons { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); display: flex; gap: 8px; pointer-events: auto; }
.hud-btn { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: var(--gold-light); padding: 0;
  border: 2px solid var(--gold); background: radial-gradient(circle at 40% 30%, var(--wood-light), var(--wood)); box-shadow: 0 3px 8px rgba(0,0,0,0.5); }
.hud-btn svg { width: 22px; height: 22px; }
#click-resume { position: absolute; left: 50%; top: 58%; transform: translateX(-50%); pointer-events: auto; }

/* ---------- touch ---------- */
#touch-controls { position: absolute; inset: 0; pointer-events: auto; }
#joy-zone { position: absolute; left: 0; bottom: 0; width: 45%; height: 60%; }
#look-zone { position: absolute; right: 0; top: 0; width: 55%; height: 100%; }
#joy-base { position: absolute; width: 120px; height: 120px; border-radius: 50%; left: 40px; bottom: 60px; opacity: 0.55;
  border: 2px solid var(--gold); background: radial-gradient(circle, rgba(42, 26, 14, 0.4), rgba(42, 26, 14, 0.75)); }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: radial-gradient(circle at 40% 30%, #b3262b, var(--crimson-dark)); border: 2px solid var(--gold-light); }
.touch-buttons { position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.t-btn { width: 70px; height: 70px; border-radius: 50%; font-family: var(--heading); font-weight: 700; font-size: 0.85rem; color: var(--gold-light);
  border: 2px solid var(--gold); background: radial-gradient(circle at 40% 30%, var(--wood-light), var(--wood)); box-shadow: 0 3px 10px rgba(0,0,0,0.5); opacity: 0.88; }
.t-btn[aria-pressed='true'] { background: radial-gradient(circle at 40% 30%, #b3262b, var(--crimson-dark)); }

/* ---------- modals ---------- */
#modal-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(8, 4, 2, 0.6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.modal { position: fixed; inset: 0; z-index: 31; display: grid; place-items: center; padding: 14px; }
.modal-frame { width: min(520px, 96vw); max-height: calc(100vh - 28px); overflow: auto; padding: 30px clamp(18px, 5vw, 40px) 28px; border-radius: 3px; animation: pop 0.28s ease-out; }
.modal.wide .modal-frame { width: min(1180px, 97vw); }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h2 { font-family: var(--display); color: var(--crimson-dark); text-align: center; margin: 0; font-size: clamp(1.3rem, 4.5vw, 1.9rem); }
.close-x { position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; z-index: 2;
  border: 2px solid var(--gold); background: var(--crimson); color: #fff3d0; font-size: 1.1rem; line-height: 1; }
.menu-list { display: flex; flex-direction: column; gap: 10px; align-items: stretch; max-width: 320px; margin: 0 auto; }
.small-note { font-style: italic; color: var(--ink-soft); line-height: 1.45; }
.settings { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-family: var(--heading); font-weight: 700; font-size: 0.92rem; display: flex; justify-content: space-between; gap: 10px; }
.field output { font-family: var(--body); font-weight: 400; color: var(--crimson); }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field.check input { width: 22px; height: 22px; accent-color: var(--crimson); }
select { font-family: var(--body); font-size: 1rem; padding: 10px 12px; min-height: 44px; width: 100%; color: var(--ink); border-radius: 3px;
  border: 2px solid var(--ink-soft); background: #f8eed6; }
input[type='range'] { width: 100%; accent-color: var(--crimson); height: 28px; }
.keys { width: 100%; border-collapse: collapse; font-size: 1.05rem; }
.keys th { text-align: left; padding: 8px 10px 8px 0; white-space: nowrap; font-weight: 400; }
.keys td { padding: 8px 0; border-bottom: 1px dashed rgba(90, 65, 40, 0.4); }
kbd { display: inline-block; min-width: 30px; padding: 3px 7px; margin-right: 4px; text-align: center; font-family: var(--heading); font-size: 0.85rem;
  color: var(--gold-light); background: linear-gradient(180deg, var(--wood-light), var(--wood)); border: 1px solid var(--gold); border-radius: 3px; }
.credits { padding-left: 20px; line-height: 1.55; font-size: 1.05rem; }
.credits a { color: var(--crimson); }
#message-body { font-size: 1.1rem; line-height: 1.5; text-align: center; }

.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; margin-top: 14px; }
.map-wrap { position: relative; align-self: start; justify-self: center; width: 100%; max-width: calc(100vh - 150px); border: 3px double var(--ink-soft); background: #e9d7ae; }
#map-canvas { width: 100%; height: auto; display: block; aspect-ratio: 1; }
.waypoints h3 { font-family: var(--heading); color: var(--crimson-dark); margin: 0 0 4px; }
#waypoint-list { display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 260px); overflow: auto; padding-right: 4px; }
.wp { text-align: left; font-family: var(--body); font-size: 1rem; padding: 9px 12px; min-height: 42px; cursor: pointer; border-radius: 3px;
  color: var(--ink); border: 1px solid rgba(90, 65, 40, 0.55); background: rgba(255, 248, 225, 0.55); }
.wp:hover { background: var(--crimson); color: #fff3d0; border-color: var(--gold); }
.wp::before { content: '⚜ '; color: var(--gold); }

@media (max-width: 760px) {
  .map-layout { grid-template-columns: 1fr; }
  #waypoint-list { max-height: 220px; display: grid; grid-template-columns: 1fr 1fr; }
  #location-banner { top: 60px; }
  .ribbon { padding: 6px 28px; }
  #plaque { display: none; }
  #hint { bottom: 170px; font-size: 0.95rem; }
  #compass { height: 32px; left: 12px; transform: none; width: calc(100vw - 140px); }
}
@media (pointer: coarse) { #crosshair { display: none; } }
@media (prefers-reduced-motion: reduce) { .scroll, .modal-frame { animation: none; } }
