:root {
  color-scheme: light;
  /* SIB brand (sib.org.bz): burgundy, gold, teal on warm neutrals */
  --brand: #800020;
  --brand-dark: #5c0017;
  --brand-tint: #f6e2e6;
  --gold: #f6b143;
  --gold-2: #ffcc33;
  --teal: #01a79d;
  --coral: #dc4e41;
  --surface: #fffdfa;
  --surface-2: #f4f1ea;
  --line: #d9d6cc;
  --ink: #333333;
  --ink-2: #4d4d4d;
  --ink-3: #8a857b;
  --accent: var(--brand);
  --accent-ink: #ffffff;
  --sea: #dbe6ea;
  --land: #f4f1ea;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(60, 20, 30, .16);
  --font: 'Lato', -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-head: 'Raleway', 'Lato', "Segoe UI", Arial, sans-serif;
  --topbar-h: 62px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: var(--font); color: var(--ink); background: var(--sea); overflow: hidden; }
button { font: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.15; font-family: var(--font-head); font-weight: 700; }
h1 { font-size: clamp(36px, 5vw, 64px); letter-spacing: -.01em; }
h2 { font-size: 22px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--brand); margin-top: 1.3em; font-weight: 600; }
p { margin: 0 0 .8em; line-height: 1.45; }
.muted { color: var(--ink-2); }
.light { color: rgba(255,255,255,.85) !important; }
.kicker { font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); margin-bottom: .6em; font-family: var(--font-head); font-weight: 600; }
[hidden] { display: none !important; }

/* ---- top bar ---- */
#topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 30;
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: var(--brand); color: #fff; border-bottom: 4px solid var(--gold);
}
#screen-tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav-btn {
  border: 1px solid transparent; background: transparent; color: rgba(255,255,255,.85);
  padding: 10px 14px; border-radius: 10px; font-size: 15px; white-space: nowrap; min-height: 44px; font-family: var(--font-head); font-weight: 600;
}
.nav-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-btn.active { background: #fff; color: var(--brand); }
.help-btn, .lang-btn { border-color: rgba(255,255,255,.5); color: #fff; }
.help-btn:hover, .lang-btn:hover { background: var(--gold); color: var(--brand-dark); border-color: var(--gold); }
.sib-mark { display: inline-block; background: var(--gold); color: var(--brand-dark); font-weight: 800; padding: 2px 6px; border-radius: 6px; font-size: 13px; letter-spacing: .05em; margin-right: 4px; }
#search { font: inherit; min-height: 44px; width: 220px; padding: 8px 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.4); background: rgba(255,255,255,.14); color: #fff; }
#search::placeholder { color: rgba(255,255,255,.7); }
#search:focus { outline: 2px solid var(--gold); background: #fff; color: var(--ink); }

/* ---- map ---- */
#map { position: fixed; inset: var(--topbar-h) 0 0 0; }
.maplibregl-ctrl-attrib { display: none; }
.tooltip {
  position: fixed; z-index: 40; pointer-events: none; max-width: 290px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 10px 12px; font-size: 14px;
}
.tooltip strong { display: block; font-size: 15px; margin-bottom: 4px; font-family: var(--font-head); }
.tooltip .row { display: flex; justify-content: space-between; gap: 16px; }
.tooltip .row b { font-variant-numeric: tabular-nums; }

/* ---- home ---- */
.screen { position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 20; overflow: auto; }
#screen-home { background: var(--surface-2); }
.home-band { background: linear-gradient(135deg, var(--brand-dark) 0%, var(--brand) 60%, #a0203f 100%); color: #fff; padding: 46px 0 40px; text-align: center; border-bottom: 5px solid var(--gold); }
.home-band h1 { color: #fff; }
.home-inner { max-width: 1120px; margin: 0 auto; padding: 0 24px; text-align: center; }
.home-inner > .cards { margin-top: -26px; }
.lede { font-size: 18px; max-width: 780px; margin: 0 auto; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; text-align: left; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 20px; display: flex; flex-direction: column; gap: 8px; min-height: 170px; border-top: 4px solid var(--brand);
  box-shadow: 0 2px 10px rgba(60,20,30,.06); transition: transform .12s, box-shadow .12s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-top-color: var(--gold); }
.card strong { font-size: 19px; font-family: var(--font-head); color: var(--brand-dark); }
.card span:last-child { color: var(--ink-2); font-size: 14px; line-height: 1.4; }
.card-icon { font-size: 28px; color: var(--gold); line-height: 1; font-weight: 700; }
.fineprint { margin: 28px 0 40px; color: var(--ink-3); font-size: 14px; }

/* ---- side panel (collapsible) ---- */
.panel {
  position: fixed; top: calc(var(--topbar-h) + 14px); left: 14px; bottom: 14px; width: 370px; z-index: 25;
  background: rgba(255,253,250,.97); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: transform .25s ease;
}
.panel-scroll { position: absolute; inset: 0; overflow-y: auto; padding: 18px 18px 16px; }
.panel.collapsed { transform: translateX(calc(-100% - 14px)); }
.panel.collapsed .panel-scroll { visibility: hidden; }
.panel-toggle {
  position: absolute; top: 12px; right: -22px; width: 44px; height: 56px; border-radius: 0 12px 12px 0; border: 1px solid var(--line); border-left: 0;
  background: var(--brand); color: #fff; font-size: 16px; box-shadow: 4px 2px 10px rgba(60,20,30,.15); z-index: 1;
}
.panel.collapsed .panel-toggle { right: -58px; border-radius: 12px; border-left: 1px solid var(--line); width: 56px; }
.stories.collapsed { right: -460px; }
.stories-toggle {
  position: fixed; top: calc(var(--topbar-h) + 26px); right: 450px; width: 44px; height: 56px; z-index: 26;
  border-radius: 12px 0 0 12px; border: 1px solid var(--line); border-right: 0; background: var(--brand); color: #fff; font-size: 16px;
  box-shadow: -4px 2px 10px rgba(60,20,30,.15); transition: right .25s ease;
}
#stories.collapsed + .stories-toggle { right: 0; border-radius: 12px 0 0 12px; }
#stories[hidden] + .stories-toggle { display: none; }
.panel-head h2 { font-size: 20px; color: var(--brand-dark); }
.control { margin: 14px 0; }
.control label { display: block; font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; font-family: var(--font-head); font-weight: 600; }
.control select, .control input[type=range] { width: 100%; }
input[type=range] { accent-color: var(--brand); }
select { font: inherit; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: #fff; min-height: 44px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-height: 44px; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 10px; color: var(--ink-2); }
.seg button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.primary-btn { background: var(--brand); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 12px 18px; font-weight: 700; min-height: 44px; font-family: var(--font-head); }
.primary-btn:hover { background: var(--brand-dark); }
.gold-btn { background: var(--gold); color: var(--brand-dark); }
.gold-btn:hover { background: var(--gold-2); }
.ghost-btn { background: #fff; color: var(--ink-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-height: 44px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.tile { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; border-left: 3px solid var(--gold); }
.tile .v { font-size: 22px; font-weight: 700; letter-spacing: -.01em; color: var(--brand-dark); font-family: var(--font-head); }
.tile .l { font-size: 12px; color: var(--ink-3); }
.hero { font-size: 44px; font-weight: 700; letter-spacing: -.02em; line-height: 1; margin: 6px 0 2px; color: var(--brand); font-family: var(--font-head); }
.hero-l { color: var(--ink-3); font-size: 13px; margin-bottom: 10px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--font); fill: var(--ink-2); }
.chart .grid line { stroke: var(--line); }
.bar-list { list-style: none; padding: 0; margin: 8px 0; }
.bar-list li { display: grid; grid-template-columns: 120px 1fr 56px; align-items: center; gap: 8px; font-size: 13px; margin: 4px 0; }
.bar-list .bar { height: 10px; border-radius: 4px; background: var(--brand); }
.bar-list .n { text-align: right; font-variant-numeric: tabular-nums; }
.year-big { font-size: 40px; font-weight: 700; letter-spacing: -.02em; color: var(--brand); font-family: var(--font-head); }
.playrow { display: flex; gap: 8px; align-items: center; }
.small { font-size: 13px; color: var(--ink-3); }
.note { font-size: 13px; color: var(--ink-2); background: var(--brand-tint); border-radius: 10px; padding: 10px 12px; }
.legend-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.ctl3d { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.ctl3d button { min-height: 48px; border: 1px solid var(--line); background: #fff; border-radius: 10px; font-size: 14px; color: var(--ink-2); }
.ctl3d button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 12px; font-size: 13px; color: var(--ink-2); min-height: 38px; }
.chips button:hover, .chips button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.rank { list-style: none; padding: 0; margin: 6px 0; }
.rank li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; padding: 7px 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.rank li:hover { background: var(--surface-2); }
.rank .i { color: var(--gold); font-weight: 800; font-size: 13px; }
.rank .v { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--brand-dark); }
.rank .s { color: var(--ink-3); font-size: 12px; display: block; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 13px; }
table.cmp th { text-align: right; color: var(--ink-3); font-weight: 500; padding: 3px 0; }
table.cmp th:first-child { text-align: left; }
table.cmp td { padding: 3px 0; text-align: right; font-variant-numeric: tabular-nums; }
table.cmp td:first-child { text-align: left; }
table.cmp td.a { font-weight: 700; color: var(--brand-dark); }

/* ---- quiz ---- */
.quiz-q { font-size: 20px; font-family: var(--font-head); font-weight: 700; color: var(--brand-dark); margin: 6px 0 12px; line-height: 1.3; }
.quiz-opts { display: grid; gap: 8px; }
.quiz-opts button { text-align: left; min-height: 48px; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 14px; font-size: 15px; }
.quiz-opts button:hover { border-color: var(--brand); }
.quiz-opts button.correct { background: #e4f5ee; border-color: var(--teal); font-weight: 700; }
.quiz-opts button.wrong { background: #fbe6e3; border-color: var(--coral); }
.quiz-opts button:disabled { cursor: default; }
.guess-val { font-size: 40px; font-weight: 700; color: var(--brand); font-family: var(--font-head); text-align: center; margin: 6px 0; }
.quiz-result { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); font-size: 15px; }
.quiz-result.good { background: #e4f5ee; }
.quiz-result.bad { background: #fbe6e3; }
.score { display: flex; gap: 6px; margin: 8px 0 14px; }
.score span { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.score span.ok { background: var(--teal); border-color: var(--teal); color: #fff; }
.score span.ko { background: var(--coral); border-color: var(--coral); color: #fff; }
.score span.cur { border-color: var(--brand); }

/* ---- legend ---- */
.legend {
  position: fixed; right: 14px; bottom: 14px; z-index: 25; max-width: 320px;
  background: rgba(255,253,250,.97); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 13px;
  box-shadow: var(--shadow);
}
.legend .t { font-weight: 700; margin-bottom: 6px; font-family: var(--font-head); color: var(--brand-dark); }
.legend .ramp { height: 10px; border-radius: 5px; margin: 6px 0 4px; }
.legend .ends { display: flex; justify-content: space-between; color: var(--ink-3); }
.legend .cat { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.legend .nd { color: var(--ink-3); margin-top: 6px; }

/* ---- stories ---- */
.stories {
  position: fixed; top: var(--topbar-h); right: 0; bottom: 0; width: 450px; z-index: 25; overflow-y: auto;
  padding: 24px 22px 45vh; background: linear-gradient(90deg, rgba(255,253,250,0) 0, rgba(255,253,250,.94) 40px);
  scroll-behavior: smooth; transition: right .25s ease;
}
.step {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 20px 16px; border-top: 4px solid var(--line);
  margin: 0 0 40vh 0; box-shadow: 0 2px 10px rgba(60,20,30,.05); opacity: .55; transition: opacity .25s, transform .25s;
}
.step.active { opacity: 1; transform: translateX(-4px); box-shadow: var(--shadow); border-top-color: var(--gold); }
.step .n { font-size: 12px; color: var(--brand); text-transform: uppercase; letter-spacing: .1em; font-family: var(--font-head); font-weight: 600; }
.step h2 { font-size: 22px; margin: 4px 0 8px; color: var(--brand-dark); }
.step p { font-size: 15px; color: var(--ink-2); }
.step .hero { font-size: 40px; }
.step-nav { display: flex; gap: 8px; margin-top: 6px; }
.stories-intro { text-align: center; color: var(--ink-3); font-size: 13px; margin-bottom: 14px; }

/* ---- overlay ---- */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(60,10,20,.5); display: flex; align-items: center; justify-content: center; padding: 20px; }
.overlay-card { position: relative; background: var(--surface); border-radius: 18px; max-width: 640px; width: 100%; max-height: 90vh; overflow: auto; padding: 28px 30px 24px; box-shadow: var(--shadow); border-top: 6px solid var(--brand); }
.overlay-card ul { padding-left: 20px; line-height: 1.5; }
.close-btn { position: absolute; top: 12px; right: 12px; border: 0; background: var(--surface-2); width: 44px; height: 44px; border-radius: 50%; font-size: 24px; }

/* ---- hint / attract / loading ---- */
.hint { position: fixed; left: 50%; transform: translateX(-50%); bottom: 28px; z-index: 45; background: var(--brand-dark); color: #fff; padding: 12px 18px; border-radius: 999px; font-size: 15px; box-shadow: var(--shadow); }
.attract {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); z-index: 50;
  background: var(--gold); color: var(--brand-dark); font-size: 22px; font-weight: 700; padding: 18px 30px; border-radius: 999px; font-family: var(--font-head);
  box-shadow: var(--shadow); animation: pulse 2s ease-in-out infinite; pointer-events: none;
}
@keyframes pulse { 0%, 100% { transform: translateX(-50%) scale(1); } 50% { transform: translateX(-50%) scale(1.05); } }
.loading { position: fixed; inset: 0; z-index: 70; background: var(--brand); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; }
.spinner { width: 42px; height: 42px; border: 4px solid rgba(255,255,255,.3); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .panel { width: auto; left: 10px; right: 10px; top: auto; bottom: 10px; max-height: 46vh; }
  .panel.collapsed { transform: translateY(calc(100% + 10px)); }
  .panel-toggle { top: -22px; right: 12px; transform: rotate(-90deg); }
  .stories { width: 100%; background: none; padding-top: 40vh; }
  .stories.collapsed { right: -100%; }
  .stories-toggle { right: 0; }
  .legend { bottom: auto; top: calc(var(--topbar-h) + 10px); right: 10px; }
  .nav-btn span:not(.sib-mark) { display: none; }
  #search { width: 140px; }
}
