/* Mutation playground (playground.html). Shared tokens come from site.css. */

.skip-link { position: absolute; left: -9999px; top: 0; }
.skip-link:focus { left: 16px; top: 8px; z-index: 100; background: var(--paper); padding: 6px 12px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.small { font-size: 14px; }
.mono { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.ok { color: var(--st-formalized); font-weight: 600; }
.bad { color: #b3261e; font-weight: 600; }

/* ---- Hero ---- */
.pg-hero { background: var(--brand-gradient); padding: var(--s6) 0 var(--s5); margin-bottom: var(--s5); }
.pg-hero h1 { font-size: clamp(34px, 6vw, 52px); line-height: 1.1; margin: 6px 0 var(--s2); }
.eyebrow { margin: 0; font-weight: 600; font-size: 14px; color: var(--accent); letter-spacing: 0.02em; }
.lede { font-size: 18px; max-width: 760px; margin: 0 0 var(--s3); }
.toc { display: flex; flex-wrap: wrap; gap: 8px 10px; }
.toc a {
  background: rgba(255, 255, 255, 0.75); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-weight: 600; font-size: 14px; color: var(--ink);
}
.toc a:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }

/* ---- Toy sections ---- */
.toy {
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  padding: var(--s4); margin: 0 0 var(--s5); box-shadow: 0 1px 2px rgba(0, 54, 163, 0.04);
  scroll-margin-top: 80px;
}
.toy-head h2 { font-size: 32px; margin: 0 0 var(--s1); line-height: 1.2; }
.toy-head p { max-width: 860px; }
.toy-num { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.subtoy { border-top: 1px solid var(--line); padding-top: var(--s3); margin-top: var(--s3); scroll-margin-top: 80px; }
.subtoy-h { font-family: var(--serif); font-weight: 400; font-size: 24px; margin: 0 0 var(--s1); }
.subtoy > p { max-width: 860px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin: var(--s2) 0; }
.tool-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline-field { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.num-input { width: 4.2em; }
input[type='number'], select {
  font: inherit; font-size: 15px; padding: 6px 8px; border: 1px solid #b9c7e6; border-radius: 8px;
  background: var(--paper); color: var(--ink); min-height: 36px;
}
input[type='checkbox'] { width: 18px; height: 18px; accent-color: var(--accent); }

.pg-btn {
  font: inherit; font-size: 14px; font-weight: 600; padding: 7px 14px; min-height: 36px;
  border-radius: 999px; border: 1.5px solid var(--accent); background: var(--paper); color: var(--accent); cursor: pointer;
}
.pg-btn:hover:not(:disabled) { background: var(--brand-light); }
.pg-btn:disabled { opacity: 0.45; cursor: default; }
.pg-btn-primary { background: var(--accent); color: var(--accent-ink); }
.pg-btn-primary:hover:not(:disabled) { background: #0a44b8; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
  font: inherit; font-size: 14px; font-weight: 600; padding: 7px 12px; min-height: 36px;
  border: 1.5px solid var(--accent); border-radius: 999px; background: var(--paper); color: var(--accent); cursor: pointer;
}
.seg-btn[aria-checked='true'] { background: var(--accent); color: var(--accent-ink); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; color: var(--ink); min-height: 30px;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.toy-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: var(--s3); align-items: start; }
.canvas-col, .side-col { min-width: 0; }
.canvas-frame { border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcff; overflow: hidden; }
.canvas-frame svg { display: block; width: 100%; height: auto; }
.canvas-hint { font-size: 14px; color: var(--muted); margin: 8px 0 0; min-height: 1.6em; }
.side-block { background: var(--panel); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.side-block h3 { font-family: var(--sans); font-size: 15px; font-weight: 700; margin: 0 0 8px; }
.side-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px; }
.side-block p { margin: 8px 0 0; }

/* ---- Matrices ---- */
.matrix-wrap { overflow-x: auto; max-width: 100%; }
table.matrix { border-collapse: collapse; font-family: var(--mono); font-size: 13px; background: var(--paper); }
table.matrix th, table.matrix td { padding: 3px 7px; text-align: right; border: 1px solid #e3e9f6; min-width: 2.2em; }
table.matrix th { background: var(--brand-light); font-weight: 600; color: var(--accent); }
table.matrix th.frozen-h { background: #eef0f4; color: var(--muted); }
table.matrix th.hot { background: var(--accent); color: var(--accent-ink); }
table.matrix tr.frozen-start > * { border-top: 2px solid #9fb5e6; }
table.matrix td.pos { color: var(--accent); font-weight: 600; }
table.matrix td.neg { color: #8a2b20; font-weight: 600; }
table.matrix td.zero { color: #a3a3a3; }
table.matrix .seg-name { font-weight: 400; color: var(--muted); }
.cell-input { width: 3.4em; min-height: 26px !important; padding: 1px 4px !important; font-family: var(--mono); font-size: 13px !important; }
/* Exact entries can be very long: wrap them in a narrow column; past 40 digits they start elided. */
table.matrix td.long { max-width: 16ch; overflow-wrap: anywhere; word-break: break-all; font-size: 12px; line-height: 1.35; }
table.matrix td.long.expanded { max-width: 24ch; }
.cell-input.wide { width: 11em; }
.num-elided { font: inherit; color: inherit; background: none; border: 0; padding: 0; text-align: right; cursor: pointer; overflow-wrap: anywhere; word-break: break-all; }
.num-elided:hover, .num-elided:focus-visible { text-decoration: underline; }
.num-elided .num-digits { display: block; color: var(--muted); font-weight: 400; white-space: nowrap; word-break: normal; }

/* ---- Quiver canvas ---- */
.canvas-bg { fill: transparent; }
.mode-mutate .canvas-bg { cursor: default; }
.vertex { cursor: pointer; touch-action: none; outline: none; }
.vertex .vshape { fill: var(--paper); stroke: var(--accent); stroke-width: calc(2.2px * var(--k, 1)); }
.vertex.frozen .vshape { fill: #eef0f4; stroke: #6b6b6b; }
.vertex .vlabel { font-family: var(--sans); font-weight: 600; fill: var(--ink); pointer-events: none; user-select: none; }
.vertex:hover .vshape, .vertex:focus-visible .vshape { stroke-width: calc(3.5px * var(--k, 1)); fill: var(--brand-light); }
.vertex:focus-visible .vshape { stroke: var(--focus); }
.vertex.pending .vshape { fill: #ffe9b8; stroke: #a35c00; }
.vertex.pulse .pulse-ring { fill: none; stroke: var(--accent); stroke-width: 3; animation: pulse 0.9s ease-out forwards; }
@keyframes pulse { from { r: 15; opacity: 0.9; } to { r: 34; opacity: 0; } }
.arrow .arrow-line { fill: none; stroke: #2f3b52; stroke-width: calc(1.7px * var(--k, 1)); }
.arrow .arrow-hit { fill: none; stroke: transparent; stroke-width: calc(16px * var(--k, 1)); cursor: pointer; }
.arrowhead { fill: #2f3b52; }
.arrow.flash-rev .arrow-line { animation: flashRev 1.2s ease-out; }
.arrow.flash-new .arrow-line { animation: flashNew 1.2s ease-out; }
@keyframes flashRev { from { stroke: #a35c00; stroke-width: calc(4px * var(--k, 1)); } to { stroke: #2f3b52; stroke-width: calc(1.7px * var(--k, 1)); } }
@keyframes flashNew { from { stroke: #1f7a4d; stroke-width: calc(4.5px * var(--k, 1)); } to { stroke: #2f3b52; stroke-width: calc(1.7px * var(--k, 1)); } }
.arrow-gone { stroke: #b3261e; stroke-width: 3; stroke-dasharray: 5 4; animation: fadeOut 1.2s ease-out forwards; pointer-events: none; }
@keyframes fadeOut { from { opacity: 0.9; } to { opacity: 0; } }
.mult-bg { fill: var(--paper); stroke: #2f3b52; stroke-width: 1; }
.mult-label { font-family: var(--sans); font-weight: 600; fill: var(--ink); }
.qt-note { margin-top: 4px; }
.history-formula { font-size: 17px; overflow-x: auto; padding: 4px 0; }
.iso-status { margin-top: 8px; }
.class-result { margin-top: 10px; }
.class-result p { margin: 6px 0 0; }

/* ---- Polygon toy ---- */
.poly { fill: #f6f8fe; stroke: #2f3b52; stroke-width: 2; }
.poly-vertex { fill: #2f3b52; }
.poly-label { font: 600 14px var(--sans); fill: var(--muted); }
.diag-g { cursor: pointer; outline: none; }
.diag { stroke: #2f3b52; stroke-width: 2.2; }
.diag-g:hover .diag, .diag-g:focus-visible .diag { stroke: var(--accent); stroke-width: 4; }
.diag-hit { stroke: transparent; stroke-width: calc(18px * var(--k, 1)); }
.diag-new { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: drawIn 0.7s ease-out forwards; stroke: var(--accent); }
@keyframes drawIn { to { stroke-dashoffset: 0; } }
.diag-old { stroke: #b3261e; stroke-width: 2.5; stroke-dasharray: 6 5; animation: fadeOut 0.9s ease-in forwards; pointer-events: none; }
.q-arrow { stroke: #1f7a4d; stroke-width: 1.6; pointer-events: none; }
.pt-svg .arrowhead { fill: #1f7a4d; }
.q-arrow.flash-new { animation: flashQ 1.4s ease-out; }
@keyframes flashQ { from { stroke: #a35c00; stroke-width: 4; } to { stroke: #1f7a4d; stroke-width: 1.6; } }
.q-frozen { fill: #eef0f4; stroke: #6b6b6b; stroke-width: 1.3; pointer-events: none; }
.q-vertex { cursor: pointer; }
.q-vertex circle { fill: var(--paper); stroke: #1f7a4d; stroke-width: 1.8; }
.q-vertex text { font-family: var(--sans); font-weight: 600; fill: var(--ink); pointer-events: none; }
.q-vertex.pulse circle { animation: qpulse 1s ease-out; }
@keyframes qpulse { from { fill: #ffe9b8; stroke-width: 4; } to { fill: #fff; stroke-width: 1.8; } }
.fg-block { margin-top: 12px; }
.flip-check { margin-top: 6px; background: var(--panel); border-radius: 8px; padding: 8px 12px; }
.fg-frame { border: 1px solid var(--line); border-radius: 8px; background: var(--paper); margin-top: 8px; }
.fg-svg { display: block; width: 100%; height: auto; }
.fg-edge { stroke: #c9d4ea; stroke-width: 1.2; }
.fg-edge.hot { stroke: var(--accent); stroke-width: 2; }
.fg-node { fill: #fff; stroke: #7d8db0; stroke-width: 1.4; cursor: pointer; outline: none; }
.fg-node.nbr { fill: var(--brand-light); stroke: var(--accent); }
.fg-node.current { fill: var(--accent); stroke: var(--accent); }
.fg-node:hover, .fg-node:focus-visible { stroke: var(--focus); stroke-width: 3; }

/* ---- Rank two ---- */
.r2-head { overflow-x: auto; }
.r2-summary p { margin: 6px 0; }
.r2-list { list-style: none; padding: 0; margin: 8px 0 0; }
.r2-list li { padding: 6px 10px; border-bottom: 1px solid #edf1f9; overflow-x: auto; overflow-y: hidden; }
.r2-list li.repeat { background: #f2faf6; }
.r2-list .katex-display { margin: 0; text-align: left; }
.r2-list .katex-display > .katex { text-align: left; }
.value-table { border-collapse: collapse; font-size: 14px; width: 100%; }
.value-table th, .value-table td { text-align: left; padding: 3px 8px; border-bottom: 1px solid #e3e9f6; }
.value-table th { color: var(--muted); font-weight: 600; }

/* ---- Markov ---- */
.markov-triple { font: 400 34px var(--serif); display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin: 6px 0 10px; }
.markov-entry {
  font: 600 26px var(--sans); min-width: 56px; padding: 6px 12px; border-radius: 10px; cursor: pointer;
  border: 1.5px solid var(--accent); background: var(--paper); color: var(--accent); overflow-wrap: anywhere;
}
.markov-entry:hover { background: var(--brand-light); }
.markov-entry.changed { animation: flashBox 0.9s ease-out; }
@keyframes flashBox { from { background: #ffe9b8; } to { background: var(--paper); } }
.markov-check { overflow-x: auto; margin-bottom: 8px; }
.markov-path { overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; margin-bottom: 8px; }
.tree-frame { overflow: auto; max-height: 560px; background: var(--paper); border-radius: 8px; border: 1px solid var(--line); }
.markov-tree { display: block; width: 100%; height: auto; }
.tree-edge { fill: none; stroke: #c9d4ea; stroke-width: 1.2; }
.tree-node { cursor: pointer; outline: none; }
.tree-node text { font: 12px var(--mono); fill: var(--ink); }
.tree-node:hover text, .tree-node:focus-visible text { fill: var(--accent); font-weight: 700; }
.tree-node .tree-bg { fill: transparent; }
.tree-node.current .tree-bg { fill: var(--accent); }
.tree-node.current text { fill: var(--accent-ink); font-weight: 700; }
.markov-layout { grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.3fr); }

/* ---- Somos ---- */
.somos-list { columns: 2 280px; column-gap: 24px; padding-left: 0; list-style: none; margin: 8px 0 0; }
.somos-list li { break-inside: avoid; padding: 2px 0; border-bottom: 1px dotted #e3e9f6; }
.somos-list li.nonint { background: #fff1f0; }
.somos-list .idx { display: inline-block; min-width: 2.6em; color: var(--muted); font-size: 14px; }
.somos8 { margin-top: 12px; background: var(--panel); border-radius: 8px; padding: 8px 12px; overflow-x: auto; }

/* ---- Formalized-as boxes ---- */
.formalized {
  margin-top: var(--s3); border-left: 4px solid var(--accent); background: var(--brand-light);
  border-radius: 0 var(--radius) var(--radius) 0; padding: 14px 18px;
}
.formalized h3 { font-family: var(--sans); font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin: 0 0 8px; }
.fz-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px 18px; }
.fz-group { grid-column: 1 / -1; font-weight: 700; font-size: 13px; color: var(--muted); margin-top: 6px; border-bottom: 1px solid var(--line); }
.fz-item { font-size: 14px; line-height: 1.45; min-width: 0; }
.fz-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.fz-title { color: var(--ink); }
.fz-title:hover .fz-name { text-decoration: underline; }
.fz-num { font-weight: 700; color: var(--accent); white-space: nowrap; }
.fz-note { color: var(--muted); font-size: 13px; margin-top: 2px; }
.fz-lean { margin-top: 2px; display: flex; flex-wrap: wrap; gap: 2px 8px; }
.fz-decl code { font-size: 12px; color: #0b3d91; overflow-wrap: anywhere; }

/* ---- Plabic ---- */
.pl-edge { stroke: #2f3b52; stroke-width: 2; }
.pl-edge.trip { stroke: #a35c00; stroke-width: 4; }
.pl-white { fill: #fff; stroke: #141414; stroke-width: 2; }
.pl-black { fill: #141414; stroke: #141414; stroke-width: 2; }
.pl-bdry { fill: #6b6b6b; }
.pl-disk { fill: #fbfcff; stroke: #9fb5e6; stroke-width: 1.5; }
.pl-face { fill: transparent; cursor: pointer; }
.pl-face:hover, .pl-face:focus-visible { fill: rgba(0, 54, 163, 0.08); outline: none; }
.pl-face.squareable { fill: rgba(31, 122, 77, 0.07); }
.pl-face.flash { animation: faceFlash 1.2s ease-out; }
@keyframes faceFlash { from { fill: rgba(255, 196, 0, 0.45); } to { fill: transparent; } }
.pl-label { font: 600 12px var(--sans); fill: var(--muted); }
.pl-trip-path { fill: none; stroke: #a35c00; stroke-width: 3.5; stroke-linejoin: round; opacity: 0.85; pointer-events: none; }
.pl-quiver { stroke: #1f7a4d; stroke-width: 1.5; pointer-events: none; }
.pl-fv { fill: #fff; stroke: #1f7a4d; stroke-width: 1.5; pointer-events: none; }
.pl-fv.frozen { fill: #eef0f4; stroke: #6b6b6b; }
.pl-fv-label { font: 600 10px var(--sans); fill: var(--ink); pointer-events: none; }
.perm { font-family: var(--mono); font-size: 14px; }

@media (max-width: 860px) {
  .toy-layout { grid-template-columns: minmax(0, 1fr); }
  .toy { padding: var(--s3) 18px; }
}
@media (max-width: 640px) {
  .pg-hero { padding: var(--s4) 0 var(--s3); }
  .toy { padding: 18px 14px; border-radius: 12px; }
  .toy-head h2 { font-size: 26px; }
  .toolbar { gap: 8px 10px; }
  .seg-btn { padding: 6px 9px; font-size: 13px; }
  .fz-list { grid-template-columns: minmax(0, 1fr); }
  .markov-entry { font-size: 20px; min-width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
