/* minimal dark UI */
:root{
  --bg:#0b0d12;
  --panel:#0f131a;
  --panel2:#0c1016;
  --border:rgba(255,255,255,.08);
  --text:rgba(255,255,255,.92);
  --muted:rgba(255,255,255,.65);
  --muted2:rgba(255,255,255,.45);
  --accent:#5aa2ff;
  --accent2:#ff6b57;
  --hi:#e7d37c;
  --growth-neg:#ff7b6b;
  --growth-zero:#2b323c;
  --growth-pos:#86e7b0;
  --shadow: 0 18px 60px rgba(0,0,0,.45);
  --radius: 16px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

*{box-sizing:border-box}
html, body{
  height:100%;
  overflow:hidden;
}
body{
  margin:0;
  background: radial-gradient(1000px 500px at 20% -10%, rgba(90,162,255,.10), transparent 60%),
              radial-gradient(900px 600px at 80% -10%, rgba(255,107,87,.10), transparent 60%),
              var(--bg);
  color:var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  display:flex;
  flex-direction:column;
  overflow:hidden;
}

.topbar{
  display:flex;
  justify-content:space-between;
  gap:16px;
  padding:16px 24px;
  border-bottom:1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent);
}

.brand .title{font-size:20px;font-weight:800;letter-spacing:.2px}
.brand .subtitle{font-size:13px;color:var(--muted);margin-top:2px}

.controls{
  display:flex;
  gap:10px;
  align-items:flex-end;
  flex-wrap:wrap;
}
.field{display:flex;flex-direction:column;gap:6px}
.label{font-size:12px;color:var(--muted)}
input,select{
  height:38px;
  padding:0 10px;
  border-radius:12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.03);
  color:var(--text);
  outline:none;
  min-width:120px;
}
select{min-width:170px}
select{background: rgba(255,255,255,.12); color:#fff}
select option{background:#fff;color:#111}
.segmented{
  display:flex;
  gap:6px;
  background: rgba(255,255,255,.06);
  border:1px solid var(--border);
  border-radius:12px;
  padding:4px;
  min-width:0;
}
.segBtn{
  flex:1;
  height:30px;
  padding:0 8px;
  border-radius:9px;
  border:1px solid transparent;
  background: transparent;
  color:var(--muted);
  cursor:pointer;
  font-size:12px;
  font-weight:600;
}
.segBtn.is-active{
  background: rgba(255,255,255,.14);
  color:var(--text);
  border-color: rgba(255,255,255,.18);
}
.segBtn:hover{color:var(--text)}

.controls .field{
  min-width:0;
}
.controls .field:has(.segmented){
  flex:1 1 220px;
}
.controls .field:has(input){
  flex:1 1 160px;
}
.controls .field:has(select){
  flex:0 1 140px;
}
.controls .field:has(#topN){
  flex:0 1 110px;
}
.growthLegend{
  display:flex;
  align-items:center;
  gap:8px;
  padding:4px 10px;
  height:38px;
  border-radius:12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
}
.growthLegend.is-hidden{display:none}
.legendBar{
  width:120px;
  height:10px;
  border-radius:6px;
  background: linear-gradient(90deg, var(--growth-neg), var(--growth-zero), var(--growth-pos));
  position:relative;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.legendMid{
  position:absolute;
  left:50%;
  top:50%;
  transform:translate(-50%, -50%);
  font-size:10px;
  color:var(--muted);
  background: rgba(0,0,0,.45);
  padding:1px 4px;
  border-radius:6px;
}
.legendLabel{
  font-size:11px;
  color:var(--muted);
  font-family: var(--mono);
}

.btn{
  height:38px;
  padding:0 14px;
  border-radius:12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color:var(--text);
  cursor:pointer;
}
.btn:hover{background: rgba(255,255,255,.06)}

.layout{
  display:grid;
  grid-template-columns: 1fr 360px;
  gap:14px;
  padding:14px;
  flex:1 1 auto;
  min-height:0;
  min-width:0;
  overflow:hidden;
}

.canvas{
  background: rgba(255,255,255,.02);
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
  display:flex;
  flex-direction:column;
  min-width:0;
}

.grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:12px;
  padding:12px;
  flex:1 1 auto;
  min-height: 0;
  min-width:0;
}

.card{
  background: rgba(255,255,255,.02);
  border:1px solid var(--border);
  border-radius: 14px;
  overflow:hidden;
  display:flex;
  flex-direction:column;
  min-height:0;
  position:relative;
}
.card::before{
  content:"";
  position:absolute;
  inset:0;
  background-size:cover;
  background-position:center;
  opacity:.14;
  filter: saturate(.8) blur(1.5px) brightness(.9);
  z-index:0;
}
.card > *{
  position:relative;
  z-index:1;
}

.cardHeader{
  padding:12px 12px 10px 12px;
  border-bottom:1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent);
}
.cardTitle{font-size:16px;font-weight:800}
.cardHint{font-size:12px;color:var(--muted2);margin-top:2px}

.treemap{
  width:100%;
  flex:1 1 auto;
  min-height:0;
  display:block;
}

.footerNote{
  padding:10px 12px 12px 12px;
  color:var(--muted2);
  border-top:1px solid var(--border);
  font-size:12px;
}

.side{
  display:flex;
  flex-direction:column;
  gap:12px;
  min-height:0;
  min-width:0;
}

.panel{
  background: rgba(255,255,255,.02);
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}
.panelTitle{
  padding:12px 12px 10px 12px;
  border-bottom:1px solid var(--border);
  font-weight:800;
}
.panelBody{padding:12px}
.subtle{color:var(--muted)}

.legendRow{display:flex;align-items:center;gap:10px;margin:8px 0;color:var(--muted)}
.swatch{width:12px;height:12px;border-radius:4px;display:inline-block}
.swatch.usa{background: rgba(90,162,255,.7)}
.swatch.chn{background: rgba(255,107,87,.7)}
.swatch.hi{background: rgba(231,211,124,.9)}
.swatch.flag{background: rgba(255,255,255,.35)}

.subSectionTitle{
  margin-top:10px;
  font-size:12px;
  font-weight:700;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.08em;
}
.newsItem{
  margin-top:6px;
  font-size:12px;
  line-height:1.35;
}
.newsItem a{
  color:var(--text);
  text-decoration:none;
}
.newsItem a:hover{
  text-decoration:underline;
}

.tooltip{
  position:fixed;
  z-index:10;
  background: rgba(10,12,16,.95);
  border:1px solid rgba(255,255,255,.10);
  border-radius: 12px;
  padding:10px 10px;
  box-shadow: var(--shadow);
  pointer-events:none;
  max-width: 320px;
}
.tooltip .t1{font-weight:800;margin-bottom:4px}
.tooltip .t2{font-family: var(--mono); color: var(--muted); font-size:12px; line-height:1.35}
.kv{display:flex;justify-content:space-between;gap:12px}
.kv span{color:var(--muted);font-size:12px}
.kv b{color:var(--text);font-family: var(--mono); font-size:12px}

.tile.is-dim rect{opacity:.25}
.tile.is-hi rect{stroke: rgba(231,211,124,.95); stroke-width: 2; opacity: .95}
.tile.is-hi .tileLabel{fill: rgba(231,211,124,.98)}
.tile.is-hi .tileValue{fill: rgba(231,211,124,.78)}

@media (max-width: 900px){
  .card::before{opacity:.08;}
}

/* Flag image tint/outline */
.flagImg{
  opacity: .9;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.35));
}
