/* Shared styles for the String-2 loop tracers.
   Same palette and layout as AbecedarianAnimation.html / ScrabbleAnimation.html. */
:root {
  --bg: #f6f5f0;
  --panel: #ffffff;
  --border: #dcd9cf;
  --text: #23241f;
  --muted: #6b6a62;
  --outer: #e07b00;     /* the main loop index */
  --inner: #0a8fb0;     /* a second index / helper position */
  --match: #4f9a12;
  --bad: #d0284f;
  --cell: #fbfaf6;
  --code-bg: #272822;
  --code-hl: #49483e;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1c18;
    --panel: #23241f;
    --border: #3a3b34;
    --text: #f0efe8;
    --muted: #a09f95;
    --outer: #fd971f;
    --inner: #66d9ef;
    --match: #a6e22e;
    --bad: #f92672;
    --cell: #2c2d27;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1c18;
  --panel: #23241f;
  --border: #3a3b34;
  --text: #f0efe8;
  --muted: #a09f95;
  --outer: #fd971f;
  --inner: #66d9ef;
  --match: #a6e22e;
  --bad: #f92672;
  --cell: #2c2d27;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  line-height: 1.45;
}
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
main.wide { max-width: 1400px; }   /* pages whose code has long lines */
h1 { font-size: 1.5rem; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 20px; max-width: 900px; }
code, .mono { font-family: "Victor Mono", ui-monospace, monospace; font-variant-ligatures: none; }
a { color: var(--inner); }

/* Navigation between problems */
.nav { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-size: 0.85rem; margin-bottom: 14px; }
.nav a { color: var(--muted); text-decoration: none; }
.nav a:hover { color: var(--text); text-decoration: underline; }
.nav .home { font-weight: 600; }
.nav .pn { display: flex; gap: 14px; }
.nav .spacer { flex: 1; }

/* Controls */
.controls {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; margin-bottom: 16px;
}
.controls input[type=text], .controls input[type=number] {
  font: 600 1rem "Victor Mono", monospace; font-variant-ligatures: none;
  padding: 7px 10px; border-radius: 6px; width: 170px; max-width: 100%;
  border: 1px solid var(--border); background: var(--cell); color: var(--text);
}
.controls input[type=number] { width: 70px; }
.controls select, .controls button {
  font: 600 0.9rem Inter, sans-serif;
  padding: 7px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--cell); color: var(--text);
}
.controls button.primary { background: var(--outer); border-color: var(--outer); color: #1b1c18; }
.controls button:disabled { opacity: 0.4; cursor: default; }
.controls label { font-size: 0.85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.controls .spacer { flex: 1; }

/* Layout */
.grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; }
.grid.wide { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
@media (max-width: 860px) { .grid, .grid.wide { grid-template-columns: minmax(0, 1fr); } }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px; min-width: 0;
}
.card h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 12px; }

/* Code panel (always Monokai, to match the answer-key screenshots) */
pre.code {
  margin: 0; background: var(--code-bg); color: #f8f8f2;
  border-radius: 8px; padding: 12px 0; overflow-x: auto;
  font: 13px/1.6 "Victor Mono", monospace;
}
/* No ligatures: students should see <=, != and ==, not a fused glyph. */
pre.code, .narr code, .frame table, .cell, .strip-label, .result, .controls input { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
pre.code .ln { display: block; padding: 0 14px; white-space: pre; border-left: 4px solid transparent; transition: background .15s; }
pre.code .ln.active { background: var(--code-hl); border-left-color: var(--outer); }
pre.code .ln.active.in { border-left-color: var(--inner); }
.k { color: #f92672; } .t { color: #66d9ef; font-style: italic; }
.f { color: #a6e22e; } .n { color: #ae81ff; } .s { color: #e6db74; }
.cm { color: #75715e; font-style: italic; }

/* String strips */
.strip-label { font: 600 0.9rem "Victor Mono", monospace; margin: 4px 0 2px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.strip-label .tag { font: 600 0.7rem Inter, sans-serif; text-transform: uppercase; letter-spacing: 0.06em; padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, var(--inner) 20%, transparent); color: var(--inner); }
.strip-label .tag.outer { background: color-mix(in srgb, var(--outer) 20%, transparent); color: var(--outer); }
.strip-label .tag.match { background: color-mix(in srgb, var(--match) 22%, transparent); color: var(--match); }
.strip-wrap { overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; position: relative; scroll-behavior: smooth; }
.strip { display: grid; grid-auto-flow: column; grid-auto-columns: 42px; gap: 5px; width: max-content; }
.col { display: grid; grid-template-rows: 20px 42px 20px; gap: 3px; justify-items: center; align-items: center; }
.strip.badges .col { grid-template-rows: 20px 42px 20px 24px; }
.ptr { font: 600 12px "Victor Mono", monospace; white-space: nowrap; font-variant-ligatures: none; }
.ptr.outer { color: var(--outer); }
.ptr.inner { color: var(--inner); }
.ptr.match { color: var(--match); }
.ptr.bad { color: var(--bad); }
.ptr.muted { color: var(--muted); }
.cell {
  width: 42px; height: 42px; border-radius: 8px;
  display: grid; place-items: center; position: relative;
  font: 600 20px "Victor Mono", monospace;
  background: var(--cell); border: 2px solid var(--border);
  transition: border-color .15s, background .15s, transform .15s, opacity .15s;
}
.cell .idx { position: absolute; top: 1px; left: 4px; font-size: 10px; color: var(--muted); font-weight: 400; }
.cell.space { color: var(--muted); }
.cell.ghost { border-style: dashed; background: transparent; color: var(--muted); }
.cell.empty { width: auto; padding: 0 12px; border-style: dashed; background: transparent; color: var(--muted); font: 400 13px Inter, sans-serif; white-space: nowrap; }
.cell.win { background: color-mix(in srgb, var(--outer) 16%, var(--cell)); border-color: color-mix(in srgb, var(--outer) 55%, var(--border)); }
.cell.win2 { background: color-mix(in srgb, var(--inner) 16%, var(--cell)); border-color: color-mix(in srgb, var(--inner) 55%, var(--border)); }
.cell.outer { border-color: var(--outer); transform: translateY(-3px); }
.cell.inner { transform: translateY(-3px); box-shadow: 0 0 0 3px color-mix(in srgb, var(--inner) 45%, transparent); }
.cell.hit { background: color-mix(in srgb, var(--match) 35%, var(--cell)); border-color: var(--match); }
.cell.soft { background: color-mix(in srgb, var(--match) 14%, var(--cell)); }
.cell.miss { background: color-mix(in srgb, var(--bad) 22%, var(--cell)); border-color: var(--bad); }
.cell.new { background: color-mix(in srgb, var(--match) 35%, var(--cell)); border-color: var(--match); transform: translateY(-3px); }
.cell.done { opacity: 0.35; }
.badge {
  font: 600 11px "Victor Mono", monospace; padding: 2px 6px; border-radius: 999px;
  white-space: nowrap; font-variant-ligatures: none;
}
.badge.ok { background: color-mix(in srgb, var(--match) 25%, transparent); color: var(--match); }
.badge.no { background: color-mix(in srgb, var(--bad) 22%, transparent); color: var(--bad); }
.badge.mid { background: color-mix(in srgb, var(--outer) 22%, transparent); color: var(--outer); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--c); }

/* Narration + variables */
.narr {
  font-size: 1.02rem; min-height: 3.2em; margin: 16px 0 0;
  padding: 12px 14px; border-radius: 8px; background: var(--cell); border-left: 4px solid var(--outer);
}
.narr.in { border-left-color: var(--inner); }
.narr.err { border-left-color: var(--bad); }
.narr code { font-size: 0.95em; }
.vars { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.vars.one { grid-template-columns: 1fr; }
@media (max-width: 520px) { .vars { grid-template-columns: 1fr; } }
.frame { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; transition: opacity .2s; min-width: 0; }
.frame.idle { opacity: 0.45; }
.frame h3 { margin: 0 0 6px; font: 600 0.85rem "Victor Mono", monospace; color: var(--outer); }
.frame.chk h3 { color: var(--inner); }
.frame table { border-collapse: collapse; width: 100%; font: 14px "Victor Mono", monospace; table-layout: fixed; }
.frame td { padding: 2px 0; overflow-wrap: anywhere; vertical-align: top; }
.frame td:first-child { color: var(--muted); width: 45%; padding-right: 8px; }
.frame td.changed { color: var(--outer); font-weight: 600; }
.ck { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 10px; padding: 3px 0; font: 14px "Victor Mono", monospace; font-variant-ligatures: none; border-bottom: 1px dashed var(--border); }
.ck:last-child { border-bottom: 0; }
.ck .e { overflow-wrap: anywhere; }
.ck .v { margin-left: auto; color: var(--muted); overflow-wrap: anywhere; text-align: right; }
.ck .v.ok { color: var(--match); font-weight: 600; }
.ck .v.no { color: var(--bad); font-weight: 600; }

.result {
  margin-top: 16px; padding: 12px 14px; border-radius: 8px; font-weight: 700; text-align: center;
  display: none; font-family: "Victor Mono", monospace; overflow-wrap: anywhere;
}
.result.on { display: block; }
.result.true { background: color-mix(in srgb, var(--match) 22%, transparent); color: var(--match); }
.result.false { background: color-mix(in srgb, var(--bad) 20%, transparent); color: var(--bad); }
.result.val { background: color-mix(in srgb, var(--outer) 18%, transparent); color: var(--outer); }
.progress { height: 4px; background: var(--border); border-radius: 2px; margin-top: 14px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--outer); transition: width .15s; }
.stepcount { font-size: 0.8rem; color: var(--muted); margin-top: 6px; text-align: right; }
