/* VNciv shell. One type family, one spacing step, one tile size. Loaded after style.css. */

@import url("typography.css");

:root {
  --ink: #163038;
  --ink-dim: #5c7278;
  --gold: #e26d4a;
  --gold-bright: #9a3412;
  --panel: #f7f4ee;
  --panel-2: #fffdf8;
  --line: rgba(22, 48, 56, 0.12);
  --crimson: #12343a;
  --crimson-hi: #1c4a52;
  --crimson-lo: #0e282e;
  --baltic: #d5e4e6;
  --fw-1: 400;
  --fw-2: 700;
  --fw-3: 700;
  --gap: 8px;
  --tile: 64px;
  --target: 44px;
  --bottom-tool-height: 56px;
  --bottom-bar: calc(var(--bottom-tool-height) + 2 * var(--gap) + env(safe-area-inset-bottom));
  --kpi-height: 84px;
  --radius: 16px;
  --topbar-h: 64px;
  --rail-w: 248px;
  --score-h: 96px;
}

html, body.vnciv, body.vnciv button, body.vnciv input, body.vnciv kbd {
  font-family: var(--sans);
  line-height: var(--lh);
  font-size: var(--fs-2);
  font-weight: var(--fw-1);
  letter-spacing: 0;
}
body.vnciv { background: var(--baltic); color: var(--ink); }

#topbar {
  height: var(--topbar-h);
  left: 0; right: 0;
  display: flex; align-items: center; gap: var(--gap);
  padding: 0 16px 0 calc(var(--rail-w) + 16px);
  background: #12343a;
  color: #f4f7f2;
  border: none;
  box-shadow: none;
}
.brand { color: #f4f7f2; gap: 10px; }
.brand-words { line-height: var(--lh); }
.brand-text { font-size: var(--fs-4); font-weight: var(--fw-3); letter-spacing: -0.04em; color: #f4f7f2; text-shadow: none; line-height: var(--lh); }
.brand-tag { font-style: normal; font-size: var(--fs-1); font-weight: var(--fw-1); color: #f0b9a4; }
.lang-switch { margin-left: auto; border: none; border-radius: 999px; overflow: hidden; background: rgba(255,255,255,.08); }
.lang-switch a {
  min-width: 44px; min-height: 44px; display: grid; place-items: center;
  padding: 0 12px; color: #f4f7f2; background: transparent; font-weight: var(--fw-2); font-size: var(--fs-1);
}
.lang-switch a[aria-current="page"] { background: #f4f7f2; color: #12343a; }

#rail {
  position: fixed; z-index: 14;
  top: 0; left: 0; bottom: 0; width: var(--rail-w);
  display: flex; flex-direction: column; gap: var(--gap);
  padding: 12px;
  background: #12343a;
  color: #f4f7f2;
  overflow: hidden auto;
}
#rail .search { flex: none; width: 100%; min-width: 0; }
#rail .search { margin: 0; }
.search .search-ic {
  left: 12px; color: #b9d5d8;
}
.search #search-input {
  min-width: 0; height: var(--target); border-radius: 12px; border: 1px solid transparent;
  background: rgba(255,255,255,.10); color: #f4f7f2; font-size: var(--fs-2);
  padding: 0 12px 0 36px; box-shadow: none;
}
.search #search-input::placeholder { color: #c2d7d9; opacity: 1; }
.search #search-input:focus-visible { outline: 2px solid #a4d7da; outline-offset: -2px; }
.sr-item { min-height: var(--target); }
#lens-area {
  position: static; left: auto; right: auto; top: auto; bottom: auto;
  width: auto; display: flex; flex-direction: column; gap: var(--gap);
  pointer-events: auto; flex: none; min-height: 0;
}
.lens-dock, .lens-quick {
  display: flex; flex-direction: column; align-items: stretch; gap: var(--gap);
  background: transparent; border: none; box-shadow: none; padding: 0; width: 100%;
}
.lens-btn, #btn-lenses, .rail-tools .btn {
  height: var(--tile); width: 100%;
  display: grid; place-items: center; text-align: center;
  border-radius: 12px; border: none;
  background: rgba(255,255,255,.08); color: #f4f7f2;
  font-size: var(--fs-1); font-weight: var(--fw-2); line-height: 1.2;
  padding: 8px;
}
body.vnciv #rail :is(.lens-btn, .btn, .btn-ext):hover { background: rgba(255,255,255,.16); }
body.vnciv #rail .lens-btn.active:not(.res-toggle) { background: #a54127; color: #fff; }
body.vnciv #rail .lens-btn.res-toggle.active { background: #284d53; color: #f4f7f2; }
body.vnciv #rail :is(.lens-btn, .btn, .btn-ext)[aria-expanded="true"],
body.vnciv #rail :is(.btn, .btn-ext, .res-toggle)[aria-pressed="true"] { box-shadow: inset 0 0 0 2px #a4d7da; }
body.vnciv #rail :is(.lens-btn, .btn, .btn-ext):focus-visible {
  outline: 2px solid #fff; outline-offset: -3px;
}
.rail-tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); }
.rail-tools .btn { min-width: 0; }

#scorecard {
  position: fixed; z-index: 12;
  left: calc(var(--rail-w) + 16px); right: 16px; bottom: 16px;
  display: grid;
}
.kpi-row, #yields.yields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
  width: 100%;
}
.kpi, button.kpi {
  min-height: var(--kpi-height);
  display: grid; place-items: center; align-content: center; gap: 2px;
  text-align: center;
  background: #fffdf8; color: var(--ink);
  border: none; border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(18, 52, 58, 0.12);
  padding: 10px 8px; cursor: pointer;
}
.kpi-label { font-size: var(--fs-1); font-weight: var(--fw-2); color: var(--ink-dim); }
.kpi-value { font-size: var(--fs-4); font-weight: var(--fw-3); color: #12343a; letter-spacing: -0.03em; }
.kpi .caret, .kpi .ico { display: none; }

#legend.legend {
  position: fixed; z-index: 12;
  left: calc(var(--rail-w) + 16px); bottom: calc(16px + var(--kpi-height) + 16px);
  width: min(420px, calc(100vw - var(--rail-w) - 32px));
  background: #fffdf8; color: var(--ink);
  border: none; border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(18, 52, 58, 0.12);
}
.legend .title, .lg-head { color: #12343a; font-family: var(--sans); font-size: var(--fs-3); font-weight: var(--fw-3); }
.legend .desc, .lg-note, .lg-meta, .ticks { color: var(--ink-dim); font-size: var(--fs-1); }

#city-panel {
  top: var(--topbar-h); right: 0; bottom: 0; left: auto;
  width: min(420px, 100vw);
  border-radius: 0;
  background: #fffdf8; color: var(--ink);
  border: none; border-left: 1px solid var(--line);
  box-shadow: -16px 0 40px rgba(18, 52, 58, 0.12);
}
.cp-name { font-size: var(--fs-4); font-weight: var(--fw-3); color: #12343a; text-align: left; }
.cp-kind, .cp-section h3 { font-size: var(--fs-1); font-weight: var(--fw-2); letter-spacing: 0.04em; text-transform: uppercase; color: #e26d4a; }
.yield-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.yield-tile {
  min-height: 72px; display: grid; place-items: center; text-align: center;
  background: #f3efe6; border: none; border-radius: 12px; color: var(--ink);
}
.yield-tile .val { font-size: var(--fs-3); font-weight: var(--fw-3); }
.yield-tile .lbl, .yield-tile .rank { font-size: var(--fs-1); font-weight: var(--fw-1); color: var(--ink-dim); }
.stat-row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px var(--gap); align-items: center;
  min-height: var(--target); padding: var(--gap) 0; border-bottom: 1px solid var(--line); font-size: var(--fs-2);
}
.stat-value { display: flex; align-items: baseline; justify-content: space-between; gap: var(--gap); }
.stat-row .cmp { margin: 0; font-size: var(--fs-1); text-align: right; }
#city-panel .good { color: #367436 !important; }
#city-panel .bad { color: #a54127 !important; }
.stat-row .sl { min-width: 0; }
.stat-row .sl svg { flex: none; }
.stat-note { grid-column: 1 / -1; font-size: var(--fs-1); color: var(--ink-dim); }
.city-row { min-height: 44px; border-radius: 12px; background: #f3efe6; border: none; }

.panel { background: #fffdf8; color: var(--ink); border: none; border-radius: var(--radius); }
.tooltip { background: #12343a; color: #f4f7f2; border: none; border-radius: 12px; font-size: var(--fs-2); }
.tooltip b { color: #fff; font-family: var(--sans); }

#minimap-wrap { left: auto; right: 16px; bottom: calc(16px + var(--kpi-height) + 16px); background: #fffdf8; border-radius: 12px; }

#pedia .modal-card, .help-card, .yield-report {
  background: #fffdf8; color: var(--ink); border-radius: var(--radius);
}
#pedia-body, #pedia-nav, .yr-head h2, .yr-nm, .cp-name { font-family: var(--sans); color: #12343a; }
#loading { background: #12343a; color: #f4f7f2; font-family: var(--sans); }
#loading .ld-title { font-size: var(--fs-5); font-weight: var(--fw-3); color: #fff; }

@media (max-width: 1024px) {
  :root { --rail-w: 184px; --topbar-h: 56px; }
  .kpi-value { font-size: var(--fs-3); }
}
#lens-picker.lens-picker {
  position: fixed; z-index: 30;
  left: calc(var(--rail-w) + 12px); top: calc(var(--topbar-h) + 12px);
  width: min(560px, calc(100vw - var(--rail-w) - 24px));
  max-height: min(70vh, 640px);
  background: #fffdf8; color: var(--ink);
}
body.panel-open #scorecard { right: min(436px, 92vw); }
body.panel-open #legend.legend { display: none; }

/* Equal tiles, one type scale, docks clear of the rail. These beat style.css phone rules. */
body.vnciv, body.vnciv button, body.vnciv input, body.vnciv select, body.vnciv textarea {
  font-family: var(--sans);
}
body.vnciv .brand-tag { display: block; }
body.vnciv .brand-text { display: block; }
body.vnciv #yields.yields { display: grid; }
body.vnciv #lens-dock.panel,
body.vnciv .lens-dock,
body.vnciv .lens-quick {
  background: transparent;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: none;
  border-radius: 0;
}
body.vnciv #lens-area {
  position: static;
  left: auto; right: auto; top: auto; bottom: auto;
  container-type: normal;
  align-items: stretch;
  margin: 0;
  width: auto;
}
body.vnciv #rail .lens-btn {
  box-sizing: border-box;
  height: var(--tile);
  min-height: var(--target);
  width: 100%;
  margin: 0;
  white-space: normal;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  overflow: hidden;
  flex: none;
}
body.vnciv #rail .lens-btn span,
body.vnciv #rail .lens-more span,
body.vnciv #rail .res-toggle span,
body.vnciv #rail .map-layers-btn span {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-align: center;
  line-height: var(--lh);
  white-space: normal;
  font-size: var(--fs-1);
  font-weight: var(--fw-2);
}
body.vnciv #rail .lens-btn .caret { display: none; }
body.vnciv .rail-tools {
  grid-template-columns: 1fr 1fr;
}
@media (min-width: 769px) {
  body.vnciv #lens-dock {
    display: grid;
    grid-auto-rows: var(--tile);
    align-content: start;
    gap: var(--gap);
  }
  body.vnciv #lens-quick { display: contents; }
}
body.vnciv .rail-tools .btn,
body.vnciv .rail-tools .btn-ext {
  min-height: var(--target);
  height: var(--tile);
  width: 100%;
  min-width: 0;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: normal;
  gap: 2px;
  font-size: var(--fs-1);
  font-weight: var(--fw-2);
  background: rgba(255,255,255,.08);
  color: #f4f7f2;
  border: none;
  border-radius: 12px;
}
body.vnciv .rail-tools .btn .lbl,
body.vnciv .rail-tools .btn-ext .lbl { display: block; line-height: var(--lh); }
body.vnciv .app-dock.app-dock-left {
  left: calc(var(--rail-w) + 12px);
  top: calc(var(--topbar-h) + 12px);
  bottom: calc(var(--score-h) + 28px);
  width: min(420px, calc(100vw - var(--rail-w) - 48px));
  height: auto;
  border-radius: var(--radius);
  z-index: 16;
}
body.vnciv .app-dock .adv-root {
  --adv: #e26d4a;
  font-size: var(--fs-2);
  line-height: var(--lh);
  color: var(--ink);
}
body.vnciv .adv-head {
  background: #12343a;
  border-bottom: none;
  box-shadow: none;
  min-height: 56px;
}
body.vnciv .adv-tabs button { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
body.vnciv .adv-title,
body.vnciv .adv-title h2,
body.vnciv .adv-sec h3,
body.vnciv .adv-card b,
body.vnciv .adv-kind,
body.vnciv .adv-role,
body.vnciv .adv-kicker {
  font-family: var(--sans);
  font-style: normal;
  letter-spacing: 0;
  line-height: var(--lh);
  color: #12343a;
}
body.vnciv .adv-title h2 { font-size: var(--fs-4); font-weight: var(--fw-3); }
body.vnciv .adv-sec h3, body.vnciv .adv-card b { font-size: var(--fs-3); font-weight: var(--fw-3); }
body.vnciv .adv-tiles { align-items: stretch; }
body.vnciv .adv-tile {
  min-height: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #f3efe6;
  border: none;
  border-radius: 12px;
  color: var(--ink);
  font-size: var(--fs-1);
}
body.vnciv .adv-card { min-height: 64px; background: #f3efe6; border: none; border-radius: 12px; }
body.vnciv .lp-tiles { align-items: stretch; }
body.vnciv .lp-tile {
  min-height: var(--tile);
  height: var(--tile);
  text-align: center;
  align-items: center;
  background: #f3efe6;
  border: none;
  border-radius: 12px;
  color: var(--ink);
  font-size: var(--fs-1);
  font-weight: var(--fw-2);
}
body.vnciv .legend .lg-close,
body.vnciv .cp-close,
body.vnciv .icon-btn { min-width: 44px; min-height: 44px; width: 44px; height: 44px; }
body.vnciv .city-row { min-height: 48px; }
body.vnciv .yield-grid { align-items: stretch; }
body.vnciv .yield-tile { min-height: 88px; height: 88px; }

body.vnciv .lp-nm { white-space: normal; overflow-wrap: anywhere; }
body.vnciv .lp-tile.active { background: #a54127; color: #fff; }
body.vnciv :is(.ml-row, .lg-cat, .opt, #pedia-nav button, .sr-item) { min-height: var(--target); }
#map-layers-pop {
  position: fixed; z-index: 30; left: calc(var(--rail-w) + 12px);
  top: calc(var(--topbar-h) + 12px); width: min(280px, calc(100vw - 24px)); margin: 0;
}
.legend .lg-head { gap: var(--gap); }
.legend .ticks { height: 1.5em; }
.legend .lg-cats { gap: var(--gap); }
body.vnciv #rail :is(.lens-btn, .btn, .btn-ext) :is(svg, .emoji) { flex: none; }

@media (max-width: 768px) {
  :root { --topbar-h: 56px; --kpi-height: 64px; --score-h: calc(2 * var(--kpi-height) + var(--gap)); }
  body.vnciv .brand-text { font-size: var(--fs-3); }
  body.vnciv .brand-tag, #topbar .spacer { display: none; }
  #topbar {
    padding: env(safe-area-inset-top) max(var(--gap), env(safe-area-inset-right)) 0 max(var(--gap), env(safe-area-inset-left));
    height: calc(var(--topbar-h) + env(safe-area-inset-top));
    overflow: hidden;
  }
  #topbar .brand, #topbar .lang-switch { flex: none; }
  #topbar .search { order: 0; flex: 1 1 auto; margin: 0; min-width: 0; }
  #rail .search { display: none; }
  #rail {
    --tools-per-view: 4;
    top: auto; left: 0; right: 0; bottom: 0; width: auto;
    display: grid; grid-auto-flow: column;
    grid-auto-columns: calc((100% - (var(--tools-per-view) - 1) * var(--gap)) / var(--tools-per-view));
    align-items: center;
    padding: var(--gap) max(var(--gap), env(safe-area-inset-right))
      calc(var(--gap) + env(safe-area-inset-bottom)) max(var(--gap), env(safe-area-inset-left));
    scroll-padding-inline: max(var(--gap), env(safe-area-inset-left)) max(var(--gap), env(safe-area-inset-right));
    overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; overflow-anchor: none;
    scrollbar-width: none;
  }
  #rail[data-ready] { scroll-snap-type: x mandatory; }
  body.vnciv #rail :is(#lens-area, #lens-dock, #lens-quick, .rail-tools) { display: contents; }
  body.vnciv #rail :is(.lens-btn, .btn, .btn-ext) {
    width: 100%; height: var(--bottom-tool-height); min-width: var(--target);
    padding: 3px 4px; scroll-snap-align: start;
  }
  body.vnciv #rail .rail-tools :is(.btn, .btn-ext) .lbl { display: block; }
  #scorecard { left: var(--gap); right: var(--gap); bottom: var(--bottom-bar); }
  #yields.yields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body.vnciv.panel-open #scorecard, body.vnciv.dock-open #scorecard { display: none; }
  #legend.legend {
    left: var(--gap); right: var(--gap); width: auto; margin: 0;
    bottom: calc(var(--bottom-bar) + var(--score-h) + var(--gap));
    max-height: max(90px, calc(100dvh - var(--topbar-h) - env(safe-area-inset-top) - var(--bottom-bar) - var(--score-h) - 2 * var(--gap)));
    overflow: auto;
  }
  #legend .lg-note, #legend .desc { overflow-wrap: anywhere; }
  #lens-picker.lens-picker, #map-layers-pop {
    left: var(--gap); right: var(--gap); top: auto;
    bottom: var(--bottom-bar); width: auto; max-width: none; margin: 0;
  }
  body.vnciv #city-panel,
  body.vnciv .app-dock.app-dock-left {
    top: auto; left: 0; right: 0; bottom: var(--bottom-bar); width: auto; max-width: none;
    height: min(58dvh, 520px); z-index: 20;
    border-radius: 20px 20px 0 0; border-left: none;
  }
  #city-panel { padding-inline: env(safe-area-inset-left) env(safe-area-inset-right); }
  .sheet-grip { display: block; position: sticky; top: 0; z-index: 2; height: 18px; margin-bottom: -18px; touch-action: none; }
  .sheet-grip::before { content: ""; position: absolute; left: calc(50% - 22px); top: 6px; width: 44px; height: 4px; border-radius: 2px; background: var(--line); }
  .cp-head { padding-top: 18px; touch-action: none; }
  #city-panel .stat-row { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  #minimap-wrap, .minimap-toggle { display: none !important; }
}
@media (min-width: 600px) and (max-width: 768px) {
  #rail { --tools-per-view: 8; }
}

@media (min-width: 769px) and (max-height: 820px) {
  :root { --tile: 56px; }
}

.river-key {
  position: fixed; z-index: 13;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + var(--gap));
  right: max(var(--gap), env(safe-area-inset-right));
  width: min(340px, calc(100vw - 2 * var(--gap))); max-height: 45dvh; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(18, 52, 58, 0.15);
}
body:is(.panel-open, .dock-open) .river-key { display: none; }
.river-key summary { min-height: var(--target); padding: 12px; cursor: pointer; font-weight: 700; }
.river-key-body { padding: 0 12px 12px; }
.river-key-body h2 { margin: 0; font-size: var(--fs-3); }
.river-key-body h2 i {
  display: inline-block; width: 14px; height: 4px; border-radius: 2px;
  margin-right: var(--gap); vertical-align: middle; background: var(--river-color);
}
.river-key-body p { margin: var(--gap) 0; }
.river-key-body canvas { display: block; width: 100%; height: auto; background: #e8f0f1; border-radius: 8px; }
.river-key-body a { display: inline-grid; align-items: center; min-height: var(--target); }

@media (min-width: 769px) {
  .river-key { max-height: min(70dvh, calc(100dvh - var(--topbar-h) - var(--kpi-height) - 6 * var(--gap))); }
  body:has(.river-key[open]:not([hidden])) #minimap-wrap { visibility: hidden; }
}
