:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-strong: #fdfdfd;
  --ink: #171717;
  --muted: #6b7280;
  --soft: #e8eaf0;
  --line: #dfe3ea;
  --line-strong: #c9ced8;
  --rose: #b84a68;
  --gold: #d6a84c;
  --mint: #2f9b82;
  --blue: #3f6fb8;
  --danger: #d64c4c;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.1);
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(180deg, #fbfcfd 0%, #f4f6f8 42%, #eef1f4 100%);
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.app-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid rgba(214, 219, 228, 0.82);
  backdrop-filter: blur(18px);
  z-index: 30;
}

.brand-wrap,
.topbar-actions,
.metric-row,
.section-row,
.mobile-row {
  display: flex;
  align-items: center;
}

.brand-wrap {
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #10131c 0%, #26324d 52%, #d6a84c 100%);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(23, 23, 23, 0.16);
  flex: 0 0 auto;
}

.title-stack {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.title-stack input {
  width: min(38vw, 280px);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
  font-size: 16px;
  line-height: 1.1;
  padding: 5px 6px;
  border-radius: 9px;
  outline: none;
}

.title-stack input:focus {
  border-color: var(--line);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(71, 117, 202, 0.12);
}

.title-stack span {
  padding-left: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.topbar-actions {
  gap: 10px;
}

.icon-button,
.soft-button,
.primary-button,
.danger-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: 999px;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, color 160ms ease;
  user-select: none;
}

.icon-button {
  width: 38px;
  padding: 0;
  color: #303744;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.icon-button:hover,
.soft-button:hover,
.primary-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
}

.icon-button:active,
.soft-button:active,
.primary-button:active,
.danger-button:active,
.material-card:active {
  transform: scale(0.98);
}

.icon-button.subtle {
  background: rgba(255, 255, 255, 0.75);
}

.soft-button {
  padding: 0 14px;
  color: #27303f;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
  font-weight: 700;
  font-size: 13px;
}

.primary-button {
  padding: 0 16px;
  background: #151719;
  color: #fff;
  box-shadow: 0 12px 28px rgba(23, 23, 23, 0.18);
  font-weight: 800;
  font-size: 13px;
}

.primary-button:hover {
  background: #000;
  box-shadow: 0 14px 32px rgba(23, 23, 23, 0.24);
}

.danger-button {
  padding: 0 14px;
  color: #b42323;
  background: #fff7f7;
  border: 1px solid #ffd1d1;
  font-weight: 800;
}

.text-button {
  min-height: 30px;
  color: var(--blue);
  background: transparent;
  font-size: 12px;
  font-weight: 800;
  padding: 0 2px;
}

.gradient-action {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(105deg, #25304b 0%, #b84a68 46%, #d6a84c 100%);
  box-shadow: 0 10px 24px rgba(184, 74, 104, 0.2);
}

.studio-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 310px minmax(420px, 1fr) 310px;
  gap: 14px;
  padding: 14px;
}

.library-panel,
.summary-panel,
.canvas-panel {
  min-height: 0;
  border: 1px solid rgba(214, 219, 228, 0.88);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
}

.library-panel,
.summary-panel {
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.canvas-panel {
  position: relative;
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}

.panel-section {
  padding: 16px;
  border-bottom: 1px solid rgba(223, 227, 234, 0.76);
}

.library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h2,
h3,
p {
  margin-top: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
  line-height: 1.1;
}

h3 {
  margin-bottom: 0;
  font-size: 15px;
}

.search-section {
  padding-top: 12px;
  padding-bottom: 12px;
}

.search-box {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f9fafb;
  padding: 0 12px;
}

.search-box svg {
  width: 16px;
  height: 16px;
  color: #8b95a6;
}

.search-box input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.search-box.compact {
  height: 38px;
  flex: 1;
}

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(223, 227, 234, 0.76);
  scrollbar-width: thin;
}

.category-tab {
  height: 32px;
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 0 12px;
  background: #f4f5f7;
  color: #687386;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid transparent;
}

.category-tab.active {
  color: #fff;
  background: #171717;
  border-color: #171717;
  box-shadow: 0 8px 18px rgba(23, 23, 23, 0.14);
}

.material-grid {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
  align-content: start;
}

.material-card {
  position: relative;
  min-height: 118px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid #edf0f5;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
  padding: 10px 7px 8px;
  display: grid;
  justify-items: center;
  gap: 6px;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.material-card:hover {
  border-color: #9eb5e5;
  box-shadow: 0 10px 24px rgba(71, 117, 202, 0.13);
  transform: translateY(-2px);
}

.material-card.disabled {
  opacity: 0.55;
  filter: grayscale(0.4);
  cursor: not-allowed;
}

.material-preview {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  position: relative;
}

.mini-bead {
  width: var(--size, 38px);
  height: var(--size, 38px);
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255,255,255,0.96), rgba(255,255,255,0.28) 26%, transparent 42%),
    radial-gradient(circle at 63% 74%, rgba(0,0,0,0.18), transparent 34%),
    linear-gradient(135deg, var(--c1), var(--c2));
  box-shadow: inset -7px -9px 15px rgba(0,0,0,0.22), inset 4px 4px 10px rgba(255,255,255,0.46), 0 5px 10px rgba(15,23,42,0.12);
}

.mini-bead.spacer {
  height: calc(var(--size, 38px) * 0.62);
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.85), transparent 22%, rgba(0,0,0,0.16) 72%, rgba(255,255,255,0.44)),
    linear-gradient(135deg, var(--c1), var(--c2));
}

.mini-bead.pendant {
  width: calc(var(--size, 38px) * 0.72);
  height: calc(var(--size, 38px) * 1.18);
  border-radius: 50% 50% 48% 48%;
  clip-path: polygon(50% 0, 86% 26%, 78% 100%, 22% 100%, 14% 26%);
}

.material-name {
  width: 100%;
  color: #27303f;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.material-meta {
  display: flex;
  justify-content: center;
  gap: 5px;
  color: #8b95a6;
  font-size: 9px;
  font-weight: 800;
}

.stock-chip {
  position: absolute;
  top: 7px;
  right: 7px;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #edfdf6;
  color: #168064;
  font-size: 9px;
  font-weight: 900;
}

.canvas-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(223, 227, 234, 0.78);
  background: rgba(255, 255, 255, 0.94);
  z-index: 5;
}

.metric-row {
  min-width: 0;
  gap: 8px;
}

.metric-pill {
  height: 34px;
  max-width: 210px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  padding: 0 12px;
  background: rgba(244, 247, 246, 0.96);
  border: 1px solid #e2e7ea;
  color: #256a5a;
}

.metric-pill.dark {
  color: #fff;
  background: #171717;
  border-color: #171717;
}

.metric-pill span {
  color: currentColor;
  opacity: 0.58;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.metric-pill strong {
  min-width: 0;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-count-pill {
  display: none;
}

.zoom-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom-tools .icon-button {
  width: 34px;
  height: 34px;
  min-height: 34px;
}

#zoomLabel {
  width: 46px;
  text-align: center;
  font-size: 12px;
  font-weight: 900;
  color: #526071;
}

.canvas-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(226,232,240,0.45) 1px, transparent 1px),
    linear-gradient(180deg, rgba(226,232,240,0.45) 1px, transparent 1px),
    linear-gradient(180deg, #ffffff 0%, #f7f9fc 54%, #eef2f7 100%);
  background-size: 32px 32px, 32px 32px, auto;
}

#braceletCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#braceletCanvas.dragging {
  cursor: grabbing;
}

.trash-zone {
  position: absolute;
  right: 28px;
  bottom: 30px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #8f9aad;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid #e4e7ed;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
  z-index: 4;
}

.trash-zone.active {
  color: #fff;
  background: var(--danger);
  border-color: #c93737;
  box-shadow: 0 12px 32px rgba(214, 76, 76, 0.32);
  transform: rotate(8deg) scale(1.08);
}

.canvas-hint {
  position: absolute;
  left: 18px;
  bottom: 18px;
  max-width: min(430px, calc(100% - 120px));
  padding: 9px 12px;
  border-radius: 999px;
  color: #526071;
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid #e4e7ed;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
  z-index: 4;
}

.summary-panel {
  overflow: auto;
}

.summary-panel h2 {
  word-break: break-word;
}

.stat-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 15px;
}

.stat-stack div {
  min-height: 62px;
  border-radius: 14px;
  border: 1px solid #edf0f5;
  background: #fafbfc;
  padding: 10px;
}

.stat-stack span {
  display: block;
  color: #798497;
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 7px;
}

.stat-stack strong {
  display: block;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.status-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: linear-gradient(135deg, #fff, #fbfbfd);
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 4px;
  background: var(--gold);
  box-shadow: 0 0 0 5px rgba(200, 150, 62, 0.13);
  flex: 0 0 auto;
}

.status-card.good .status-dot {
  background: var(--mint);
  box-shadow: 0 0 0 5px rgba(47, 155, 130, 0.13);
}

.status-card.warn .status-dot {
  background: var(--rose);
  box-shadow: 0 0 0 5px rgba(199, 77, 112, 0.13);
}

.status-card strong {
  display: block;
  font-size: 14px;
  margin-bottom: 5px;
}

.status-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.base-style-panel {
  display: grid;
  gap: 10px;
}

.base-style-panel h3,
.mobile-base-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.base-control-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(66px, 1fr));
  gap: 7px;
}

.base-option-button {
  min-width: 0;
  height: 34px;
  border-radius: 12px;
  border: 1px solid #e1e5ed;
  background: #f8fafc;
  color: #465264;
  font-size: 12px;
  font-weight: 900;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, color 160ms ease, transform 160ms ease;
}

.base-option-button:hover {
  transform: translateY(-1px);
  border-color: #b8c4d6;
}

.base-option-button.active {
  color: #fff;
  background: #171717;
  border-color: #171717;
  box-shadow: 0 8px 18px rgba(23, 23, 23, 0.14);
}

.base-swatch-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.base-metal-button {
  min-width: 0;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 12px;
  border: 1px solid #e1e5ed;
  background: #fff;
  color: #465264;
  font-size: 12px;
  font-weight: 900;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.base-metal-button:hover {
  transform: translateY(-1px);
  border-color: #b8c4d6;
}

.base-metal-button.active {
  border-color: #171717;
  box-shadow: 0 0 0 2px rgba(23, 23, 23, 0.08), 0 8px 18px rgba(23, 23, 23, 0.08);
}

.metal-dot {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255,255,255,0.95), rgba(255,255,255,0.18) 34%, transparent 52%),
    linear-gradient(135deg, var(--metal-light), var(--metal-base) 48%, var(--metal-dark));
  box-shadow: inset -4px -5px 8px rgba(0, 0, 0, 0.18), inset 3px 3px 5px rgba(255, 255, 255, 0.38);
}

.section-row {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.used-empty {
  min-height: 54px;
  border-radius: 14px;
  border: 1px dashed #d9dee8;
  color: #8b95a6;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 12px;
  font-size: 12px;
  font-weight: 700;
  background: #fbfcfd;
}

.used-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 9px;
  align-items: center;
  min-height: 44px;
  padding: 7px;
  border-radius: 13px;
  border: 1px solid #edf0f5;
  background: #fff;
}

.used-item .mini-bead {
  width: 28px;
  height: 28px;
}

.used-item strong {
  display: block;
  font-size: 12px;
  line-height: 1.2;
}

.used-item span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-top: 2px;
}

.used-count {
  min-width: 26px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #f0f3f8;
  color: #465264;
  font-size: 11px;
  font-weight: 900;
}

.action-stack {
  display: grid;
  gap: 10px;
  border-bottom: 0;
}

.wide {
  width: 100%;
  min-height: 44px;
}

.toast-region {
  position: fixed;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
}

.toast {
  min-width: 240px;
  max-width: min(420px, calc(100vw - 32px));
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(23, 23, 23, 0.92);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 700;
  animation: toast-in 180ms ease both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.preview-dialog {
  width: min(900px, calc(100vw - 30px));
  border: 0;
  padding: 0;
  border-radius: 22px;
  background: transparent;
}

.preview-dialog::backdrop {
  background: rgba(12, 16, 24, 0.62);
  backdrop-filter: blur(8px);
}

.preview-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(280px, 1.08fr) minmax(260px, 0.92fr);
  gap: 0;
  background: #fff;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.24);
}

.dialog-close {
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 2;
}

.preview-visual {
  min-height: 460px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #f8fafc, #eef2f7);
  padding: 28px;
}

.preview-visual img {
  width: min(100%, 520px);
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 18px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.12);
  background: #fff;
}

.preview-copy {
  padding: 42px 32px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.preview-copy h2 {
  font-size: 28px;
}

.preview-copy p {
  color: var(--muted);
}

.preview-copy label {
  display: grid;
  gap: 8px;
  color: #4b5563;
  font-size: 12px;
  font-weight: 800;
}

.preview-copy textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f9fafb;
  padding: 12px;
  color: #243041;
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: auto;
}

.mobile-menu-button,
.mobile-library,
.mobile-base-style {
  display: none;
}

.mobile-tool {
  flex: 0 0 auto;
}

.primary-icon {
  color: #fff;
  background: #151719;
  border-color: #151719;
  box-shadow: 0 10px 24px rgba(23, 23, 23, 0.18);
}

.danger-icon {
  color: #b42323;
  background: #fff7f7;
  border-color: #ffd1d1;
}

.mobile-grip {
  width: 96px;
  height: 6px;
  border-radius: 999px;
  background: #d7dce5;
  margin: 10px auto 8px;
}

.mobile-row {
  gap: 10px;
  padding: 0 12px 8px;
}

@media (max-width: 1180px) {
  .studio-layout {
    grid-template-columns: 270px minmax(360px, 1fr);
  }

  .summary-panel {
    display: none;
  }

  .desktop-only {
    display: none;
  }
}

@media (max-width: 840px) {
  html,
  body,
  .app-shell {
    height: 100dvh;
    min-height: 100svh;
  }

  body {
    overflow: hidden;
    overscroll-behavior: none;
  }

  .topbar {
    flex: 0 0 58px;
    height: 58px;
    padding: 0 10px;
    gap: 8px;
  }

  .brand-mark,
  .topbar .primary-button,
  .topbar .gradient-action {
    display: none;
  }

  .title-stack input {
    width: min(52vw, 220px);
    font-size: 15px;
  }

  .title-stack span {
    max-width: 52vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-menu-button {
    display: inline-flex;
  }

  .studio-layout {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-columns: 1fr;
    padding: 0;
    gap: 0;
  }

  .library-panel {
    display: none;
  }

  .canvas-panel {
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .canvas-head {
    flex: 0 0 auto;
    min-height: 50px;
    padding: 8px 10px;
    gap: 8px;
  }

  .metric-row {
    flex: 1 1 auto;
    min-width: 0;
    gap: 6px;
  }

  .metric-pill {
    height: 31px;
    min-width: 0;
    max-width: none;
    padding: 0 10px;
  }

  .metric-pill span {
    display: none;
  }

  .mobile-count-pill {
    display: inline-flex;
  }

  .zoom-tools .icon-button {
    display: none;
  }

  #zoomLabel {
    width: 42px;
  }

  .canvas-stage {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
  }

  .trash-zone {
    width: 48px;
    height: 48px;
    right: 12px;
    bottom: 18px;
  }

  .canvas-hint {
    left: 10px;
    bottom: 14px;
    max-width: calc(100% - 80px);
    font-size: 11px;
    border-radius: 14px;
  }

  .mobile-library {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    grid-template-rows: 16px 74px 42px minmax(0, 1fr);
    flex: 0 0 clamp(292px, 42dvh, 430px);
    height: clamp(292px, 42dvh, 430px);
    min-height: 0;
    overflow: hidden;
    border-top: 1px solid #dfe3ea;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 -12px 28px rgba(15, 23, 42, 0.12);
    z-index: 12;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .mobile-grip,
  .mobile-row,
  .mobile-base-style {
    flex: 0 0 auto;
    position: relative;
    z-index: 3;
    background: rgba(255, 255, 255, 0.97);
  }

  .mobile-grip {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 84px;
    height: 5px;
    margin: 7px auto 4px;
  }

  .mobile-row {
    grid-column: 1;
    grid-row: 2 / 5;
    align-self: stretch;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    padding: 8px 8px max(10px, env(safe-area-inset-bottom));
    border-right: 1px solid rgba(223, 227, 234, 0.72);
  }

  .mobile-row .search-box {
    width: 100%;
    min-width: 0;
    flex: 0 0 40px;
    height: 40px;
    padding: 0 8px;
  }

  .mobile-row .search-box svg {
    flex: 0 0 auto;
  }

  .mobile-row .search-box input {
    min-width: 0;
    font-size: 12px;
  }

  .mobile-tool {
    width: 40px;
    height: 40px;
    min-height: 40px;
    margin-inline: auto;
  }

  .mobile-tool svg {
    width: 17px;
    height: 17px;
  }

  .mobile-base-style {
    display: block;
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
    padding: 6px 10px 7px;
    border-bottom: 1px solid rgba(223, 227, 234, 0.56);
  }

  .mobile-base-title {
    height: 18px;
    color: #27303f;
    font-size: 12px;
    font-weight: 900;
    line-height: 18px;
  }

  .mobile-base-controls {
    display: grid;
    grid-template-columns: minmax(58px, 0.84fr) minmax(92px, 1.36fr) minmax(66px, 0.78fr);
    gap: 6px;
    margin-top: 5px;
    min-width: 0;
  }

  .base-control-group.compact,
  .base-swatch-row.compact {
    gap: 4px;
  }

  .base-control-group.compact {
    grid-template-columns: repeat(auto-fit, minmax(26px, 1fr));
  }

  .base-swatch-row.compact {
    grid-template-columns: repeat(3, 20px);
    justify-content: end;
  }

  .base-control-group.compact .base-option-button {
    height: 29px;
    border-radius: 9px;
    padding: 0 3px;
    font-size: 11px;
  }

  .base-swatch-row.compact .base-metal-button {
    width: 20px;
    height: 29px;
    padding: 0;
    border-radius: 9px;
  }

  .base-swatch-row.compact .base-metal-button span:not(.metal-dot) {
    display: none;
  }

  .base-swatch-row.compact .metal-dot {
    width: 15px;
    height: 15px;
  }

  .mobile-tabs {
    grid-column: 2;
    grid-row: 3;
    flex: 0 0 auto;
    min-height: 42px;
    padding: 7px 12px;
    border-bottom-color: rgba(223, 227, 234, 0.56);
    background: rgba(255, 255, 255, 0.97);
    scrollbar-width: none;
    position: relative;
    z-index: 2;
  }

  .mobile-tabs::-webkit-scrollbar {
    display: none;
  }

  .mobile-grid {
    grid-column: 2;
    grid-row: 4;
    flex: 1 1 0;
    min-height: 0;
    grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
    padding: 8px 10px max(14px, env(safe-area-inset-bottom));
    gap: 8px;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .material-card {
    min-height: 90px;
    padding: 7px 5px 6px;
    border-radius: 14px;
  }

  .material-preview {
    width: 38px;
    height: 38px;
  }

  .mini-bead {
    --size: 32px;
  }

  .material-name {
    font-size: 9px;
  }

  .material-meta {
    font-size: 8px;
  }

  .preview-card {
    grid-template-columns: 1fr;
    max-height: calc(100dvh - 28px);
    overflow: auto;
  }

  .preview-visual {
    min-height: 260px;
    padding: 18px;
  }

  .preview-copy {
    padding: 24px 20px 20px;
  }

  .preview-copy h2 {
    font-size: 22px;
  }
}

@media (max-width: 460px) {
  .topbar {
    padding: 0 8px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .icon-button {
    width: 36px;
    min-height: 36px;
  }

  .metric-pill {
    padding: 0 8px;
  }

  .metric-pill strong {
    font-size: 11px;
  }

  #zoomLabel {
    display: none;
  }

  .mobile-library {
    flex-basis: clamp(300px, 44dvh, 410px);
    height: clamp(300px, 44dvh, 410px);
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .mobile-row {
    gap: 6px;
    padding: 7px 6px max(9px, env(safe-area-inset-bottom));
  }

  .mobile-row .search-box {
    height: 38px;
    flex-basis: 38px;
    padding: 0 7px;
  }

  .mobile-tool {
    width: 38px;
    height: 38px;
    min-height: 38px;
  }

  .mobile-grid {
    grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
    padding-inline: 10px;
  }

  .canvas-hint {
    max-width: calc(100% - 72px);
    padding: 8px 10px;
  }
}

@media (max-width: 840px) and (max-height: 720px) {
  .topbar {
    flex-basis: 52px;
    height: 52px;
  }

  .title-stack span {
    display: none;
  }

  .canvas-head {
    min-height: 44px;
    padding-block: 6px;
  }

  .mobile-library {
    flex-basis: clamp(260px, 42dvh, 330px);
    height: clamp(260px, 42dvh, 330px);
    grid-template-rows: 16px 66px 40px minmax(0, 1fr);
  }

  .mobile-grip {
    margin-block: 7px 6px;
  }

  .mobile-row {
    min-height: 42px;
  }

  .mobile-tabs {
    min-height: 40px;
    padding-block: 6px;
  }

  .material-card {
    min-height: 88px;
  }
}

@media (max-width: 840px) and (orientation: landscape) {
  .mobile-library {
    flex-basis: clamp(220px, 54dvh, 280px);
    height: clamp(220px, 54dvh, 280px);
    grid-template-rows: 14px 52px 36px minmax(0, 1fr);
  }

  .mobile-base-style {
    padding-block: 4px 5px;
  }

  .mobile-base-title {
    display: none;
  }

  .mobile-base-controls {
    margin-top: 0;
  }

  .mobile-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .material-card {
    min-height: 82px;
  }

  .material-preview {
    width: 32px;
    height: 32px;
  }

  .mini-bead {
    --size: 28px;
  }
}
