:root {
  --pico-font-family: 'Fira Sans', system-ui, sans-serif;
  --pico-font-family-monospace: 'Fira Code', ui-monospace, monospace;
  --pico-font-size: 20px;
  --face: var(--pico-card-background-color, #fff);
  --line: var(--pico-muted-border-color, #d5dce4);
  --dim: var(--pico-muted-color, #667080);
  --string-outline: #808080;
  --up: #1769aa; --up-bg: #e7f2ff;
  --left: #a1397f; --left-bg: #fceafa;
  --diagonal: #19734b; --diagonal-bg: #e5f4eb;
  --active: #a45e00; --active-bg: #fff1d4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --up: #85bfff; --up-bg: #172f49;
    --left: #f1a1d6; --left-bg: #402039;
    --diagonal: #83dcb1; --diagonal-bg: #17382b;
    --active: #ffce75; --active-bg: #3d301b;
  }
}
[hidden] { display: none !important; }
body, body :not(h1) { font-size: 1rem; }
main.container { max-width: min(1600px, 95vw); padding-block: 1.5rem 3rem; }
h1 { font-size: 1.8rem; margin-bottom: 1.2rem; }
#input-panel { border: 1px solid var(--line); border-radius: .5rem; padding: .9rem; }
#input-panel summary { margin-bottom: 0; }
#input-panel[open] summary { margin-bottom: .9rem; }
#setup { margin-bottom: 0; }
#setup { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }
#setup label { flex: 1 1 12rem; margin: 0; }
#setup input { margin-bottom: 0; font-family: var(--pico-font-family-monospace); }
#setup button { width: auto; margin: 0; }
#error { color: var(--pico-del-color, #b42318); }
#controls { margin-block: 1.5rem 1rem; }
.control-row { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; }
.playback { width: auto; margin: 0; }
.playback button { padding: .5rem .85rem; margin: 0; }
.playback .wide { min-width: 7rem; }
.speed, .progress { display: flex; align-items: center; gap: .6rem; margin: 0; }
.progress { flex: 1 1 12rem; }
.speed input { width: 8rem; margin: 0; }
.speed output { min-width: 5ch; }
#scrub { flex: 1 1 12rem; width: auto; min-width: 8rem; margin: 0; }
#work { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.5rem; align-items: start; }
#board-column { min-width: 0; }
.definition, .hint, .code-note { color: var(--dim); }
.definition { margin: 0 0 1rem; padding: .9rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--face); }
.definition code { padding: 0; background: none; }
#table-scroll { overflow: auto; max-height: 65vh; border: 1px solid var(--line); border-radius: .5rem; padding: .7rem; }
#table-stage { position: relative; width: max-content; padding: 1.5rem 0 0 1.5rem; }
.string-frame { position: absolute; border: 1px solid var(--string-outline); pointer-events: none; z-index: 1; }
.string-frame span { position: absolute; color: var(--string-outline); font-family: var(--pico-font-family-monospace); }
#string-frame-a span { bottom: calc(100% + .2rem); left: 50%; transform: translateX(-50%); }
#string-frame-b span { right: calc(100% + .4rem); top: 50%; transform: translateY(-50%); }
#dp-table { --cell-gap: 5px; --cell-size: 2.7rem; --string-thickness: calc(var(--cell-size) * .8); --string-spacing: .5rem; width: auto; margin: 0; border-collapse: separate; border-spacing: var(--cell-gap); font-family: var(--pico-font-family-monospace); }
#dp-table caption { text-align: left; font-family: var(--pico-font-family); padding: 0 0 .5rem; color: var(--dim); }
#dp-table th, #dp-table td { padding: 0; border: 0; text-align: center; background: none; min-width: var(--cell-size); height: var(--cell-size); }
#dp-table th { font-weight: 500; color: var(--dim); }
#dp-table thead th { height: auto; padding-bottom: var(--string-spacing); }
#dp-table th[scope="row"], #dp-table thead th:first-child { min-width: 0; padding-right: var(--string-spacing); }
.string-letter { position: relative; display: flex; align-items: center; justify-content: center; width: var(--cell-size); height: var(--cell-size); }
#dp-table thead .string-letter { height: var(--string-thickness); }
#dp-table th[scope="row"] .string-letter, #dp-table thead th:first-child .string-letter { width: var(--string-thickness); }
#dp-table th.prefix .string-letter { background: var(--active-bg); color: var(--active); }
/* Fill the gaps between highlighted headers to form one prefix rectangle. */
#dp-table thead th.prefix + th.prefix .string-letter::before,
#dp-table tbody tr:has(> th.prefix) + tr > th.prefix .string-letter::before {
  content: ''; position: absolute; background: var(--active-bg); pointer-events: none;
}
#dp-table thead th.prefix + th.prefix .string-letter::before {
  inset: 0 100% 0 auto; width: var(--cell-gap);
}
#dp-table tbody tr:has(> th.prefix) + tr > th.prefix .string-letter::before {
  inset: auto 0 100% 0; height: var(--cell-gap);
}
.cell { display: block; position: relative; width: var(--cell-size); height: var(--cell-size); padding: 0; margin: 0; border: 1px solid var(--line); border-radius: .3rem; background: var(--face); color: inherit; font: inherit; box-shadow: none; transition: none; }
.cell.pending { color: var(--dim); border-style: dashed; opacity: .55; }
.cell.base { background: var(--pico-code-background-color, #f3f5f7); }
.cell.path { background: var(--active-bg); border-color: var(--active); }
.cell.matched { background: var(--diagonal-bg); border-color: var(--diagonal); }
.up { --dep: var(--up); --dep-bg: var(--up-bg); color: var(--up); }
.left { --dep: var(--left); --dep-bg: var(--left-bg); color: var(--left); }
.diagonal { --dep: var(--diagonal); --dep-bg: var(--diagonal-bg); color: var(--diagonal); }
.cell.dependency { border-color: var(--dep); color: var(--dep); background: var(--dep-bg); opacity: 1; }
.cell.winner { border-width: 3px; font-weight: 700; }
.cell.current, .cell.inspected { outline: 3px solid var(--active); outline-offset: 1px; opacity: 1; }
.cell.current::after { content: ''; position: absolute; right: 3px; bottom: 3px; width: 5px; height: 5px; border-radius: 50%; background: var(--active); }
.cell:focus-visible { outline: 3px solid var(--pico-primary); outline-offset: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: .5rem 1.1rem; margin-block: .8rem .4rem; }
.hint { margin-bottom: .8rem; }
#reconstruction { padding-inline: .9rem; }
.reconstruct-buttons { display: flex; flex-wrap: wrap; gap: .7rem; margin: 0 .9rem .5rem; }
.reconstruct-buttons button { width: auto; margin-bottom: .4rem; }
#reconstruction-strings { padding-block: .3rem .7rem; }
.reconstruction-string { display: grid; grid-template-columns: 1ch minmax(0, 1fr); align-items: end; gap: .5rem; margin-bottom: .7rem; font-family: var(--pico-font-family-monospace); }
.reconstruction-string > b { padding-bottom: .3rem; }
.reconstruction-scroll { overflow-x: auto; min-width: 0; padding-bottom: .3rem; }
.reconstruction-track { --letter-width: 1.6rem; position: relative; display: flex; width: max-content; margin-inline: 2rem; padding-top: 2rem; }
.reconstruction-character { display: flex; align-items: center; justify-content: center; flex: 0 0 var(--letter-width); width: var(--letter-width); height: 2rem; border-bottom: 1px solid var(--line); white-space: pre; }
.reconstruction-character.passed { color: var(--dim); }
.reconstruction-character.selected { background: var(--diagonal-bg); color: var(--diagonal); font-weight: 700; border-color: var(--diagonal); }
.reconstruction-pointer { position: absolute; top: 0; left: calc(var(--position) * var(--letter-width)); transform: translateX(-50%); color: var(--active); line-height: 1; text-align: center; white-space: nowrap; }
.reconstruction-pointer::after { content: '↓'; display: block; }
#reconstruction-equation { font-family: var(--pico-font-family-monospace); white-space: pre-wrap; overflow-wrap: anywhere; }
.reconstruction-continuation { display: inline-block; margin-left: 2ch; max-width: calc(100% - 2ch); vertical-align: top; }
#panels { min-width: 0; }
#panels details { margin: 0 0 .8rem; border: 1px solid var(--line); border-radius: .5rem; padding: .9rem 0 0; overflow: hidden; }
#panels summary { padding: 0 .9rem .9rem; margin: 0; }
.code-note { padding: .3rem .9rem; margin: 0; }
pre { background: none; margin: 0; padding: .5rem .5rem .9rem; font-family: var(--pico-font-family-monospace); line-height: 1.7; overflow: auto; }
#iterative-code { margin: 0 .9rem .9rem; border: 1px solid var(--line); border-radius: .5rem; }
#iterative-code, #iterative-code * { font-size: .9rem; }
.code-line { display: block; width: max-content; min-width: 100%; padding-inline: .4rem; }
.code-line.now { background: var(--active-bg); color: var(--active); box-shadow: inset 3px 0 var(--active); font-weight: 700; }
#cell-tooltip { position: fixed; z-index: 10; width: max-content; max-width: min(1000px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; padding: .75rem .9rem; background: var(--face); color: var(--pico-color, #29323d); border: 1px solid var(--active); border-radius: .6rem; box-shadow: 0 5px 24px #0002; }
#cell-tooltip .formula { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .25rem .6ch; font-family: var(--pico-font-family-monospace); }
#cell-tooltip .equation { white-space: pre-wrap; overflow-wrap: anywhere; }
footer { margin-top: 1.5rem; color: var(--dim); }
@media (min-width: 1100px) {
  #work { grid-template-columns: minmax(0, 1fr) 26rem; }
  #panels { position: sticky; top: 1rem; }
}
@media (max-width: 640px) {
  #setup label { flex-basis: 100%; }
  #setup button { flex: 1 1 10rem; }
  .playback { width: 100%; }
  .playback button { flex: 1; padding-inline: .4rem; }
  .speed { width: 100%; }
  .speed input { flex: 1; }
}
