:root {
  color-scheme: light;
  --ink: #20241f;
  --muted: #666d64;
  --paper: #efeade;
  --card: #fffdf7;
  --line: #d4cdbd;
  --seed: #14584f;
  --boundary: #e6dfd0;
  --accent: #cf7048;
  --ancestor: #dceafb;
  --ancestor-strong: #b9d5f6;
  --descendant: #f7dfbd;
  --fraction: #5650a5;
  --cell-track: 26px;
  --row-track: 52px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 12% 0%, rgb(255 255 255 / 78%), transparent 31rem),
    var(--paper);
  color: var(--ink);
}

button, input, select { font: inherit; }

button, select, input {
  border: 1px solid #beb7a8;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

button { cursor: pointer; }
button:hover { border-color: #8c877c; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgb(207 112 72 / 25%);
  outline-offset: 2px;
}

main {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 42px 0 64px;
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 32px;
  margin: 0 2px 30px;
}

.eyebrow, .pattern-number {
  margin: 0 0 8px;
  color: var(--seed);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1, .workbench-heading h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(3rem, 6.5vw, 6.2rem);
  letter-spacing: -.055em;
  line-height: .88;
}

.introduction {
  max-width: 520px;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.explorer {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  align-items: start;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 18px 52px rgb(54 47 36 / 9%);
}

.controls {
  min-height: 100%;
  padding: 10px 20px 22px;
  border-right: 1px solid var(--line);
  background: #f8f4eb;
}

.control-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.control-section:last-child { border-bottom: 0; }
.control-section h2 {
  margin: 0 0 12px;
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.field-label, .field-pair label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 700;
}

select, .field-pair input {
  width: 100%;
  height: 34px;
  padding: 4px 8px;
}

#preset { width: 100%; margin-bottom: 13px; }

.mode-picker {
  display: flex;
  gap: 14px;
  margin: 0 0 13px;
  padding: 0;
  border: 0;
}
.mode-picker legend {
  float: left;
  width: 100%;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 700;
}
.mode-picker label, .check-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
}
.mode-picker input, .check-list input { accent-color: var(--seed); }

.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.wide-button {
  width: 100%;
  margin-top: 10px;
  padding: 7px 10px;
  background: #fff;
  font-size: .79rem;
}

.transport, .seek-transport { display: flex; gap: 8px; align-items: center; }
.transport button, .seek-transport button {
  width: 38px;
  height: 34px;
  padding: 0;
  flex: 0 0 auto;
}
.transport button.active, .seek-transport button.active, .mode-toggle.active {
  border-color: var(--seed);
  background: var(--seed);
  color: #fff;
}
.seek-transport input[type="range"] { min-width: 0; width: 100%; accent-color: var(--seed); }
.mode-toggle { margin-top: 0; }
.small-status {
  min-height: 1.1em;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: .75rem;
  line-height: 1.4;
}
.check-list label + label { margin-top: 9px; }

.workbench { min-width: 0; }
.workbench-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line);
}
.workbench-heading h2 { margin: 0; font-size: clamp(1.7rem, 3vw, 2.4rem); }
.rule {
  margin-bottom: 3px;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.1rem;
  white-space: nowrap;
}
.hint {
  margin: 0;
  padding: 11px 28px;
  border-bottom: 1px solid #e8e2d6;
  background: #fffaf0;
  color: var(--muted);
  font-size: .78rem;
}

.pattern-scroll {
  min-height: 460px;
  overflow-x: auto;
  padding: 26px 28px;
  background: linear-gradient(#fffdf8, #fff);
}

.frieze-grid {
  display: grid;
  grid-template-columns: repeat(var(--column-count), var(--cell-track));
  grid-template-rows: repeat(var(--row-count), var(--row-track));
  align-items: center;
  isolation: isolate;
  width: max-content;
  min-width: 100%;
  padding: 6px 0;
}

.period-band {
  z-index: -1;
  align-self: stretch;
  width: 52px;
  border-left: 1px solid rgb(20 88 79 / 22%);
  background: linear-gradient(90deg, rgb(20 88 79 / 7%), transparent);
  pointer-events: none;
}

.step-toggle {
  z-index: 5;
  justify-self: start;
  width: 30px;
  height: 26px;
  margin-left: 2px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: #8b867c;
  font-size: 1rem;
}
.step-toggle:hover { border-color: var(--line); background: #fff; color: var(--seed); }

.cell {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  justify-self: center;
  width: 46px;
  height: 32px;
  border: 1px solid #d5d0c6;
  border-radius: 999px;
  background: #fff;
  font: 650 .84rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  transition: opacity 140ms ease, border-color 120ms ease, box-shadow 120ms ease, color 120ms ease, transform 120ms ease, background 120ms ease;
  user-select: none;
}
.cell.boundary { border-color: #cbc3b4; background: var(--boundary); color: #625d54; }
.cell.seed:not(.boundary) { border-color: var(--seed); background: var(--seed); color: #fff; }
.cell.fraction { color: var(--fraction); }
.cell.undefined { border-style: dashed; border-color: #d8968e; color: #a33830; }

.cell.can-move:hover {
  border: 1px dashed var(--seed);
  box-shadow: 0 0 0 2px rgb(20 88 79 / 11%);
  cursor: pointer;
}
.cell.seed { cursor: text; }
.cell.boundary.seed { cursor: default; }
.cell.forced { cursor: pointer; }

.cell.ancestor { background: var(--ancestor); }
.cell.descendant { background: var(--descendant); }
.cell.pin-parent { z-index: 3; background: var(--ancestor-strong); box-shadow: inset 0 0 0 2px #3976b4; }
.cell.pinned { z-index: 4; border-color: #181b18; box-shadow: 0 0 0 3px rgb(32 36 31 / 16%); transform: scale(1.07); }
.cell.feeding-seed { box-shadow: 0 0 0 3px #4f8fc9, 0 0 0 5px rgb(79 143 201 / 18%); }
.cell.dimmed { opacity: .18; }
.cell.repeat-dimmed { opacity: .48; }
.cell.repeat-chain {
  z-index: 5;
  border-color: #7656ad;
  box-shadow: 0 0 0 2px rgb(118 86 173 / 24%);
}
.frieze-grid .cell.repeat-current {
  z-index: 8;
  border-color: #55368c;
  background: #f2ebff;
  color: #2e2047;
  box-shadow: 0 0 0 4px rgb(118 86 173 / 32%);
  transform: scale(1.1);
}
.cell.repeat-partner {
  z-index: 7;
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.cell.phantom {
  border-style: dashed;
  border-color: #a9a19b;
  background: transparent;
  color: #8b837c;
  opacity: .58;
}
.cell.phantom.repeat-dimmed { opacity: .24; }
.cell[data-repeat-label]::after {
  content: attr(data-repeat-label);
  position: absolute;
  top: -14px;
  right: -5px;
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 17px;
  padding: 0 3px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font: 800 .58rem/1 ui-sans-serif, system-ui, sans-serif;
}
.cell[data-repeat-badge]::before {
  content: attr(data-repeat-badge);
  position: absolute;
  z-index: 2;
  bottom: -13px;
  left: -4px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #20241f;
  color: #fff;
  font: italic 800 .68rem/1 Georgia, serif;
}

.cell.boundary-valued { outline: 2px solid #2b8c79; outline-offset: 2px; }
.cell.fraction-loud { border: 3px double #6659c5; font-weight: 850; }
.cell.undefined-loud { outline: 3px solid #c94539; outline-offset: 2px; background: #fff0ed; }

.cell.hovered {
  z-index: 9;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(207 112 72 / 22%);
  transform: scale(1.09);
}
.cell.parent {
  z-index: 8;
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 2px rgb(255 255 255 / 80%);
}
.cell.invariant-cell { outline: 2px dashed #7656ad; outline-offset: 3px; }
.cell[data-label]::after {
  content: attr(data-label);
  position: absolute;
  top: -13px;
  right: -3px;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font: 800 .65rem/1 Georgia, serif;
}
.cell.invariant-cell:not(.parent):not(.hovered)[data-label]::after { background: #7656ad; }

.cell.unrevealed {
  border-color: #e7e2d9;
  background: transparent;
  color: transparent;
  box-shadow: none;
  cursor: default;
  pointer-events: none;
}
.cell.wave-front { animation: reveal-pulse 300ms ease-out; }
@keyframes reveal-pulse {
  0% { border-color: var(--accent); box-shadow: 0 0 0 7px rgb(207 112 72 / 24%); transform: scale(1.12); }
  100% { box-shadow: 0 0 0 0 transparent; transform: scale(1); }
}

.seed-input {
  width: 40px;
  height: 26px;
  padding: 2px 3px;
  border: 0;
  background: #fff;
  color: var(--ink);
  text-align: center;
  font: 650 .78rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.cell.invalid-flash, .invalid-field { animation: invalid-flash 500ms ease; }
@keyframes invalid-flash {
  0%, 100% { background: inherit; }
  35% { border-color: #b42d25; background: #ffd9d4; transform: translateX(3px); }
  60% { transform: translateX(-3px); }
}

.derivation {
  min-height: 50px;
  padding: 14px 28px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f8f5ee;
  color: #353933;
  font: 600 .86rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.repeat-panel {
  border-top: 1px solid var(--line);
  background: #faf7f0;
}
.repeat-transport {
  display: grid;
  grid-template-columns: 36px 36px 36px minmax(140px, 1fr) auto;
  align-items: center;
  gap: 7px;
  padding: 13px 28px;
}
.repeat-transport button { width: 36px; height: 32px; padding: 0; }
.repeat-transport button.active { border-color: #7656ad; background: #7656ad; color: #fff; }
.repeat-transport input { width: 100%; accent-color: #7656ad; }
.repeat-transport .small-status { min-width: 112px; margin: 0; text-align: right; }
.repeat-ledger {
  overflow-x: auto;
  padding: 14px 28px;
  border-top: 1px solid #e2dcd0;
  border-bottom: 1px solid #e2dcd0;
  background: #fff;
  white-space: nowrap;
  font: 650 .9rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.repeat-ledger .current-term {
  padding: 3px 5px;
  border-radius: 4px;
  background: #eadffd;
  color: #3b245f;
}
.repeat-ledger .walk-divider { padding: 0 10px; color: var(--muted); }
.repeat-explanation {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  padding: 16px 28px 18px;
  color: #4f554d;
  font-family: Georgia, "Times New Roman", serif;
  font-size: .87rem;
  line-height: 1.5;
}
.repeat-explanation p { margin: 0; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 13px 20px;
  padding: 14px 28px 17px;
  color: var(--muted);
  font-size: .74rem;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 20px; height: 13px; border: 1px solid var(--line); border-radius: 999px; }
.seed-swatch { border-color: var(--seed); background: var(--seed); }
.ancestor-swatch { background: var(--ancestor); }
.descendant-swatch { background: var(--descendant); }
.parent-swatch { box-shadow: inset 0 0 0 2px var(--accent); }
.boundary-value-swatch { outline: 2px solid #2b8c79; outline-offset: 1px; }

.about {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgb(255 253 247 / 76%);
}
.about summary { padding: 14px 18px; cursor: pointer; font-weight: 750; }
.about-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 22px;
  padding: 2px 18px 18px;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.5;
}
.about-grid p { margin: 0; }

[hidden] { display: none !important; }

@media (max-width: 900px) {
  main { width: min(100% - 20px, 1500px); padding-top: 28px; }
  .page-header { display: block; }
  .introduction { margin-top: 18px; }
  .explorer { grid-template-columns: 1fr; }
  .controls {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 18px;
    overflow-x: auto;
    padding: 0 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .control-section { border-bottom: 0; }
  .pattern-scroll { min-height: 400px; }
}

@media (max-width: 620px) {
  .controls { grid-template-columns: repeat(5, 210px); }
  .workbench-heading { display: block; padding: 20px 18px 15px; }
  .rule { margin-top: 10px; }
  .hint, .derivation, .legend { padding-inline: 18px; }
  .pattern-scroll { padding: 20px 14px; }
  .repeat-transport { grid-template-columns: 36px 36px 36px 1fr; padding-inline: 18px; }
  .repeat-transport .small-status { grid-column: 1 / -1; text-align: left; }
  .repeat-ledger, .repeat-explanation { padding-inline: 18px; }
  .repeat-explanation { grid-template-columns: 1fr; gap: 10px; }
  .about-grid { grid-template-columns: 1fr; gap: 12px; }
}
