:root {
  --color-primary: #1F4E79;
  --color-accent: #E65100;
  --color-good: #2E7D32;
  --color-warn: #F57F17;
  --color-danger: #C62828;
  --color-env: #4CAF50;
  --color-env-dark: #1B5E20;
  --bg-main: #F5F7FA;
  --bg-panel: #FFFFFF;
  --border-light: #E0E6ED;
  --text-dark: #1A1A1A;
  --text-gray: #666;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; font-family: 'Sarabun', 'Tahoma', system-ui, sans-serif; background: var(--bg-main); color: var(--text-dark); }

body { display: grid; grid-template-rows: 56px 42px 1fr 64px; height: 100vh; }

/* ====== TOP BAR ====== */
.top-bar {
  background: linear-gradient(135deg, var(--color-primary) 0%, #2C5F93 100%);
  color: white; padding: 0 20px; display: flex;
  justify-content: space-between; align-items: center;
  box-shadow: var(--shadow-md);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand .icon { font-size: 26px; flex-shrink: 0; }
.brand > div { min-width: 0; }
.brand .title { font-size: 16px; font-weight: 700; line-height: 1.2;
                white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .title .badge {
  background: rgba(255,255,255,0.2); padding: 2px 8px; border-radius: 10px;
  font-size: 11px; margin-left: 6px; vertical-align: middle;
}
.brand .subtitle { font-size: 11px; opacity: 0.85; line-height: 1.25;
                   white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 6px; }

.btn-small {
  background: rgba(255,255,255,0.15); color: white; border: 1px solid rgba(255,255,255,0.2);
  padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 13px;
  font-family: inherit;
  transition: background 0.2s;
}
.btn-small:hover { background: rgba(255,255,255,0.28); }
.btn-small.off { opacity: 0.5; }

/* ====== RECOMMENDATION BANNER ====== */
.reco-banner {
  background: linear-gradient(135deg, #FFF9C4 0%, #FFE082 100%);
  border-bottom: 2px solid #FFB300;
  padding: 6px 20px; display: flex; justify-content: space-between; align-items: center;
  gap: 20px;
}
.reco-left { display: flex; align-items: center; gap: 12px; }
.reco-trophy { font-size: 24px; }
.reco-title { font-size: 14px; font-weight: 700; color: #6D4C00; }
.reco-title strong { color: var(--color-accent); }
.reco-sub { font-size: 11px; color: #795548; margin-top: 1px; }
.reco-cta {
  background: var(--color-accent); color: white; border: none;
  padding: 8px 16px; border-radius: 20px; font-weight: 700; cursor: pointer;
  font-size: 13px; font-family: inherit;
  transition: all 0.2s;
}
.reco-cta:hover { background: #BF360C; transform: translateY(-1px); }

/* ====== MAIN LAYOUT ====== */
.main-layout {
  display: grid; grid-template-columns: 1fr 360px;
  grid-template-rows: 62px 1fr;
  grid-template-areas: "scenarios panel" "scene panel";
  overflow: hidden;
}

/* ====== SCENARIO BAR ====== */
.scenario-bar {
  grid-area: scenarios;
  display: flex; gap: 8px; padding: 10px 12px; background: var(--bg-panel);
  border-bottom: 1px solid var(--border-light);
}
.scenario-btn {
  flex: 1; background: #F8F9FA; border: 2px solid var(--border-light);
  border-radius: 8px; padding: 6px 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  transition: all 0.2s; font-family: inherit;
}
.scenario-btn:hover { background: #E8F4FD; border-color: var(--color-primary); }
.scenario-btn.active {
  background: var(--color-primary); color: white; border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}
.scenario-btn .s-label { font-size: 13px; font-weight: 700; }
.scenario-btn .s-desc { font-size: 10px; opacity: 0.85; line-height: 1.2; text-align: center; }

/* ====== 3D SCENE ====== */
.scene-container {
  grid-area: scene; position: relative; background: #9CC5E8; overflow: hidden;
}
#scene-3d { width: 100%; height: 100%; }

.scene-info {
  position: absolute; top: 12px; left: 12px; z-index: 10;
  background: rgba(0,0,0,0.65); color: white; padding: 8px 14px;
  border-radius: 8px; backdrop-filter: blur(8px);
  display: flex; flex-direction: column; gap: 4px;
}
.info-item { display: flex; gap: 12px; align-items: baseline; font-size: 12px; }
.info-label { opacity: 0.8; }
.info-val { font-weight: 700; font-size: 15px; color: #FFD54F; }

.legend {
  position: absolute; bottom: 12px; left: 12px; z-index: 10;
  background: rgba(0,0,0,0.65); color: white; padding: 8px 12px;
  border-radius: 8px; backdrop-filter: blur(8px);
  font-size: 11px; display: flex; flex-direction: column; gap: 3px;
}
.legend-item { display: flex; align-items: center; gap: 8px; }
.swatch { display: inline-block; width: 16px; height: 10px; border-radius: 3px; }
.swatch.car { background: #E53935; }
.swatch.moto { background: #43A047; }
.swatch.truck { background: #795548; }
.swatch.bus { background: #FFD54F; }

.zoom-controls {
  position: absolute; top: 12px; right: 12px; z-index: 10;
  display: flex; flex-direction: column; gap: 4px;
}
.zoom-btn {
  width: 34px; height: 34px; border: none; border-radius: 6px;
  background: rgba(0,0,0,0.65); color: white; font-size: 18px; font-weight: 700;
  cursor: pointer; backdrop-filter: blur(8px);
  transition: background 0.15s;
}
.zoom-btn:hover { background: rgba(0,0,0,0.85); }

.attribution {
  position: absolute; bottom: 6px; right: 12px; z-index: 10;
  background: rgba(0,0,0,0.55); color: #ddd;
  padding: 4px 10px; border-radius: 4px;
  font-size: 10px; letter-spacing: 0.2px; line-height: 1.35;
  backdrop-filter: blur(6px);
  pointer-events: none;
  max-width: 60vw; text-align: right;
}
.attribution .dev-credit {
  font-size: 10px; color: #c9d3db; opacity: 0.75;
  font-style: italic; margin-top: 1px;
}

/* ====== LOADING ====== */
.loading-overlay {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 100;
  background: rgba(31,78,121,0.92); color: white;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px;
}
.spinner {
  width: 50px; height: 50px; border: 5px solid rgba(255,255,255,0.25);
  border-top-color: #FFD54F; border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 16px; font-weight: 500; }

/* ====== SIDE PANEL ====== */
.side-panel {
  grid-area: panel; background: var(--bg-panel); overflow-y: auto;
  border-left: 1px solid var(--border-light); padding: 0;
  display: flex; flex-direction: column;
}

/* ====== TABS ====== */
.tab-bar {
  display: flex; border-bottom: 2px solid var(--border-light);
  background: #F8F9FA;
  position: sticky; top: 0; z-index: 5;
}
.tab-btn {
  flex: 1; background: transparent; border: none; padding: 12px 8px;
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  color: var(--text-gray);
  border-bottom: 3px solid transparent;
  transition: all 0.15s;
}
.tab-btn:hover { background: rgba(31,78,121,0.08); color: var(--color-primary); }
.tab-btn.active {
  color: var(--color-primary); border-bottom-color: var(--color-primary);
  background: white;
}
.tab-panel { display: none; padding: 16px; }
.tab-panel.active { display: block; }
.tab-panel h3 { font-size: 14px; color: var(--color-primary); margin-bottom: 12px; font-weight: 700; }
.tab-panel h4 { font-size: 13px; color: var(--color-primary); margin: 14px 0 8px; font-weight: 700; }
.footnote { font-size: 11px; color: var(--text-gray); margin-top: 8px; font-style: italic; }

/* ====== STAT CARDS & BARS ====== */
.compare-row { margin-bottom: 14px; }
.stat-card {
  background: #F8F9FA; border-radius: 8px; padding: 10px 12px;
  border-left: 3px solid var(--color-primary);
}
.stat-card.danger { border-left-color: var(--color-danger); background: #FFF3E0; }
.stat-h { font-size: 13px; font-weight: 700; color: var(--text-dark); }
.stat-unit { font-size: 10px; color: var(--text-gray); margin-bottom: 8px; }

.bars { display: flex; flex-direction: column; gap: 4px; }
.bar {
  position: relative; height: 22px; background: #E8ECF0; border-radius: 4px;
  overflow: hidden; display: flex; align-items: center;
}
.bar-lbl {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  font-size: 11px; font-weight: 600; z-index: 2; color: var(--text-dark);
}
.bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, #64B5F6, #1976D2);
  transition: width 0.4s ease-out;
}
.bar-val {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font-size: 11px; font-weight: 700; z-index: 2; color: var(--text-dark);
}
.bar.over .bar-fill { background: linear-gradient(90deg, #FFB74D, #C62828); }
.bar[data-scenario*="win"] .bar-fill,
.bar:has(.bar-lbl:first-child:nth-last-child(3)):last-child .bar-fill {
  background: linear-gradient(90deg, #81C784, #2E7D32);
}

/* ====== METRICS TABLE ====== */
.metrics-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.metrics-table th, .metrics-table td {
  padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--border-light);
}
.metrics-table th { background: var(--color-primary); color: white; font-weight: 600; }
.metrics-table td:first-child, .metrics-table th:first-child { text-align: left; font-weight: 600; }
.metrics-table td.win { color: var(--color-good); font-weight: 700; background: #E8F5E9; }
.metrics-table td.danger { color: var(--color-danger); font-weight: 700; background: #FFEBEE; }

/* ====== ENV PANEL ====== */
.env-compare {
  background: linear-gradient(135deg, #E8F5E9 0%, #F1F8E9 100%);
  border: 2px solid var(--color-env); border-radius: 10px; padding: 12px;
  margin-bottom: 10px;
}
.env-row { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.env-row:last-child { margin-bottom: 0; }
.env-icon { font-size: 22px; }
.env-body { flex: 1; }
.env-label { font-size: 11px; color: var(--text-gray); }
.env-val { font-size: 17px; font-weight: 700; color: var(--color-env-dark); }
.env-delta { font-size: 11px; font-weight: 600; margin-top: 2px; }
.env-delta.down { color: var(--color-good); }
.env-delta.up { color: var(--color-accent); }

.climate-equiv {
  background: #FFF; border: 1px solid var(--color-env);
  border-radius: 8px; padding: 12px; font-size: 12px;
}
.equiv-title { font-weight: 700; color: var(--color-env-dark); margin-bottom: 6px; }
.equiv-line { padding: 3px 0; color: var(--text-dark); }
.equiv-line span { font-weight: 700; color: var(--color-env-dark); }

/* ====== ROADMAP ====== */
.roadmap-section {
  border-top: 1px solid var(--border-light); padding: 16px;
  background: #FAFBFC;
}
.roadmap-section h3 { font-size: 14px; color: var(--color-primary); margin-bottom: 10px; font-weight: 700; }
.timeline {
  list-style: none; padding-left: 16px; position: relative;
}
.timeline::before {
  content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px;
  width: 2px; background: #CFD8DC;
}
.timeline li {
  position: relative; padding: 6px 0 10px 16px; font-size: 12px; color: var(--text-dark);
}
.timeline li::before {
  content: ""; position: absolute; left: -13px; top: 10px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #CFD8DC; border: 2px solid white;
  box-shadow: 0 0 0 1px #CFD8DC;
}
.timeline li.done::before { background: var(--color-good); box-shadow: 0 0 0 1px var(--color-good); }
.timeline li.active::before {
  background: var(--color-accent); box-shadow: 0 0 0 1px var(--color-accent);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 1px var(--color-accent); }
  50% { box-shadow: 0 0 0 5px rgba(230,81,0,0.3); }
}
.timeline .tl-title { font-weight: 700; color: var(--color-primary); }
.timeline .tl-date { font-size: 10px; color: var(--text-gray); margin-left: 6px; }
.timeline .tl-desc { font-size: 11px; color: var(--text-gray); line-height: 1.4; margin-top: 1px; }
.timeline li.done .tl-title { color: var(--color-good); }
.timeline li.active .tl-title { color: var(--color-accent); }

/* ====== CONTROLS BAR ====== */
.controls-bar {
  display: flex; gap: 16px; align-items: center; padding: 10px 20px;
  background: var(--bg-panel); border-top: 1px solid var(--border-light);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
}
.btn-play {
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: var(--color-primary); color: white; font-size: 18px; cursor: pointer;
  transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.btn-play:hover { background: #2C5F93; transform: scale(1.05); }

.timeline-wrapper { flex: 1; display: flex; flex-direction: column; gap: 2px; }
#timeline { width: 100%; accent-color: var(--color-primary); cursor: pointer; }
.timeline-labels { font-size: 11px; color: var(--text-gray); display: flex; justify-content: space-between; }

.speed-control { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.speed-control label { font-weight: 600; }
.speed-control select {
  padding: 4px 8px; border: 1px solid var(--border-light); border-radius: 4px;
  font-family: inherit; cursor: pointer;
}

/* ====== MODAL ====== */
.modal-overlay {
  position: fixed; top:0; left:0; right:0; bottom:0; z-index: 1000;
  background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center;
}
.modal {
  background: white; border-radius: 12px; padding: 24px;
  max-width: 500px; width: 90%; max-height: 85vh; overflow-y: auto;
  position: relative; box-shadow: var(--shadow-md);
}
.modal h2 { color: var(--color-primary); margin-bottom: 12px; }
.modal h3 { color: var(--color-primary); margin: 12px 0 6px; font-size: 14px; }
.modal ul { padding-left: 20px; margin-bottom: 8px; }
.modal li { margin: 4px 0; font-size: 14px; line-height: 1.5; }
.modal p { font-size: 14px; line-height: 1.6; margin-top: 6px; }
.modal-close {
  position: absolute; top: 10px; right: 14px; background: none; border: none;
  font-size: 28px; cursor: pointer; color: var(--text-gray);
}
.modal-close:hover { color: var(--color-accent); }

/* ====== RESPONSIVE ====== */
@media (max-width: 900px) {
  .main-layout { grid-template-columns: 1fr; grid-template-rows: 62px 1fr auto; grid-template-areas: "scenarios" "scene" "panel"; }
  .side-panel { max-height: 45vh; }
  .brand .subtitle { display: none; }
  .reco-banner { flex-direction: column; gap: 6px; padding: 6px 12px; }
}

@media (max-width: 600px) {
  body { grid-template-rows: 56px auto 1fr 56px; }
  .scene-info, .legend { font-size: 10px; padding: 6px 10px; }
  .controls-bar { padding: 8px; gap: 8px; flex-wrap: wrap; }
  .btn-play { width: 38px; height: 38px; font-size: 16px; }
  .speed-control label { display: none; }
  .reco-title { font-size: 12px; }
  .reco-sub { font-size: 10px; }
  .zoom-controls .zoom-btn { width: 30px; height: 30px; font-size: 16px; }
}
