:root {
  --paper: #f4eee4;
  --paper-deep: #e9dfcf;
  --card: #fffcf6;
  --card-soft: #f8f1e5;
  --ink: #2b2620;
  --ink-soft: #5d5548;
  --muted: #8a8172;
  --faint: #aaa08f;
  --line: #e5dccd;
  --line-strong: #d6c9b5;
  --accent: #d45a38;
  --accent-dark: #b8482a;
  --accent-soft: #fae7de;
  --teal: #2c6e63;
  --teal-soft: #deece7;
  --danger: #c2402f;
  --shadow-sm: 0 1px 2px rgba(70, 52, 28, .05);
  --shadow: 0 1px 2px rgba(70, 52, 28, .05), 0 10px 30px -14px rgba(70, 52, 28, .25);
  --radius: 16px;
  --mono: "SFMono-Regular", "Cascadia Mono", "Roboto Mono", Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(circle at 1px 1px, rgba(96, 72, 38, .075) 1px, transparent 0);
  background-size: 18px 18px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection { background: var(--accent-soft); }

/* ---------- header ---------- */

.app-header {
  height: 64px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  padding: 0 18px;
  background: rgba(255, 252, 246, .88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 3px;
  background: var(--card-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: var(--shadow-sm);
}

.brand-mark .b {
  position: relative;
  border-radius: 50%;
  background: var(--c, var(--accent));
  box-shadow: inset 0 -1px 1px rgba(0, 0, 0, .12);
}
.brand-mark .b::after {
  content: "";
  position: absolute;
  inset: 3.5px;
  border-radius: 50%;
  background: #fff8ed;
  opacity: .92;
}
.brand-mark .b1 { --c: #d45a38; }
.brand-mark .b2 { --c: #e8926f; }
.brand-mark .b3 { --c: #f1c8b6; }
.brand-mark .b4 { --c: #2c6e63; }
.brand-mark .b5 { --c: #d9a441; }
.brand-mark .b6 { --c: #7f9f8b; }
.brand-mark .b7 { --c: #3f5d82; }
.brand-mark .b8 { --c: #e3c4a5; }
.brand-mark .b9 { --c: #b75f4a; }

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: .06em;
  font-weight: 800;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 10.5px;
  line-height: 1;
  color: var(--muted);
  letter-spacing: .12em;
}

.project-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

.project-name {
  width: min(340px, 38vw);
  padding: 6px 4px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-size: 14.5px;
  font-weight: 650;
  text-align: center;
  text-overflow: ellipsis;
  transition: background .15s, border-color .15s;
}
.project-name:hover:not(:disabled) { background: var(--card-soft); }
.project-name:focus { background: #fff; border-color: var(--line-strong); outline: none; }
.project-name:disabled { color: var(--faint); }
.project-name::placeholder { color: var(--faint); font-weight: 500; }

.save-state {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.header-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- buttons ---------- */

.btn {
  height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .06s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .42; }

.btn.primary {
  background: var(--accent);
  color: #fffaf4;
  box-shadow: 0 1px 2px rgba(150, 50, 25, .18), inset 0 1px 0 rgba(255, 255, 255, .18);
}
.btn.primary:hover:not(:disabled) { background: var(--accent-dark); }

.btn.ghost { border-color: var(--line); color: var(--ink-soft); background: rgba(255, 255, 255, .35); }
.btn.ghost:hover:not(:disabled) { background: var(--card-soft); border-color: var(--line-strong); }

.btn.subtle { background: var(--card-soft); border-color: var(--line); color: var(--ink-soft); }
.btn.subtle:hover:not(:disabled) { border-color: var(--line-strong); background: #f3e9da; }

.btn.large { height: 44px; padding: 0 20px; border-radius: 12px; font-size: 14px; }
.btn.block { width: 100%; }

.text-btn {
  border: 0;
  background: none;
  padding: 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  border-radius: 4px;
}
.text-btn:hover { color: var(--accent-dark); text-decoration: underline; text-underline-offset: 3px; }

.link-btn {
  border: 0;
  background: none;
  padding: 4px;
  font-size: 11.5px;
  color: var(--muted);
  border-radius: 4px;
}
.link-btn:hover { color: var(--accent); }

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
}
.icon-btn:hover { background: var(--card-soft); border-color: var(--line); }

/* ---------- layout ---------- */

.app-main {
  height: calc(100dvh - 64px);
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr) 286px;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

.panel {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.panel::-webkit-scrollbar { width: 7px; }
.panel::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; }
.panel::-webkit-scrollbar-track { background: transparent; }

.panel-left { display: flex; flex-direction: column; gap: 12px; padding-right: 2px; }
.panel-right { display: flex; flex-direction: column; gap: 12px; padding-left: 2px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 11px;
}
.card-head h2 {
  margin: 0;
  font-size: 12.5px;
  font-weight: 750;
  letter-spacing: .03em;
  color: var(--ink);
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 6px;
  background: var(--card-soft);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.hint {
  margin: 9px 0 0;
  font-size: 11px;
  line-height: 1.55;
  color: var(--muted);
}

/* ---------- upload ---------- */

.drop-zone { min-height: 156px; }

.drop-empty {
  border: 1.5px dashed var(--line-strong);
  border-radius: 13px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .55), rgba(248, 241, 229, .45));
  padding: 18px 14px 14px;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.drop-empty:hover { border-color: var(--accent); background: var(--accent-soft); }

.upload-glyph {
  width: 42px;
  height: 42px;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(212, 90, 56, .18);
}
.upload-glyph .icon { width: 21px; height: 21px; }

.drop-title { margin: 0; font-size: 13.5px; font-weight: 700; }
.drop-hint { margin: 4px 0 11px; font-size: 11px; color: var(--muted); line-height: 1.5; }

.drop-empty .btn { height: 34px; padding: 0 16px; font-size: 12.5px; }
.drop-empty .link-btn { display: block; margin: 7px auto 0; }

.image-preview { display: flex; flex-direction: column; gap: 10px; }

.preview-frame {
  height: 170px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background-color: #fbf7ef;
  background-image:
    linear-gradient(45deg, #eee5d6 25%, transparent 25%, transparent 75%, #eee5d6 75%),
    linear-gradient(45deg, #eee5d6 25%, transparent 25%, transparent 75%, #eee5d6 75%);
  background-size: 14px 14px;
  background-position: 0 0, 7px 7px;
  overflow: hidden;
}
.preview-frame img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 5px;
  box-shadow: 0 2px 8px rgba(50, 35, 15, .14);
}

.image-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 2px;
}
.image-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.image-size { font-size: 10.5px; color: var(--muted); font-family: var(--mono); }

.board-summary {
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px dashed var(--line-strong);
  background: var(--card-soft);
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.4;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------- controls ---------- */

.field-label {
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 6px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  background: #f1e9db;
  border-radius: 10px;
  margin-bottom: 12px;
}
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.segmented.three button { font-size: 10.5px; padding: 0 4px; }
.segmented button {
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  transition: background .15s, color .15s, box-shadow .15s;
}
.segmented button:hover { color: var(--ink-soft); }
.segmented button.active {
  background: #fffdf8;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(80, 55, 25, .12);
}
.segmented button:disabled { opacity: .42; cursor: not-allowed; }

.slider-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 8px;
  height: 30px;
}
.slider-row label { font-size: 11.5px; color: var(--muted); }
.slider-row output {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-soft);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent) 0 var(--fill, 50%), #e3d8c7 var(--fill, 50%) 100%);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 99px;
  background: #e3d8c7;
}
input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 99px;
  background: var(--accent);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: #fffdf8;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(80, 40, 20, .22);
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fffdf8;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(80, 40, 20, .22);
}
input[type="range"]:disabled { opacity: .45; cursor: not-allowed; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 11px;
  cursor: pointer;
  user-select: none;
}
.switch-row > span {
  font-size: 12px;
  line-height: 1.3;
}
.switch-row small {
  display: block;
  margin-top: 1px;
  font-size: 10.5px;
  font-weight: 400;
  color: var(--muted);
}
.switch-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.switch-row > i {
  width: 36px;
  height: 21px;
  flex: none;
  border-radius: 99px;
  background: #ded2bf;
  box-shadow: inset 0 1px 2px rgba(60, 40, 15, .12);
  transition: background .18s;
  position: relative;
}
.switch-row > i::after {
  content: "";
  position: absolute;
  top: 2.5px;
  left: 2.5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fffdf8;
  box-shadow: 0 1px 3px rgba(60, 40, 15, .25);
  transition: transform .18s;
}
.switch-row input:checked + i { background: var(--accent); }
.switch-row input:checked + i::after { transform: translateX(15px); }
.switch-row input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-row input:disabled + i { opacity: .4; }

.switch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
}
.switch-row.compact { margin-top: 4px; }
.switch-row.compact > span { font-size: 11.5px; }

/* ---------- stage ---------- */

.stage { min-width: 0; min-height: 0; }

.canvas-shell {
  position: relative;
  height: 100%;
  min-height: 260px;
  border-radius: 18px;
  border: 1px solid var(--line);
  overflow: hidden;
  background-color: #ece2d2;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(84, 62, 30, .10) 1px, transparent 0),
    linear-gradient(180deg, #f0e8da 0%, #e8ddcb 100%);
  background-size: 16px 16px, 100% 100%;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
}

#patternCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
body.is-busy #patternCanvas { cursor: progress; }

.toolbar {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 252, 246, .94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  max-width: calc(100% - 24px);
}

.tool {
  height: 34px;
  min-width: 34px;
  padding: 0 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 600;
  transition: background .13s, color .13s;
  white-space: nowrap;
}
.tool .icon { width: 17px; height: 17px; }
.tool:hover { background: var(--card-soft); color: var(--ink); }
.tool.active { background: var(--accent); color: #fffaf4; box-shadow: 0 1px 4px rgba(150, 55, 25, .25); }
.tool.active:hover { background: var(--accent-dark); color: #fff; }
.tool:disabled { opacity: .32; }
.tool:disabled:hover { background: transparent; }
.tool.danger:hover { background: #fae3df; color: var(--danger); }

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--line);
  margin: 0 3px;
  flex: none;
}

.zoom-pill {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  display: flex;
  align-items: center;
  padding: 4px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(255, 252, 246, .94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.zoom-pill button {
  height: 30px;
  min-width: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
}
.zoom-pill button:hover { background: var(--card-soft); color: var(--ink); }
.zoom-pill .icon { width: 16px; height: 16px; }
.zoom-pill .zoom-value {
  min-width: 54px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.stage-status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  padding: 7px 11px;
  border-radius: 9px;
  background: rgba(43, 38, 32, .82);
  color: rgba(255, 250, 242, .86);
  font-size: 11px;
  line-height: 1;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.stage-status #cursorStatus {
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-left: 10px;
  border-left: 1px solid rgba(255, 255, 255, .18);
  white-space: nowrap;
}
.selected-chip i {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, .4);
  background: #ccc;
}
.selected-chip b {
  font-family: var(--mono);
  font-size: 10.5px;
  color: #fff;
}
.selected-chip span { font-size: 10px; opacity: .62; }

.empty-stage {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(255, 252, 246, .96), rgba(244, 238, 228, .9) 72%);
  text-align: center;
}
.empty-stage[hidden] { display: none; }

.empty-inner { max-width: 360px; display: flex; flex-direction: column; align-items: center; }

.bead-heart { width: 132px; opacity: .96; margin-bottom: 2px; }
.bead-heart svg { width: 100%; height: auto; filter: drop-shadow(0 6px 10px rgba(160, 70, 40, .14)); }

.empty-inner h2 {
  margin: 8px 0 6px;
  font-size: 21px;
  letter-spacing: .02em;
  font-weight: 800;
}
.empty-inner p {
  margin: 0 0 16px;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--muted);
}
.empty-inner .btn { margin-bottom: 10px; }
.privacy-note { font-size: 10.5px !important; margin-bottom: 0 !important; color: var(--faint) !important; }

/* ---------- stats ---------- */

.stats-card {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 13px 8px;
}
.stat { text-align: center; min-width: 0; }
.stat strong {
  display: block;
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 650;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.stat span {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  color: var(--muted);
}

/* ---------- legend ---------- */

.legend-card {
  flex: 1;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.legend-search {
  position: relative;
  margin-bottom: 8px;
}
.legend-search .icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--faint);
  pointer-events: none;
}
.legend-search input {
  width: 100%;
  height: 32px;
  padding: 0 10px 0 29px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  font-size: 11.5px;
  outline: none;
}
.legend-search input:focus { border-color: var(--accent); }
.legend-search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.legend-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 1px 4px 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.legend-list::-webkit-scrollbar { width: 6px; }
.legend-list::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; }

.legend-item {
  width: 100%;
  display: grid;
  grid-template-columns: 21px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 6px 7px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  transition: background .12s, border-color .12s;
}
.legend-item:hover { background: var(--card-soft); }
.legend-item.selected {
  background: var(--accent-soft);
  border-color: rgba(212, 90, 56, .5);
}
.legend-item.selected .legend-code { color: var(--accent-dark); }

.legend-swatch {
  width: 21px;
  height: 21px;
  border-radius: 6px;
  border: 1px solid rgba(40, 30, 15, .15);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
  position: relative;
}
.legend-item.selected .legend-swatch::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 8px;
  border: 1.5px solid var(--accent);
}

.legend-code {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.legend-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}
.legend-count { font-family: var(--mono); font-size: 11px; color: var(--ink-soft); }
.legend-pct { font-size: 9.5px; color: var(--faint); }

.legend-empty {
  padding: 22px 8px;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--muted);
  text-align: center;
}

.palette-note {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 9.5px;
  line-height: 1.5;
  color: var(--faint);
  text-align: center;
}

/* ---------- drag overlay ---------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(244, 238, 228, .82);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  pointer-events: none;
}
body.dragging .drop-overlay { display: grid; }
.drop-overlay-inner {
  width: min(520px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 54px 24px;
  border: 2.5px dashed var(--accent);
  border-radius: 24px;
  background: rgba(255, 252, 246, .92);
  box-shadow: var(--shadow);
  text-align: center;
}
.drop-overlay-inner .icon { width: 34px; height: 34px; color: var(--accent); margin-bottom: 4px; }
.drop-overlay-inner strong { font-size: 17px; }
.drop-overlay-inner span { font-size: 11.5px; color: var(--muted); }

/* ---------- dialog ---------- */

.dialog {
  width: min(620px, 92vw);
  max-height: min(78vh, 720px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 30px 80px -20px rgba(50, 30, 10, .45);
  overflow: hidden;
}
.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop {
  background: rgba(40, 30, 18, .38);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--line);
}
.dialog-head h2 { margin: 0; font-size: 17px; letter-spacing: .02em; }
.dialog-sub { margin: 4px 0 0; font-size: 11px; color: var(--muted); }

.project-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
}

.project-item {
  cursor: pointer;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 12px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffefa;
  text-align: left;
  transition: border-color .15s, background .15s;
}
.project-item:hover { border-color: var(--line-strong); background: #fff; }
.project-item.current { border-color: var(--accent); background: var(--accent-soft); }

.project-thumb {
  width: 58px;
  height: 58px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  object-fit: cover;
}
.project-info { min-width: 0; }
.project-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-title .current-tag {
  flex: none;
  font-size: 9px;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid rgba(212, 90, 56, .35);
  border-radius: 4px;
  padding: 1px 4px;
}
.project-meta {
  margin-top: 4px;
  font-size: 10.5px;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-date {
  margin-top: 2px;
  font-size: 9.5px;
  color: var(--faint);
  font-family: var(--mono);
}
.project-del { color: var(--faint); }
.project-del:hover { color: var(--danger); background: #fae3df; border-color: #f0c7bf; }

.dialog-foot {
  display: flex;
  justify-content: flex-start;
  padding: 12px 20px 18px;
  border-top: 1px solid var(--line);
}

.project-empty {
  padding: 40px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

/* ---------- composer ---------- */

body.composing { overflow: hidden; }

.composer {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  background: #1b1814;
  color: #f4eee2;
}
.composer[hidden] { display: none !important; }
.composer:focus { outline: none; }

.composer-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 20px;
  padding: 13px 20px;
  background: #231f19;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  flex: none;
}

.composer-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.composer-kicker {
  flex: none;
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  background: rgba(212, 90, 56, .16);
  border: 1px solid rgba(212, 90, 56, .4);
  color: #f09a7d;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
}
.composer-title h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 750;
  letter-spacing: .01em;
  color: #fbf5e9;
  white-space: nowrap;
}
.composer-title p {
  margin: 3px 0 0;
  font-size: 10.5px;
  color: rgba(244, 238, 226, .5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-sizes {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .06);
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.composer-sizes::-webkit-scrollbar { display: none; }
.composer-sizes button {
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: rgba(244, 238, 226, .62);
  font-family: var(--mono);
  font-size: 10.5px;
  white-space: nowrap;
}
.composer-sizes button:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.composer-sizes button.active {
  background: var(--accent);
  color: #fffaf4;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .28);
}

.composer-actions { display: flex; gap: 8px; }
.composer-actions .btn { height: 36px; }
.composer-cancel {
  border-color: rgba(255, 255, 255, .16) !important;
  background: rgba(255, 255, 255, .04) !important;
  color: rgba(255, 250, 242, .82) !important;
}
.composer-cancel:hover { background: rgba(255, 255, 255, .09) !important; }

.composer-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
}

.composer-stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background-color: #14110e;
  background-image: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .05) 1px, transparent 0);
  background-size: 18px 18px;
}
#cropCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: move;
}

.composer-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 11px;
  border-radius: 8px;
  background: rgba(24, 21, 17, .78);
  border: 1px solid rgba(255, 255, 255, .12);
  color: #f2e9da;
  font-family: var(--mono);
  font-size: 10.5px;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.composer-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(24, 21, 17, .78);
  border: 1px solid rgba(255, 255, 255, .1);
  color: rgba(244, 238, 226, .62);
  font-size: 10px;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.composer-side {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  background: #241f19;
  border-left: 1px solid rgba(255, 255, 255, .09);
  overflow-y: auto;
}
.composer-section h3 {
  margin: 0 0 9px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  color: rgba(244, 238, 226, .4);
}

.composer-preset {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 11px;
  margin-bottom: 7px;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 10px;
  background: rgba(255, 255, 255, .035);
  color: #f2eadb;
  text-align: left;
  transition: background .15s, border-color .15s;
}
.composer-preset span { font-size: 12px; font-weight: 650; }
.composer-preset small { font-size: 10px; color: rgba(244, 238, 226, .42); line-height: 1.45; }
.composer-preset:hover { background: rgba(255, 255, 255, .07); border-color: rgba(255, 255, 255, .18); }
.composer-preset:active { transform: translateY(1px); }

.composer-custom-size {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: center;
  gap: 6px;
}
.composer-custom-size input {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 6px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 8px;
  background: rgba(255, 255, 255, .055);
  color: #f4eddf;
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
  -moz-appearance: textfield;
}
.composer-custom-size input::-webkit-outer-spin-button,
.composer-custom-size input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.composer-custom-size input:focus { outline: none; border-color: var(--accent); }
.composer-custom-size > span { color: rgba(244, 238, 226, .4); font-size: 11px; }
.composer-custom-size button {
  height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  color: #f2eadb;
  font-size: 11px;
  font-weight: 650;
}
.composer-custom-size button:hover { background: rgba(255, 255, 255, .11); }

.composer-tip {
  margin: 7px 0 0;
  font-size: 9.5px;
  line-height: 1.55;
  color: rgba(244, 238, 226, .36);
}

.composer-switch { margin-top: 0; }
.composer-mirror {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}

.bg-controls { margin-top: 10px; }
.bg-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.bg-color-label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex: 1;
  padding: 3px 7px 3px 3px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 8px;
  background: rgba(255, 255, 255, .04);
  font-family: var(--mono);
  font-size: 10px;
  color: rgba(244, 238, 226, .7);
}
.bg-color-label input[type="color"] {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.bg-color-label input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.bg-color-label input[type="color"]::-webkit-color-swatch {
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 6px;
}
.bg-pick-btn {
  height: 33px;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 8px;
  background: rgba(255, 255, 255, .05);
  color: rgba(244, 238, 226, .68);
  font-size: 10px;
  white-space: nowrap;
}
.bg-pick-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.bg-pick-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fffaf4;
}

.composer .slider-row { grid-template-columns: 34px minmax(0, 1fr) 26px; height: 28px; }
.composer .slider-row label { color: rgba(244, 238, 226, .5); font-size: 10.5px; }
.composer .slider-row output { color: rgba(244, 238, 226, .68); font-size: 9.5px; }
.composer .slider-row input[type="range"]::-webkit-slider-runnable-track {
  background: linear-gradient(90deg, var(--accent) 0 var(--fill, 50%), rgba(255, 255, 255, .16) var(--fill, 50%) 100%);
}
.composer .slider-row input[type="range"]::-moz-range-track { background: rgba(255, 255, 255, .16); }

.bg-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  margin-top: 9px;
  border-radius: 9px;
  background: rgba(255, 255, 255, .06);
}
.bg-mode button {
  height: 28px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: rgba(244, 238, 226, .5);
  font-size: 10px;
}
.bg-mode button.active {
  background: rgba(255, 255, 255, .14);
  color: #fffaf4;
}
.bg-reset { margin-top: 8px; color: rgba(240, 154, 125, .9); }
.composer-switch > span { color: #f0e8db; }
.composer-switch small { color: rgba(244, 238, 226, .4); }
.composer-switch > i { background: #4a4238; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .3); }
.composer-switch input:checked + i { background: var(--accent); }

.composer-readout { display: flex; flex-direction: column; gap: 7px; }
.composer-readout div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .04);
}
.composer-readout span { font-size: 10px; color: rgba(244, 238, 226, .42); }
.composer-readout strong { font-family: var(--mono); font-size: 10.5px; font-weight: 550; color: #f3eadc; }

.composer-note {
  margin: auto 0 0;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: 10px;
  line-height: 1.65;
  color: rgba(244, 238, 226, .38);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 200;
  transform: translate(-50%, 12px);
  max-width: min(420px, 88vw);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(43, 38, 32, .94);
  color: #fffaf2;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 12px 30px -8px rgba(30, 20, 10, .4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */

@media (max-width: 1240px) {
  .app-main { grid-template-columns: 276px minmax(0, 1fr) 266px; gap: 12px; padding: 12px; }
  .tool-label { display: none; }
  .tool { padding: 0 8px; }
}

@media (max-width: 1060px) {
  body { overflow: auto; }
  .app-header { position: sticky; top: 0; }
  .app-main {
    height: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    overflow: visible;
  }
  .stage {
    order: -1;
    height: min(56vh, 560px);
    min-height: 320px;
  }
  .panel { overflow: visible; padding: 0; }
  .panel-left {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
    gap: 12px;
  }
  .panel-right { display: block; }
  .legend-card { max-height: 480px; }
  .legend-list { max-height: 340px; }
  .stats-card { margin-bottom: 12px; }
}

@media (max-width: 900px) {
  .composer { overflow-y: auto; }
  .composer-head {
    position: sticky;
    top: 0;
    z-index: 6;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 9px 12px;
    padding: 10px 12px;
    background: #231f19;
  }
  .composer-title p { display: none; }
  .composer-title h2 { font-size: 15.5px; }
  .composer-sizes {
    grid-column: 1 / -1;
    grid-row: 2;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .composer-sizes::-webkit-scrollbar { display: none; }
  .composer-sizes button { flex: 1; }
  .composer-actions .btn { height: 33px; padding: 0 11px; font-size: 12px; }
  .composer-main { flex: none; display: flex; flex-direction: column; }
  .composer-stage { height: 52vh; min-height: 310px; flex: none; }
  .composer-side {
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, .09);
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-content: start;
    gap: 14px;
    padding: 14px;
  }
  .composer-section:first-child {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
  }
  .composer-section:first-child h3 { grid-column: 1 / -1; margin-bottom: 1px; }
  .composer-section:nth-child(2),
  .composer-section:nth-child(3) { grid-column: 1 / -1; }
  .composer-preset { margin: 0; height: 100%; }
  .composer-preset small { display: none; }
  .composer-note { grid-column: 1 / -1; margin: 0; padding-top: 10px; }
  .composer-hint { display: none; }
}

@media (max-width: 560px) {
  .composer-kicker { display: none; }
  .composer-title h2 { font-size: 15px; }
  .composer-sizes button { font-size: 9.5px; padding: 0 5px; }
  .composer-stage { height: 46vh; min-height: 280px; }
  .composer-side { grid-template-columns: 1fr; gap: 12px; }
  .composer-section:first-child { grid-template-columns: 1fr; }
  .composer-badge { top: 9px; left: 9px; height: 25px; padding: 0 8px; font-size: 9.5px; }
}

@media (max-width: 720px) {
  .app-header {
    height: 58px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: 0 10px;
  }
  .brand { gap: 8px; }
  .brand-mark { width: 32px; height: 32px; border-radius: 9px; padding: 2.5px; }
  .brand-text p { display: none; }
  .brand-text h1 { font-size: 15.5px; letter-spacing: .04em; }
  .project-name { width: 100%; font-size: 12.5px; padding: 5px 2px; }
  .save-state { display: none; }
  .header-actions { gap: 4px; }
  .header-actions .btn { width: 34px; height: 34px; padding: 0; }
  .header-actions .btn .label { display: none; }
  .header-actions .btn.primary { width: 38px; }

  .app-main { padding: 8px; gap: 10px; }
  .stage { height: min(48vh, 460px); min-height: 300px; }
  .canvas-shell { border-radius: 14px; min-height: 0; }

  .toolbar {
    top: 8px;
    left: 8px;
    right: 8px;
    max-width: none;
    padding: 3px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .tool { height: 32px; min-width: 32px; padding: 0 6px; }
  .tool .icon { width: 16px; height: 16px; }
  .toolbar-sep { margin: 0 2px; }

  .zoom-pill { top: auto; bottom: 46px; right: 8px; padding: 3px; }
  .zoom-pill button { height: 28px; min-width: 28px; }
  .zoom-pill .zoom-value { min-width: 48px; }

  .stage-status {
    left: 8px;
    right: 8px;
    bottom: 8px;
    max-width: none;
    padding: 6px 9px;
    font-size: 10px;
  }
  .selected-chip { padding-left: 7px; gap: 5px; }
  .selected-chip span { display: none; }

  .panel-left { grid-template-columns: 1fr; }
  .empty-inner h2 { font-size: 19px; }
  .bead-heart { width: 110px; }
  .privacy-note { font-size: 10px !important; }

  .card { padding: 13px; border-radius: 14px; }
  .preview-frame { height: 184px; }
  .dialog { width: 94vw; max-height: 82vh; }
  .dialog-head { padding: 16px 16px 12px; }
  .project-list { padding: 10px 16px; }
  .project-item { grid-template-columns: 48px minmax(0, 1fr) 30px; gap: 10px; }
  .project-thumb { width: 48px; height: 48px; }
  .toast { bottom: 18px; }
}

@media (max-width: 340px) {
  .brand-text { display: none; }
  .stage { min-height: 280px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
