/* Candy Tycoon — self-contained, responsive, dark theme.
   Tokens mirror the portfolio palette so the game feels of-a-piece. */

:root {
  --ct-bg:        #0d0f12;
  --ct-surface:   #161a20;
  --ct-surface-2: #1e242c;
  --ct-border:    #2a313b;
  --ct-text:      #eae0d5;
  --ct-text-dim:  #9aa3af;
  --ct-accent:    #e6a23c;
  --ct-accent-2:  #7fb069;
  --ct-danger:    #d96c6c;
  --ct-radius:    12px;
  --ct-radius-sm: 8px;
  --ct-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: linear-gradient(160deg, #14181e, #0d0f12 60%);
  color: var(--ct-text);
  font-family: var(--ct-font);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Topbar ── */
.ct-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--ct-border);
  background: rgba(13, 15, 18, 0.7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.ct-logo {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0.02em;
  color: var(--ct-accent);
}

.ct-notice {
  margin: 0;
  padding: 0.6rem 1.25rem;
  background: rgba(230, 162, 60, 0.12);
  border-bottom: 1px solid var(--ct-border);
  color: var(--ct-text);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
/* display:flex above overrides the [hidden] attribute's display:none — restore it */
.ct-notice[hidden] { display: none; }
.ct-notice-close {
  background: none;
  border: none;
  color: var(--ct-text-dim);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
  flex: 0 0 auto;
}
.ct-notice-close:hover { color: var(--ct-text); }

/* ── Patch-notes modal ── */
.ct-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
}
.ct-modal[hidden] { display: none; }
.ct-modal-card {
  background: var(--ct-surface);
  border: 1px solid var(--ct-border);
  border-radius: var(--ct-radius);
  padding: 1.25rem 1.5rem;
  max-width: 460px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.ct-modal-title { margin: 0 0 0.75rem; color: var(--ct-accent); }
.ct-patch-version { margin: 0.75rem 0 0.35rem; font-size: 0.9rem; }
.ct-patch-list { margin: 0; padding-left: 1.1rem; font-size: 0.85rem; color: var(--ct-text-dim); line-height: 1.5; }
.ct-patch-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--ct-border);
}
.ct-patch-pos { font-size: 0.8rem; color: var(--ct-text-dim); }
.ct-patch-nav .ct-btn[disabled] { opacity: 0.35; cursor: default; }
.ct-modal-card .ct-btn-primary { margin-top: 0.75rem; width: 100%; }

/* ── Market news ticker ── */
.ct-news {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-left: 1.25rem;
  background: var(--ct-surface);
  border-bottom: 1px solid var(--ct-border);
  overflow: hidden;
}
.ct-news[hidden] { display: none; }
.ct-news-tag {
  flex: 0 0 auto;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ct-bg);
  background: var(--ct-accent);
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
}
.ct-news-window { flex: 1; overflow: hidden; }
.ct-news-track {
  display: inline-block;
  white-space: nowrap;
  padding: 0.5rem 0;
  font-size: 0.8rem;
  color: var(--ct-text);
  animation: ct-marquee 45s linear infinite; /* duration overridden in JS for constant speed */
}
.ct-news-item { color: var(--ct-text); }      /* filler — default colour */
.ct-news-item.ct-news-good { color: var(--ct-accent-2); }
.ct-news-item.ct-news-bad { color: var(--ct-danger); }
.ct-news:hover .ct-news-track { animation-play-state: paused; }
@keyframes ct-marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

/* ── Price trend badges ── */
.ct-trend { font-size: 0.72rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; margin-left: 0.25rem; }
.ct-trend-up { color: var(--ct-accent-2); }
.ct-trend-down { color: var(--ct-danger); }

/* ── Board layout ── */
.ct-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;          /* panels are only as tall as their content */
  gap: 1rem;
  padding: 1rem;
  max-width: 1280px;
  margin: 0 auto;
}
@media (max-width: 820px) {
  .ct-board { grid-template-columns: 1fr; }
}
/* Left column stacks the Upgrades panel above Candy production */
.ct-col { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

.ct-panel {
  background: var(--ct-surface);
  border: 1px solid var(--ct-border);
  border-radius: var(--ct-radius);
  padding: 1rem;
  min-width: 0;
}
.ct-panel-title {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ct-text-dim);
}

/* ── Candy rows ── */
.ct-candy-list { display: flex; flex-direction: column; gap: 0.6rem; }
.ct-candy {
  background: var(--ct-surface-2);
  border: 1px solid var(--ct-border);
  border-radius: var(--ct-radius-sm);
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.ct-candy-optswrap { display: flex; flex-direction: column; }
.ct-candy-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}
.ct-candy-name { font-weight: 600; }
.ct-candy-stock { color: var(--ct-accent-2); font-variant-numeric: tabular-nums; }
.ct-candy-meta {
  font-size: 0.78rem;
  color: var(--ct-text-dim);
  margin: 0.35rem 0 0.6rem;
  font-variant-numeric: tabular-nums;
}
.ct-candy-body { display: flex; flex-direction: column; gap: 0.4rem; }
.ct-candy-opts { display: flex; flex-direction: column; gap: 0.4rem; }

/* Stock colour-coded by net flow: surplus (green) / draining (red) / steady */
.ct-stock-up   { color: var(--ct-accent-2); }
.ct-stock-down { color: var(--ct-danger); }
.ct-stock-flat { color: var(--ct-text-dim); }

/* Collapse toggles (candy header + shop "Upgrades" header) */
.ct-row-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  width: 100%;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
  text-align: left;
}
.ct-row-header:hover .ct-candy-name,
.ct-row-header:hover { color: var(--ct-accent); }
.ct-caret { color: var(--ct-text-dim); font-size: 0.7rem; width: 0.8rem; flex: 0 0 auto; }
.ct-candy-header .ct-candy-stock { margin-left: auto; }
/* Upgrade fold toggles styled as clear, bordered buttons */
.ct-candy-upgrades-toggle,
.ct-shop-upgrades-toggle,
.ct-research-toggle {
  margin-top: 0.3rem;
  width: 100%;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  background: var(--ct-surface);
  border: 1px solid var(--ct-border);
  border-radius: var(--ct-radius-sm);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ct-text-dim);
}
.ct-candy-upgrades-toggle:hover,
.ct-shop-upgrades-toggle:hover,
.ct-research-toggle:hover { border-color: var(--ct-accent); color: var(--ct-text); }
/* Stays highlighted while the fold is open; reverts when collapsed */
.ct-candy-upgrades-toggle.is-open,
.ct-shop-upgrades-toggle.is-open,
.ct-research-toggle.is-open {
  background: rgba(230, 162, 60, 0.14);
  border-color: var(--ct-accent);
  color: var(--ct-accent);
}

/* Research fold in the Upgrades panel */
.ct-research { margin-top: 0.5rem; }
.ct-research-body { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.4rem; }
.ct-shop-meta { font-size: 0.78rem; color: var(--ct-accent-2); margin: -0.3rem 0 0.6rem; font-variant-numeric: tabular-nums; }

/* ── Stats / info ── */
.ct-chart-wrap { position: relative; aspect-ratio: 1 / 1; max-width: 240px; margin: 0 auto; }
.ct-chart { width: 100%; height: 100%; touch-action: none; }
.ct-chart-tooltip {
  position: absolute;
  transform: translate(-50%, -135%);
  background: var(--ct-bg);
  border: 1px solid var(--ct-border);
  border-radius: var(--ct-radius-sm);
  padding: 0.25rem 0.5rem;
  font-size: 0.72rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
  font-variant-numeric: tabular-nums;
}

/* Chart-only metric tabs (Mix / By candy) */
.ct-chart-tabs { display: flex; gap: 0.4rem; justify-content: center; margin: 0.6rem 0 0.2rem; }
.ct-chart-tab {
  font-size: 0.72rem;
  padding: 0.3rem 0.7rem;
  background: var(--ct-surface-2);
  border: 1px solid var(--ct-border);
  border-radius: 2rem;
  color: var(--ct-text-dim);
}

/* Shared selector affordance (stat boxes + chart tabs) */
.ct-selector { cursor: pointer; font: inherit; transition: border-color 0.12s, background 0.12s, color 0.12s; }
.ct-selector:hover { border-color: var(--ct-accent); }
.ct-selector.is-selected { border-color: var(--ct-accent); color: var(--ct-accent); background: rgba(230, 162, 60, 0.12); }
.ct-selector.is-selected .ct-stat-label { color: var(--ct-accent); }

.ct-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  margin: 0.75rem 0;
  font-size: 0.75rem;
  color: var(--ct-text-dim);
}
.ct-legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.ct-legend-swatch { width: 0.7rem; height: 0.7rem; border-radius: 2px; display: inline-block; }

.ct-stats { display: flex; gap: 0.75rem; margin: 0.5rem 0 0.9rem; }
.ct-stat {
  flex: 1 1 0;
  min-width: 0;                 /* allow boxes to shrink so 3 fit on one row */
  background: var(--ct-surface-2);
  border: 1px solid var(--ct-border);
  border-radius: var(--ct-radius-sm);
  padding: 0.6rem 0.5rem;
  text-align: center;
  color: var(--ct-text);        /* <button> doesn't inherit text colour */
}
.ct-stat-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ct-text-dim); white-space: nowrap; }
.ct-stat-value {
  display: block;
  width: 100%;
  font-size: 1.15rem;          /* max; JS shrinks to fit the box (see #fitText) */
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}
.ct-info-actions { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.75rem; }

/* Global upgrades */
.ct-upgrade-list { display: flex; flex-direction: column; gap: 0.5rem; }
.ct-global-upgrade { display: flex; flex-direction: column; gap: 0.15rem; }
.ct-upgrade-name { font-size: 0.82rem; font-weight: 600; color: var(--ct-text); }
.ct-upgrade-desc { font-size: 0.72rem; color: var(--ct-text-dim); line-height: 1.35; white-space: normal; }
.ct-global-upgrade:disabled .ct-upgrade-name { color: var(--ct-text-dim); }

/* ── Shops ── */
/* "Set all shops" bulk-assign bar */
.ct-bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; margin-bottom: 0.75rem; }
.ct-bulk-bar[hidden] { display: none; }
.ct-bulk-label { font-size: 0.72rem; color: var(--ct-text-dim); margin-right: 0.25rem; }
.ct-bulk-chip { font-size: 0.74rem; padding: 0.3rem 0.6rem; }

/* Stop-loss: warning + press-and-hold reset */
.ct-shop-stopped { font-size: 0.78rem; color: var(--ct-danger); margin-bottom: 0.5rem; }
.ct-hold-btn { position: relative; overflow: hidden; text-align: center; user-select: none; touch-action: none; }
.ct-hold-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0;
  background: var(--ct-accent);
  opacity: 0.35;
}
.ct-hold-btn.is-holding .ct-hold-fill { width: 100%; transition: width 1.5s linear; } /* duration overridden inline per holdButton */
.ct-hold-label { position: relative; z-index: 1; }

.ct-shop-list { display: flex; flex-direction: column; gap: 0.75rem; }
.ct-shop {
  background: var(--ct-surface-2);
  border: 1px solid var(--ct-border);
  border-radius: var(--ct-radius-sm);
  padding: 0.8rem;
}
.ct-shop-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }
.ct-shop-header .ct-shop-rate { margin-left: auto; }
.ct-shop-body { display: flex; flex-direction: column; }
.ct-shop-title { font-weight: 600; }
.ct-shop-rate { color: var(--ct-accent-2); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.ct-field-label { display: block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ct-text-dim); margin-bottom: 0.4rem; }

/* Product picker — tappable candy chips + a Closed chip */
.ct-shop-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.4rem;
  margin-bottom: 0.7rem;
}
.ct-chip {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  background: var(--ct-bg);
  border: 1px solid var(--ct-border);
  border-radius: var(--ct-radius-sm);
  padding: 0.4rem 0.5rem;
  color: var(--ct-text);
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.12s, background 0.12s;
}
.ct-chip:hover { border-color: var(--ct-accent); }
.ct-chip-selected {
  border-color: var(--ct-accent);
  background: rgba(230, 162, 60, 0.14);
}
.ct-chip-name { font-size: 0.8rem; font-weight: 600; line-height: 1.2; }
.ct-chip-subrow { display: flex; align-items: baseline; gap: 0.15rem; }
.ct-chip-sub { font-size: 0.72rem; color: var(--ct-text-dim); font-variant-numeric: tabular-nums; }
.ct-chip-trend { font-size: 0.72rem; font-weight: 700; }
.ct-chip-trend.ct-trend-up { color: var(--ct-accent-2); }
.ct-chip-trend.ct-trend-down { color: var(--ct-danger); }
.ct-chip-selected .ct-chip-sub { color: var(--ct-accent); }

.ct-shop-upgrades { display: flex; flex-direction: column; gap: 0.4rem; }

/* ── Buttons ── */
.ct-btn {
  font: inherit;
  font-size: 0.82rem;
  border: 1px solid var(--ct-border);
  border-radius: var(--ct-radius-sm);
  padding: 0.45rem 0.7rem;
  background: var(--ct-surface);
  color: var(--ct-text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.ct-btn:hover:not(:disabled) { border-color: var(--ct-accent); }
.ct-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ct-btn-primary { background: var(--ct-accent); color: #1a1205; border-color: var(--ct-accent); font-weight: 600; text-align: center; }
.ct-btn-ghost { background: transparent; text-align: center; }
.ct-btn-buy { background: var(--ct-surface); }
.ct-btn-research { width: 100%; text-align: center; border-style: dashed; border-color: var(--ct-accent); color: var(--ct-accent); }
.ct-btn-opt { font-size: 0.78rem; }
.ct-btn-upgrade { font-size: 0.78rem; }
.ct-topbar-action { flex: 0 0 auto; }

/* Panel header with a collapse-all toggle on the right. */
.ct-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.ct-panel-titlewrap { display: flex; align-items: baseline; gap: 0.5rem; min-width: 0; }
.ct-shop-total { font-size: 0.75rem; font-weight: 600; color: var(--ct-accent-2); white-space: nowrap; }
.ct-collapse-all {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--ct-text-dim);
  font-size: 1rem;
  line-height: 1;
  padding: 0.15rem 0.3rem;
  cursor: pointer;
  border-radius: var(--ct-radius-sm);
}
.ct-collapse-all:hover { color: var(--ct-accent); background: var(--ct-surface-2); }

/* Bulk-buy multiplier selector */
.ct-buy-mult {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0.1rem 0 0.6rem;
}
.ct-buy-mult-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ct-text-dim);
  margin-right: 0.15rem;
}
.ct-buy-mult-btn {
  flex: 1;
  background: var(--ct-surface);
  border: 1px solid var(--ct-border);
  color: var(--ct-text-dim);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.25rem 0;
  border-radius: var(--ct-radius-sm);
  cursor: pointer;
}
.ct-buy-mult-btn:hover { color: var(--ct-text); border-color: var(--ct-accent); }
.ct-buy-mult-btn.is-on {
  background: var(--ct-accent);
  border-color: var(--ct-accent);
  color: #1a1207;
}

/* Purchased-upgrades fold in the Information panel. */
.ct-owned { margin-top: 0.75rem; }
.ct-owned-title { font-size: 0.85rem; font-weight: 600; color: var(--ct-text-dim); }
.ct-owned-list { display: flex; flex-direction: column; gap: 0.3rem; padding-top: 0.4rem; }
.ct-owned-item {
  font-size: 0.82rem;
  color: var(--ct-text-dim);
  padding: 0.25rem 0.5rem;
  background: var(--ct-surface-2);
  border-radius: var(--ct-radius-sm);
}

/* Market-conditions readout in the news bar, between the MARKET tag and the crawl. */
.ct-market-status {
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ct-accent-2);
  cursor: help;
  white-space: nowrap;
  padding-right: 0.75rem;
  margin-right: 0.5rem;
  border-right: 1px solid var(--ct-border);
}

/* R&D Department auto-buy toggle (shown once that upgrade is owned). */
.ct-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  padding: 0.5rem 0.65rem;
  background: var(--ct-surface-2);
  border: 1px solid var(--ct-border);
  border-radius: var(--ct-radius-sm);
  cursor: pointer;
  user-select: none;
}
.ct-toggle-input { accent-color: var(--ct-accent); cursor: pointer; }
.ct-toggle-label { color: var(--ct-text-dim); font-size: 0.9rem; }
