/* Carbon Reservoirs */

:root {
  --accent:       #004445;
  --accent-light: #006668;
  --focus-glow:   #FFD166;
  --ink:          #2C3E3E;
  --muted:        #5A6E6E;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #F5F1E5;
  font-family: Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ──
   Stage on the left, one vertical control panel on the right (the signed-off
   layout sketch; Rajat's standing preference). */

#sim-app {
  display: flex;
  flex-direction: row;
  height: 100%;
}

#stage-panel {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

#sim-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#sim-canvas:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: -2px;
}

/* Flow tooltip — plain DOM over the canvas, so it measures and wraps itself. */
#flow-tip {
  background: rgba(20, 26, 26, 0.94);
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  line-height: 1.45;
  max-width: 230px;
  padding: 7px 10px;
  pointer-events: none;
  position: absolute;
  z-index: 20;
}

#flow-tip strong { font-weight: 600; }
#flow-tip em { color: #cbd5cf; font-style: normal; }

#control-panel {
  width: 300px;
  flex: none;
  background: #F7F9F9;
  border-left: 1px solid #CFD8D8;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* The side panel is the layout (Rajat's standing preference), so it holds on as
   far down as it can: it narrows first, and only drops below the stage when the
   stage would otherwise be too thin to carry two columns. */
@media (max-width: 1000px) {
  #control-panel { width: 250px; }
}

@media (max-width: 700px) {
  #sim-app { flex-direction: column; }
  #stage-panel { flex: 1 1 auto; min-height: 340px; }
  #control-panel {
    width: 100%;
    flex: 0 1 auto;
    border-left: none;
    border-top: 1px solid #CFD8D8;
  }
}

/* ── Numbers overlay (?numbers) ──
   A build-step scaffold, not part of the sim: the model's raw figures over the
   scene so the arithmetic can be checked against MODEL-NOTES.md. Goes away at
   build step 5, once the budget panel carries the same numbers. */

#numbers-overlay {
  background: rgba(247, 249, 249, 0.96);
  bottom: 0;
  left: 0;
  overflow: auto;
  padding: 14px 18px 24px;
  position: absolute;
  right: 0;
  top: 0;
  z-index: 15;
}

.readout-head {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  margin-bottom: 16px;
}

.readout-metric {
  display: flex;
  flex-direction: column;
}

.metric-label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.readout-metric strong {
  color: var(--accent);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

#numbers-overlay h3 {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  margin: 16px 0 6px;
  text-transform: uppercase;
}

.readout-cols {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
}

.readout-cols > div { flex: 1 1 260px; }

table.readout {
  border-collapse: collapse;
  color: var(--ink);
  font-size: 13px;
  width: 100%;
}

table.readout th,
table.readout td {
  border-bottom: 1px solid #E3E9E9;
  padding: 3px 10px 3px 0;
  text-align: left;
}

table.readout th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

table.readout .num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

table.readout tr.sum td {
  border-top: 1px solid #9FB3B3;
  font-weight: 600;
}

table.readout tr.lane-slow td { color: var(--muted); }

/* ── Control panel ── */

#control-panel h2 {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.ctrl-block { border-bottom: 1px solid #E3E9E9; padding-bottom: 12px; }
.ctrl-block:last-child { border-bottom: none; }

.ctrl-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.ctrl-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin-top: 6px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

.chip {
  background: #fff;
  border: 1px solid #CFD8D8;
  border-radius: 999px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  padding: 4px 11px;
}

.chip.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.slider-row {
  align-items: center;
  display: grid;
  gap: 2px 8px;
  grid-template-columns: 1fr auto;
  margin-bottom: 8px;
}

.slider-row label { font-size: 12px; }

.slider-row input[type="range"] {
  accent-color: var(--accent);
  grid-column: 1 / 2;
  width: 100%;
}

.slider-row output {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
}

.btn {
  background: #fff;
  border: 1px solid #CFD8D8;
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  padding: 5px 12px;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
  min-width: 74px;
}

.seg {
  border: 1px solid #CFD8D8;
  border-radius: 6px;
  display: inline-flex;
  overflow: hidden;
}

.seg-btn {
  background: #fff;
  border: none;
  border-right: 1px solid #CFD8D8;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  padding: 5px 10px;
}

.seg-btn:last-child { border-right: none; }
.seg-btn.is-on { background: var(--accent); color: #fff; }

#control-panel input[type="number"] {
  border: 1px solid #CFD8D8;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  padding: 4px 6px;
  width: 74px;
}

#control-panel label,
#control-panel span { font-size: 12px; }

.btn.wide { display: block; margin-top: 10px; width: 100%; }

.btn[disabled] { cursor: default; opacity: 0.45; }

.btn:focus-visible,
.chip:focus-visible,
.seg-btn:focus-visible,
#control-panel input:focus-visible {
  outline: 2px solid var(--focus-glow);
  outline-offset: 1px;
}

/* ── Relative-size strip ── */

.size-strip {
  border: 1px solid #CFD8D8;
  border-radius: 4px;
  display: flex;
  height: 16px;
  overflow: hidden;
}

/* Hairlines between the segments: the deep ocean really is most of the bar, so
   the small reservoirs must at least be countable. Widths are never padded — a
   faked segment would undo the thing the strip exists to show. */
.size-strip span {
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.85);
  display: block;
  height: 100%;
}

.size-strip span:last-child { box-shadow: none; }

.strip-legend {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  margin-top: 5px;
}

/* ── Budget panel ──
   Pinned to the bottom of the panel, per the signed-off layout sketch. */

.budget-block { margin-top: auto; }

table.budget {
  border-collapse: collapse;
  font-size: 12px;
  width: 100%;
}

table.budget td {
  border-bottom: 1px solid #EEF2F2;
  padding: 2px 0;
}

table.budget td:last-child {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

table.budget tr.head td { font-weight: 600; }
table.budget tr.sub td { color: var(--muted); padding-left: 10px; }

table.budget tr.sum td {
  border-bottom: none;
  border-top: 1px solid #9FB3B3;
  font-weight: 600;
}

/* ── Reset confirmation ── */

#reset-dialog {
  background: #fff;
  border: 1px solid #CFD8D8;
  border-radius: 12px;
  color: var(--ink);
  padding: 22px 24px;
  width: min(420px, calc(100vw - 32px));
}

#reset-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

#reset-dialog h2 {
  color: var(--accent);
  font-size: 15px;
  margin-bottom: 8px;
}

#reset-dialog p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 18px;
}

.reset-dialog-controls { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Accessibility ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Info dialog ──
   The dialog is Tuva Sims "chrome", so its accent is espresso (#5c4738),
   NOT the sim's green var(--accent). Header = purple with white text; active
   tab / h3 / footer button = purple; tabs/footer surface = #F8FBFB; body text =
   var(--ink). The shared toolbar stylesheet also injects these purple rules
   (scoped to #info-dialog) so existing green sims reskin automatically — keep
   this block in sync with it; do not redefine per sim. */
#info-dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 80px);
  overflow: hidden;
  margin: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
  background: #ffffff;
}

#info-dialog::backdrop {
  background: rgba(30, 16, 48, 0.55);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #5c4738;
  color: #ffffff;
}

.dialog-header h2 {
  font-size: 16px;
  font-weight: 600;
}

#dialog-close-btn {
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 18px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#dialog-close-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

#dialog-close-btn:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: 2px;
}

.dialog-tabs {
  display: flex;
  border-bottom: 2px solid #E5EAE9;
  background: #F8FBFB;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  padding: 10px 0;
  font-family: Roboto, Arial, sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
  color: #5c4738;
}

.tab-btn.active,
.tab-btn[aria-selected="true"] {
  color: #5c4738;
  border-bottom-color: #5c4738;
}

.tab-btn:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: -3px;
}

.dialog-body {
  padding: 16px 20px;
  overflow-y: auto;
  max-height: calc(100vh - 240px);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

.dialog-body h3 {
  font-size: 14px;
  font-weight: 600;
  color: #5c4738;
  margin-top: 14px;
  margin-bottom: 6px;
}

.dialog-body h3:first-child {
  margin-top: 0;
}

.dialog-body p {
  margin-bottom: 8px;
}

.dialog-body ul,
.dialog-body ol {
  padding-left: 20px;
  margin-bottom: 8px;
}

.dialog-body li {
  margin-bottom: 4px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  padding: 12px 20px;
  border-top: 1px solid #E5EAE9;
  background: #F8FBFB;
}

.dialog-close-footer {
  background: #5c4738;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 8px 20px;
  font-family: Roboto, Arial, sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.dialog-close-footer:hover {
  background: #7d6c60;
}

.dialog-close-footer:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: 2px;
}

/* ── Intro slides (optional; house pattern) ──
   Overlay div, not <dialog>.showModal(): the native top layer would sit above
   the shared toolbar; z-index 9990 keeps the top bar clickable (toolbar is
   9999). Enable by filling INTRO_STEPS in the sim JS. The panel is sim
   content, so it uses the sim palette (var(--accent)), not the dialog's
   purple chrome. */
#intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 9990;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

#intro-overlay.hidden { display: none; }

.intro-panel {
  background: #ffffff;
  border-radius: 12px;
  padding: 28px 30px 22px;
  width: min(500px, calc(100vw - 32px));
  color: var(--ink);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
}

#intro-img {
  display: block;
  max-width: 100%;
  height: 220px;
  object-fit: contain;
  margin: 0 auto 18px;
  border-radius: 8px;
}

#intro-text {
  font-size: 16px;
  line-height: 1.7;
  min-height: 108px;
  margin-bottom: 20px;
}

.intro-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

#intro-skip {
  background: transparent;
  border: none;
  color: var(--muted);
  font: 500 14px Roboto, Arial, sans-serif;
  cursor: pointer;
  padding: 8px 4px;
  text-decoration: underline;
}

#intro-skip:hover { color: var(--ink); }

#intro-skip:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: 2px;
}

#intro-count {
  margin-left: auto;
  font: 500 12px Roboto, Arial, sans-serif;
  color: var(--muted);
}

.intro-btn {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 8px 20px;
  font: 600 14px Roboto, Arial, sans-serif;
  cursor: pointer;
}

.intro-btn:hover { background: var(--accent-light); }

.intro-btn.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.intro-btn:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: 2px;
}

/* ── TODO: Add sim-specific styles below ── */

/* Model-year readout beside Play */
.year-readout {
  color: var(--muted);
  font-size: 12px;
  margin-left: auto;
  white-space: nowrap;
}
.year-readout strong {
  color: var(--ink, #1f2937);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
}

/* Mode / run controls */
.seg-wide { display: flex; margin-bottom: 8px; }
.seg-wide .seg-btn { flex: 1; text-align: center; }
.ctrl-label { font-size: 12px; white-space: nowrap; }
.ctrl-label strong { font-variant-numeric: tabular-nums; }
#in-until { font: inherit; font-size: 13px; padding: 3px 6px; width: 5.5em; }
#cut-note { margin-top: 0; }
.slider-row.locked { opacity: 0.55; }
.slider-row.locked input[type="range"] { cursor: not-allowed; }
