/*
 * Sim kit styles: one look for every simulation, React or standalone HTML.
 * Source of truth; copied to public/shared/sim-kit.css by scripts/build-sim-kit.mjs.
 * Everything is opt-in through .sk-* classes; nothing here restyles bare elements
 * except inside .sk-page (the body class for standalone demos).
 */

:root {
  --sk-bg: #00152e;
  --sk-panel: #062a50;
  --sk-panel-2: #0a3463;
  --sk-border: rgba(76, 201, 240, 0.18);
  --sk-border-strong: rgba(76, 201, 240, 0.4);
  --sk-text: #e8eef7;
  --sk-muted: #9db1c9;
  --sk-accent: #ffc300; /* site gold: primary actions */
  --sk-accent-ink: #001d3d; /* text on gold */
  --sk-accent-2: #4cc9f0; /* site cyan: sliders, focus */
  --sk-ok: #34d399;
  --sk-warn: #fbbf24;
  --sk-danger: #f87171;
  --sk-radius: 10px;
  --sk-gap: 12px;
  --sk-font: 'Poppins', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --sk-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Body class for standalone demos */
.sk-page {
  margin: 0;
  background: var(--sk-bg);
  color: var(--sk-text);
  font: 14px/1.5 var(--sk-font);
  -webkit-font-smoothing: antialiased;
}
.sk-page *,
.sk-page *::before,
.sk-page *::after {
  box-sizing: border-box;
}

/* Layout */
.sk-layout {
  display: grid;
  gap: var(--sk-gap);
  grid-template-columns: minmax(0, 1fr);
  padding: var(--sk-gap);
}
@media (min-width: 900px) {
  .sk-layout--side {
    grid-template-columns: minmax(0, 1fr) 300px;
  }
}

/*
 * Side by side (wide screens): the animation column sets the height, and the controls column
 * (.sk-side) takes exactly that height and scrolls inside itself. An embedded demo is then as
 * tall as its animation, not as tall as its controls. `contain: size` keeps the column's content
 * out of the row height; the scroll chains to the page at its ends, so nothing traps the wheel.
 * Embedded demos must not size their stage in vh: the iframe's height follows the content.
 */
@media (min-width: 900px) {
  .sk-side {
    contain: size;
    align-self: stretch;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--sk-border) transparent;
  }
}

/*
 * Fullscreen (html.sk-fullscreen, set by the kit when the article's DemoFrame goes fullscreen):
 * a layout marked .sk-fit fills the screen; inside it a .sk-fill column stretches and the
 * .sk-grow element (the stage) takes the spare height. Narrow screens keep the normal flow.
 */
html.sk-fullscreen,
html.sk-fullscreen body {
  height: 100%;
}
@media (min-width: 900px) {
  html.sk-fullscreen .sk-fit {
    height: 100%;
    grid-template-rows: minmax(0, 1fr);
  }
  html.sk-fullscreen .sk-fit > * {
    min-height: 0;
  }
  html.sk-fullscreen .sk-fill {
    align-self: stretch;
    display: flex;
    flex-direction: column;
  }
  html.sk-fullscreen .sk-grow {
    flex: 1 1 0;
    align-self: stretch;
    min-height: 0;
    height: auto;
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
  }
}
.sk-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.sk-stack {
  display: flex;
  flex-direction: column;
  gap: var(--sk-gap);
}

/* Panels */
.sk-panel {
  background: var(--sk-panel);
  border: 1px solid var(--sk-border);
  border-radius: var(--sk-radius);
  padding: 14px;
}
.sk-panel-title {
  margin: 0 0 10px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--sk-accent-2);
}

/* Canvas */
.sk-canvas {
  display: block;
  width: 100%;
  border-radius: var(--sk-radius);
  border: 1px solid var(--sk-border);
  background: #000c1c;
}

/* Fields */
.sk-field {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
}
.sk-field:last-child {
  margin-bottom: 0;
}
.sk-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--sk-text);
}
.sk-value {
  font-family: var(--sk-mono);
  font-size: 0.8rem;
  color: var(--sk-accent);
  white-space: nowrap;
}
.sk-help {
  font-size: 0.75rem;
  color: var(--sk-muted);
}
.sk-help--warn {
  color: var(--sk-warn);
}
.sk-panel > .sk-row:not(:last-child),
.sk-panel > .sk-stats:not(:last-child) {
  margin-bottom: 12px;
}
.sk-range {
  width: 100%;
  margin: 0;
  accent-color: var(--sk-accent-2);
  cursor: pointer;
}
/* A slider with unphysical zones (ui.slider(...).setZones): those parts of the track are red.
   The track is drawn here, so it carries the value fill (--sk-value) and the zones itself. */
.sk-range--zones {
  -webkit-appearance: none;
  appearance: none;
  height: 18px;
  background: transparent;
  --sk-zones: linear-gradient(
    to right,
    var(--sk-danger) var(--sk-zone-lo, 0%),
    transparent var(--sk-zone-lo, 0%),
    transparent var(--sk-zone-hi, 100%),
    var(--sk-danger) var(--sk-zone-hi, 100%)
  );
  --sk-fill: linear-gradient(to right, var(--sk-accent-2) var(--sk-value, 0%), #3b3b3b var(--sk-value, 0%));
}
.sk-range--zones::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: var(--sk-zones), var(--sk-fill);
}
.sk-range--zones::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--sk-zones), var(--sk-fill);
}
.sk-range--zones::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border: 2px solid var(--sk-bg);
  border-radius: 50%;
  background: var(--sk-accent-2);
}
.sk-range--zones::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2px solid var(--sk-bg);
  border-radius: 50%;
  background: var(--sk-accent-2);
}
.sk-help--danger {
  color: var(--sk-danger);
}
.sk-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}
.sk-check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--sk-accent-2);
}
.sk-select,
.sk-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--sk-border);
  background: var(--sk-panel-2);
  color: var(--sk-text);
  font: inherit;
  font-size: 0.85rem;
}

/* Buttons */
.sk-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--sk-border-strong);
  background: var(--sk-panel-2);
  color: var(--sk-text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.sk-btn:hover {
  border-color: var(--sk-accent-2);
}
.sk-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.sk-btn--primary {
  background: var(--sk-accent);
  border-color: var(--sk-accent);
  color: var(--sk-accent-ink);
  font-weight: 600;
}
.sk-btn--primary:hover {
  background: #ffd23f;
  border-color: #ffd23f;
}
.sk-btn--ghost {
  background: transparent;
}
.sk-btn[aria-pressed='true'] {
  border-color: var(--sk-accent-2);
  color: var(--sk-accent-2);
}

/* Readouts */
.sk-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}
.sk-stat {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--sk-panel-2);
  border: 1px solid var(--sk-border);
}
.sk-stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--sk-muted);
}
.sk-stat-value {
  display: block;
  font-family: var(--sk-mono);
  font-size: 0.95rem;
  color: var(--sk-text);
  font-variant-numeric: tabular-nums;
}

/* Progress (long computations: Monte Carlo, basin maps). Use <progress class="sk-progress"> */
.sk-progress {
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 999px;
  background: var(--sk-panel-2);
  overflow: hidden;
  appearance: none;
}
.sk-progress::-webkit-progress-bar {
  background: var(--sk-panel-2);
  border-radius: 999px;
}
.sk-progress::-webkit-progress-value {
  background: var(--sk-accent-2);
  border-radius: 999px;
}
.sk-progress::-moz-progress-bar {
  background: var(--sk-accent-2);
  border-radius: 999px;
}

/* Focus: visible for keyboard users everywhere */
.sk-btn:focus-visible,
.sk-range:focus-visible,
.sk-select:focus-visible,
.sk-input:focus-visible,
.sk-check input:focus-visible,
.sk-canvas:focus-visible {
  outline: 2px solid var(--sk-accent-2);
  outline-offset: 2px;
}

/*
 * Full-window app (body.sk-page.sk-app): a demo opened on its own fills the window exactly, nothing
 * scrolls. Wide screens: a title bar, the controls panel on the left (scrolls by itself) and the
 * views filling the rest edge to edge. Small screens: the views fill the screen, the bar keeps only
 * its back link, and the controls become a sheet that slides up (handle: ui.controlSheet).
 * Markup: .sk-app-bar, then .sk-app-main > .sk-app-stage + .sk-app-controls. Preview mode is untouched.
 */
.sk-app:not(.sk-preview) {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.sk-app:not(.sk-preview) .sk-app-bar {
  display: flex;
  align-items: center;
  gap: 6px 20px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--sk-border);
}
.sk-app:not(.sk-preview) .sk-app-bar > :first-child {
  flex: 1;
  min-width: 0;
}
.sk-app:not(.sk-preview) .sk-app-main {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 0;
}
.sk-app:not(.sk-preview) .sk-app-controls {
  order: -1;
  display: flex;
  flex-direction: column;
  gap: var(--sk-gap);
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px;
  border-right: 1px solid var(--sk-border);
}
.sk-app:not(.sk-preview) .sk-app-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
}
.sk-sheet-handle {
  display: none;
}
@media (max-width: 899px) {
  .sk-app:not(.sk-preview) {
    --sk-peek: 52px;
    display: block;
  }
  .sk-app:not(.sk-preview) .sk-app-bar {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 20;
    padding: 0;
    border: 0;
  }
  .sk-app:not(.sk-preview) .sk-app-bar > :not(a) {
    display: none;
  }
  .sk-app:not(.sk-preview) .sk-app-bar a {
    padding: 6px 12px;
    font-size: 0.8rem;
  }
  .sk-app:not(.sk-preview) .sk-app-main {
    display: block;
  }
  .sk-app:not(.sk-preview) .sk-app-stage {
    position: absolute;
    inset: 0 0 var(--sk-peek) 0;
  }
  .sk-app:not(.sk-preview) .sk-app-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    max-height: 72%;
    padding: 0 10px calc(10px + env(safe-area-inset-bottom));
    border: 0;
    border-top: 1px solid var(--sk-border);
    border-radius: 16px 16px 0 0;
    background: var(--sk-bg);
    box-shadow: 0 -8px 24px rgb(0 0 0 / 0.35);
    transform: translateY(calc(100% - var(--sk-peek)));
    transition: transform 0.25s ease;
  }
  .sk-app:not(.sk-preview) .sk-app-controls.is-open {
    transform: none;
  }
  .sk-app:not(.sk-preview) .sk-sheet-handle {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 1;
    height: var(--sk-peek);
    margin: 0 -10px;
    padding: 0;
    border: 0;
    background: var(--sk-bg);
    color: var(--sk-text);
    font: 600 0.95rem var(--sk-font);
    cursor: pointer;
  }
}
@media (max-width: 899px) and (prefers-reduced-motion: reduce) {
  .sk-app .sk-app-controls {
    transition: none;
  }
}

/* Visually hidden, still read by screen readers */
.sk-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;
}

/* Embedded in an article iframe: hide standalone-only chrome (e.g. "back to the article") */
.sk-in-frame .sk-hide-in-frame {
  display: none !important;
}

/* Preview mode (?preview=1): hide chrome, let the canvas fill the card */
.sk-preview .sk-hide-in-preview {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .sk-btn {
    transition: none;
  }
}

/* Guided tour (ui.tour): a card in a corner of the stage, and an outline on what the step is about. */
.sk-tour {
  position: absolute;
  z-index: 40;
  left: 12px;
  bottom: 12px;
  width: min(370px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow-y: auto;
  padding: 12px 14px;
  border: 1px solid var(--sk-border-strong);
  border-radius: var(--sk-radius);
  background: var(--sk-panel);
  color: var(--sk-text);
  font-size: 0.88rem;
  line-height: 1.5;
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.45);
}
.sk-tour[hidden] {
  display: none;
}
.sk-tour--right {
  left: auto;
  right: 12px;
}
.sk-tour--top {
  top: 12px;
  bottom: auto;
}
.sk-tour-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--sk-muted);
  font-size: 0.75rem;
}
.sk-tour-close {
  border: 0;
  background: none;
  color: var(--sk-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.sk-tour-close:hover {
  color: var(--sk-text);
}
.sk-tour-title {
  margin: 2px 0 6px;
  color: var(--sk-accent);
  font-size: 1rem;
  font-weight: 600;
}
.sk-tour-body p {
  margin: 0 0 6px;
}
.sk-tour-task {
  display: flex;
  gap: 8px;
  margin: 8px 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--sk-panel-2);
}
.sk-tour-task[hidden] {
  display: none;
}
.sk-tour-task.is-done {
  color: var(--sk-ok);
}
.sk-tour-check {
  flex: none;
  font-weight: 700;
}
.sk-tour-nav {
  justify-content: flex-end;
}
.sk-tour--offer .sk-tour-body {
  margin: 0 0 10px;
}
.sk-tour-focus {
  outline: 3px solid var(--sk-accent) !important;
  outline-offset: -3px;
  border-radius: 8px;
}
/* The tour's start button inside the controls is for phones (wide screens have it in the title bar). */
.sk-tour-start {
  display: none;
}
@media (max-width: 899px) {
  .sk-app:not(.sk-preview) .sk-tour-start {
    display: inline-flex;
  }
}

/* Author credit inside every animation (ui.credit, <Credit /> in React): bottom-right, unobtrusive.
   Under the guided-tour card (z-index 40) and the controls sheet; hidden in preview mode. */
.sk-credit {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 5;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgb(0 21 46 / 0.62);
  color: var(--sk-muted);
  font: 500 0.7rem/1.5 var(--sk-font);
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}
.sk-preview .sk-credit {
  display: none;
}
