:root {
  --accent: rgb(242, 115, 166);
  --accent-soft: rgb(252, 217, 230);
  --text-pink: rgb(217, 89, 140);
  --board: rgb(247, 230, 235);
  --bg-start: rgb(255, 230, 240);
  --bg-end: rgb(230, 220, 250);
  --ink: rgb(66, 50, 60);
  --muted: rgb(120, 102, 112);
  --panel: rgba(255, 255, 255, 0.92);
  --line: rgba(242, 115, 166, 0.24);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: ui-rounded, "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  background: linear-gradient(135deg, var(--bg-start), var(--bg-end));
}

button, input, select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  color: var(--text-pink);
  background: white;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.header {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 14px 22px;
  background: rgba(255, 255, 255, 0.72);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  color: var(--text-pink);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab {
  min-height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  font-weight: 700;
}

.tab.active {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.main {
  min-height: 0;
}

.workbench {
  height: calc(100vh - 67px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
}

.canvas-stage {
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
  background:
    radial-gradient(circle at 20px 20px, rgba(255,255,255,0.55) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(135deg, rgba(255,255,255,0.32), rgba(255,255,255,0.08));
}

.pattern-canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  background: var(--board);
  box-shadow: 0 18px 50px rgba(136, 78, 112, 0.2);
  transform-origin: 0 0;
  touch-action: none;
}

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.empty-state h1 {
  margin: 0 0 6px;
  color: var(--text-pink);
  font-size: 36px;
}

.zoom-bar {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 8px 20px rgba(136, 78, 112, 0.12);
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.side-panel {
  min-height: 0;
  overflow: auto;
  padding: 16px;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,0.58), rgba(255,255,255,0.28));
}

.group {
  margin-bottom: 16px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(136, 78, 112, 0.1);
}

.group h2 {
  margin: 0 0 12px;
  color: var(--text-pink);
  font-size: 17px;
}

.control {
  display: grid;
  gap: 7px;
  margin: 12px 0;
}

.control label,
.label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.segmented.three {
  grid-template-columns: repeat(3, 1fr);
}

.segment,
.shape-option {
  min-height: 38px;
  padding: 8px 4px;
  border-radius: 8px;
  font-size: 13px;
  white-space: nowrap;
}

.segment.active,
.shape-option.active {
  color: var(--text-pink);
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.shape-option {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  text-align: left;
  font-size: 12px;
  overflow: hidden;
}

.shape-option canvas {
  width: 34px;
  height: 34px;
}

.number-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px auto;
  align-items: center;
  gap: 8px;
}

input[type="number"],
input[type="text"] {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--ink);
  background: white;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.primary {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  color: white;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 800;
}

.secondary {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  font-weight: 800;
}

.file-button {
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  cursor: pointer;
  font-weight: 800;
}

.file-button input {
  display: none;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 8px;
}

.status {
  margin-top: 8px;
  color: rgb(32, 128, 78);
  font-size: 13px;
}

.bead-list {
  display: grid;
  gap: 8px;
}

.bead-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.15);
}

.gallery {
  padding: 20px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
}

.card {
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(136, 78, 112, 0.1);
}

.card canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background: var(--board);
  border-radius: 8px;
}

.card-title {
  margin: 10px 0 4px;
  color: var(--text-pink);
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  color: var(--muted);
  font-size: 13px;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(72, 46, 62, 0.34);
}

.modal {
  width: min(980px, 100%);
  max-height: min(760px, 92vh);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: white;
  border-radius: 8px;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-body {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
}

.detail-canvas-wrap {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: linear-gradient(135deg, var(--bg-start), var(--bg-end));
}

.detail-canvas-wrap canvas {
  display: block;
  margin: auto;
  background: var(--board);
}

.detail-side {
  min-height: 0;
  overflow: auto;
  padding: 16px;
  border-left: 1px solid var(--line);
}

@media (max-width: 840px) {
  .header {
    flex-wrap: wrap;
  }

  .workbench {
    height: auto;
    min-height: calc(100vh - 107px);
    grid-template-columns: 1fr;
  }

  .canvas-stage {
    height: 55vh;
  }

  .side-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .modal-body {
    grid-template-columns: 1fr;
  }

  .detail-side {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
