:root {
  --ink: #0f1c26;
  --panel: rgba(16, 28, 38, 0.94);
  --panel-solid: #12212c;
  --line: rgba(217, 164, 65, 0.35);
  --brass: #d9a441;
  --brass-hi: #f3d488;
  --text: #f1e9d6;
  --muted: #a9b3b1;
  --serif: "Fraunces", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --top: 60px;
  --food: #9fcf5e; --production: #e08a4c; --gold: #f0c64d; --science: #6fb7e6; --culture: #c88ad8; --pop: #e8dcc0; --wonder: #f3d488;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Scrollbars: hidden everywhere; panels still scroll by wheel, trackpad and touch. */
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { width: 0; height: 0; display: none; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); font: 14px/1.45 var(--sans); overflow: hidden; -webkit-font-smoothing: antialiased; }
a { color: var(--brass-hi); }
button { font: inherit; color: inherit; cursor: pointer; }
code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
#map { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; cursor: grab; }
#map:active { cursor: grabbing; }

/* Top bar */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10; min-height: var(--top);
  display: flex; align-items: center; gap: 18px; padding: 8px 14px;
  background: linear-gradient(180deg, rgba(12, 22, 30, 0.97), rgba(12, 22, 30, 0.88));
  border-bottom: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.emblem { width: 36px; height: 36px; }
.brand h1 { margin: 0; font: 600 21px/1 var(--serif); letter-spacing: 0.01em; }
.brand .civ { color: var(--brass-hi); font-style: italic; }
.brand .tag { font: italic 500 12.5px/1.2 var(--serif); color: var(--brass-hi); margin-top: 3px; }
#yields { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; justify-content: safe center; }
#yields::-webkit-scrollbar { display: none; }
.yield { display: flex; align-items: center; gap: 6px; padding: 5px 9px; border: 1px solid transparent; border-radius: 7px; background: rgba(255, 255, 255, 0.03); white-space: nowrap; }
.yield:hover { border-color: var(--line); background: rgba(255, 255, 255, 0.07); }
.yield .ico { width: 18px; height: 18px; display: inline-flex; }
.yield .v { font-weight: 700; font-size: 14px; }
.yield .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.ico svg { width: 100%; height: 100%; fill: currentColor; }
.y-pop { color: var(--pop); } .y-food { color: var(--food); } .y-production { color: var(--production); } .y-gold { color: var(--gold); }
.y-science { color: var(--science); } .y-culture { color: var(--culture); } .y-wonder { color: var(--wonder); }
.yield .v, .yield .l { color: var(--text); }
.yield .l { color: var(--muted); }
.actions { display: flex; align-items: center; gap: 8px; flex: none; }
.btn { background: transparent; border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; font-weight: 500; font-size: 13px; }
.btn:hover { background: rgba(217, 164, 65, 0.12); }
.api-pill { display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: 999px; text-decoration: none; color: #1a1205; background: linear-gradient(180deg, #f6dc94, #d9a441); font-size: 12.5px; box-shadow: 0 2px 10px rgba(217, 164, 65, 0.35); white-space: nowrap; }
.api-pill span { opacity: 0.8; }
.api-pill:hover { filter: brightness(1.06); }

/* Lens card */
#lens-card {
  position: fixed; z-index: 8; left: 14px; top: calc(var(--top) + 14px); width: 214px; max-height: calc(100vh - var(--top) - 230px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.lens-head { display: flex; justify-content: space-between; align-items: center; font: 600 15px var(--serif); padding: 2px 6px 6px; color: var(--brass-hi); }
.lens-head.small { font-size: 13px; padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, 0.08); margin-top: 6px; }
.lens-group-h { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 6px 6px 2px; }
.lens { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 5px 8px; border-radius: 6px; font-size: 13px; }
.lens:hover { background: rgba(255, 255, 255, 0.06); }
.lens.on { background: rgba(217, 164, 65, 0.2); color: var(--brass-hi); box-shadow: inset 2px 0 0 var(--brass); }
.layer { display: flex; align-items: center; gap: 8px; padding: 3px 8px; font-size: 13px; cursor: pointer; }
.layer input { accent-color: var(--brass); }
#lens-card .x { display: none; }
.fab { display: none; }
#api-mobile { display: none; }

/* Legend */
#legend {
  position: fixed; z-index: 8; left: 14px; bottom: 34px; width: 300px; padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.legend-h { font: 600 14px var(--serif); margin-bottom: 8px; }
.legend-h .lvl { font: 500 10.5px var(--sans); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-left: 4px; }
.ramp { height: 10px; border-radius: 3px; }
.ticks { position: relative; height: 16px; font-size: 10.5px; color: var(--muted); margin: 3px 6px 0; }
.ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; font-size: 12px; }
.sw { display: flex; align-items: center; gap: 6px; }
.sw i { width: 12px; height: 12px; border-radius: 3px; flex: none; border: 1px solid rgba(0, 0, 0, 0.3); }
.sw i.hill { background: linear-gradient(180deg, transparent 40%, #7a6640 40%); clip-path: polygon(0 100%, 50% 20%, 100% 100%); border: 0; }
.sw i.mtn { background: #5f574d; clip-path: polygon(0 100%, 50% 0, 100% 100%); border: 0; }
.legend-blurb { margin: 6px 0 4px; font-size: 12px; color: var(--muted); }
.legend-src { font-size: 11px; color: var(--muted); margin-top: 6px; }
.cite { color: var(--muted); text-decoration: underline; text-decoration-color: rgba(169, 179, 177, 0.4); text-underline-offset: 2px; }
.cite:hover { color: var(--brass-hi); }

/* Zoom */
#zoom { position: fixed; z-index: 8; right: 14px; bottom: 34px; display: flex; flex-direction: column; gap: 6px; }
#zoom button { width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); font-size: 19px; line-height: 1; }
#zoom button:hover { background: var(--panel-solid); color: var(--brass-hi); }
body.panel-open #zoom { right: 400px; }

/* Panel */
#panel {
  position: fixed; z-index: 9; right: 14px; top: calc(var(--top) + 14px); bottom: 34px; width: 372px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  display: flex; flex-direction: column;
}
#panel-body { overflow: auto; padding: 16px 18px 20px; overscroll-behavior: contain; -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 24px), transparent); mask-image: linear-gradient(180deg, #000 calc(100% - 24px), transparent); }
.x { position: absolute; top: 8px; right: 10px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.06); font-size: 18px; line-height: 1; z-index: 2; }
.x:hover { background: rgba(255, 255, 255, 0.14); }
.kicker { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--brass-hi); display: flex; align-items: center; gap: 6px; padding-right: 30px; }
.kicker a { color: inherit; }
.pdot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; flex: none; }
#panel h2 { font: 600 24px/1.15 var(--serif); margin: 6px 0 2px; }
#panel h2 .muted { font-weight: 400; color: var(--muted); font-size: 18px; }
#panel h3 { font: 600 14px var(--serif); color: var(--brass-hi); margin: 18px 0 8px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.sub { color: var(--muted); font-size: 12.5px; }
.muted { color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 12px; }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.stat { background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 8px; padding: 7px 8px; min-width: 0; }
.stat-v { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-s { font-size: 11px; color: var(--muted); }
.src { font-size: 11px; color: var(--muted); margin-top: 8px; line-height: 1.5; }
.bar { display: grid; grid-template-columns: 116px 1fr 46px; align-items: center; gap: 8px; font-size: 12.5px; margin: 4px 0; }
.bar-t { height: 8px; background: rgba(255, 255, 255, 0.07); border-radius: 4px; overflow: hidden; }
.bar-t i { display: block; height: 100%; border-radius: 4px; }
.bar-v { text-align: right; font-variant-numeric: tabular-nums; }
.ages { display: flex; height: 12px; border-radius: 4px; overflow: hidden; }
.ages-l { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.ages-l b { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; }
.yrow { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.ychip { display: flex; flex-direction: column; align-items: center; padding: 7px 2px; border-radius: 8px; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.06); }
.ychip .ico { width: 18px; height: 18px; display: inline-flex; }
.ychip b { color: var(--text); font-size: 13px; margin-top: 2px; }
.ychip small { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.03em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; }
button.chip:hover { background: rgba(217, 164, 65, 0.15); }
.chip small { color: var(--muted); }
.rule { font-size: 12px; color: var(--muted); margin-top: 16px; padding: 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.03); }
.rule b { color: var(--text); font-weight: 600; }
.lensval { margin-top: 12px; padding: 9px 10px; border-radius: 8px; background: rgba(217, 164, 65, 0.1); border: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.lensval span { font-size: 12px; color: var(--brass-hi); }
.lensval b { font-size: 16px; }
.lensval small { grid-column: 1 / -1; font-size: 11px; color: var(--muted); }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 5px 0; border-bottom: 1px dashed rgba(255, 255, 255, 0.07); }
.kv span { color: var(--muted); }
.board { display: flex; flex-direction: column; gap: 2px; margin-top: 12px; }
.brow { display: grid; grid-template-columns: 22px 110px 1fr 64px; align-items: center; gap: 8px; border: 0; background: none; padding: 4px 4px; border-radius: 6px; text-align: left; font-size: 13px; }
.brow:hover { background: rgba(255, 255, 255, 0.06); }
.rank { color: var(--muted); font-size: 11px; text-align: right; }
.bn { display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; }
.bt { height: 8px; background: rgba(255, 255, 255, 0.06); border-radius: 4px; overflow: hidden; }
.bt i { display: block; height: 100%; background: linear-gradient(90deg, #b07a2a, var(--brass-hi)); }
.bv { text-align: right; font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: auto; display: block; margin-top: 4px; }
.spark .sx { fill: var(--muted); font-size: 10px; }
.spark .sp { fill: #cfe8a8; font-size: 10px; font-weight: 600; }
.chip.more { display: block; width: 100%; margin-top: 8px; text-align: center; color: var(--brass-hi); }
.ico.inline { width: 15px; height: 15px; display: inline-flex; }

/* Tooltip */
#tip { position: fixed; z-index: 12; pointer-events: none; padding: 7px 10px; border-radius: 8px; background: rgba(10, 18, 24, 0.94); border: 1px solid var(--line); font-size: 12.5px; max-width: 260px; }
.tip-h { font: 600 14px var(--serif); }

/* Modal */
#modal { position: fixed; inset: 0; z-index: 20; background: rgba(5, 10, 14, 0.6); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; }
#modal[hidden] { display: none; }
.modal-card { position: relative; width: min(820px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); }
#modal-body { overflow: auto; padding: 26px 30px 30px; }
#modal-body h2 { font: 600 28px/1.15 var(--serif); margin: 0 0 10px; padding-right: 30px; }
#modal-body h3 { font: 600 17px var(--serif); color: var(--brass-hi); margin: 22px 0 8px; }
.lede { font-size: 16px; }
.code { margin: 10px 0; border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 8px; overflow: hidden; }
.code-h { font-size: 12px; color: var(--muted); padding: 6px 10px; background: rgba(255, 255, 255, 0.04); }
.code pre { margin: 0; padding: 10px 12px; overflow-x: auto; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: #e8f0d8; background: #0b151c; }
.rules dt { font-weight: 600; text-transform: capitalize; margin-top: 8px; }
.rules dd { margin: 2px 0 0; color: var(--muted); }
.gaps li { margin: 6px 0; color: var(--muted); }
.gaps b { color: var(--text); }
.almanac article { padding: 12px 0; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.almanac h3 { margin: 0 0 4px !important; font-size: 15px !important; }
.almanac h3 a { color: var(--text); }
.almanac h3 code { color: var(--muted); font-weight: 400; margin-left: 6px; }
.almanac .meta { font-size: 12.5px; color: var(--muted); }
.almanac .lic { color: #d8c08a; }
.almanac .used, .almanac .orig { font-size: 13px; margin-top: 4px; }
.almanac .orig { color: var(--muted); font-size: 12px; }
.almanac .calls { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.almanac .calls code { background: #0b151c; padding: 3px 7px; border-radius: 5px; color: #cfe3b0; overflow-x: auto; white-space: nowrap; }

#credit { position: fixed; z-index: 7; bottom: 8px; left: 50%; transform: translateX(-50%); font-size: 11.5px; color: rgba(241, 233, 214, 0.75); text-shadow: 0 1px 3px #000; white-space: nowrap; }
#credit a { color: var(--brass-hi); }

/* Medium screens: fold the yields' labels */
@media (max-width: 1280px) {
  .yield .l { display: none; }
  .btn { padding: 6px 8px; }
}
@media (max-width: 1020px) {
  .api-pill span { display: none; }
}

/* Phone */
@media (max-width: 760px) {
  :root { --top: 96px; }
  #topbar { flex-wrap: wrap; gap: 6px 8px; padding: 8px 10px 6px; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand { flex: 1; }
  .emblem { width: 30px; height: 30px; }
  .brand h1 { font-size: 18px; }
  .brand .civ { color: var(--brass-hi); font-style: italic; }
.brand .tag { font-size: 11.5px; }
  #yields { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .yield { padding: 4px 7px; }
  .yield .v { font-size: 13px; }
  .actions { gap: 6px; }
  #btn-almanac { display: none; }
  .btn { font-size: 12px; padding: 5px 8px; }
  .api-pill { display: none; }
  #api-mobile { display: block; position: fixed; z-index: 9; top: calc(var(--top) + 8px); left: 50%; transform: translateX(-50%); white-space: nowrap; padding: 5px 12px; border-radius: 999px; font-size: 12px; text-decoration: none; color: #1a1205; background: linear-gradient(180deg, #f6dc94, #d9a441); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4); }
  body.panel-open #api-mobile, body.lens-open #api-mobile { display: none; }
  #lens-card { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 62vh; border-radius: 14px 14px 0 0; transform: translateY(105%); transition: transform 0.22s ease; z-index: 15; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  body.lens-open #lens-card { transform: none; }
  #lens-card .x { display: block; position: static; }
  #lens-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0 6px; }
  #layer-list { display: grid; grid-template-columns: 1fr 1fr; }
  .fab { display: inline-flex; gap: 6px; align-items: center; position: fixed; z-index: 9; left: 10px; bottom: calc(26px + env(safe-area-inset-bottom)); padding: 9px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-weight: 600; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4); }
  .fab .k { color: var(--brass-hi); font-weight: 500; }
  #legend { left: 10px; right: 10px; width: auto; bottom: calc(76px + env(safe-area-inset-bottom)); padding: 8px 10px; }
  #legend .legend-blurb, #legend .legend-src { display: none; }
  #legend.terrain { display: none; }
  #legend .legend-h { margin-bottom: 4px; font-size: 13px; }
  .swatches { grid-template-columns: 1fr 1fr 1fr; font-size: 11px; }
  #zoom { right: 10px; bottom: calc(26px + env(safe-area-inset-bottom)); flex-direction: row; }
  #zoom button { width: 36px; height: 36px; }
  body.panel-open #zoom { right: 10px; }
  #panel { left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 58vh; border-radius: 16px 16px 0 0; z-index: 14; padding-bottom: env(safe-area-inset-bottom); }
  body.panel-open #legend, body.panel-open .fab, body.panel-open #zoom { display: none; }
  .bar { grid-template-columns: 104px 1fr 44px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  #credit { bottom: 6px; font-size: 10.5px; left: 10px; right: 10px; transform: none; text-align: center; white-space: normal; display: none; }
  #modal { padding: 0; place-items: end stretch; }
  .modal-card { max-height: 92vh; border-radius: 16px 16px 0 0; }
  #modal-body { padding: 20px 18px 28px; }
  #modal-body h2 { font-size: 22px; }
}

.load-error { position: fixed; inset: 45% 0 auto; text-align: center; color: var(--text); font: 15px var(--sans); z-index: 30; }
