:root {
  --bead-coral: #e85f69;
  --bead-coral-dark: #cb4652;
  --bead-cream: #fff8ef;
  --bead-ink: #31292a;
}

body {
  background:
    radial-gradient(circle at 92% 4%, rgba(255, 213, 195, .45), transparent 28%),
    linear-gradient(145deg, #fffaf4, #fff4f5 62%, #f9f5ef);
}

.bead-app { max-width: 1500px; }
.bead-header { padding-bottom: 18px; border-bottom: 1px solid rgba(166, 88, 82, .12); }
.bead-eyebrow { display: block; margin-bottom: 5px; color: var(--bead-coral); font-size: .7rem; font-weight: 900; letter-spacing: .12em; }
.bead-header h1 { letter-spacing: 0; }

.bead-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  min-width: 0;
}

.control-panel,
.workspace-panel,
.inventory-panel { min-width: 0; padding: 18px; }
.control-panel { position: sticky; top: 12px; max-height: calc(100dvh - 24px); overflow: auto; scrollbar-width: thin; }
.control-section + .control-section { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.section-heading > span { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 50%; background: #ffe1df; color: var(--bead-coral-dark); font-size: .68rem; font-weight: 900; }
.section-heading h2, .workspace-heading h2 { margin: 0; font-size: 1rem; letter-spacing: 0; }

.dropzone { min-height: 118px; border: 1px dashed rgba(214, 86, 95, .48); background: linear-gradient(135deg, #fff9f4, #fff0f2); }
.dropzone-icon { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; background: var(--bead-coral); color: #fff; font-size: 1.25rem; }
.dropzone.is-dragging { border-color: var(--bead-coral); background: #ffe9eb; transform: scale(.99); }

.source-preview-wrap { position: relative; margin-top: 12px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #f8edf1; }
#sourcePreview { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: contain; }
#sourceHint { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); font-size: .82rem; pointer-events: none; }

.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.form-grid > .field { min-width: 0; }
.dimensions-grid { margin-top: 10px; }
.range-field { grid-column: 1 / -1; }
.scheme-field { margin-top: 13px; }
.offset-grid { display: grid; gap: 8px; margin-top: 10px; }
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: .8rem; font-weight: 700; }
.check-row.inline { margin: 0; white-space: nowrap; }
.compact { padding: 12px 0 0; }
.import-toolbar { display: grid; grid-template-columns: 1fr 1fr; }
.generate-button { width: 100%; margin-top: 10px; background: var(--bead-coral); }
.generate-button:hover { background: var(--bead-coral-dark); }

.bead-main-column { display: grid; min-width: 0; gap: 14px; }
.workspace-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.board-status { padding: 5px 9px; border-radius: 999px; background: #fff0ec; color: #b9545b; font-size: .72rem; font-weight: 800; }
.editor-toolbar { padding: 0 0 12px; }
.toolbar-divider { width: 1px; height: 30px; background: var(--line); }
.zoom-control { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .78rem; font-weight: 800; }
.zoom-control input { width: 100px; }

.canvas-scroller {
  position: relative;
  min-height: 560px;
  max-height: 72vh;
  overflow: auto;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: #f9f3f6;
  background-image: linear-gradient(45deg, #f1e5e9 25%, transparent 25%), linear-gradient(-45deg, #f1e5e9 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #f1e5e9 75%), linear-gradient(-45deg, transparent 75%, #f1e5e9 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}
#beadCanvas { display: none; margin: auto; touch-action: none; image-rendering: pixelated; box-shadow: 0 14px 36px rgba(89,54,66,.16); }
#beadCanvas.is-pan-tool { cursor: grab; }
#beadCanvas.is-panning { cursor: grabbing; }
.canvas-empty { position: absolute; inset: 0; display: grid; place-content: center; gap: 8px; padding: 24px; color: var(--muted); text-align: center; }
.canvas-empty strong { color: #5d4e54; font-size: 1rem; }
.canvas-empty span { max-width: 380px; line-height: 1.6; }

.palette-editor { margin-top: 12px; }
.palette-heading { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; color: var(--muted); font-size: .82rem; }
.palette-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); gap: 6px; max-height: 146px; overflow: auto; padding: 3px; }
.color-swatch { position: relative; aspect-ratio: 1; border: 2px solid white; border-radius: 7px; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.color-swatch::after { position: absolute; inset: auto 2px 1px; overflow: hidden; color: rgba(25,20,22,.72); content: attr(data-code); font-size: 7px; font-weight: 900; text-align: center; text-shadow: 0 1px rgba(255,255,255,.7); }
.color-swatch.active { box-shadow: 0 0 0 3px var(--bead-coral), 0 7px 14px rgba(167,91,116,.2); transform: scale(.9); }

.process-panel { display: grid; gap: 9px; margin-top: 12px; padding: 12px; border: 1px solid #f2c6c9; border-radius: 8px; background: #fff8f7; }
.process-panel[hidden] { display: none; }
.process-panel > div { display: flex; justify-content: space-between; gap: 12px; color: #715e62; font-size: .8rem; }
.process-panel progress { width: 100%; accent-color: var(--bead-coral); }

.inventory-panel { position: relative; }
.inventory-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; list-style: none; }
.inventory-head::-webkit-details-marker { display: none; }
.inventory-head div { display: grid; gap: 4px; }
.inventory-head span { color: var(--muted); font-size: .8rem; }
.summary-hint { white-space: nowrap; }
.inventory-actions { display: flex; justify-content: flex-end; margin-top: -36px; padding-right: 92px; pointer-events: none; }
.inventory-actions .icon-btn { pointer-events: auto; }
.inventory-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 8px; max-height: 340px; margin: 16px 0; overflow: auto; }
.inventory-item { display: grid; grid-template-columns: 26px minmax(0,1fr) auto; gap: 9px; align-items: center; padding: 8px; border-radius: 8px; background: var(--surface-soft); font-size: .8rem; }
.inventory-chip { width: 26px; height: 26px; border: 2px solid white; border-radius: 7px; box-shadow: 0 0 0 1px var(--line); }
.inventory-item small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.export-stack { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.muted { color: var(--muted); font-size: .82rem; line-height: 1.6; }

@media (max-width: 980px) {
  .bead-layout { grid-template-columns: minmax(250px, 310px) minmax(0, 1fr); }
  .export-stack { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .bead-layout { grid-template-columns: 1fr; }
  .control-panel { position: static; max-height: none; }
  .workspace-panel { padding: 12px; }
  .editor-toolbar {
    position: fixed;
    right: 10px;
    bottom: 10px;
    left: 10px;
    z-index: 20;
    display: none;
    max-height: 30vh;
    overflow: auto;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255,255,255,.96);
    box-shadow: 0 16px 36px rgba(89,54,66,.2);
    backdrop-filter: blur(18px);
  }
  body.has-bead-project .editor-toolbar { display: flex; }
  body.has-bead-project .bead-app { padding-bottom: 118px; }
  .zoom-control { flex: 1 1 170px; }
  .canvas-scroller { min-height: 430px; max-height: 62vh; padding: 16px; }
  .inventory-list { grid-template-columns: 1fr 1fr; max-height: none; }
  .export-stack { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .range-field { grid-column: auto; }
  .canvas-scroller { min-height: 360px; padding: 10px; }
  .inventory-list { grid-template-columns: 1fr; }
  .export-stack { grid-template-columns: 1fr; }
}

@media print {
  body { background: white; }
  .app-header, .control-panel, .editor-toolbar, .palette-editor, .export-stack, .inventory-actions { display: none !important; }
  .app-shell, .workspace-panel, .inventory-panel { padding: 0; box-shadow: none; border: 0; }
  .bead-layout { display: block; }
  .canvas-scroller { min-height: 0; max-height: none; overflow: visible; padding: 10mm; border: 0; background: white; }
  #beadCanvas { max-width: 180mm; max-height: 180mm; box-shadow: none; }
  .inventory-list { grid-template-columns: repeat(4, 1fr); max-height: none; }
}
