/* ============================================================
   VIZ.CSS — Inline Chapter Visualizations (Book 5)
   Extends fulltext.css · Dark theme · Gold accent
   ============================================================ */

/* ---- Base Container ---- */
.viz {
  margin: 2.4em 0;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.viz.viz-visible {
  opacity: 1;
  transform: none;
}

.viz-inner {
  background: var(--bg-card, #12121a);
  border: 1px solid var(--border, #2a2a36);
  border-radius: 8px;
  padding: 28px 24px 20px;
  position: relative;
  overflow: hidden;
}

/* subtle gold glow on left edge */
.viz-inner::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--accent-gold, #d4b255), transparent 80%);
  border-radius: 3px 0 0 3px;
}

/* ---- Header ---- */
.viz-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.viz-badge {
  font-family: var(--sans-en, 'Inter', sans-serif);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--bg-deep, #0a0a0f);
  background: var(--accent-gold, #d4b255);
  padding: 3px 8px;
  border-radius: 3px;
  line-height: 1.4;
}

.viz-title {
  font-family: var(--sans-kr, 'Pretendard Variable', sans-serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary, #e8e6e3);
  line-height: 1.4;
}

.viz-source {
  font-family: var(--sans-en, 'Inter', sans-serif);
  font-size: 11px;
  color: var(--text-muted, #c5c5c5);
  margin-top: 14px;
  opacity: 0.7;
  letter-spacing: 0.2px;
}

/* ---- Tier 3: Stat Grid ---- */
.viz-grid {
  display: grid;
  gap: 16px;
}

.viz-grid-2 { grid-template-columns: 1fr 1fr; }
.viz-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.viz-grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.viz-stat {
  text-align: center;
  padding: 12px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
}

.viz-num {
  font-family: var(--sans-en, 'Inter', sans-serif);
  font-size: 32px;
  font-weight: 700;
  color: var(--accent-gold, #d4b255);
  line-height: 1.1;
  display: inline-block;
}

.viz-unit {
  font-family: var(--sans-en, 'Inter', sans-serif);
  font-size: 16px;
  font-weight: 500;
  color: var(--accent-gold, #d4b255);
  opacity: 0.8;
}

.viz-label {
  display: block;
  font-family: var(--sans-kr, 'Pretendard Variable', sans-serif);
  font-size: 12px;
  color: var(--text-muted, #c5c5c5);
  margin-top: 6px;
  line-height: 1.5;
}

.viz-note {
  display: block;
  font-size: 11px;
  color: var(--text-muted, #c5c5c5);
  opacity: 0.6;
  margin-top: 2px;
}

/* Color variants for stats */
.viz-stat--gold .viz-num,
.viz-stat--gold .viz-unit { color: var(--accent-gold, #d4b255); }

.viz-stat--blue .viz-num,
.viz-stat--blue .viz-unit { color: #5b9bd5; }

.viz-stat--red .viz-num,
.viz-stat--red .viz-unit { color: #e06c60; }

.viz-stat--green .viz-num,
.viz-stat--green .viz-unit { color: #5bb57a; }

.viz-stat--muted .viz-num,
.viz-stat--muted .viz-unit { color: var(--text-muted, #c5c5c5); }

/* ---- Tier 2: Bar Charts ---- */
.viz-bar-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.viz-bar-row {
  display: grid;
  grid-template-columns: 100px 1fr 48px;
  align-items: center;
  gap: 10px;
}

.viz-bar-label {
  font-family: var(--sans-kr, 'Pretendard Variable', sans-serif);
  font-size: 13px;
  color: var(--text-secondary, #e8e6e3);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viz-bar-track {
  height: 20px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 4px;
  overflow: hidden;
}

.viz-bar-fill {
  height: 100%;
  border-radius: 4px;
  width: 0;
  transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
  background: var(--accent-gold, #d4b255);
}

.viz.viz-visible .viz-bar-fill {
  width: var(--bar-pct, 0%);
}

/* bar color variants */
.viz-bar-fill--gold { background: var(--accent-gold, #d4b255); }
.viz-bar-fill--blue { background: #5b9bd5; }
.viz-bar-fill--red { background: #e06c60; }
.viz-bar-fill--green { background: #5bb57a; }
.viz-bar-fill--dim { background: rgba(255, 255, 255, 0.12); }

.viz-bar-value {
  font-family: var(--sans-en, 'Inter', sans-serif);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #f0eeeb);
  text-align: right;
}

/* ---- Tier 2: Donut Charts (CSS conic-gradient) ---- */
.viz-donut-wrap {
  display: flex;
  align-items: center;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
}

.viz-donut-ring {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: conic-gradient(
    var(--c1, #d4b255) 0% calc(var(--seg1, 50) * 1%),
    var(--c2, #5b9bd5) calc(var(--seg1, 50) * 1%) calc((var(--seg1, 50) + var(--seg2, 30)) * 1%),
    var(--c3, #2a2a36) calc((var(--seg1, 50) + var(--seg2, 30)) * 1%) 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}

.viz-donut-center {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--bg-card, #12121a);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.viz-donut-big {
  font-family: var(--sans-en, 'Inter', sans-serif);
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-gold, #d4b255);
  line-height: 1;
}

.viz-donut-sub {
  font-family: var(--sans-kr, 'Pretendard Variable', sans-serif);
  font-size: 11px;
  color: var(--text-muted, #c5c5c5);
  margin-top: 4px;
}

.viz-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.viz-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans-kr, 'Pretendard Variable', sans-serif);
  font-size: 13px;
  color: var(--text-secondary, #e8e6e3);
}

.viz-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ---- Tier 2: Comparison / Arrow ---- */
.viz-compare {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.viz-compare-box {
  text-align: center;
  padding: 16px 20px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  min-width: 100px;
}

.viz-compare-box .viz-num { font-size: 28px; }

.viz-arrow {
  font-family: var(--sans-en, 'Inter', sans-serif);
  font-size: 22px;
  color: var(--accent-gold, #d4b255);
  flex-shrink: 0;
}

/* ---- Tier 2: Price Escalation ---- */
.viz-escalation {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 20px;
  padding: 8px 0;
}

.viz-esc-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.viz-esc-bar {
  width: 56px;
  border-radius: 4px 4px 0 0;
  background: var(--accent-gold, #d4b255);
  transition: height 0.8s cubic-bezier(0.22, 1, 0.36, 1);
  min-height: 4px;
}

.viz.viz-visible .viz-esc-bar { height: var(--esc-h, 40px); }
.viz:not(.viz-visible) .viz-esc-bar { height: 4px; }

.viz-esc-price {
  font-family: var(--sans-en, 'Inter', sans-serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-gold, #d4b255);
}

.viz-esc-name {
  font-family: var(--sans-kr, 'Pretendard Variable', sans-serif);
  font-size: 11px;
  color: var(--text-muted, #c5c5c5);
  text-align: center;
  max-width: 80px;
}

/* ---- Tier 2: Decline / Trend Line ---- */
.viz-trend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 0;
}

.viz-trend-point {
  text-align: center;
}

.viz-trend-year {
  font-family: var(--sans-en, 'Inter', sans-serif);
  font-size: 11px;
  color: var(--text-muted, #c5c5c5);
  display: block;
  margin-top: 4px;
}

.viz-trend-line {
  flex: 1;
  height: 2px;
  max-width: 80px;
  position: relative;
}

.viz-trend-line::after {
  content: '';
  position: absolute;
  right: -6px;
  top: -4px;
  border: 5px solid transparent;
  border-left-color: var(--accent-gold, #d4b255);
}

.viz-trend-line--down {
  background: linear-gradient(90deg, var(--accent-gold, #d4b255), #e06c60);
  transform: rotate(8deg);
}

.viz-trend-line--down::after { border-left-color: #e06c60; }

/* ---- Tier 1: Radar Chart ---- */
.viz-radar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.viz-radar-svg {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1;
}

.viz-radar-total {
  text-align: center;
}

.viz-radar-total .viz-num {
  font-size: 40px;
}

.viz-radar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: center;
  margin-top: 4px;
}

.viz-radar-legend-item {
  font-family: var(--sans-kr, 'Pretendard Variable', sans-serif);
  font-size: 12px;
  color: var(--text-secondary, #e8e6e3);
  display: flex;
  align-items: center;
  gap: 4px;
}

.viz-radar-legend-score {
  font-family: var(--sans-en, 'Inter', sans-serif);
  font-weight: 700;
  color: var(--accent-gold, #d4b255);
}

/* ---- Tier 1: Demographic Counter ---- */
.viz-counter-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.viz-counter-box {
  text-align: center;
  padding: 16px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border, #2a2a36);
  min-width: 120px;
  flex: 1;
  max-width: 180px;
}

.viz-counter-box .viz-num {
  font-size: 36px;
  font-variant-numeric: tabular-nums;
}

.viz-counter-box .viz-label {
  font-size: 12px;
}

.viz-counter-compare {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

.viz-counter-pill {
  font-family: var(--sans-kr, 'Pretendard Variable', sans-serif);
  font-size: 12px;
  color: var(--text-muted, #c5c5c5);
  padding: 4px 12px;
  border-radius: 12px;
  border: 1px solid var(--border, #2a2a36);
  white-space: nowrap;
}

.viz-counter-pill strong {
  color: var(--text-primary, #f0eeeb);
  font-weight: 600;
}

/* ---- Responsive ---- */
@media (max-width: 720px) {
  .viz-inner { padding: 22px 18px 16px; }
  .viz-grid-3 { grid-template-columns: 1fr 1fr; }
  .viz-grid-4 { grid-template-columns: 1fr 1fr; }
  .viz-num { font-size: 26px; }
  .viz-bar-row { grid-template-columns: 80px 1fr 40px; }
  .viz-donut-wrap { flex-direction: column; }
  .viz-donut-ring { width: 140px; height: 140px; }
  .viz-donut-center { width: 86px; height: 86px; }
  .viz-escalation { gap: 12px; }
  .viz-esc-bar { width: 44px; }
  .viz-compare { gap: 10px; }
  .viz-compare-box { min-width: 80px; padding: 12px 14px; }
  .viz-compare-box .viz-num { font-size: 22px; }
  .viz-radar-svg { max-width: 280px; }
  .viz-radar-total .viz-num { font-size: 32px; }
  .viz-counter-box .viz-num { font-size: 28px; }
}

@media (max-width: 560px) {
  .viz { margin: 1.8em 0; }
  .viz-inner { padding: 18px 14px 14px; }
  .viz-grid-2 { grid-template-columns: 1fr 1fr; }
  .viz-grid-3 { grid-template-columns: 1fr; }
  .viz-grid-4 { grid-template-columns: 1fr 1fr; }
  .viz-num { font-size: 24px; }
  .viz-title { font-size: 14px; }
  .viz-bar-row { grid-template-columns: 64px 1fr 36px; }
  .viz-bar-label { font-size: 12px; }
  .viz-escalation { flex-wrap: wrap; gap: 8px; }
  .viz-esc-bar { width: 40px; }
  .viz-radar-svg { max-width: 240px; }
  .viz-counter-row { flex-direction: column; align-items: center; }
  .viz-counter-box { max-width: 200px; width: 100%; }
}

/* ---- Print ---- */
@media print {
  .viz { opacity: 1; transform: none; break-inside: avoid; }
  .viz-inner { border-color: #ccc; }
  .viz-bar-fill { width: var(--bar-pct, 0%) !important; }
}
