/* Algo Animation — shared skin for every lesson page.
   Loaded after each lesson's style.css. It only re-skins (colour, type, surface, motion);
   spacing and layout stay in the lesson files so every trace still fits its viewport.
   Direction: a tracing notebook. Dot-grid paper, ink text, teal pen for "in the structure",
   amber highlighter for "happening now" (current element, executing line). */
:root {
  color-scheme: light dark;
  --sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'PingFang TC',
    'Noto Sans TC', sans-serif;
  --mono: 'IBM Plex Mono', 'SF Mono', Menlo, Consolas, monospace;
  --bg: #f4f6f9;
  --grid: #d5dbe3;
  --panel: #fff;
  --panel-2: #f8f9fb;
  --field: #fff;
  --well: #f3f5f8;
  --cell: #eef1f5;
  --cell-2: #e2e7ee;
  --line: #e2e6ec;
  --line-2: #cdd4dd;
  --line-3: #97a3b1;
  --text: #18202b;
  --muted: #566173;
  --faint: #8792a1;
  --active: #0b8a73;
  --active-line: #58b8a5;
  --active-bg: #dcf2ec;
  --active-ink: #06594b;
  --active-hover: #097562;
  --on-active: #fff;
  --focus: #b4560b;
  --focus-bg: #fdedcc;
  --danger: #c43349;
  --mint: var(--active);
  --orange: var(--focus);
  --shadow: 0 1px 2px #18202b0d, 0 10px 28px -16px #18202b30;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1217;
    --grid: #1d242d;
    --panel: #151a21;
    --panel-2: #12171d;
    --field: #0f1318;
    --well: #0f1419;
    --cell: #1d242d;
    --cell-2: #27313c;
    --line: #252d37;
    --line-2: #333d4a;
    --line-3: #5a6674;
    --text: #e7ebf0;
    --muted: #9ba6b3;
    --faint: #6d7987;
    --active: #4fd1b0;
    --active-line: #2f8f7b;
    --active-bg: #12392f;
    --active-ink: #a9f1dd;
    --active-hover: #80e2c8;
    --on-active: #06231d;
    --focus: #ffb46b;
    --focus-bg: #3b2b1b;
    --danger: #ff9d9d;
    --shadow: 0 1px 2px #0007, 0 12px 30px -16px #000c;
  }
}

body {
  font-family: var(--sans);
  background:
    radial-gradient(circle at 1px 1px, var(--grid) 1px, transparent 1.4px) 0 0/22px
      22px fixed,
    var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'tnum';
}
::selection {
  background: var(--focus-bg);
  color: var(--text);
}

/* Header & title */
header {
  border-bottom-color: var(--line);
}
.brand {
  font-family: var(--sans);
  letter-spacing: 0.06em;
  font-weight: 600;
}
.mark {
  background: var(--text);
  color: var(--bg);
  border-radius: 6px;
  font-family: var(--mono);
  box-shadow: 3px 3px 0 var(--active);
}
.edition,
.eyebrow {
  font-family: var(--mono);
  letter-spacing: 0.04em;
  color: var(--faint);
}
.eyebrow span {
  color: var(--focus);
}
h1 {
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.accent {
  color: var(--active);
  background: linear-gradient(transparent 62%, var(--focus-bg) 62%);
  padding: 0 2px;
}
.back-home {
  border-radius: 999px;
  border-color: var(--line-2);
  color: var(--active);
  background: var(--panel);
  font-family: var(--sans);
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease;
}
.complexity {
  font-family: var(--mono);
}
.complexity b {
  color: var(--active);
}

/* Inputs */
.inputs {
  background: var(--panel);
  border-color: var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
input:not([type='range']),
select,
textarea {
  background: var(--field);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  color: var(--text);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}
input:not([type='range']):focus,
textarea:focus,
select:focus {
  border-color: var(--active);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--active) 18%, transparent);
  outline: none;
}
textarea {
  font-family: var(--mono);
}
button {
  border-radius: 8px;
  border-color: var(--line-2);
  background: var(--panel);
  color: var(--text);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    transform 0.12s var(--ease);
}
button:active:not(:disabled) {
  transform: scale(0.97);
}
.examples button {
  border-radius: 999px;
  background: var(--panel-2);
  border-color: var(--line);
}
.primary {
  background: var(--active);
  border-color: var(--active);
  color: var(--on-active);
  box-shadow:
    inset 0 1px 0 #ffffff2e,
    0 6px 16px -8px color-mix(in srgb, var(--active) 70%, transparent);
}
@media (hover: hover) and (pointer: fine) {
  button:hover:not(:disabled) {
    background: var(--cell);
    border-color: var(--active);
  }
  .primary:hover:not(:disabled) {
    background: var(--active-hover);
    border-color: var(--active-hover);
    color: var(--on-active);
  }
  .back-home:hover {
    border-color: var(--active);
    background: var(--active-bg);
  }
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--active);
  outline-offset: 3px;
}
#error {
  color: var(--danger);
}

/* Panels */
.panel {
  background: var(--panel);
  border-color: var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.panel-head {
  background: var(--panel-2);
  border-bottom-color: var(--line);
  color: var(--muted);
  font-weight: 500;
}
.panel-head .tag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--active-bg);
  color: var(--active-ink);
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
.stats small {
  font-family: var(--mono);
  color: var(--muted);
}
.stats b {
  font-family: var(--mono);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.legend {
  color: var(--muted);
}
.signed-note {
  color: var(--muted);
}

/* Narration */
.explanation {
  border-left: 3px solid var(--active);
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--active) 7%, transparent),
    transparent 70%
  );
  border-radius: 0 10px 10px 0;
  padding-top: 6px;
  padding-bottom: 6px;
}
.explanation > span {
  font-family: var(--mono);
  color: var(--active);
  letter-spacing: 0.06em;
}
.explanation h2 {
  font-weight: 600;
  letter-spacing: -0.01em;
}
.explanation output {
  font-family: var(--mono);
  color: var(--active);
}

/* Timeline */
.timeline input {
  accent-color: var(--active);
}
.timeline span,
.speed {
  font-family: var(--mono);
  color: var(--muted);
}

/* Code: the executing line gets the amber highlighter */
.code-panel pre {
  font-family: var(--mono);
  color: var(--text);
}
.code-line {
  transition:
    background-color 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease;
}
.code-line.active {
  background: var(--focus-bg);
  border-left-color: var(--focus);
  color: var(--text);
  font-weight: 500;
}
.code-line.active .line-number {
  color: var(--focus);
}
.line-number {
  color: var(--faint);
}
.insight {
  border-top-color: var(--line);
}
.insight summary {
  color: var(--active);
  font-weight: 500;
}
.insight code {
  color: var(--active-ink);
  background: var(--active-bg);
  padding: 1px 5px;
  border-radius: 4px;
}
footer {
  color: var(--faint);
}

/* SVG markers drawn by script with literal colours */
marker path[fill='#ffb16b'] {
  fill: var(--focus);
}
marker path[fill='#9aacc1'] {
  fill: var(--muted);
}

/* ===== Motion =====
   Page load: one staggered entrance. Ambient: the phase tag's light breathes and a single highlight
   travels round the visualisation panel. Per-step feedback stays as colour transitions only. */
@property --angle {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}
@keyframes spin-border {
  to {
    --angle: 360deg;
  }
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}
@keyframes ripple {
  0% {
    opacity: 0.6;
    transform: scale(0.6);
  }
  80%,
  100% {
    opacity: 0;
    transform: scale(2.6);
  }
}
.heading,
.inputs,
.workspace > * {
  animation: rise 0.45s var(--ease) both;
}
.inputs {
  animation-delay: 40ms;
}
.workspace > :nth-child(1) {
  animation-delay: 90ms;
}
.workspace > :nth-child(2) {
  animation-delay: 140ms;
}
.panel-head .tag::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 currentColor;
  position: relative;
}
.panel-head .tag::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: ripple 2.4s var(--ease) infinite;
}
.panel-head .tag {
  position: relative;
}
.panel-head .tag::after {
  left: 10px;
  top: calc(50% - 3px);
}
.workspace > .panel:first-child {
  position: relative;
  isolation: isolate;
}
.workspace > .panel:first-child::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1.5px;
  pointer-events: none;
  z-index: 3;
  background: conic-gradient(
    from var(--angle),
    transparent 0 64%,
    color-mix(in srgb, var(--active) 60%, transparent) 82%,
    var(--active) 88%,
    transparent 97%
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: spin-border 9s linear infinite;
  opacity: 0.8;
}

@media (prefers-reduced-motion: reduce) {
  .heading,
  .inputs,
  .workspace > * {
    animation: none;
  }
  .panel-head .tag::after {
    animation: none;
    opacity: 0;
  }
  .workspace > .panel:first-child::before {
    animation: none;
    opacity: 0.35;
  }
  button:active:not(:disabled) {
    transform: none;
  }
}
@media (prefers-contrast: more) {
  :root {
    --line: var(--line-3);
    --line-2: var(--line-3);
    --muted: var(--text);
  }
}
