:root {
  --navy: #17324d;
  --blue: #2e6fdb;
  --teal: #129b8d;
  --violet: #7868d8;
  --amber: #e5a93d;
  --red: #c64747;
  --text: #243746;
  --muted: #657786;
  --panel: rgba(250, 253, 255, .88);
  --line: rgba(66, 102, 126, .16);
  --shadow: 0 18px 50px rgba(39, 72, 94, .13), 0 2px 8px rgba(39, 72, 94, .06);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: var(--text);
  background: #dfedf3;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid rgba(46, 111, 219, .32); outline-offset: 3px; }
#app, #scene-container { position: fixed; inset: 0; }
#scene-container canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#scene-container canvas:active { cursor: grabbing; }
.atmosphere {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(circle at 52% 38%, transparent 30%, rgba(62, 99, 118, .06) 100%), linear-gradient(180deg, rgba(255,255,255,.18), transparent 28%, rgba(26,62,80,.05));
}

.topbar {
  position: fixed; z-index: 10; top: 0; left: 0; right: 0; height: 86px;
  display: flex; align-items: center; justify-content: space-between; padding: 18px 26px;
  background: linear-gradient(180deg, rgba(239,248,251,.94), rgba(239,248,251,.56) 65%, transparent);
  pointer-events: none;
}
.brand, .top-actions { pointer-events: auto; }
.eyebrow, .panel-kicker { display: block; color: var(--blue); font-size: 10px; line-height: 1.2; font-weight: 760; letter-spacing: .18em; }
.brand h1 { margin: 4px 0 0; color: var(--navy); font-size: 23px; line-height: 1; letter-spacing: -.03em; }
.brand h1 span { color: var(--teal); font-size: 13px; font-weight: 700; letter-spacing: .06em; vertical-align: middle; margin-left: 5px; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.live-pill {
  display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  border: 1px solid rgba(18,155,141,.22); border-radius: 20px; background: rgba(255,255,255,.74);
  color: var(--navy); font-size: 12px; font-weight: 650; backdrop-filter: blur(14px);
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 4px rgba(18,155,141,.12); }
.text-button, .view-switcher button, .transport button {
  border: 1px solid var(--line); background: rgba(255,255,255,.82); border-radius: 9px; cursor: pointer;
  transition: background .2s, border-color .2s, transform .2s, color .2s;
}
.text-button { height: 36px; padding: 0 14px; font-size: 12px; font-weight: 650; }
.text-button:hover, .view-switcher button:hover, .transport button:hover { background: #fff; border-color: rgba(46,111,219,.4); transform: translateY(-1px); }
.text-button[aria-pressed="false"] { color: var(--muted); background: rgba(255,255,255,.5); }
#metrics-button { display: none; }

.panel {
  position: fixed; z-index: 8; border: 1px solid rgba(255,255,255,.78); border-radius: 18px;
  background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(22px) saturate(1.15);
}
.narrative-panel { left: 24px; top: 102px; width: 336px; padding: 21px; max-height: calc(100vh - 286px); overflow-y: auto; scrollbar-width: thin; }
.quarter-heading { display: flex; align-items: center; gap: 14px; margin: 14px 0 15px; }
.quarter-number { color: var(--navy); font-size: 52px; line-height: .95; font-weight: 260; letter-spacing: -.06em; font-variant-numeric: tabular-nums; }
.quarter-heading h2, .panel-heading h2 { margin: 0; color: var(--navy); font-size: 18px; letter-spacing: -.02em; }
.quarter-heading p { margin: 5px 0 0; color: var(--teal); font-size: 12px; font-weight: 650; }
.news { margin: 0 0 13px; color: #415666; font-size: 12px; line-height: 1.72; }
.consensus { padding: 11px 12px; border-left: 3px solid var(--amber); border-radius: 0 9px 9px 0; background: rgba(229,169,61,.09); }
.consensus span { color: #926d27; font-size: 10px; font-weight: 750; letter-spacing: .08em; }
.consensus p { margin: 4px 0 0; color: #5d5140; font-size: 11px; line-height: 1.55; }
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 15px; }
.kpi-card { position: relative; min-height: 79px; padding: 11px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,.6); overflow: hidden; }
.kpi-card::after { content: ""; position: absolute; left: 0; bottom: 0; width: 100%; height: 2px; background: linear-gradient(90deg, var(--blue), transparent); opacity: .65; }
.kpi-card span { display: block; color: var(--muted); font-size: 10px; }
.kpi-card strong { display: block; margin-top: 6px; color: var(--navy); font-size: 20px; line-height: 1; font-weight: 680; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kpi-card strong.negative { color: var(--red); }
.kpi-card small { display: block; margin-top: 6px; color: #82919c; font-size: 9px; }
.decision-details { margin-top: 13px; border-top: 1px solid var(--line); padding-top: 10px; }
.decision-details summary { color: var(--blue); font-size: 11px; font-weight: 650; cursor: pointer; }
.decision-details p { margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.7; }

.factory-panel { right: 24px; top: 102px; width: 306px; padding: 20px; max-height: calc(100vh - 286px); overflow-y: auto; scrollbar-width: thin; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.panel-heading h2 { margin-top: 5px; font-size: 17px; }
.qualification-badge { padding: 5px 8px; border-radius: 7px; background: rgba(229,169,61,.14); color: #8b672a; font-size: 9px; font-weight: 750; white-space: nowrap; }
.qualification-badge.qualified { background: rgba(120,104,216,.13); color: #6251bd; }
.metric-list { margin-top: 15px; }
.metric-row { padding: 10px 0 9px; border-bottom: 1px solid var(--line); }
.metric-copy { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.metric-copy span { color: var(--muted); font-size: 11px; }
.metric-copy strong { color: var(--navy); font-size: 16px; font-weight: 680; font-variant-numeric: tabular-nums; }
.metric-bar { height: 4px; margin-top: 7px; border-radius: 3px; background: #e5edf1; overflow: hidden; }
.metric-bar i { display: block; width: 0; height: 100%; border-radius: inherit; transition: width .55s cubic-bezier(.2,.75,.25,1); }
.bar-blue { background: var(--blue); }.bar-amber { background: var(--amber); }.bar-violet { background: var(--violet); }.bar-teal { background: var(--teal); }.bar-red { background: var(--red); }
.metric-row small { display: block; margin-top: 5px; color: #82919c; font-size: 9px; }
.capacity-strip { display: flex; align-items: baseline; gap: 8px; margin-top: 12px; padding: 11px 12px; border-radius: 10px; background: var(--navy); color: #fff; }
.capacity-strip span { font-size: 10px; opacity: .72; }
.capacity-strip strong { margin-left: auto; font-size: 20px; font-weight: 650; }
.capacity-strip small { font-size: 9px; opacity: .65; }
.spark-wrap { margin-top: 15px; }
.spark-heading { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.spark-heading strong { color: var(--teal); font-size: 12px; }
#equity-spark { display: block; width: 100%; height: 76px; margin-top: 6px; overflow: visible; }
.spark-full { fill: none; stroke: #cfdae1; stroke-width: 1.5; stroke-dasharray: 3 4; }
.spark-area { fill: url(#spark-fill); stroke: none; }
.spark-current { fill: none; stroke: var(--teal); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.spark-dot { fill: #fff; stroke: var(--teal); stroke-width: 2.5; }
.spark-axis { display: flex; justify-content: space-between; color: #94a2ac; font-size: 8px; }
.zone-legend { display: flex; flex-wrap: wrap; gap: 9px 13px; margin-top: 13px; color: var(--muted); font-size: 9px; }
.zone-legend span { display: flex; align-items: center; gap: 5px; }
.zone-legend i { width: 6px; height: 6px; border-radius: 50%; }
.legend-blue { background: var(--blue); }.legend-violet { background: var(--violet); }.legend-amber { background: var(--amber); }.legend-gold { background: #d9a82e; }

.view-switcher {
  position: fixed; z-index: 9; left: 50%; bottom: 151px; transform: translateX(-50%); display: flex; gap: 4px;
  padding: 5px; border: 1px solid rgba(255,255,255,.72); border-radius: 13px; background: rgba(248,252,254,.8); box-shadow: 0 8px 28px rgba(39,72,94,.1); backdrop-filter: blur(16px);
}
.view-switcher button { padding: 8px 12px; border-color: transparent; background: transparent; color: var(--muted); font-size: 11px; white-space: nowrap; }
.view-switcher button.active { background: var(--navy); color: #fff; box-shadow: 0 4px 12px rgba(23,50,77,.18); }

.timeline-panel {
  position: fixed; z-index: 10; left: 24px; right: 24px; bottom: 29px; min-height: 104px;
  display: grid; grid-template-columns: 300px 1fr 300px; align-items: center; gap: 24px; padding: 17px 22px;
  border: 1px solid rgba(255,255,255,.8); border-radius: 18px; background: rgba(250,253,255,.92); box-shadow: var(--shadow); backdrop-filter: blur(22px);
}
.transport { display: flex; align-items: center; gap: 7px; }
.transport button { height: 38px; padding: 0 12px; color: var(--muted); font-size: 11px; }
.transport .play-button { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 86px; background: var(--navy); color: #fff; border-color: var(--navy); }
.transport .play-button:hover { background: #244763; }
.play-icon { width: 0; height: 0; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 8px solid currentColor; }
.play-button.playing .play-icon { width: 8px; height: 10px; border: 0; border-left: 3px solid currentColor; border-right: 3px solid currentColor; }
.timeline-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.timeline-meta strong { color: var(--navy); font-size: 11px; font-variant-numeric: tabular-nums; }
#quarter-slider { --progress: 0%; width: 100%; height: 22px; margin: 8px 0 0; appearance: none; background: transparent; cursor: pointer; }
#quarter-slider::-webkit-slider-runnable-track { height: 5px; border-radius: 4px; background: linear-gradient(90deg, var(--teal) var(--progress), #dce6eb var(--progress)); }
#quarter-slider::-moz-range-track { height: 5px; border-radius: 4px; background: #dce6eb; }
#quarter-slider::-moz-range-progress { height: 5px; border-radius: 4px; background: var(--teal); }
#quarter-slider::-webkit-slider-thumb { width: 17px; height: 17px; margin-top: -6px; appearance: none; border: 4px solid #fff; border-radius: 50%; background: var(--teal); box-shadow: 0 1px 7px rgba(18,155,141,.45); }
#quarter-slider::-moz-range-thumb { width: 11px; height: 11px; border: 4px solid #fff; border-radius: 50%; background: var(--teal); box-shadow: 0 1px 7px rgba(18,155,141,.45); }
.timeline-ticks { display: flex; justify-content: space-between; color: #8b9aa5; font-size: 8px; }
.timeline-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.timeline-stats div { padding-left: 13px; border-left: 2px solid rgba(46,111,219,.2); }
.timeline-stats span { display: block; color: var(--muted); font-size: 9px; }
.timeline-stats strong { display: block; margin-top: 5px; color: var(--navy); font-size: 16px; font-weight: 680; font-variant-numeric: tabular-nums; }
.timeline-stats strong::after { content: "B$"; margin-left: 4px; color: #8b9aa5; font-size: 8px; font-weight: 500; }

.source-note { position: fixed; z-index: 5; left: 28px; bottom: 9px; color: rgba(38,65,80,.62); font-size: 8px; letter-spacing: .02em; }
.keyboard-hint { position: fixed; z-index: 5; right: 28px; bottom: 9px; color: rgba(38,65,80,.55); font-size: 8px; }
.zone-tooltip { position: fixed; z-index: 20; display: none; max-width: 260px; padding: 9px 11px; border: 1px solid rgba(255,255,255,.8); border-radius: 9px; background: rgba(23,50,77,.9); color: #fff; box-shadow: 0 8px 20px rgba(23,50,77,.2); pointer-events: none; font-size: 10px; line-height: 1.5; backdrop-filter: blur(10px); }
.zone-tooltip strong { display: block; margin-bottom: 2px; color: #9fe3da; font-size: 11px; }

#loading-screen { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #e8f3f7; transition: opacity .55s, visibility .55s; }
#loading-screen.loaded { opacity: 0; visibility: hidden; pointer-events: none; }
#loading-screen p { margin: 18px 0 5px; color: var(--navy); font-size: 15px; font-weight: 650; }
#loading-screen small { color: var(--muted); font-size: 10px; }
.loader-mark { display: flex; gap: 6px; }
.loader-mark span { width: 10px; height: 28px; border-radius: 3px; background: var(--blue); animation: load 1s ease-in-out infinite; }
.loader-mark span:nth-child(2) { background: var(--teal); animation-delay: .14s; }
.loader-mark span:nth-child(3) { background: var(--violet); animation-delay: .28s; }
@keyframes load { 0%,100% { transform: scaleY(.5); opacity: .5; } 50% { transform: scaleY(1); opacity: 1; } }
#webgl-error { position: fixed; z-index: 110; inset: 20% 25%; padding: 35px; border-radius: 18px; background: #fff; box-shadow: var(--shadow); text-align: center; }
#webgl-error h2 { color: var(--navy); }
#webgl-error p { color: var(--muted); line-height: 1.7; }

@media (max-width: 1250px) {
  .narrative-panel { width: 300px; left: 16px; }
  .factory-panel { width: 280px; right: 16px; }
  .timeline-panel { left: 16px; right: 16px; grid-template-columns: 260px 1fr 240px; gap: 15px; }
  .view-switcher button { padding: 8px 9px; }
}

@media (max-width: 900px) {
  .topbar { height: 72px; padding: 13px 14px; }
  .brand h1 { font-size: 19px; }
  .eyebrow { font-size: 8px; }
  .live-pill, #labels-button { display: none; }
  #metrics-button { display: block; }
  .text-button { height: 33px; padding: 0 11px; font-size: 11px; }
  .narrative-panel { top: 76px; left: 12px; width: 274px; max-height: 225px; padding: 15px; border-radius: 14px; }
  .quarter-heading { margin: 9px 0; gap: 10px; }
  .quarter-number { font-size: 39px; }
  .quarter-heading h2 { font-size: 15px; }
  .news { display: none; }
  .consensus { padding: 8px 9px; }
  .consensus p { font-size: 10px; }
  .kpi-grid { margin-top: 10px; gap: 6px; }
  .kpi-card { min-height: 62px; padding: 8px; }
  .kpi-card strong { font-size: 16px; }
  .kpi-card small { display: none; }
  .decision-details { display: none; }
  .factory-panel { display: none; top: 76px; left: 12px; right: auto; width: min(330px, calc(100vw - 24px)); max-height: calc(100vh - 235px); z-index: 30; }
  body.metrics-open .factory-panel { display: block; }
  body.metrics-open .narrative-panel { opacity: 0; pointer-events: none; }
  .view-switcher { bottom: 133px; max-width: calc(100vw - 20px); overflow-x: auto; }
  .view-switcher button { padding: 7px 9px; font-size: 10px; }
  .timeline-panel { left: 9px; right: 9px; bottom: 20px; min-height: 96px; grid-template-columns: auto 1fr; gap: 13px; padding: 13px; border-radius: 14px; }
  .transport { gap: 5px; }
  .transport button { height: 34px; padding: 0 9px; font-size: 10px; }
  .transport button:first-child, .transport button:last-child { width: 34px; padding: 0; font-size: 0; }
  .transport button:first-child::after { content: "−"; font-size: 18px; }
  .transport button:last-child::after { content: "+"; font-size: 17px; }
  .transport .play-button { min-width: 62px; }
  .timeline-stats { display: none; }
  .source-note { left: 13px; bottom: 6px; max-width: 85vw; font-size: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .keyboard-hint { display: none; }
}

@media (max-width: 520px) {
  .narrative-panel { width: calc(100vw - 24px); max-height: 176px; }
  .panel-kicker { font-size: 8px; }
  .quarter-heading { float: left; width: 43%; margin-bottom: 0; }
  .quarter-number { font-size: 36px; }
  .quarter-heading p { font-size: 10px; }
  .consensus { margin-left: 45%; min-height: 61px; }
  .consensus span { font-size: 8px; }
  .consensus p { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .kpi-grid { clear: both; grid-template-columns: repeat(4, 1fr); padding-top: 9px; }
  .kpi-card { min-height: 51px; padding: 7px 5px; text-align: center; }
  .kpi-card span { font-size: 8px; }
  .kpi-card strong { font-size: 12px; letter-spacing: -.04em; }
  .view-switcher { bottom: 127px; }
  .view-switcher button { padding: 6px 8px; font-size: 9px; }
  .timeline-panel { grid-template-columns: 116px 1fr; gap: 8px; }
  .transport .play-button { min-width: 48px; }
  #play-label { display: none; }
  .timeline-meta span { font-size: 8px; }
  .timeline-ticks { font-size: 7px; }
  #webgl-error { inset: 18% 8%; padding: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
