:root {
  color-scheme: light;
  --paper: #f5f2e9;
  --ink: #24282a;
  --muted: #555b51;
  --rule: #c9cbbf;
  --cell-size: 48px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-size: 16px;
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; padding: 28px clamp(16px, 4.4vw, 64px) 24px; line-height: 1.5; }
button, input { font: inherit; color: inherit; }
button, input, summary, .projects { min-height: 44px; }
button { border: 1px solid #8a8d82; border-radius: 5px; background: #fffefa; padding: 10px 14px; font-size: 14px; font-weight: 650; cursor: pointer; }
button:hover { background: #eaece2; border-color: var(--ink); }
button:active { background: #dde2d3; }
button:disabled { cursor: default; color: #686b63; background: #e8e7df; border-color: #b7b9ae; }
a { color: inherit; text-underline-offset: 5px; }
:focus-visible { outline: 3px solid #174fb0; outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(32px, 3.1vw, 44px); line-height: 1.15; letter-spacing: -1.5px; font-weight: 750; }
h2 { font-size: 16px; font-weight: 700; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; max-width: 1600px; margin: 0 auto 25px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 750; color: var(--muted); margin-bottom: 9px; }
.intro { margin-top: 10px; color: var(--muted); }
.projects { display: inline-flex; align-items: center; flex-shrink: 0; font-size: 16px; }
main, footer { max-width: 1600px; margin-inline: auto; }
.setup { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px 32px; flex-wrap: wrap; }
#size-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.size-field { display: flex; flex-direction: column; gap: 5px; }
label { font-size: 14px; font-weight: 650; }
input[type=number] { width: 88px; height: 44px; border: 1px solid #8a8d82; border-radius: 4px; background: white; padding: 8px 12px; font-variant-numeric: tabular-nums; }
input[aria-invalid=true] { border: 2px solid #a32535; }
.primary { color: white; background: var(--ink); border-color: var(--ink); }
.primary:hover { color: white; background: #444b40; }
.support { color: var(--muted); font-size: 14px; }
#size-hint, .files > .support { margin-top: 7px; }
.files h2 { font-size: 14px; margin-bottom: 5px; }
.file-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.file-tools button { min-width: 116px; }
.error { margin-top: 12px; padding: 10px 14px; color: #872030; background: #fff1ef; border-left: 4px solid #a32535; font-size: 14px; max-width: 600px; overflow-wrap: anywhere; }
.palette-section { margin: 24px 0 22px; }
.section-line { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px 16px; }
#selected-tool { font-size: 14px; font-weight: 650; }
.palette { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 11px; }
.palette button { display: flex; align-items: center; gap: 11px; min-width: 118px; padding: 8px 12px; min-height: 50px; }
.palette button[aria-pressed=true] { outline: 2px solid var(--ink); outline-offset: 1px; background: white; }
.palette button[aria-pressed=true]:focus-visible { outline: 3px solid #174fb0; outline-offset: 3px; }
.bead { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; width: 32px; height: 32px; flex-shrink: 0; font: 700 22px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.red { background: #c73548; color: white; }
.blue { background: #245bb3; color: white; }
.yellow { background: #f2c94c; color: #24282a; }
.green { background: #27754b; color: white; }
.black { background: #24282a; color: white; }
.white { background: #fff; color: #24282a; border: 1.5px solid #24282a; }
.eraser-icon { background: transparent; border: 1px dashed #666c60; color: #444b40; font-family: system-ui, sans-serif; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 220px 300px; gap: 28px; align-items: start; border-top: 1px solid var(--rule); padding-top: 22px; }
.chart-section { min-width: 0; }
#dimensions { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.board-help { font-size: 14px; color: var(--muted); margin: 8px 0 14px; max-width: 670px; }
.board-scroll { max-width: 100%; max-height: 530px; overflow: auto; border: 1px solid #8a8d82; background: #eaece3; scrollbar-color: #8a8d82 #eaece3; scrollbar-gutter: stable; overscroll-behavior: contain; }
#chart { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: max-content; margin: 0; background: white; font-variant-numeric: tabular-nums; }
#chart th, #chart td { padding: 0; width: var(--cell-size); min-width: var(--cell-size); height: var(--cell-size); border-right: 1px solid #cdd1c5; border-bottom: 1px solid #cdd1c5; text-align: center; }
#chart th { background: #eaece3; font-size: 14px; font-weight: 650; color: #444b42; }
#chart thead th { position: sticky; top: 0; z-index: 3; border-bottom-color: #8a8d82; }
#chart tbody th { position: sticky; left: 0; z-index: 2; border-right-color: #8a8d82; }
#chart thead th:first-child { left: 0; z-index: 4; }
#chart .cell { display: flex; align-items: center; justify-content: center; width: calc(var(--cell-size) - 1px); height: calc(var(--cell-size) - 1px); min-width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 0; background: white; }
#chart .cell:hover { background: #eef0e6; box-shadow: inset 0 0 0 2px #7a8370; }
#chart .cell:focus-visible { outline: 3px solid #174fb0; outline-offset: -3px; position: relative; z-index: 1; }
#chart .bead { width: 38px; height: 38px; font-size: 25px; pointer-events: none; }
.print-cell { display: none; }
.chart-foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; color: var(--muted); font-size: 14px; }
.status { color: #384b30; font-size: 14px; padding-top: 12px; min-height: 40px; }
.transform-section { padding-top: 47px; }
.edit-tools { display: flex; flex-direction: column; gap: 18px; margin-top: 13px; }
.edit-tools button { width: 100%; min-height: 48px; }
.edit-tools button span { margin-right: 5px; font-size: 18px; line-height: 1; }
.edit-tools .support { margin-top: 8px; }
.tool-note { margin: 25px 0 9px; color: var(--muted); }
.example-help { margin-top: 8px; max-width: 320px; }
.quantities { border-left: 1px solid var(--rule); padding-left: 27px; }
.quantities h2 { font-size: 24px; letter-spacing: -.6px; line-height: 1.25; margin-bottom: 8px; }
.total { display: flex; align-items: baseline; gap: 14px; margin: 18px 0; }
.total strong { font-size: 58px; line-height: 1.1; letter-spacing: -2px; font-weight: 750; font-variant-numeric: tabular-nums; }
.total span { font-size: 14px; font-weight: 600; }
.counts-table { border-collapse: collapse; width: 100%; }
.counts-table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding-bottom: 10px; border-bottom: 1px solid #aeb3a3; text-align: left; }
.counts-table thead th:last-child { text-align: right; }
.counts-table tbody th { font-weight: 450; text-align: left; padding: 11px 0; }
.counts-table tbody td { text-align: right; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.counts-table tbody tr { border-bottom: 1px solid #d5d8cb; }
.color-label { display: flex; gap: 12px; align-items: center; }
.legend-note { color: var(--muted); font-size: 14px; margin: 16px 0 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.example-section { border-block: 1px solid var(--rule); margin-top: 26px; padding: 9px 0; }
summary { display: list-item; width: fit-content; cursor: pointer; font-size: 14px; padding: 10px 2px; text-decoration: underline; text-underline-offset: 4px; }
.import-details { max-width: 800px; font-size: 14px; color: var(--muted); padding: 8px 0 13px; }
.import-details p { margin-bottom: 12px; }
.example-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.import-details .format-note { margin: 16px 0 0; }
footer { padding-top: 18px; color: var(--muted); font-size: 12px; }
@media (max-width: 1199px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 280px; gap: 22px 28px; }
  .chart-section { grid-column: 1; grid-row: 1; }
  .transform-section { grid-column: 1; grid-row: 2; padding-top: 0; }
  .quantities { grid-column: 2; grid-row: 1 / 3; }
  .edit-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
  .edit-tools > button { grid-column: 1 / -1; }
  .tool-note { margin-top: 15px; }
}
@media (max-width: 800px) {
  .workspace { display: flex; flex-direction: column; gap: 24px; }
  .chart-section, .transform-section, .quantities { width: 100%; }
  .quantities { border-left: 0; border-top: 1px solid var(--rule); padding: 22px 0 0; }
  .counts-table { max-width: 540px; }
  .total { margin: 14px 0; }
  .board-scroll { max-height: 60vh; }
  .setup { gap: 19px; }
}
@media (max-width: 520px) {
  body { padding-top: 14px; }
  .page-header { flex-direction: column; gap: 7px; margin-bottom: 20px; }
  .projects { order: -1; align-self: flex-end; }
  .eyebrow { letter-spacing: 1px; }
  h1 { font-size: 34px; }
  .setup > section { width: 100%; }
  #size-form { gap: 12px; }
  #size-form .primary { flex-basis: 100%; }
  .size-field { flex: 1; min-width: 0; }
  input[type=number] { width: 100%; }
  .file-tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .file-tools button { min-width: 0; padding-inline: 8px; }
  .palette { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .palette button { min-width: 0; }
  .palette button:last-child { grid-column: 1 / -1; }
  .edit-tools { grid-template-columns: 1fr; }
  .edit-tools > button { grid-column: auto; }
  .example-actions { flex-direction: column; }
}
@media (forced-colors: active) {
  .bead { border: 1px solid CanvasText; }
  .palette button[aria-pressed=true] { outline-color: Highlight; }
}
@page { size: A4 portrait; margin: 12mm; }
@media print {
  :root { background: white; color: black; --cell-size: min(5mm, calc((100vw - 4px) / 33)); }
  body { padding: 0; background: white; font-size: 12px; }
  .screen-only, noscript { display: none !important; }
  .page-header { display: block; margin: 0 0 4mm; }
  .eyebrow { margin-bottom: 1mm; color: black; font-size: 12px; }
  h1 { font-size: 26px; letter-spacing: -.5px; }
  .intro { font-size: 12px; margin-top: 1mm; color: black; }
  .workspace { display: block; padding-top: 3mm; border-top: 1px solid black; }
  .chart-heading { margin-bottom: 2mm; }
  h2 { font-size: 16px; }
  #dimensions { font-size: 12px; color: black; }
  .board-scroll { display: block; width: max-content; max-width: none; max-height: none; height: auto; overflow: visible; border: 1px solid #666; scrollbar-gutter: auto; background: white; }
  #chart { width: max-content; break-inside: avoid; }
  #chart th, #chart td { width: var(--cell-size); min-width: var(--cell-size); height: var(--cell-size); border-color: #888; }
  #chart th, #chart thead th, #chart tbody th { position: static; background: white; color: black; font-size: min(12px, calc(var(--cell-size) * .6)); }
  #chart .cell { display: none; }
  .print-cell { display: flex; align-items: center; justify-content: center; width: calc(var(--cell-size) - 1px); height: calc(var(--cell-size) - 1px); }
  #chart .print-cell .bead { width: calc(var(--cell-size) * .84); height: calc(var(--cell-size) * .84); font-size: min(12px, calc(var(--cell-size) * .6)); background: white; color: black; border: 1px solid #444; }
  .chart-foot { margin: 2mm 0 3mm; font-size: 12px; color: black; }
  .quantities { border: 0; padding: 0; break-inside: avoid; }
  .quantities h2 { font-size: 18px; margin: 0 0 1mm; }
  .quantities .support, .legend-note { font-size: 12px; color: black; }
  .total { gap: 10px; margin: 1mm 0; }
  .total strong { font-size: 28px; letter-spacing: -.5px; }
  .total span { font-size: 12px; }
  .counts-table { max-width: 110mm; }
  .counts-table thead th { color: black; padding-bottom: 1mm; }
  .counts-table tbody th { font-size: 12px; padding: .6mm 0; }
  .counts-table tbody td { font-size: 14px; }
  .counts-table .bead { width: 5mm; height: 5mm; font-size: 12px; color: black; background: white; border: 1px solid #444; }
  .legend-note { margin: 2mm 0 1mm; }
}

/* Keep the drawing board reachable before secondary file controls. */
.files { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--rule); }
@media screen and (max-width: 520px) {
  body { padding-top: 8px; }
  .page-header { gap: 0; margin-bottom: 12px; }
  .eyebrow { margin-bottom: 4px; font-size: 10px; }
  h1 { font-size: 30px; }
  .intro { font-size: 16px; margin-top: 5px; }
  #size-form { display: grid; grid-template-columns: 1fr 1fr 1.6fr; gap: 8px; }
  #size-form .primary { padding: 5px 8px; line-height: 1.2; }
  .size-field { gap: 2px; }
  .setup .support { font-size: 14px; margin-top: 5px; }
  .palette-section { margin-block: 12px; }
  .palette { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 8px; }
  .palette button { flex-direction: column; gap: 2px; padding: 4px 2px; font-size: 14px; min-height: 58px; }
  .palette button:last-child { grid-column: auto; }
  .palette .bead { width: 26px; height: 26px; font-size: 18px; }
  .workspace { padding-top: 12px; }
  .board-help { margin: 5px 0 9px; font-size: 14px; }
  #dimensions { font-size: 14px; }
}
