:root {
  --ink: #172026;
  --muted: #62717b;
  --line: #d8e1e3;
  --paper: #f7f7f2;
  --panel: #ffffff;
  --green: #3f8d6b;
  --blue: #3c6da8;
  --amber: #c99135;
  --red: #bd5c55;
  --violet: #695c9c;
  --teal: #2e8f95;
  --shadow: 0 20px 60px rgba(23, 32, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(63, 141, 107, 0.07), transparent 28%),
    linear-gradient(180deg, #f5f3ea, #eef4f2 55%, #f7f7f2);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 330px) minmax(520px, 1fr) minmax(300px, 360px);
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
}

.left-panel,
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.brand-block,
.controls-panel,
.ranking-panel,
.story-panel,
.metric-panel,
.drivers-panel,
.chart-panel,
.map-stage {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(216, 225, 227, 0.9);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(23, 32, 38, 0.07);
}

.brand-block {
  padding: 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: 1.75rem;
  line-height: 1.05;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

.subhead,
.story-copy {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.controls-panel,
.ranking-panel,
.story-panel,
.drivers-panel,
.chart-panel {
  padding: 16px;
}

.control-row {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.control-row label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
}

.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toggle-grid label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  color: #35434b;
  font-size: 0.86rem;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.8rem;
}

.ranking-list {
  display: grid;
  gap: 8px;
}

.rank-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px;
  background: #f8faf8;
  cursor: pointer;
}

.rank-item:hover,
.rank-item.active {
  border-color: rgba(63, 141, 107, 0.45);
  background: #eef7f1;
}

.rank-badge {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #fff;
  background: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
}

.rank-name {
  font-weight: 800;
  line-height: 1.15;
}

.rank-meta {
  color: var(--muted);
  font-size: 0.76rem;
}

.rank-score {
  color: var(--ink);
  font-weight: 850;
}

.map-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.map-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.map-topbar h2 {
  max-width: 760px;
  font-size: 1.15rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: 160px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.76rem;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.map-wrap {
  position: relative;
  flex: 1;
  min-height: 640px;
  background:
    linear-gradient(rgba(23, 32, 38, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 32, 38, 0.045) 1px, transparent 1px),
    #edf3ee;
  background-size: 34px 34px;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 640px;
  display: block;
}

.map-status {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 2;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}

.map-marker {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid #fff;
  border-radius: 50%;
  color: #fff;
  box-shadow: 0 6px 18px rgba(23, 32, 38, 0.28);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 900;
}

.project-marker {
  background: var(--violet);
}

.project-marker.medium {
  width: 21px;
  height: 21px;
  background: var(--blue);
}

.risk-marker {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--red);
}

.mapboxgl-popup-content {
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  font: 0.82rem Inter, ui-sans-serif, system-ui, sans-serif;
  line-height: 1.4;
}

.mapboxgl-popup-content strong,
.mapboxgl-popup-content span {
  display: block;
}

.metric-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  overflow: hidden;
  background: var(--line);
}

.metric {
  min-height: 86px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.92);
}

.metric span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}

.metric strong {
  font-size: 1.05rem;
}

ul {
  margin: 0;
  padding-left: 18px;
}

li {
  margin-bottom: 8px;
  color: #31414a;
  line-height: 1.35;
}

.risk-copy li::marker {
  color: var(--red);
}

.price-chart {
  display: grid;
  align-items: end;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  height: 170px;
  padding-top: 8px;
}

.bar-wrap {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 6px;
  min-width: 0;
  height: 100%;
}

.bar {
  align-self: end;
  width: 100%;
  min-height: 4px;
  border-radius: 5px 5px 0 0;
  background: linear-gradient(180deg, var(--green), var(--blue));
}

.bar-label {
  color: var(--muted);
  font-size: 0.68rem;
  text-align: center;
}

.tooltip {
  position: fixed;
  z-index: 10;
  max-width: 280px;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 0.82rem;
}

.tooltip strong {
  display: block;
  margin-bottom: 4px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 300px 1fr;
  }

  .right-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
  }

  .metric-panel {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px 10px 96px;
  }

  .right-panel {
    display: flex;
  }

  .map-topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 14px;
  }

  .legend {
    justify-content: flex-start;
  }

  .map-wrap,
  #map {
    min-height: 60vh;
  }

  /* Larger touch targets */
  select { min-height: 44px; font-size: 1rem; }
  .toggle-grid label { min-height: 44px; font-size: 0.95rem; }
  .toggle-grid input[type="checkbox"] { width: 18px; height: 18px; }
  .rank-item { min-height: 56px; padding: 10px; }

  .brand-block { padding: 14px 16px; }
  h1 { font-size: 1.25rem; margin-bottom: 6px; }
  .subhead { font-size: 0.85rem; }
}

/* Mobile tabbed mode */
body.m-mode .app-shell {
  display: flex;
  flex-direction: column;
}
body.m-mode .left-panel { order: 2; }
body.m-mode .map-stage { order: 1; }
body.m-mode .right-panel { order: 3; display: flex; flex-direction: column; gap: 10px; }

body.m-mode[data-m-tab="map"] .left-panel,
body.m-mode[data-m-tab="map"] .right-panel { display: none; }

body.m-mode[data-m-tab="controls"] .map-stage,
body.m-mode[data-m-tab="controls"] .ranking-panel,
body.m-mode[data-m-tab="controls"] .right-panel { display: none; }
body.m-mode[data-m-tab="controls"] .brand-block { display: none; }

body.m-mode[data-m-tab="ranking"] .map-stage,
body.m-mode[data-m-tab="ranking"] .controls-panel,
body.m-mode[data-m-tab="ranking"] .right-panel { display: none; }
body.m-mode[data-m-tab="ranking"] .brand-block { display: none; }

body.m-mode[data-m-tab="details"] .map-stage,
body.m-mode[data-m-tab="details"] .left-panel { display: none; }

body.m-mode .map-wrap,
body.m-mode #map { min-height: calc(100vh - 160px); }

.m-tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.98);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(23, 32, 38, 0.08);
}
.m-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
  min-height: 48px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.m-tab.active {
  background: var(--green);
  color: #fff;
}
.m-tab.pulse {
  animation: mTabPulse 0.6s ease 2;
  color: var(--green);
}
@keyframes mTabPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

