:root {
  --paper: #15132F; --ink: #EDEBFF; --soft: #A9A6D6; --line: #38356B; --panel: #211E4D;
  --accent: #8E86FF; --on-accent: #14123A; --good: #4CCB9E; --warn: #F0B35E; --bad: #FF7D92;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 16px/1.5 'Golos Text', system-ui, sans-serif; }
.shell { max-width: 1760px; margin: 0 auto; padding: 16px 24px 32px; }
.top { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
h1 { font: 700 32px/1.1 Unbounded, sans-serif; margin: 0; letter-spacing: -0.02em; }
.tab-current { margin: 0; font-weight: 600; color: var(--accent); }
.layout { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(340px, 1fr); gap: 24px; margin-top: 12px; }
.work { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.stage { min-width: 0; touch-action: none; cursor: grab; }
.stage canvas { display: block; position: absolute; inset: 0; }
.net { width: 100%; max-height: 60vh; }
.net polygon { stroke: #17162e; stroke-width: 0.012; cursor: pointer; }
.net polygon:hover { stroke-width: 0.03; }
.net polygon.flag { animation: flag 0.9s ease-in-out infinite alternate; stroke: var(--bad); stroke-width: 0.05; }
@keyframes flag { to { opacity: 0.55; } }
.side { min-width: 0; }
h2 { font: 500 18px/1.2 Unbounded, sans-serif; margin: 20px 0 8px; }
h2:first-child { margin-top: 4px; }
h3 { font-size: 16px; margin: 0 0 4px; }
.hint { color: var(--soft); margin: 0 0 12px; max-width: 60ch; }
.stats { margin: 0 0 8px; color: var(--soft); }
.palette { display: grid; grid-template-columns: repeat(6, 56px); gap: 8px 6px; margin-bottom: 12px; }
.swatch-cell { display: grid; justify-items: center; gap: 2px; }
.count { font-size: 12px; line-height: 1.2; color: var(--soft); white-space: nowrap; }
.count.ok { color: var(--good); font-weight: 600; }
.count.over { color: var(--bad); font-weight: 600; }
.swatch { min-height: 44px; width: 44px; height: 44px; padding: 0; background: var(--c); border: 2px solid #17162e; clip-path: polygon(50% 0, 100% 38%, 82% 100%, 18% 100%, 0 38%); border-radius: 0; }
.swatch[aria-checked="true"] { outline: 3px solid var(--accent); outline-offset: 1px; clip-path: none; border-radius: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; align-items: center; }
.solve-row label { color: var(--soft); }
button, select, .alg { font: 500 15px/1.2 'Golos Text', sans-serif; color: var(--ink); background: var(--panel); border: 1.5px solid var(--line); border-radius: 8px; padding: 10px 14px; min-height: 42px; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.6; cursor: progress; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.alg { flex: 1 1 160px; min-width: 0; }
.message:empty { display: none; }
.message { margin: 12px 0; padding: 12px 14px; border-left: 4px solid var(--soft); background: var(--panel); border-radius: 0 8px 8px 0; }
.message p { margin: 0 0 6px; }
.message.bad { border-color: var(--bad); }
.message.warn { border-color: var(--warn); }
.message.good { border-color: var(--good); color: var(--good); font-weight: 600; }
.player { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.player button { min-width: 44px; }
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 5px; padding: 2px; margin: 0; max-height: 36vh; overflow: auto; }
.chip { font: 500 14px/1 Unbounded, sans-serif; min-height: 34px; padding: 8px 9px; border-bottom-width: 3px; }
.chip.done { opacity: 0.4; }
.chip.now { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
#live-toast { position: fixed; bottom: 16px; left: 50%; translate: -50% 0; background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#live-toast.show { opacity: 1; }
#live-toast.bad { background: var(--bad); color: #fff; }
@media (max-width: 860px) {
  .shell { padding: 12px 16px 24px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .stage-wrap { height: 92vw; min-height: 0; }
  h1 { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) { .net polygon.flag { animation: none; } }

.stage-wrap { position: relative; height: 74vh; min-height: 380px; flex: none; }
.now-move { position: absolute; left: 0; bottom: 0; margin: 0; font-size: 16px; pointer-events: none; }
.now-move strong { font: 700 28px/1 Unbounded, sans-serif; color: var(--accent); margin-right: 6px; }
.delay { display: inline-flex; align-items: center; gap: 6px; color: var(--soft); }
.delay input { width: 72px; font: inherit; color: var(--ink); background: var(--panel); border: 1.5px solid var(--line); border-radius: 8px; padding: 9px; }
.wizard:empty, .shell:not(.wizard-on) .face-input { display: none; }
.wizard h2 { margin: 0 0 4px; font-size: 24px; }
.face-input { width: 100%; max-height: 52vh; }
.face-input polygon { stroke: #17162e; stroke-width: 0.012; cursor: pointer; }
.face-input polygon:hover { stroke-width: 0.03; }
.face-input .neighbour { stroke: #17162e; stroke-width: 0.012; }
.wizard-on .net { display: none; }
.stage { position: absolute; inset: 0; }
.wizard-on .work { display: grid; grid-template-columns: minmax(0, 1fr) minmax(200px, 320px); grid-template-rows: auto minmax(0, 1fr); align-items: start; }
.wizard-on .wizard { grid-column: 1 / -1; }
.wizard-on .face-input { grid-column: 1; grid-row: 2; max-height: 66vh; }
.wizard-on .stage-wrap { grid-column: 2; grid-row: 2; height: 320px; min-height: 0; }
.wizard-on .now-move { display: none; }
@media (max-width: 860px) { .wizard-on .stage-wrap { height: 160px; } }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.palette:has(.swatch-cell:nth-child(6):last-child) { grid-template-columns: repeat(6, 56px); }
.net, .face-input { touch-action: none; user-select: none; }
.more { margin-top: 18px; border-top: 1.5px solid var(--line); padding-top: 12px; }
.more summary { font: 500 16px/1.2 Unbounded, sans-serif; cursor: pointer; }
.more .hint { margin-top: 8px; }
.chip.static { display: inline-block; background: var(--panel); border: 1.5px solid var(--line); border-radius: 8px; }
.progress { display: flex; align-items: center; gap: 12px; }
.bar { flex: 1; height: 12px; background: var(--panel); border: 1.5px solid var(--line); border-radius: 6px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--good); transition: width .25s; }
.bar-text { font-weight: 600; white-space: nowrap; }
.wizard-on .progress { grid-column: 1 / -1; }
.wizard-on .work { grid-template-rows: auto auto minmax(0, 1fr); }
.wizard-on .face-input, .wizard-on .stage-wrap { grid-row: 3; }
.steps:empty { display: none; }
.steps { margin: 12px 0; padding: 12px 14px; background: var(--panel); border-radius: 8px; }
.steps .chips { max-height: 24vh; margin-bottom: 8px; }
.steps .chip.static { background: var(--paper); }

.search-chart { margin: 8px 0 12px; padding: 10px 10px 8px; background: var(--panel); border: 1.5px solid var(--line); border-radius: 8px; }
.search-chart[hidden] { display: none; }
.search-chart svg { display: block; width: 100%; height: auto; }
.search-chart text { fill: var(--soft); font: 400 11px 'Golos Text', sans-serif; }
.search-chart .empty { font-size: 13px; }
.search-chart .grid { stroke: var(--line); stroke-width: 1; }
.search-chart .axis { stroke: var(--soft); stroke-width: 1; }
.search-chart .best { fill: none; stroke: var(--good); stroke-width: 2; }
.search-chart .bound { fill: none; stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 4 3; }
.search-chart .dot { fill: var(--accent); }
.search-chart .dot.top { fill: var(--good); stroke: var(--paper); stroke-width: 1.5; }
.search-chart figcaption { margin-top: 4px; font-size: 13px; color: var(--soft); }
