/* Bead Sprite - a bright craft-table page: the pegboard is the hero, the controls stay out of its way. */
:root, [data-theme="light"] {
  --bg: #faf7f2; --card: #ffffff; --ink: #1f1d2b; --muted: #676377; --line: #e3ddd2; --soft: #f1ece3;
  --accent: #e5484d; --accent-ink: #ffffff; --accent-soft: #fde8e8; --good: #1f8a4c; --warn: #9a5b00;
  --board: #efece6; --peg: #d3cec4; --cell-line: rgba(0, 0, 0, .2); --board-line: #e5484d; --veil: rgba(255, 255, 255, .8);
  --shadow: 0 1px 2px rgba(31, 29, 43, .06), 0 8px 24px rgba(31, 29, 43, .07);
}
[data-theme="dark"] {
  --bg: #15141b; --card: #1e1d27; --ink: #f1eff7; --muted: #a9a5b8; --line: #34323f; --soft: #272631;
  --accent: #ff6b6f; --accent-ink: #1a0b0c; --accent-soft: #3a2024; --good: #6fd39a; --warn: #f0b860;
  --board: #2a2933; --peg: #3c3a47; --cell-line: rgba(255, 255, 255, .22); --board-line: #ff6b6f; --veil: rgba(21, 20, 27, .8);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; overflow-x: hidden; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; background: var(--card); padding: 6px 10px; z-index: 20; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top { display: flex; align-items: center; gap: 14px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--card); }
.top .back { text-decoration: none; font-size: 14px; color: var(--muted); }
.brand { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 8px; letter-spacing: -.01em; }
.brand-mark { width: 20px; height: 20px; border-radius: 50%; background: radial-gradient(circle, var(--card) 0 24%, var(--accent) 26% 100%); display: inline-block; }
.top #theme { margin-left: auto; }

.btn { border: 1px solid var(--line); background: var(--card); padding: 9px 16px; border-radius: 10px; min-height: 42px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center; }
.btn:hover:not(:disabled):not(.primary) { background: var(--soft); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 6px 12px; min-height: 40px; font-size: 14px; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.file { position: relative; overflow: hidden; cursor: pointer; }
.btn.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; font-weight: 600; min-height: 0; }

main { max-width: 1260px; margin: 0 auto; padding: 0 16px 48px; }
.hero { text-align: center; padding: 34px 0 18px; }
.hero h1 { font-size: clamp(30px, 5vw, 50px); line-height: 1.06; letter-spacing: -.025em; margin: 0 0 10px; }
.lede { max-width: 62ch; margin: 0 auto 14px; color: var(--muted); font-size: 18px; }
.trust { list-style: none; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding: 0; margin: 0 0 20px; }
.trust li { background: var(--soft); border-radius: 999px; padding: 5px 13px; font-size: 14px; font-weight: 600; }
.trust li::before { content: "\2713\00a0"; color: var(--good); }
.drop { max-width: 660px; margin: 0 auto; border: 2px dashed var(--line); border-radius: 18px; background: var(--card); padding: 24px 18px 16px; box-shadow: var(--shadow); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-title { margin: 0 0 12px; font-weight: 600; }
.drop .btn.primary { font-size: 18px; padding: 13px 28px; min-height: 52px; }
.drop-alt { margin: 12px 0 0; font-size: 14px; color: var(--muted); }
.coarse { display: none; }
@media (pointer: coarse) { .fine { display: none; } .coarse { display: inline; } }
.error { color: var(--accent); font-weight: 600; margin: 10px 0 0; }
.samples { margin-top: 20px; }
.samples p { margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.sample-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.sample { border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 6px 6px 4px; display: grid; gap: 2px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow); transition: transform .12s; }
.sample:hover { transform: translateY(-2px); border-color: var(--accent); }
.sample canvas { width: 132px; height: 132px; border-radius: 10px; display: block; background: var(--board); }
.hero.compact { padding: 14px 0 8px; }
.hero.compact h1 { font-size: 24px; margin-bottom: 8px; }
.hero.compact .lede, .hero.compact .trust, .hero.compact .drop { display: none; }
.hero.compact .samples { margin-top: 0; }
.hero.compact .sample canvas { width: 56px; height: 56px; }
.hero.compact .sample span { display: none; }
.hero.compact .samples p { display: none; }

.work { margin-top: 6px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: thin; }
.tab { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 9px 16px; min-height: 42px; font-weight: 700; white-space: nowrap; flex: 0 0 auto; }
.tab.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.bench { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
@media (min-width: 900px) { .bench { grid-template-columns: minmax(0, 1fr) 400px; } .stage { position: sticky; top: 10px; } }
.stage, .panel { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); min-width: 0; }
.stage { padding: 12px; }
.panel { padding: 16px; }
.stage-bar { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 8px 12px; min-height: 40px; min-width: 40px; font-weight: 600; font-size: 14px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: var(--bg); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }
.stage-wrap { overflow: auto; max-height: 78vh; border-radius: 10px; background: var(--board); display: flex; }
.stage-inner { position: relative; margin: 0 auto; line-height: 0; flex: 0 0 auto; }
#board { display: block; touch-action: pan-x pan-y; }
#board.drawing { touch-action: none; cursor: crosshair; }
#orig { position: absolute; left: 0; top: 0; pointer-events: none; }
.divider { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); pointer-events: none; }
.compare-range { width: 100%; margin: 10px 0 0; accent-color: var(--accent); height: 28px; }
.summary { margin: 10px 2px 0; font-weight: 600; font-size: 15px; }
.pointer-line { margin: 2px 2px 0; min-height: 1.3em; font-size: 13px; color: var(--muted); }

.field { display: grid; gap: 6px; margin: 0 0 14px; font-weight: 700; font-size: 14px; }
.field > span { display: flex; justify-content: space-between; gap: 8px; }
.field output { font-weight: 600; color: var(--accent); }
.field.inline { grid-template-columns: 130px minmax(0, 1fr); align-items: center; font-weight: 600; margin-bottom: 8px; }
select, input[type=number], input[type=search] { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 10px; min-height: 42px; width: 100%; min-width: 0; }
input[type=range] { width: 100%; accent-color: var(--accent); min-height: 28px; margin: 0; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); flex: 0 0 auto; margin: 0; }
.check { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; min-height: 40px; }
.check small { color: var(--muted); font-weight: 500; }
.owned-row { grid-template-columns: 1fr auto; align-items: center; }
.size-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.size-row input[type=number] { width: 84px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--soft); border-radius: 999px; padding: 6px 12px; min-height: 40px; font-size: 13px; font-weight: 600; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip:disabled { opacity: .45; }
.toggles { margin-bottom: 8px; }
.more { border-top: 1px solid var(--line); padding: 10px 0 4px; margin-top: 6px; }
.more summary { font-weight: 700; cursor: pointer; min-height: 40px; display: flex; align-items: center; }
.note { font-size: 14px; color: var(--muted); margin: 8px 0; }
#ownedNote, #convertNote, #missingNote { background: var(--soft); border-radius: 10px; padding: 8px 12px; color: var(--ink); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.actions .primary { flex: 1 1 100%; font-size: 17px; min-height: 50px; }
.pane-label { font-weight: 700; font-size: 14px; margin: 12px 0 6px; }

.tools { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tool { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 12px; min-height: 42px; font-weight: 600; font-size: 14px; }
.tool.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.edit-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.edit-row .field { margin: 0; flex: 1 1 200px; }
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; max-height: 300px; overflow: auto; padding: 3px; }
.slot { display: grid; grid-template-columns: 24px 1fr; column-gap: 6px; align-items: center; text-align: left; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 5px 6px; min-height: 44px; font-size: 12px; }
.slot .sw { grid-row: span 2; }
.slot small { color: var(--muted); }
.slot.on { outline: 3px solid var(--accent); outline-offset: 1px; }
.sw { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .25); font: 700 12px ui-monospace, Menlo, Consolas, monospace; flex: 0 0 auto; vertical-align: middle; }
.in-hand { font-weight: 600; }

.list-opts { display: grid; gap: 4px; }
.totals { font-weight: 700; margin: 8px 0; }
.table-wrap { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
.list th, .list td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.list th { position: sticky; top: 0; background: var(--soft); font-size: 12px; }
.list .num { text-align: right; font-variant-numeric: tabular-nums; }
.colour-cell { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.cname { color: var(--muted); font-size: 13px; }
tr.need td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

.board-list { display: grid; gap: 6px; margin: 10px 0; }
.board-btn { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; min-height: 48px; padding: 4px 2px; display: grid; justify-items: center; font-size: 15px; min-width: 0; }
.board-btn small { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; max-width: 100%; }
.board-btn.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.board-btn.on small { color: inherit; }
.board-btn.empty { opacity: .5; }

.build-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.build-nav strong { text-align: center; font-size: 15px; }
.progress { height: 12px; border-radius: 999px; background: var(--soft); overflow: hidden; margin: 12px 0 6px; }
#progressBar { height: 100%; width: 0; background: var(--good); border-radius: 999px; transition: width .2s; }
.legend { display: grid; gap: 6px; max-height: 320px; overflow: auto; padding: 3px; }
.legend-item { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 6px 10px; min-height: 44px; text-align: left; font-size: 14px; }
.legend-item span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.legend-item i { margin-left: auto; font-style: normal; font-weight: 600; white-space: nowrap; }
.legend-item.on { outline: 3px solid var(--accent); outline-offset: 1px; }
.legend-item.done { opacity: .55; }

.dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink); width: min(760px, calc(100vw - 24px)); max-height: 88vh; padding: 16px; }
.dialog::backdrop { background: rgba(10, 10, 20, .55); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.dialog-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0 10px; }
.dialog-tools input { flex: 1 1 180px; width: auto; }
.colour-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 56vh; overflow: auto; padding: 3px; }
.colour-item { display: flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 5px 8px; min-height: 44px; text-align: left; font-size: 13px; min-width: 0; }
.colour-item span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.colour-item i { margin-left: auto; font-size: 10px; font-style: normal; color: var(--warn); }
.colour-item.on { border-color: var(--good); box-shadow: inset 0 0 0 1px var(--good); }

.prose { max-width: 820px; margin: 44px auto 0; }
.prose h2 { font-size: 26px; letter-spacing: -.01em; margin: 0 0 12px; }
.prose h3 { font-size: 17px; margin: 20px 0 4px; }
.prose p, .prose li { color: var(--muted); }
.prose p { margin: 0 0 8px; }
.steps { padding-left: 22px; display: grid; gap: 8px; }
.steps strong { color: var(--ink); }
.src-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.src-table th, .src-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--muted); }
.src-table th { color: var(--ink); }
.src-wrap { overflow-x: auto; }
.foot { max-width: 820px; margin: 40px auto 0; padding: 18px 16px 40px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.foot .small { font-size: 13px; }
.toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 30; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); text-align: center; }

.print-sheet { display: none; }
@media (max-width: 520px) {
  main { padding: 0 12px 40px; }
  .hero { padding-top: 22px; }
  .sample-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .sample { padding: 4px 4px 3px; font-size: 11px; min-width: 0; }
  .sample canvas { width: 100%; height: auto; aspect-ratio: 1; }
  .hero.compact .sample-row { display: flex; }
  .stage { padding: 8px; } .panel { padding: 12px; }
  .seg button { padding: 8px 9px; font-size: 13px; }
  .field.inline { grid-template-columns: 112px minmax(0, 1fr); }
  .colour-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
}
@media print {
  @page { margin: 10mm; }
  html, body { background: #fff; color: #000; }
  .top, .foot, .hero, .work, .prose, .toasts, .skip, dialog { display: none !important; }
  main { max-width: none; padding: 0; }
  .print-sheet { display: block; }
  .print-page { break-after: page; page-break-after: always; font-size: 11pt; color: #000; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page h1 { font-size: 20pt; margin: 0 0 4pt; }
  .print-page h2 { font-size: 13pt; margin: 0 0 6pt; }
  .print-page p { margin: 0 0 8pt; }
  .print-overview { display: block; max-width: 100%; max-height: 120mm; margin: 0 auto 8pt; }
  .print-board { display: block; width: 100%; max-height: 215mm; object-fit: contain; }
  .print-table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
  .print-table th, .print-table td { border-bottom: .5pt solid #999; padding: 2pt 4pt; text-align: left; }
  .print-legend { display: flex; flex-wrap: wrap; gap: 3pt 10pt; margin-top: 6pt; font-size: 9pt; }
  .print-key { display: inline-flex; align-items: center; gap: 3pt; }
  .print-key i { font-style: normal; color: #333; }
  .sw { width: 13pt; height: 13pt; font-size: 8pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
