/* =====================================================================
   DESIGN SYSTEM — Vintage Poster / Comic Cell  (all knobs live here)
   ===================================================================== */
:root {
  --color-bg: #1C2E2A;        /* Deep Vintage Teal — primary background */
  --color-panel: #223C36;     /* Slightly lifted teal — card fills */
  --color-accent: #9E2A2B;    /* Rust / Crimson — accent */
  --color-text: #FFF3D1;      /* Aged Cream / Parchment — base text */
  --color-charcoal: #212529;  /* Off-Black / Charcoal — contrast */

  --border-width: 3px;
  --shadow-offset: 5px;

  /* Chart-safe palette (on-palette but distinguishable) */
  --chart-cream: #FFF3D1;
  --chart-gold:  #D9A441;
  --chart-sage:  #7BA68A;
  --chart-rust:  #C7423F;

  --font-display: 'Alfa Slab One', Georgia, serif;
  --font-data: 'Oswald', 'Arial Narrow', sans-serif;
  --font-script: 'Caveat', cursive;
}

* { box-sizing: border-box; }

html { font-size: 18px; }           /* bumped base type scale */
html, body { margin: 0; padding: 0; }

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-data);
  font-weight: 400;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  position: relative;
  /* fixed-height dashboard: fill the viewport, no page scroll on desktop */
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  gap: 12px;
}

/* Faint paper / noise texture — page background only, CSS-generated, no asset file */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- shared poster panel: double frame + hard offset shadow ---------- */
.panel {
  position: relative;
  background: var(--color-panel);
  border: var(--border-width) solid var(--color-charcoal);
  box-shadow:
    inset 0 0 0 3px var(--color-text),
    var(--shadow-offset) var(--shadow-offset) 0 var(--color-charcoal);
  border-radius: 10px;
}

/* =====================================================================
   TOP BAR — shared header (styles in ../../shared/header.css).
   Only the page-specific positioning lives here: bleed the bar into the
   body's 12px / 16px padding so it spans the full width.
   ===================================================================== */
.topbar { margin: -12px -16px 0; }

/* =====================================================================
   WELCOME MODAL
   ===================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* blur the dashboard behind the modal */
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  background: rgba(28, 46, 42, 0.65);
}
.modal-backdrop.hidden { display: none; }

.modal {
  position: relative;
  background: var(--color-panel);
  border: var(--border-width) solid var(--color-charcoal);
  box-shadow:
    inset 0 0 0 3px var(--color-text),
    8px 8px 0 var(--color-charcoal);
  border-radius: 14px;
  max-width: 820px;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  overflow: hidden;
}

.modal-img {
  background: var(--color-charcoal);
  display: flex;
  align-items: stretch;
}
.modal-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.modal-body {
  padding: 36px 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-brand h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  line-height: 1.05;
  margin: 0 0 4px;
  text-shadow: 2px 2px 0 var(--color-charcoal);
}
.modal-brand .tagline {
  font-family: var(--font-script);
  font-size: clamp(1rem, 1.6vw, 1.3rem);
  font-weight: 700;
  display: inline-block;
  transform: rotate(-2deg);
  color: var(--chart-gold);
}

.modal-intro {
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  margin: 0;
}
.modal-intro b { font-weight: 600; color: #FFE9A8; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
}
.modal-byline {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 500;
  opacity: 0.8;
}
.modal-byline a { color: var(--color-text); text-decoration: underline; text-underline-offset: 3px; }
.modal-byline a:hover { color: #FFE9A8; }

.modal-close {
  font-family: var(--font-data);
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text);
  background: var(--color-accent);
  border: var(--border-width) solid var(--color-charcoal);
  box-shadow: 4px 4px 0 var(--color-charcoal);
  border-radius: 8px;
  padding: 9px 22px;
  cursor: pointer;
  transition: transform 0.05s, box-shadow 0.05s;
  white-space: nowrap;
}
.modal-close:hover { transform: translate(1px,1px); box-shadow: 3px 3px 0 var(--color-charcoal); }
.modal-close:active { transform: translate(4px,4px); box-shadow: 0 0 0 var(--color-charcoal); }

@media (max-width: 640px) {
  .modal { grid-template-columns: 1fr; }
  .modal-img { max-height: 200px; }
  .modal-body { padding: 24px 20px 20px; }
}

/* =====================================================================
   DASHBOARD GRID — fills remaining viewport height
   ===================================================================== */
.dash {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 340px 1fr 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 0.85fr;
  grid-template-areas:
    "side charts  charts  charts  charts"
    "side charts  charts  charts  charts"
    "side regret  table   table   table";
  gap: 12px;
}

/* ---------- left sidebar: controls + regret stacked ---------- */
.side {
  grid-area: side;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

/* ---------- section headings ---------- */
.section-title {
  font-family: var(--font-data);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.82rem;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.section-title small {
  font-family: var(--font-script);
  text-transform: none;
  letter-spacing: 0;
  font-size: 1.05rem;
  font-weight: 600;
  opacity: 0.85;
}
.section-title .star { width: 16px; height: 16px; }

/* ---------- controls ---------- */
.controls { padding: 10px 14px; flex: 1 1 auto; }
.control-block { margin-bottom: 10px; }
.control-block:last-child { margin-bottom: 0; }
.control-block label.lbl {
  display: block;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
  margin-bottom: 5px;
}
.control-block .val {
  font-weight: 600;
  color: var(--chart-gold);
}

/* algorithm selector as a vertical segmented toggle */
.algo-toggle {
  display: flex;
  flex-direction: column;
  border: var(--border-width) solid var(--color-charcoal);
  border-radius: 8px;
  overflow: hidden;
}
.algo-toggle label {
  text-align: center;
  padding: 6px 6px;
  font-weight: 500;
  font-size: 0.82rem;
  cursor: pointer;
  background: var(--color-bg);
  border-bottom: 2px solid var(--color-charcoal);
  user-select: none;
  transition: background 0.12s, color 0.12s;
}
.algo-toggle label:last-child { border-bottom: none; }
.algo-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.algo-toggle label:has(input:checked) {
  background: var(--color-accent);
  color: var(--color-text);
  font-weight: 600;
}

/* range sliders */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: var(--color-bg);
  border: 2px solid var(--color-charcoal);
  border-radius: 6px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--chart-gold);
  border: 3px solid var(--color-charcoal);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--chart-gold);
  border: 3px solid var(--color-charcoal);
  cursor: pointer;
}
.control-block.disabled { opacity: 0.4; }
.control-block.disabled input[type="range"] { cursor: not-allowed; }
/* info icon + hover tooltip (replaces inline hint subtext) */
.info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  margin-left: 6px;
  padding: 0;
  vertical-align: middle;
  border: 1.5px solid var(--color-charcoal);
  border-radius: 50%;
  background: var(--color-bg);
  color: var(--color-charcoal);
  font-family: var(--font-data, inherit);
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  text-transform: none;
  cursor: help;
  transition: background 0.12s, color 0.12s;
}
.info:hover,
.info:focus-visible {
  background: var(--color-accent);
  outline: none;
}

/* floating tooltip bubble (positioned via JS, appended to body) */
.tooltip-pop {
  position: fixed;
  z-index: 100;
  max-width: 240px;
  padding: 7px 10px;
  background: var(--color-charcoal);
  color: var(--color-bg);
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.3;
  text-transform: none;
  letter-spacing: normal;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.12s, transform 0.12s;
  pointer-events: none;
}
.tooltip-pop.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* buttons */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
button.btn {
  font-family: var(--font-data);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.8rem;
  color: var(--color-text);
  background: var(--color-charcoal);
  border: var(--border-width) solid var(--color-charcoal);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.45);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  flex: 1 1 auto;
  transition: transform 0.05s, box-shadow 0.05s;
}
button.btn.primary { background: var(--color-accent); }
button.btn:hover { transform: translate(1px, 1px); box-shadow: 2px 2px 0 rgba(0,0,0,0.45); }
button.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 rgba(0,0,0,0.45); }

/* reveal toggle */
.reveal-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.switch { position: relative; display: inline-block; width: 50px; height: 26px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-sw {
  position: absolute; inset: 0;
  background: var(--color-bg);
  border: 2px solid var(--color-charcoal);
  border-radius: 26px;
  transition: 0.15s;
  cursor: pointer;
}
.slider-sw::before {
  content: "";
  position: absolute;
  height: 18px; width: 18px;
  left: 3px; top: 2px;
  background: var(--color-text);
  border-radius: 50%;
  transition: 0.15s;
}
.switch input:checked + .slider-sw { background: var(--color-accent); }
.switch input:checked + .slider-sw::before { transform: translateX(22px); }

/* ---------- regret callout ---------- */
.regret {
  grid-area: regret;
  text-align: center;
  background: var(--color-charcoal);
  border: var(--border-width) solid var(--color-charcoal);
  box-shadow:
    inset 0 0 0 3px var(--color-accent),
    var(--shadow-offset) var(--shadow-offset) 0 var(--color-charcoal);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.regret .regret-flank {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.regret .star { width: 24px; height: 24px; background: var(--color-accent); }
.regret-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  font-size: 0.82rem;
  opacity: 0.85;
}
.regret-value {
  font-family: var(--font-data);
  font-weight: 700;
  font-size: clamp(2.2rem, 4vw, 3.2rem);
  line-height: 1;
  color: var(--chart-gold);
  margin: 2px 0;
}
.regret-sub { font-weight: 400; font-size: 0.82rem; line-height: 1.3; margin: 6px auto 0; opacity: 0.92; }
.regret-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  margin-top: 12px;
  font-size: 0.82rem;
  text-align: left;
  opacity: 0.92;
}
.regret-stats b { color: var(--color-text); font-weight: 600; }

/* metric toggle (Regret ⇄ Budget) inside the callout */
.metric-toggle {
  display: flex;
  border: 2px solid var(--color-accent);
  border-radius: 7px;
  overflow: hidden;
  margin: 0 auto 10px;
  max-width: 320px;
}
.metric-toggle label {
  flex: 1 1 0;
  text-align: center;
  padding: 4px 8px;
  font-size: 0.72rem;
  line-height: 1.15;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  user-select: none;
  background: transparent;
  transition: background 0.12s, color 0.12s;
}
.metric-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.metric-toggle label:has(input:checked) { background: var(--color-accent); color: var(--color-text); }

/* swap the three views; conversion regret shows by default */
.metric-profit, .metric-budget { display: none; }
body.show-profit .metric-regret, body.show-budget .metric-regret { display: none; }
body.show-profit .metric-profit { display: block; }
body.show-budget .metric-budget { display: block; }

.budget-kpis {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-top: 8px;
  font-size: 0.82rem;
}
.budget-kpis b { color: var(--chart-gold); font-weight: 700; }

/* negative dollars (unprofitable arm, busted bankroll) */
.neg { color: var(--chart-rust) !important; }

/* =====================================================================
   BANKRUPT BANNER — shown only when the bandit runs out of money
   ===================================================================== */
.bankrupt-banner {
  display: none;
  flex: 0 0 auto;
  text-align: center;
  background: var(--color-accent);
  color: var(--color-text);
  border: var(--border-width) solid var(--color-charcoal);
  box-shadow: inset 0 0 0 3px var(--color-text), var(--shadow-offset) var(--shadow-offset) 0 var(--color-charcoal);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 0.92rem;
}
.bankrupt-banner b { font-weight: 700; }
body.bankrupt .bankrupt-banner { display: block; }

/* ---------- four-point star (decorative chrome) ---------- */
.star {
  width: 20px;
  height: 20px;
  background: var(--chart-gold);
  clip-path: polygon(50% 0%, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0% 50%, 39% 39%);
  flex: 0 0 auto;
}

/* ---------- chart cards ---------- */
.card {
  background: var(--color-panel);
  border: 2px solid var(--color-charcoal);
  border-radius: 10px;
  box-shadow: 4px 4px 0 var(--color-charcoal);
  padding: 12px 14px 10px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.card.charts { grid-area: charts; }
.card.tablecard { grid-area: table; }

/* combined-charts toggle + swappable views */
.chart-toggle {
  display: flex;
  border: 2px solid var(--color-accent);
  border-radius: 7px;
  overflow: hidden;
  margin: 0 0 10px;
  flex: 0 0 auto;
}
.chart-toggle label {
  flex: 1 1 0;
  text-align: center;
  padding: 5px 8px;
  font-size: 0.74rem;
  line-height: 1.15;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  user-select: none;
  background: transparent;
  transition: background 0.12s, color 0.12s;
}
.chart-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.chart-toggle label:has(input:checked) { background: var(--color-accent); color: var(--color-text); }

.chart-view { display: none; flex: 1 1 auto; min-height: 0; flex-direction: column; }
.chart-view.is-active { display: flex; }
.card h3 {
  font-family: var(--font-data);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.9rem;
  margin: 0 0 2px;
}
.card p.cap { font-size: 0.78rem; opacity: 0.74; margin: 0 0 8px; font-weight: 400; line-height: 1.25; }
.chart-box { position: relative; flex: 1 1 auto; min-height: 0; width: 100%; }

/* ---------- table ---------- */
.tablecard { overflow: auto; }
table.summary {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
table.summary th, table.summary td {
  padding: 9px 10px;
  text-align: right;
  border-bottom: 2px solid rgba(255,243,209,0.18);
}
table.summary th {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.8rem;
  border-bottom: 3px solid var(--color-text);
  position: sticky;
  top: 0;
  background: var(--color-panel);
}
table.summary th:first-child, table.summary td:first-child { text-align: left; }
table.summary td.campaign { font-weight: 500; }
table.summary .swatch {
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid var(--color-charcoal);
  margin-right: 8px;
  vertical-align: middle;
}
table.summary tr.leader td { background: rgba(217,164,65,0.12); }
table.summary tr.leader td:first-child::after {
  content: " ★";
  color: var(--chart-gold);
}
.true-col { display: none; }
body.reveal .true-col { display: table-cell; }
.num { font-variant-numeric: tabular-nums; }

/* =====================================================================
   RESPONSIVE — below this size, fall back to a normal scrolling column
   (fitting everything with readable type isn't possible on small screens)
   ===================================================================== */
@media (max-width: 1024px), (max-height: 600px) {
  body { height: auto; overflow: auto; display: block; padding: 14px; }
  .topbar { flex-wrap: wrap; justify-content: center; text-align: center; gap: 8px; margin-bottom: 12px; }
  .topbar-right { justify-content: center; }
  .dash { display: block; }
  .side { display: block; overflow: visible; }
  .controls, .regret { margin-bottom: 12px; }
  .card { margin-bottom: 12px; }
  .chart-box { height: 300px; flex: none; }
  .tablecard { overflow-x: auto; }
}
