:root {
  --bg: #0f1419;
  --panel: rgba(18, 24, 31, 0.92);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f1ece2;
  --muted: #a9a293;
  --accent: #e0b25a;
  --accent-2: #7fb2d9;
  --doc: #6cc38a;
  --prob: #e0b25a;
  --recon: #d98a6c;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); }
#app { position: fixed; inset: 0; }
#app canvas { display: block; }
[hidden] { display: none !important; }
a { color: var(--accent-2); }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- start screen ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 50;
  background: radial-gradient(ellipse at 50% 30%, rgba(40, 52, 64, 0.85), rgba(10, 13, 17, 0.97)); }
.start-box { max-width: 560px; width: calc(100% - 32px); text-align: center; padding: 28px 24px; }
.start-box h1 { font-family: var(--serif); font-size: clamp(40px, 8vw, 64px); margin: 0; letter-spacing: 1px; color: var(--accent); }
.start-box .sub { margin: 4px 0 24px; color: var(--muted); font-size: 18px; }
.bar { height: 6px; background: rgba(255, 255, 255, 0.1); border-radius: 3px; overflow: hidden; margin: 12px auto 8px; max-width: 360px; }
#loadbar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
#loadtext { font-size: 13px; color: var(--muted); }
.startyear { display: inline-flex; gap: 10px; align-items: center; margin-bottom: 16px; color: var(--muted); }
.startyear input { width: 96px; font-size: 18px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--panel-border); background: #1b232c; color: var(--text); text-align: center; }
.btn { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--panel-border); background: #1f2933; color: var(--text); padding: 8px 14px; }
.btn:hover { background: #2a3642; }
.btn.primary { display: block; margin: 0 auto 18px; font-size: 20px; padding: 14px 28px; background: var(--accent); color: #1a1408; border: none; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { font-size: 13px; padding: 5px 10px; }
.keys { font-size: 13px; line-height: 1.7; color: var(--muted); }
kbd { display: inline-block; min-width: 20px; padding: 1px 6px; border: 1px solid #555; border-bottom-width: 2px; border-radius: 4px; background: #232b33; font: 12px/1.4 ui-monospace, monospace; color: var(--text); }
.credits { margin-top: 22px; font-size: 11px; color: #7d776b; line-height: 1.5; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); }
#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: rgba(255, 255, 255, 0.75); box-shadow: 0 0 2px #000; }
#yearbox { position: absolute; left: 16px; top: 14px; width: min(340px, calc(100vw - 32px)); padding: 10px 14px 12px; background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius); pointer-events: auto; text-shadow: none; }
.yearrow { display: flex; align-items: center; gap: 10px; }
#year { font-family: var(--serif); font-size: 40px; font-weight: bold; color: var(--accent); min-width: 104px; text-align: center; }
.yb { font-size: 22px; background: none; border: 1px solid var(--panel-border); color: var(--text); border-radius: 6px; cursor: pointer; width: 34px; height: 34px; }
#eraname { font-size: 15px; font-weight: 600; margin: 2px 0 6px; }
#yearslider { width: 100%; accent-color: var(--accent); cursor: pointer; }
#eranote { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.35; }
#compass { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); width: min(360px, 50vw); height: 26px; overflow: hidden; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 13px; }
#compassstrip { position: absolute; top: 4px; left: 0; white-space: nowrap; font-size: 13px; font-weight: 600; }
#compassstrip span { position: absolute; transform: translateX(-50%); }
#compassstrip span.card { color: var(--accent); }
#compass .needle { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--accent); opacity: 0.8; }
#topright { position: absolute; right: 16px; top: 14px; text-align: right; font-size: 14px; }
#discovered { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 10px; display: inline-block; text-shadow: none; }
#modeinfo { margin-top: 6px; font-size: 13px; color: var(--accent-2); }
#speedbox { position: absolute; left: 16px; bottom: 16px; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 10px; font-size: 13px; text-shadow: none; }
#sprint { color: var(--accent); font-weight: 600; }
#edgewarn { position: absolute; top: 58px; left: 50%; transform: translateX(-50%); background: rgba(120, 60, 20, 0.85); padding: 6px 14px; border-radius: 8px; font-size: 14px; }
#minimap { position: absolute; right: 16px; bottom: 16px; width: 220px; height: 220px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.25); background: rgba(10, 14, 18, 0.6); }
#minimap.off { display: none; }
#hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); font-size: 12px; color: rgba(255, 255, 255, 0.7); white-space: nowrap; }
#paused { position: absolute; left: 50%; top: 58%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--panel-border); padding: 8px 16px; border-radius: 10px; font-size: 15px; text-shadow: none; }
#nearcard { position: absolute; left: 50%; bottom: 52px; transform: translateX(-50%); width: min(520px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--panel-border); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; text-shadow: none; }
#nearcard h3 { margin: 0 0 2px; font-family: var(--serif); font-size: 19px; }
#nearcard .meta { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#nearcard .press { margin-top: 6px; font-size: 13px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: 0.3px; padding: 1px 7px; border-radius: 10px; color: #111; text-transform: uppercase; }
.badge.documented { background: var(--doc); }
.badge.probable { background: var(--prob); }
.badge.reconstruction { background: var(--recon); }
.badge.estimated { background: #9aa5b1; }
#toasts { position: absolute; top: 60px; right: 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { background: var(--panel); border: 1px solid var(--panel-border); border-left: 4px solid var(--doc); padding: 8px 12px; border-radius: 8px; font-size: 14px; text-shadow: none; animation: toastin 0.3s ease-out; max-width: 320px; }
@keyframes toastin { from { opacity: 0; transform: translateX(20px); } }
#tourarrow { position: absolute; top: 50px; left: 50%; transform: translateX(-50%); text-align: center; }
#tourarrow .arrow { font-size: 34px; color: #ffd36b; transition: transform 0.1s; }
#tourtext { font-size: 13px; background: var(--panel); padding: 3px 10px; border-radius: 8px; text-shadow: none; }

/* ---------- panels ---------- */
.panel { position: fixed; z-index: 30; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px; padding: 20px 22px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); backdrop-filter: blur(6px); }
.panel.wide { width: min(860px, calc(100vw - 32px)); }
.panel.small { width: min(320px, calc(100vw - 32px)); text-align: center; }
.panel h2 { font-family: var(--serif); margin: 0 0 10px; color: var(--accent); }
.panel .close { position: sticky; top: 0; float: right; margin: -8px -8px 0 0; font-size: 20px; background: none; border: none; color: var(--muted); cursor: pointer; }
#yearinput { width: 140px; font-size: 28px; text-align: center; padding: 6px; border-radius: 8px; border: 1px solid var(--panel-border); background: #1b232c; color: var(--text); }
.help-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; align-items: center; }
.info-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.info-head h2 { margin-bottom: 4px; }
.info-years { color: var(--muted); font-size: 14px; }
.info-text { font-size: 15px; line-height: 1.55; margin: 10px 0 14px; }
.info-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 10px 0; }
.info-photos figure { margin: 0; cursor: zoom-in; }
.info-photos img { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; display: block; background: #222; }
.info-photos figcaption { font-size: 11px; color: var(--muted); margin-top: 3px; line-height: 1.3; }
.info-photos figure.main { grid-column: 1 / -1; cursor: zoom-in; }
.info-photos figure.main img { height: auto; max-height: 360px; object-fit: contain; background: #0b0e11; }
.phase-list { list-style: none; padding: 0; margin: 8px 0; font-size: 13px; }
.phase-list li { padding: 5px 8px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.phase-list li:hover { background: rgba(255, 255, 255, 0.06); }
.phase-list li.current { background: rgba(224, 178, 90, 0.15); }
.phase-list .yrs { min-width: 90px; color: var(--accent); font-variant-numeric: tabular-nums; }
.sources { font-size: 12px; color: var(--muted); line-height: 1.6; }
.sources a { word-break: break-word; }
.tl-list { list-style: none; margin: 0; padding: 0; }
.tl-list li { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.tl-list li:hover { background: rgba(255, 255, 255, 0.06); }
.tl-list li.past { opacity: 0.55; }
.tl-list li.now { background: rgba(224, 178, 90, 0.15); }
.tl-list .y { font-family: var(--serif); font-weight: bold; color: var(--accent); font-size: 18px; }
.tl-list .t { font-weight: 600; }
.tl-list .d { font-size: 13px; color: var(--muted); margin-top: 2px; }
.lm-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px; }
.lm-list li { padding: 8px 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.04); cursor: pointer; font-size: 14px; }
.lm-list li:hover { background: rgba(255, 255, 255, 0.09); }
.lm-list li .st { font-size: 12px; color: var(--muted); }
.lm-list li.found::before { content: "✓ "; color: var(--doc); }
.lm-list li.inactive { opacity: 0.5; }
#bigmapcanvas { width: 100%; aspect-ratio: 1 / 1; max-height: calc(100vh - 140px); display: block; margin: 0 auto; border-radius: 8px; cursor: crosshair; background: #0b0e11; }
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.9); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 90px); object-fit: contain; }
.lightbox p { color: #ccc; font-size: 13px; max-width: 900px; text-align: center; }

@media (max-width: 720px) {
  #compass { display: none; }
  #minimap { width: 140px; height: 140px; }
  #hint { display: none; }
  #year { font-size: 30px; }
}
