/* studio.css -- the browser-side cartogram page.
 *
 * Everything is namespaced: --cs-* custom properties, .cs-scoped selectors,
 * cs-* ids. The host site already owns --ink, --line, --bg, .wrap and bare
 * h1/button/select rules, so nothing here may be defined on a bare element.
 * Written by hand -- an earlier attempt to namespace a stylesheet by regex
 * produced a parse error that silently killed the whole file.
 */

:root {
  --cs-paper: #fff;
  --cs-ink: #16181d;
  --cs-dim: #5c6370;
  --cs-line: #e3e6ea;
  --cs-rule: #cfd4da;
  --cs-panel: #f7f8fa;
  --cs-accent: #0072b2;
  --cs-warn: #d55e00;
  --cs-state: #d8dce1;
  --cs-outline: #9aa2ad;
  --cs-ghost: #b6bcc4;
  --cs-cell: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --cs-paper: #14161a;
    --cs-ink: #e8eaee;
    --cs-dim: #99a1ad;
    --cs-line: #2a2e35;
    --cs-rule: #3a3f47;
    --cs-panel: #1b1e23;
    --cs-accent: #4ea3dd;
    --cs-warn: #ef8b45;
    --cs-state: #333840;
    --cs-outline: #6d7580;
    --cs-ghost: #454b54;
    --cs-cell: #0f1114;
  }
}

:root[data-theme="dark"] {
  --cs-paper: #14161a; --cs-ink: #e8eaee; --cs-dim: #99a1ad;
  --cs-line: #2a2e35; --cs-rule: #3a3f47; --cs-panel: #1b1e23;
  --cs-accent: #4ea3dd; --cs-warn: #ef8b45; --cs-state: #333840;
  --cs-outline: #6d7580; --cs-ghost: #454b54; --cs-cell: #0f1114;
}
:root[data-theme="light"] {
  --cs-paper: #fff; --cs-ink: #16181d; --cs-dim: #5c6370;
  --cs-line: #e3e6ea; --cs-rule: #cfd4da; --cs-panel: #f7f8fa;
  --cs-accent: #0072b2; --cs-warn: #d55e00; --cs-state: #d8dce1;
  --cs-outline: #9aa2ad; --cs-ghost: #b6bcc4; --cs-cell: #ffffff;
}

.cs {
  max-width: 1180px;
  margin: 0 auto;
  color: var(--cs-ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.cs-head { margin: 0 0 28px; }

.cs .cs-title {
  margin: 0 0 10px;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
  color: var(--cs-ink);
}

.cs-lede {
  margin: 0;
  max-width: 62ch;
  color: var(--cs-dim);
  font-size: 15.5px;
}

.cs-link { color: var(--cs-accent); text-decoration: none; white-space: nowrap; }
.cs-link:hover { text-decoration: underline; }

/* ------------------------------------------------------------- layout ---- */

.cs-layout {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

@media (max-width: 860px) {
  .cs-layout { grid-template-columns: minmax(0, 1fr); }
  .cs-panel { position: static !important; }
}

/* ------------------------------------------------------------- panel ---- */

.cs-panel {
  position: sticky;
  top: 16px;
  background: var(--cs-panel);
  border: 1px solid var(--cs-line);
  border-radius: 10px;
  padding: 4px 16px 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.cs-group {
  padding: 14px 0;
  border-bottom: 1px solid var(--cs-line);
}
.cs-group:last-child { border-bottom: 0; }

.cs-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  color: var(--cs-dim);
}

.cs-out {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--cs-ink);
}

.cs-note {
  margin: 7px 0 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--cs-dim);
}

.cs .cs-select,
.cs .cs-num {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 9px;
  font: inherit;
  font-size: 14px;
  color: var(--cs-ink);
  background: var(--cs-paper);
  border: 1px solid var(--cs-rule);
  border-radius: 6px;
}

.cs .cs-range {
  width: 100%;
  margin: 2px 0 0;
  accent-color: var(--cs-accent);
}

.cs-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
  font-size: 13.5px;
  color: var(--cs-ink);
  cursor: pointer;
}
.cs-check input { accent-color: var(--cs-accent); margin: 0; }

.cs-row { display: flex; gap: 8px; }
.cs-row .cs-num { flex: 1; }

.cs .cs-btn {
  display: block;
  width: 100%;
  margin-top: 9px;
  padding: 8px 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--cs-ink);
  background: var(--cs-paper);
  border: 1px solid var(--cs-rule);
  border-radius: 6px;
  cursor: pointer;
}
.cs .cs-btn:hover { border-color: var(--cs-accent); color: var(--cs-accent); }
.cs .cs-btn:disabled { opacity: 0.5; cursor: default; }
.cs .cs-btn:disabled:hover { border-color: var(--cs-rule); color: var(--cs-ink); }

.cs .cs-row .cs-btn { width: auto; margin-top: 0; flex: 0 0 auto; }

.cs .cs-btn-primary {
  margin-top: 0;
  color: #fff;
  background: var(--cs-accent);
  border-color: var(--cs-accent);
}
.cs .cs-btn-primary:hover { color: #fff; filter: brightness(1.08); }

/* -------------------------------------------------------------- stage ---- */

.cs-mapwrap {
  position: relative;
  background: var(--cs-paper);
  border: 1px solid var(--cs-line);
  border-radius: 10px;
  overflow: hidden;
}

.cs-map { display: block; width: 100%; height: auto; }

.cs-progress {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: color-mix(in srgb, var(--cs-paper) 82%, transparent);
  font-size: 13px;
  color: var(--cs-dim);
  z-index: 2;
}

.cs-progress-bar {
  width: 190px;
  height: 3px;
  background: var(--cs-line);
  border-radius: 2px;
  overflow: hidden;
}
.cs-progress-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--cs-accent);
  transition: width 0.12s linear;
}

/* -------------------------------------------------------------- stats ---- */

.cs-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  margin: 14px 0 0;
  background: var(--cs-line);
  border: 1px solid var(--cs-line);
  border-radius: 8px;
  overflow: hidden;
}
.cs-stats > div { padding: 10px 12px; background: var(--cs-paper); }
.cs-stats dt {
  margin: 0 0 3px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  color: var(--cs-dim);
}
.cs-stats dd {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  color: var(--cs-ink);
}

.cs-warn {
  margin: 12px 0 0;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--cs-warn);
  background: color-mix(in srgb, var(--cs-warn) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--cs-warn) 32%, transparent);
  border-radius: 6px;
}

/* --------------------------------------------------------------- map ---- */

.cs-outline-path {
  fill: var(--cs-state);
  stroke: var(--cs-outline);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
}
.cs-has-cells .cs-outline-path { fill: none; }

.cs-cell {
  stroke: var(--cs-cell);
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
}

.cs-hull {
  fill: none;
  stroke: var(--cs-outline);
  stroke-width: 0.9;
  vector-effect: non-scaling-stroke;
}

.cs-ghost-path {
  fill: none;
  stroke: var(--cs-ghost);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  vector-effect: non-scaling-stroke;
}

.cs-lab {
  fill: var(--cs-dim);
  font-size: 9px;
  font-weight: 600;
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--cs-paper);
  stroke-width: 2.4;
  stroke-linejoin: round;
  pointer-events: none;
}

/* -------------------------------------------------------------- about ---- */

.cs-about {
  margin: 40px 0 0;
  padding-top: 22px;
  border-top: 1px solid var(--cs-line);
  max-width: 68ch;
}
.cs .cs-about h2 {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 600;
  color: var(--cs-ink);
}
.cs-about p { margin: 0 0 12px; font-size: 14.5px; color: var(--cs-dim); }
.cs-about code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  padding: 1px 4px;
  background: var(--cs-panel);
  border: 1px solid var(--cs-line);
  border-radius: 4px;
}
