.bead-studio {
  --bead-border: #d9e1d4;
  --bead-text-soft: #586b5d;
  background: #fff;
  border: 1px solid var(--bead-border);
  border-radius: 13px;
  box-shadow: 0 8px 32px #273b2a08;
  color: var(--ink, #243c30);
  scroll-margin-top: 24px;
}

.bead-studio [hidden] { display: none !important; }
.bead-studio-header, .bead-legend-header, .bead-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.bead-studio-header { padding: 16px 22px; border-bottom: 1px solid var(--bead-border); }
.bead-studio h2 { font-size: 16px; line-height: 1.35; }
.bead-studio h3, .bead-board legend, .bead-limit-label { font-size: 14px; line-height: 1.35; font-weight: 600; }
.bead-local, .bead-note { font-size: 12px; line-height: 1.5; color: var(--bead-text-soft); }
.bead-local > span { color: #527939; margin-right: 4px; }
.bead-workbench { display: grid; grid-template: "preview settings" / minmax(0, 1fr) 300px; }
.bead-preview { grid-area: preview; min-width: 0; padding: 20px; }
.bead-preview-header { margin-bottom: 12px; }
.bead-preview-header > div { min-width: 0; }
.bead-preview-header .bead-note { margin-top: 3px; overflow-wrap: anywhere; }
.bead-size-chip, .bead-total { flex: none; padding: 5px 9px; border-radius: 5px; background: #edf3e8; color: #35563c; font: 12px/1.4 'Space Mono', monospace; }
.bead-stage { overflow: hidden; border: 1px dashed #b8cbb2; border-radius: 8px; background: #f4f7f0; }
.bead-stage.is-dragging { border-color: #4c7935; background: #e0efce; }
.bead-viewport { max-height: 482px; overflow: auto; padding: 10px; }
.bead-viewport canvas {
  display: block;
  width: min(100%, var(--bead-grid-width, 100%));
  min-width: var(--bead-grid-min-width, 0);
  height: auto;
  margin-inline: auto;
}
.bead-placeholder { padding: 64px 16px; text-align: center; color: var(--bead-text-soft); font-size: 14px; }
.bead-preview-note { margin-top: 9px; }

.bead-settings { grid-area: settings; min-width: 0; padding: 20px; border-left: 1px solid var(--bead-border); }
.bead-image-actions, .bead-presets { display: flex; gap: 8px; }
.bead-image-actions { align-items: center; margin: 9px 0 6px; }
.bead-button, .bead-presets button, .bead-text-button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid #cad8c2;
  background: #fff;
  color: #243c30;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  padding: 8px 10px;
  cursor: pointer;
}
.bead-button:hover:not(:disabled), .bead-presets button:hover { background: #edf4e8; border-color: #8baa76; }
.bead-button:disabled { cursor: default; opacity: .55; }
.bead-upload > span, .bead-save > span { font-size: 17px; margin-right: 3px; }
.bead-text-button { background: transparent; border-color: transparent; color: #406642; text-decoration: underline; text-underline-offset: 3px; }
.bead-text-button:hover { color: #29452a; }
.bead-board { min-width: 0; margin: 17px 0 14px; padding: 0; border: 0; }
.bead-board legend { margin-bottom: 8px; padding: 0; }
.bead-presets button { flex: 1; white-space: nowrap; padding-inline: 5px; }
.bead-presets button[aria-pressed="true"] { background: #eaf4dc; border-color: #82a465; }
.bead-dimensions { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 9px; align-items: end; margin-top: 9px; }
.bead-dimensions > span { padding-block: 10px; }
.bead-dimensions label { min-width: 0; color: var(--bead-text-soft); font-size: 12px; }
.bead-settings input[type="number"], .bead-settings select {
  display: block;
  width: 100%;
  min-height: 39px;
  margin-top: 5px;
  padding: 6px 8px;
  border: 1px solid #cad8c2;
  border-radius: 6px;
  background: #fff;
  color: #243c30;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.3;
}
.bead-actions { display: grid; gap: 8px; margin-top: 17px; }
.bead-save { background: #d5f3a4; border-color: #abca82; }
.bead-save:hover:not(:disabled) { background: #c9ea94; }
.bead-error { margin-top: 11px; padding: 9px 10px; border-radius: 5px; background: #fff2ea; color: #883917; font-size: 13px; line-height: 1.45; }

.bead-legend { padding: 16px 20px 20px; border-top: 1px solid var(--bead-border); }
.bead-legend-header { margin-bottom: 12px; }
.bead-legend-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(166px, 1fr)); gap: 8px; padding: 0; margin: 0; list-style: none; }
.bead-legend-list button {
  display: grid;
  width: 100%;
  min-height: 47px;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  text-align: left;
  padding: 6px 8px;
  border: 1px solid var(--bead-border);
  border-radius: 6px;
  background: #f9fbf7;
  color: #243c30;
  cursor: pointer;
}
.bead-legend-list button:hover, .bead-legend-list button[aria-pressed="true"] { border-color: #5e8649; background: #eaf4dc; }
.bead-swatch { display: grid; place-items: center; width: 27px; height: 27px; border: 1px solid #0003; border-radius: 4px; font-weight: 600; font-size: 12px; }
.bead-hex { font: 12px/1.3 'Space Mono', monospace; }
.bead-quantity { font-size: 12px; font-weight: 600; white-space: nowrap; }
.bead-studio :is(button, input, select, [tabindex]):focus-visible { outline: 2px solid #4d713b; outline-offset: 2px; }
.bead-viewport:focus-visible { outline-offset: -2px; }
.bead-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.bead-print-sheets { display: none; }

@media (max-width: 760px) {
  .bead-workbench { grid-template: "settings" "preview" / minmax(0, 1fr); }
  .bead-settings { border-left: 0; border-bottom: 1px solid var(--bead-border); }
  .bead-viewport { max-height: 420px; }
}
@media (max-width: 480px) {
  .bead-studio-header, .bead-preview, .bead-settings, .bead-legend { padding-inline: 13px; }
  .bead-studio-header { align-items: flex-start; flex-direction: column; gap: 4px; }
  .bead-legend-list { grid-template-columns: repeat(auto-fit, minmax(142px, 1fr)); }
  .bead-viewport { padding: 5px; }
}

@media print {
  @page { margin: 10mm; }
  body:has(.bead-print-sheet), html:has(.bead-print-sheet) { margin: 0; background: #fff; color: #000; }
  body:has(.bead-print-sheet) > :not(main),
  #main:has(.bead-print-sheet) > :not([data-gf-tool="pixel-art-to-bead-pattern"]),
  .bead-studio:has(.bead-print-sheet) > :not(.bead-print-sheets) { display: none !important; }
  .bead-studio:has(.bead-print-sheet) { width: auto; max-width: none; margin: 0; border: 0; box-shadow: none; }
  .bead-print-sheets { display: block; color: #000; font-family: Arial, sans-serif; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .bead-print-sheet { break-after: page; break-inside: avoid-page; }
  .bead-print-sheet:last-child { break-after: auto; }
  .bead-print-sheet h2 { margin: 0 0 1.5mm; font: 700 16pt/1.2 Arial, sans-serif; }
  .bead-print-sheet > p { margin: 0 0 3mm; font-size: 9pt; line-height: 1.3; }
  .bead-print-sheet canvas { display: block; width: auto; height: auto; max-width: 165mm; max-height: 165mm; }
  .bead-print-sheet h3 { margin: 3mm 0 1.5mm; font: 700 11pt/1.2 Arial, sans-serif; }
  .bead-print-legend { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.5mm 3mm; margin: 0; padding: 0; list-style: none; }
  .bead-print-legend li { font-size: 9pt; line-height: 1.25; }
}
