/* ==========================================================================
   EasySorting HIG design system
   A professional, iOS Human Interface Guidelines inspired design language.
   Light and dark themes, hairline separators, grouped cards, fluid motion.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
  --bg: #F2F2F7;                        /* systemGroupedBackground */
  --bg-2: #FFFFFF;                      /* secondarySystemGroupedBackground */
  --bg-3: #E5E5EA;                      /* tertiarySystemGroupedBackground */
  --bg-4: #D1D1D6;
  --fill: rgba(120, 120, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.18);
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);
  --label-3: rgba(60, 60, 67, 0.38);
  --sep: rgba(60, 60, 67, 0.29);        /* hairline separator, iOS 76 */

  --accent: #007AFF;                    /* iOS blue */
  --accent-press: #0060D6;
  --accent-soft: rgba(0, 122, 255, 0.12);
  --indigo: #5856D6;
  --teal: #30B0C7;
  --purple: #AF52DE;
  --pink: #FF2D55;
  --red: #FF3B30;
  --orange: #FF9500;
  --yellow: #FFCC00;
  --green: #34C759;
  --mint: #00C7BE;

  --shadow-1: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-3: 0 16px 40px rgba(0, 0, 0, 0.18);

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Roboto Mono",
          monospace;

  --ease-ios: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur: 0.45s;
}

html[data-theme="dark"] {
  --bg: #000000;
  --bg-2: #1C1C1E;
  --bg-3: #2C2C2E;
  --bg-4: #3A3A3C;
  --fill: rgba(120, 120, 128, 0.24);
  --fill-2: rgba(120, 120, 128, 0.36);
  --label: #FFFFFF;
  --label-2: rgba(235, 235, 245, 0.6);
  --label-3: rgba(235, 235, 245, 0.32);
  --sep: rgba(84, 84, 88, 0.65);

  --accent: #0A84FF;
  --accent-press: #409CFF;
  --accent-soft: rgba(10, 132, 255, 0.18);

  --shadow-1: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.55);
  --shadow-3: 0 16px 40px rgba(0, 0, 0, 0.65);
}

/* --------------------------------------------------------------------------
   2. Reset and base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
  color: var(--label);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color var(--dur) var(--ease-ios),
              color var(--dur) var(--ease-ios);
}

img, svg, video { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-decoration: none; transition: color 0.2s ease; }
a:hover { text-decoration: none; color: var(--accent-press); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
::selection { background: var(--accent-soft); color: var(--label); }

h1, h2, h3, h4, p { margin: 0; }

a.skip-link {
  position: absolute; left: -1000px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: 10px 16px;
  border-radius: 0 0 12px 0;
}
a.skip-link:focus { left: 0; color: #fff; }

/* --------------------------------------------------------------------------
   3. Shell and layout
   -------------------------------------------------------------------------- */
.shell {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}
.shell--narrow { max-width: 860px; }
.shell--wide { max-width: 1240px; }

main.playing-field {
  padding-top: 16px;
  padding-bottom: 72px;
}

/* --------------------------------------------------------------------------
   4. Glass navigation
   -------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--sep);
  transition: background-color var(--dur) var(--ease-ios);
}
@supports not (backdrop-filter: blur(1px)) {
  .topbar { background: var(--bg); }
}
.topbar__inner {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 56px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--label);
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand__mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--indigo));
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 2px 6px rgba(0, 122, 255, 0.35);
}
.brand:hover { color: var(--label); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  list-style: none;
  padding: 0;
}
.nav-links a {
  display: block;
  padding: 7px 13px;
  border-radius: 10px;
  color: var(--label-2);
  font-size: 15px;
  font-weight: 500;
  transition: color 0.2s ease, background-color 0.2s ease;
}
.nav-links a:hover { color: var(--label); background: var(--fill); }
.nav-links a.nav-active { color: var(--accent); }

.theme-toggle {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--label-2);
  background: var(--fill);
  transition: transform 0.3s var(--ease-spring), color 0.2s ease,
              background-color 0.2s ease;
}
.theme-toggle:hover { color: var(--label); transform: rotate(16deg); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 8px;
  border-radius: 12px;
  background: var(--fill);
}
.nav-toggle span {
  display: block;
  height: 2px;
  border-radius: 2px;
  background: var(--label);
  transition: transform 0.3s var(--ease-ios), opacity 0.2s ease;
}
.nav-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav-links.nav-mobile {
  position: fixed;
  inset: 56px 12px auto 12px;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  margin: 0;
  padding: 10px;
  background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border: 1px solid var(--sep);
  border-radius: 20px;
  box-shadow: var(--shadow-2);
  transform: translateY(-8px) scale(0.98);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s var(--ease-ios), opacity 0.25s ease;
}
.nav-links.nav-mobile.nav-show {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}
.nav-links.nav-mobile a { padding: 13px 14px; font-size: 16px; border-radius: 12px; }

/* --------------------------------------------------------------------------
   5. Hero, titles, breadcrumbs
   -------------------------------------------------------------------------- */
.hero {
  padding: 40px 0 8px;
  animation: rise-in 0.7s var(--ease-ios) both;
}
.hero--tool { padding-top: 28px; }
@keyframes rise-in {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 14px;
  color: var(--label-3);
  font-size: 13px;
}
.breadcrumbs a { color: var(--label-2); }
.breadcrumbs a:hover { color: var(--accent); }
.breadcrumbs .crumb-sep::before { content: "/"; margin: 0 2px; color: var(--label-3); }

.hero__kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.hero__kicker::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--indigo));
}

.hero h1 {
  font-size: clamp(32px, 5vw, 46px);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.08;
  max-width: 22ch;
}
.hero__lead {
  margin-top: 16px;
  font-size: 19px;
  line-height: 1.6;
  color: var(--label-2);
  max-width: 62ch;
}

/* --------------------------------------------------------------------------
   6. Sections and section titles
   -------------------------------------------------------------------------- */
.section { margin-top: 56px; scroll-margin-top: 80px; }
.section__head { margin-bottom: 18px; }
.section__title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.section__title sup { font-weight: 700; }
.section__title .t-index {
  font-size: 15px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.section__desc { margin-top: 6px; color: var(--label-2); max-width: 66ch; }

/* --------------------------------------------------------------------------
   7. Cards and grids
   -------------------------------------------------------------------------- */
.card {
  background: var(--bg-2);
  border: 1px solid var(--sep);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  transition: transform 0.35s var(--ease-ios), box-shadow 0.35s var(--ease-ios),
              border-color 0.3s ease;
}
.card--lift:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-2);
  border-color: color-mix(in srgb, var(--sep) 45%, var(--accent));
}
.card--pad { padding: 22px; }
.card--pad-lg { padding: 28px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}
.card-grid--3 { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.alg-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
}
.alg-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.alg-card__name { font-size: 19px; font-weight: 700; }
.alg-card__desc { color: var(--label-2); font-size: 15px; line-height: 1.5; flex: 1; }
.alg-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  color: var(--label-2);
}
.alg-card__go {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  margin-top: 2px;
}
.alg-card__go .go-arrow { transition: transform 0.3s var(--ease-ios); }
.alg-card:hover .alg-card__go .go-arrow { transform: translateX(4px); }

.orb {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}

.alg-thumb {
  width: 48px;
  height: 48px;
  border-radius: 13px;
  object-fit: cover;
  box-shadow: var(--shadow-1);
  border: 1px solid var(--sep);
  flex-shrink: 0;
  background: var(--fill);
}

.brand__mark img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
  display: block;
}
.brand__mark.brand__mark--logo { background: transparent; box-shadow: none; }

.footer-social {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.footer-social a {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--fill);
  border: 1px solid var(--sep);
  transition: transform 0.25s var(--ease-spring), background-color 0.2s ease;
}
.footer-social a:hover { background: var(--fill-2); transform: translateY(-2px); }
.footer-social img { width: 19px; height: 19px; object-fit: contain; }

/* --------------------------------------------------------------------------
   8. Grouped inset list
   -------------------------------------------------------------------------- */
.glist { background: var(--bg-2); border: 1px solid var(--sep); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); overflow: hidden; }
.glist__cell {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 20px;
  position: relative;
}
.glist__cell + .glist__cell { border-top: 1px solid var(--sep); }
.glist__cell--link:hover { background: var(--fill); }
.glist__cell:active { background: var(--fill-2); }
.glist__main { flex: 1; min-width: 0; }
.glist__title { font-weight: 600; font-size: 16px; }
.glist__desc { color: var(--label-2); font-size: 14px; margin-top: 2px; }
.glist__chevron { color: var(--label-3); transition: transform 0.3s var(--ease-ios); transform: translateX(0); }
.glist__cell:hover .glist__chevron { transform: translateX(3px); color: var(--accent); }

/* --------------------------------------------------------------------------
   9. Buttons, segmented control, chips
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  color: var(--label);
  background: var(--bg-3);
  border: 1px solid transparent;
  transition: transform 0.16s var(--ease-ios), box-shadow 0.25s ease,
              background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
  will-change: transform;
}
.btn:hover { background: var(--fill-2); }
.btn:active { transform: scale(0.965); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn--accent { color: #fff; background: var(--accent); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 40%, transparent); }
.btn--accent:hover { background: var(--accent-press); color: #fff; }
.btn--accent:active { box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 40%, transparent); }
.btn--subtle { background: var(--fill); }
.btn--subtle:hover { background: var(--fill-2); }
.btn--ghost { background: transparent; color: var(--accent); }
.btn--ghost:hover { background: var(--accent-soft); }
.btn--sm { padding: 7px 13px; font-size: 14px; border-radius: 11px; }
.btn--lg { padding: 15px 28px; font-size: 17px; border-radius: 16px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn .spin { display: none; }
.btn.is-busy .spin { display: inline-block; }
.btn.is-busy { pointer-events: none; opacity: 0.8; }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--fill);
  border-radius: 12px;
  flex-wrap: wrap;
}
.segmented button {
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--label-2);
  transition: color 0.2s ease, background-color 0.25s var(--ease-ios),
              box-shadow 0.25s ease, transform 0.16s var(--ease-ios);
}
.segmented button:hover { color: var(--label); }
.segmented button:active { transform: scale(0.96); }
.segmented button.is-on {
  color: var(--label);
  background: var(--bg-2);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.chip--accent  { color: var(--accent);  background: color-mix(in srgb, var(--accent) 14%, transparent); }
.chip--green   { color: var(--green);   background: color-mix(in srgb, var(--green)  14%, transparent); }
.chip--orange  { color: var(--orange);  background: color-mix(in srgb, var(--orange) 14%, transparent); }
.chip--red     { color: var(--red);     background: color-mix(in srgb, var(--red)    14%, transparent); }
.chip--purple  { color: var(--purple);  background: color-mix(in srgb, var(--purple) 14%, transparent); }
.chip--indigo  { color: var(--indigo);  background: color-mix(in srgb, var(--indigo) 14%, transparent); }
.chip--teal    { color: var(--teal);    background: color-mix(in srgb, var(--teal)   14%, transparent); }
.chip--yellow  { color: #B58300;        background: color-mix(in srgb, var(--yellow) 22%, transparent); }
html[data-theme="dark"] .chip--yellow { color: var(--yellow); }

.badge-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   10. Tables
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--sep); border-radius: var(--radius-lg); background: var(--bg-2); box-shadow: var(--shadow-1); }
table.hig {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  min-width: 640px;
}
table.hig caption { caption-side: bottom; padding: 12px 16px; font-size: 13px; color: var(--label-3); text-align: left; }
table.hig th {
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--label-2);
  padding: 13px 16px;
  background: color-mix(in srgb, var(--bg-2) 86%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--sep);
  white-space: nowrap;
}
table.hig td { padding: 14px 16px; border-bottom: 1px solid var(--sep); vertical-align: middle; }
table.hig tbody tr:last-child td { border-bottom: none; }
table.hig tbody tr { transition: background-color 0.2s ease; }
table.hig tbody tr:hover { background: var(--fill); }
table.hig td.num, table.hig th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.hig a { font-weight: 600; }

/* --------------------------------------------------------------------------
   11. FAQ accordion
   -------------------------------------------------------------------------- */
.faq { display: grid; gap: 12px; }
details.faq-item {
  background: var(--bg-2);
  border: 1px solid var(--sep);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  transition: border-color 0.25s ease;
}
details.faq-item[open] { border-color: color-mix(in srgb, var(--sep) 50%, var(--accent)); }
details.faq-item summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
}
details.faq-item summary::-webkit-details-marker { display: none; }
details.faq-item summary .q-mark {
  color: var(--accent);
  font-weight: 800;
  flex-shrink: 0;
}
details.faq-item summary .faq-chevron {
  margin-left: auto;
  color: var(--label-3);
  transition: transform 0.35s var(--ease-ios);
  flex-shrink: 0;
}
details.faq-item[open] summary .faq-chevron { transform: rotate(180deg); }
.faq-item__body {
  padding: 0 18px 18px;
  color: var(--label-2);
  font-size: 15px;
}
.faq-item__body p + p { margin-top: 10px; }
.faq-item__body a { font-weight: 600; }

/* --------------------------------------------------------------------------
   12. Form controls
   -------------------------------------------------------------------------- */
.field { display: grid; gap: 8px; }
.field > label { font-size: 14px; font-weight: 600; color: var(--label-2); }

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--sep);
  background: color-mix(in srgb, var(--bg) 60%, var(--bg-2));
  color: var(--label);
  font-size: 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.25s ease;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  background: var(--bg-2);
}
input::placeholder { color: var(--label-3); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: var(--fill-2);
  outline-offset: 6px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s ease;
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.12); }
input[type="range"]:active::-webkit-slider-thumb { box-shadow: 0 1px 8px rgba(0, 0, 0, 0.45), 0 0 0 10px var(--accent-soft); }
input[type="range"]::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; border: none;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
}

.switch { position: relative; display: inline-block; width: 52px; height: 32px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch__track {
  position: absolute; inset: 0;
  border-radius: 32px;
  background: var(--fill-2);
  transition: background-color 0.25s var(--ease-ios);
}
.switch__knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s var(--ease-spring);
}
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked ~ .switch__knob { transform: translateX(20px); }
.switch input:focus-visible ~ .switch__track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------------------------
   13. Charts, bars, tracks, and tool widgets
   -------------------------------------------------------------------------- */
.chart-box { position: relative; width: 100%; }
.chart-box svg { width: 100%; height: auto; }
.chart-box svg .grid-line { stroke: var(--sep); stroke-width: 1; }
.chart-box svg .axis-label { fill: var(--label-3); font-size: 12px; font-family: var(--mono); }
.chart-box svg .curve-path {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.12));
}
.legend { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 14px; }
.legend__item { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--label-2); font-weight: 500; }
.legend__swatch { width: 16px; height: 4px; border-radius: 4px; }

.bar-row { display: grid; grid-template-columns: 132px 1fr 92px; gap: 12px; align-items: center; }
.bar-row + .bar-row { margin-top: 10px; }
.bar-row__label { font-size: 14px; font-weight: 600; text-align: right; white-space: nowrap; }
.bar-row__label small { display: block; font-weight: 500; color: var(--label-3); font-size: 12px; }
.bar-row__track { height: 22px; background: var(--fill); border-radius: 7px; overflow: hidden; position: relative; }
.bar-row__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--indigo));
  border-radius: 7px;
  width: 0%;
  transition: width 0.9s var(--ease-ios);
}
.bar-row__value { font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums; color: var(--label-2); }

.track-row { display: grid; grid-template-columns: 110px 1fr; gap: 12px; align-items: center; }
.track-row + .track-row { margin-top: 8px; }
.track-row__name { font-size: 13.5px; font-weight: 600; text-align: right; }
.track-row__rail { height: 26px; background: var(--fill); border-radius: 8px; overflow: hidden; position: relative; }
.track-row__racer {
  height: 100%;
  width: 0%;
  border-radius: 8px;
  transition: width 0.7s var(--ease-ios);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: var(--bg-2);
  border: 1px solid var(--sep);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-1);
}
.stat__label { font-size: 13px; color: var(--label-2); font-weight: 600; letter-spacing: 0.02em; }
.stat__value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat__hint { font-size: 12.5px; color: var(--label-3); margin-top: 2px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  padding: 18px;
  border: 1px solid var(--sep);
  background: var(--bg-2);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.toolbar .field { min-width: 190px; flex: 1; }

/* Slider with live value bubble */
.range-row { display: flex; align-items: center; gap: 14px; }
.range-row input { flex: 1; }
.range-value {
  min-width: 44px;
  text-align: center;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 8px;
}

/* --------------------------------------------------------------------------
   14. Tree visualizer (heap page)
   -------------------------------------------------------------------------- */
.tree-stage {
  background: var(--bg-2);
  border: 1px solid var(--sep);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 16px;
  overflow-x: auto;
}
.tree-stage svg { min-width: 420px; width: 100%; height: auto; }
.tree-stage svg .node-edge { stroke: var(--sep); stroke-width: 2; transition: stroke 0.3s ease; }
.tree-stage svg .node-edge.hot { stroke: var(--orange); stroke-width: 3.5; }
.tree-stage svg .node-circle { fill: var(--fill); stroke: var(--sep); stroke-width: 2; transition: fill 0.3s ease, stroke 0.3s ease, r 0.25s var(--ease-spring); }
.tree-stage svg .node-circle.hot { fill: color-mix(in srgb, var(--orange) 45%, transparent); stroke: var(--orange); }
.tree-stage svg .node-circle.done { fill: color-mix(in srgb, var(--green) 40%, transparent); stroke: var(--green); }
.tree-stage svg .node-circle.pivot { fill: color-mix(in srgb, var(--red) 45%, transparent); stroke: var(--red); }
.tree-stage svg .node-label { fill: var(--label); font-family: var(--mono); font-size: 14px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }

.array-strip { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.array-strip .cell {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--fill);
  font-family: var(--mono);
  font-weight: 700;
  transition: background-color 0.3s ease, transform 0.2s var(--ease-spring), box-shadow 0.3s ease;
}
.array-strip .cell.hot { background: var(--accent); color: #fff; transform: translateY(-3px); box-shadow: 0 6px 14px color-mix(in srgb, var(--accent) 45%, transparent); }
.array-strip .cell.done { background: color-mix(in srgb, var(--green) 35%, transparent); color: #0A5D21; }
html[data-theme="dark"] .array-strip .cell.done { color: #7DECA0; }

/* --------------------------------------------------------------------------
   15. Prose, steps, callouts
   -------------------------------------------------------------------------- */
.prose p { margin-top: 14px; color: var(--label); font-size: 17px; line-height: 1.65; }
.prose p + p { margin-top: 14px; }
.prose a { font-weight: 600; border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.prose strong { font-weight: 700; }
.prose ul, .prose ol { padding-left: 22px; margin-top: 14px; margin-bottom: 14px; }
.prose li { margin-top: 8px; line-height: 1.6; }
.prose code, .mono {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--fill);
  padding: 2px 7px;
  border-radius: 7px;
}

.steps { counter-reset: step; display: grid; gap: 12px; }
.step {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--sep);
  border-radius: var(--radius-md);
  padding: 16px 18px 16px 62px;
  box-shadow: var(--shadow-1);
}
.step::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 18px; top: 50%;
  transform: translateY(-50%);
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--indigo));
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-size: 15px;
}
.step__title { font-weight: 700; font-size: 16px; }
.step__desc { color: var(--label-2); font-size: 15px; margin-top: 3px; }

.callout {
  display: flex;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.55;
}
.callout + .callout { margin-top: 12px; }
.callout__icon { flex-shrink: 0; font-weight: 800; }
.callout--info  { background: var(--accent-soft); color: color-mix(in srgb, var(--accent) 65%, var(--label)); }
.callout--success { background: color-mix(in srgb, var(--green) 12%, transparent); color: color-mix(in srgb, var(--green) 60%, var(--label)); }
.callout--warn  { background: color-mix(in srgb, var(--orange) 14%, transparent); color: color-mix(in srgb, var(--orange) 55%, var(--label)); }
.callout a { text-decoration: underline; }

/* --------------------------------------------------------------------------
   16. Decision panel (hub page)
   -------------------------------------------------------------------------- */
.decision {
  background: var(--bg-2);
  border: 1px solid var(--sep);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 22px;
}
.decision__scenarios { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.scenario-btn {
  padding: 8px 15px;
  border-radius: var(--radius-pill);
  background: var(--fill);
  font-size: 14px;
  font-weight: 600;
  color: var(--label-2);
  transition: transform 0.16s var(--ease-ios), background-color 0.25s ease,
              color 0.25s ease, box-shadow 0.25s ease;
}
.scenario-btn:hover { color: var(--label); background: var(--fill-2); }
.scenario-btn:active { transform: scale(0.95); }
.scenario-btn.is-on { background: var(--accent); color: #fff; box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 45%, transparent); }
.decision__outcome {
  margin-top: 16px;
  padding: 18px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--bg) 60%, var(--bg-2));
  border: 1px dashed var(--sep);
  transition: background-color 0.3s ease;
}
.decision__outcome.is-fired { border-color: var(--accent); background: var(--accent-soft); }
.decision__pick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.decision__pick-name { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.decision__reason { color: var(--label-2); font-size: 15px; margin-top: 10px; max-width: 60ch; }
.decision__cta { display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; font-weight: 600; }

/* --------------------------------------------------------------------------
   17. Footer
   -------------------------------------------------------------------------- */
.footer {
  border-top: 1px solid var(--sep);
  background: color-mix(in srgb, var(--bg) 80%, var(--bg-2));
  padding: 44px 0 60px;
  margin-top: 48px;
}
.footer__grid { display: grid; grid-template-columns: 1.4fr repeat(3, 1fr); gap: 28px; }
.footer__brand { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 10px; color: var(--label); }
.footer__about { color: var(--label-2); font-size: 14px; line-height: 1.6; margin-top: 10px; max-width: 34ch; }
.footer h4 { font-size: 13px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--label-3); margin-bottom: 12px; }
.footer ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.footer a { color: var(--label-2); font-size: 14.5px; }
.footer a:hover { color: var(--accent); }
.footer__bottom {
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--sep);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
  justify-content: space-between;
  color: var(--label-3);
  font-size: 13px;
}

/* --------------------------------------------------------------------------
   18. Reveal-on-scroll and decorative motion
   -------------------------------------------------------------------------- */
[data-reveal] {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity 0.65s var(--ease-ios), transform 0.65s var(--ease-ios);
  transition-delay: var(--reveal-delay, 0ms);
}
[data-reveal].is-in { opacity: 1; transform: translateY(0); }

.float-slow { animation: float-slow 7s var(--ease-ios) infinite; }
@keyframes float-slow { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

.gradient-text {
  background: linear-gradient(110deg, var(--accent), var(--indigo) 60%, var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.7s linear infinite; }

.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.shake { animation: shake 0.5s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}

/* --------------------------------------------------------------------------
   19. 404 page
   -------------------------------------------------------------------------- */
.page-404 { min-height: 72vh; display: grid; place-items: center; padding: 40px 20px; text-align: center; }
.page-404__stage { position: relative; }
.bars-scene { display: flex; align-items: flex-end; gap: 6px; height: 110px; justify-content: center; margin-bottom: 22px; }
.bars-scene i {
  width: 18px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--accent), var(--indigo));
  transform-origin: bottom;
  transition: height 0.6s var(--ease-spring);
}
.bars-scene i:nth-child(1) { height: 40%; animation: wobble 3.4s 0.2s ease-in-out infinite alternate; }
.bars-scene i:nth-child(2) { height: 72%; animation: wobble 3.4s 0.7s ease-in-out infinite alternate; }
.bars-scene i:nth-child(3) { height: 30%; animation: wobble 3.4s 1.2s ease-in-out infinite alternate; }
.bars-scene i:nth-child(4) { height: 90%; animation: wobble 3.4s 0.5s ease-in-out infinite alternate; background: linear-gradient(180deg, var(--red), var(--orange)); }
.bars-scene i:nth-child(5) { height: 56%; animation: wobble 3.4s 1.6s ease-in-out infinite alternate; }
.bars-scene i:nth-child(6) { height: 78%; animation: wobble 3.4s 0.9s ease-in-out infinite alternate; }
.bars-scene i:nth-child(7) { height: 46%; animation: wobble 3.4s 1.4s ease-in-out infinite alternate; }
@keyframes wobble { 0% { transform: rotate(-3deg) translateY(0); } 100% { transform: rotate(3deg) translateY(-6px); } }

.page-404 h1 { font-size: clamp(64px, 14vw, 120px); font-weight: 900; letter-spacing: -0.04em; line-height: 1; }
.page-404 .punch { margin-top: 14px; font-size: 20px; font-weight: 600; min-height: 1.5em; }
.page-404 .help { margin-top: 10px; color: var(--label-2); max-width: 46ch; margin-inline: auto; }
.page-404 .acts { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 26px; }

/* --------------------------------------------------------------------------
   20. Utilities
   -------------------------------------------------------------------------- */
.stack { display: grid; gap: var(--stack-gap, 14px); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.row--between { justify-content: space-between; }
.center { text-align: center; margin-inline: auto; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; } .mt-4 { margin-top: 40px; }
.mb-2 { margin-bottom: 16px; }
.muted { color: var(--label-2); }
.tiny { font-size: 13px; color: var(--label-3); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }
.tabular { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   21. Reduced motion and print
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
  [data-reveal] { opacity: 1; transform: none; }
  .bars-scene i { animation: none !important; }
}

@media print {
  .topbar, .topbar-fix, .footer, .toolbar, .btn { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .table-wrap, .glist, .stat, .toolbar, .tree-stage { box-shadow: none; border-color: #ddd; }
}

/* --------------------------------------------------------------------------
   22. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .nav-links.desktop-links { display: none; }
  .nav-toggle { display: flex; }
  .footer__grid { grid-template-columns: 1fr 1fr; }
  .hero h1 { max-width: 15ch; }
  .bar-row, .track-row { grid-template-columns: 96px 1fr 76px; }
  .bar-row .bar-row__label { text-align: left; }
}

@media (max-width: 560px) {
  .footer__grid { grid-template-columns: 1fr; }
  .shell { padding: 0 16px; }
  .card--pad, .card--pad-lg { padding: 18px; }
  .step { padding-left: 56px; }
  .step::before { left: 14px; }
  .bar-row { grid-template-columns: 84px 1fr 60px; gap: 8px; }
}