:root {
  color-scheme: light;
  --ink: #29231d;
  --muted: #8c7964;
  --paper: #f6efe5;
  --tray: #e5d6bf;
  --line: rgba(77, 59, 38, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: var(--app-height, 100%);
  margin: 0;
  overscroll-behavior: none;
}

body {
  align-items: center;
  background:
    radial-gradient(circle at 50% 8%, rgba(255, 255, 255, 0.98), transparent 32rem),
    linear-gradient(145deg, #eee9e1, #cfc3b2);
  color: var(--ink);
  display: flex;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

button {
  border: 0;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  display: grid;
  height: var(--app-height, 100dvh);
  max-height: 960px;
  max-width: 420px;
  padding: 10px;
  width: min(100vw, 420px);
}

.shell:has(dialog[open]) .studio {
  filter: blur(2px);
}

.studio {
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 28px;
  box-shadow: 0 22px 70px rgba(45, 34, 22, 0.18);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto 214px;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 10px 14px 7px;
}

.fit-strip {
  align-items: center;
  background: rgba(255, 252, 247, 0.76);
  border: 1px solid rgba(88, 70, 48, 0.1);
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(45, 34, 22, 0.08);
  color: #6b5a47;
  cursor: pointer;
  display: flex;
  font-size: 11px;
  gap: 7px;
  left: 50%;
  line-height: 1;
  max-width: calc(100% - 104px);
  overflow: hidden;
  padding: 6px 9px;
  position: absolute;
  top: 58px;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 3;
}

.fit-strip:focus-visible {
  outline: 2px solid rgba(200, 148, 53, 0.62);
  outline-offset: 2px;
}

.fit-strip span {
  border-right: 1px solid rgba(91, 72, 50, 0.16);
  padding-right: 7px;
}

.fit-strip span:last-child {
  border-right: 0;
  padding-right: 0;
}

.fit-strip.ok span:last-child {
  color: #4f7650;
}

.fit-strip.short span:last-child {
  color: #a05b3c;
}

.fit-strip.long span:last-child {
  color: #8a6d26;
}

.title-stack {
  align-items: center;
  display: grid;
  gap: 2px;
  justify-items: center;
  line-height: 1.1;
}

.title-stack strong {
  color: #2c251e;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  font-weight: 600;
}

.title-stack span {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ghost,
.secondary {
  background: rgba(43, 35, 28, 0.08);
  border-radius: 999px;
  color: #5d4d3e;
  padding: 8px 12px;
}

#stage {
  display: block;
  height: 100%;
  min-height: 0;
  width: 100%;
}

.studio-loading {
  align-items: center;
  background:
    radial-gradient(circle at 50% 44%, rgba(255, 255, 255, 0.96) 0 30%, rgba(245, 239, 229, 0.84) 31% 52%, rgba(255, 255, 255, 0.92) 53% 100%);
  color: rgba(86, 68, 47, 0.72);
  display: grid;
  gap: 10px;
  grid-template-rows: auto auto;
  inset: 58px 0 266px;
  justify-items: center;
  opacity: 1;
  pointer-events: auto;
  position: absolute;
  transition: opacity 260ms ease, visibility 260ms ease;
  visibility: visible;
  z-index: 4;
}

.studio.ready .studio-loading {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.studio-loading span {
  animation: loadingPulse 1.15s ease-in-out infinite;
  background: radial-gradient(circle at 34% 28%, #fff8ed 0 12%, #a7c0c2 34%, #2b4a4d 76%, #15110f 100%);
  border-radius: 999px;
  box-shadow: inset -8px -9px 14px rgba(0, 0, 0, 0.24), inset 5px 4px 9px rgba(255, 255, 255, 0.5), 0 9px 22px rgba(57, 42, 24, 0.16);
  height: 42px;
  width: 42px;
}

.studio-loading strong {
  font-size: 12px;
  font-weight: 600;
}

@keyframes loadingPulse {
  0%,
  100% {
    transform: scale(0.96);
  }
  50% {
    transform: scale(1.04);
  }
}

.float-actions {
  display: grid;
  gap: 8px;
  position: absolute;
  right: 12px;
  top: 82px;
  z-index: 2;
}

.sheet {
  background: #fffaf2;
  border: 0;
  border-radius: 24px 24px 0 0;
  bottom: 0;
  box-shadow: 0 -18px 60px rgba(45, 34, 22, 0.28);
  color: #29231d;
  left: 50%;
  margin: 0;
  max-height: 88dvh;
  max-width: 420px;
  overflow-y: auto;
  padding: 18px;
  position: fixed;
  top: auto;
  transform: translateX(-50%);
  width: min(100vw, 420px);
}

.sheet::backdrop {
  background: rgba(30, 24, 18, 0.22);
}

.sheet-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-head strong {
  font-size: 16px;
}

.size-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, 1fr);
}

.fit-summary {
  background: rgba(43, 35, 28, 0.06);
  border: 1px solid rgba(90, 70, 46, 0.1);
  border-radius: 18px;
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, 1fr);
  padding: 12px;
}

.fit-summary div {
  display: grid;
  gap: 3px;
  justify-items: center;
}

.fit-summary span,
.size-result span {
  color: #9b8065;
  font-size: 11px;
}

.fit-summary strong {
  color: #3b3128;
  font-size: 15px;
}

.fit-summary em {
  color: #8a6d26;
  font-size: 12px;
  font-style: normal;
  grid-column: 1 / -1;
  justify-self: center;
}

.fit-mode {
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, 1fr);
}

.sheet-section {
  color: #8c7964;
  font-size: 12px;
  grid-column: 1 / -1;
  margin-top: 2px;
}

.sheet-note {
  color: #b19674;
  font-size: 11px;
  grid-column: 1 / -1;
  margin-top: -5px;
}

.size-grid button {
  background: rgba(43, 35, 28, 0.08);
  border-radius: 16px;
  color: #5d4d3e;
  display: grid;
  gap: 3px;
  justify-items: center;
  min-height: 58px;
}

.size-grid button strong {
  font-size: 13px;
  font-weight: 650;
}

.size-grid button span {
  color: #9b8065;
  font-size: 11px;
}

.size-grid button.on {
  background: #29231d;
  color: #fff8ee;
}

.size-grid button.on span {
  color: rgba(255, 248, 238, 0.72);
}

.size-result {
  align-items: center;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(90, 70, 46, 0.1);
  border-radius: 16px;
  display: grid;
  gap: 4px;
  grid-column: 1 / -1;
  justify-items: center;
  min-height: 58px;
}

.size-result strong {
  color: #3b3128;
  font-size: 18px;
}

.size-result em {
  color: #9b8065;
  font-size: 11px;
  font-style: normal;
}

.count-stepper {
  align-items: center;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(90, 70, 46, 0.1);
  border-radius: 18px;
  display: grid;
  gap: 10px;
  grid-column: 1 / -1;
  grid-template-columns: 56px 1fr 56px;
  min-height: 58px;
  padding: 6px;
}

.count-stepper button {
  border-radius: 14px;
  font-size: 20px;
  min-height: 46px;
}

.count-stepper strong {
  font-size: 18px;
  justify-self: center;
}

.pill {
  background: rgba(255, 252, 247, 0.78);
  border: 1px solid rgba(88, 70, 48, 0.12);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(45, 34, 22, 0.14);
  color: #5d4d3e;
  font-size: 12px;
  padding: 7px 10px;
}

.pill.on {
  background: #29231d;
  color: #fff8ee;
}

.toolbar {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr);
  padding: 9px 12px 8px;
}

.toolbar button {
  background: #29231d;
  border-radius: 16px;
  color: #fff8ee;
  min-height: 39px;
  min-width: 0;
  padding: 0 14px;
}

.toolbar .secondary {
  background: rgba(43, 35, 28, 0.08);
  color: #5d4d3e;
}

.toolbar .secondary.on {
  background: #c89435;
  color: #fff8ee;
}

.toolbar .icon-action {
  align-items: center;
  background: rgba(43, 35, 28, 0.08);
  border-radius: 999px;
  color: #5d4d3e;
  display: grid;
  font-size: 22px;
  justify-items: center;
  line-height: 1;
  min-height: 39px;
  padding: 0;
}

.catalog {
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid rgba(30, 27, 24, 0.08);
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  grid-template-rows: 38px minmax(0, 1fr);
  min-height: 214px;
  min-width: 0;
}

.catalog-tabs {
  align-content: start;
  display: grid;
  gap: 6px;
  grid-row: 1 / -1;
  max-height: 178px;
  overflow-y: auto;
  padding: 10px 8px 8px 10px;
  scrollbar-width: none;
}

.catalog-tabs button {
  background: rgba(36, 31, 28, 0.055);
  border-radius: 999px;
  color: #76685d;
  font-size: 11px;
  min-height: 24px;
  padding: 2px 5px;
}

.catalog-tabs button.on {
  background: #1f1a16;
  color: #fff;
}

.bead-size-strip {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: start;
  min-width: 0;
  padding: 8px 12px 0 8px;
}

.bead-size-strip button {
  background: rgba(43, 35, 28, 0.08);
  border-radius: 999px;
  color: #5d4d3e;
  font-size: 16px;
  height: 26px;
  line-height: 1;
  width: 34px;
}

.bead-size-strip strong,
.bead-size-strip span {
  color: #5d4d3e;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.bead-size-strip.muted {
  display: flex;
}

.palette {
  cursor: grab;
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 10px 14px 16px 8px;
  scrollbar-width: none;
  scroll-behavior: smooth;
  touch-action: pan-x;
  user-select: none;
}

.palette.dragging {
  cursor: grabbing;
  scroll-behavior: auto;
}

.palette::-webkit-scrollbar {
  display: none;
}

.swatch {
  align-items: center;
  background: #fff;
  border: 1px solid rgba(43, 35, 28, 0.07);
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(34, 27, 21, 0.055);
  color: #51473e;
  display: grid;
  flex: 0 0 86px;
  gap: 4px;
  grid-template-rows: 72px 17px auto;
  justify-items: center;
  min-height: 146px;
  min-width: 86px;
  padding: 8px 7px 7px;
  transition: filter 140ms ease, transform 140ms ease;
}

.swatch.pressed {
  filter: brightness(1.06) saturate(1.04);
  transform: translateY(1px) scale(0.97);
}

.swatch-dot {
  border-radius: 999px;
  box-shadow: inset -9px -10px 14px rgba(0, 0, 0, 0.26), inset 6px 5px 10px rgba(255, 255, 255, 0.45), 0 7px 15px rgba(44, 32, 20, 0.16);
  height: 66px;
  position: relative;
  transform: scale(var(--swatch-scale, 1));
  width: 66px;
}

.swatch-dot.asset-swatch {
  box-shadow: 0 4px 10px rgba(44, 32, 20, 0.18);
}

.swatch.charm .swatch-dot {
  border-radius: 18px;
}

.swatch-dot::after {
  background: rgba(255, 255, 255, 0.88);
  border-radius: 999px;
  content: "";
  height: 8px;
  left: 13px;
  position: absolute;
  top: 11px;
  width: 8px;
}

.swatch-dot.asset-swatch::after {
  display: none;
}

.swatch strong {
  background: rgba(31, 26, 22, 0.08);
  border-radius: 999px;
  color: #382f28;
  font-size: 11px;
  font-weight: 760;
  line-height: 1;
  padding: 4px 8px;
}

.swatch span {
  font-size: 12px;
  max-width: 74px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 460px) {
  html,
  body {
    height: var(--app-height, 100svh);
  }

  .shell {
    height: var(--app-height, 100svh);
    max-height: none;
    padding: 0;
    width: 100vw;
  }

  .studio {
    border-radius: 0;
    grid-template-rows: 58px minmax(0, 1fr) 52px 218px;
    height: 100%;
  }

  .topbar {
    min-height: 58px;
    padding: 8px 12px 6px;
  }

  .title-stack strong {
    font-size: 17px;
  }

  .title-stack span {
    font-size: 11px;
    letter-spacing: 0;
    text-transform: none;
  }

  .ghost,
  .secondary {
    font-size: 15px;
    padding: 8px 12px;
  }

  .fit-strip {
    font-size: 11px;
    max-width: calc(100% - 92px);
    top: 60px;
  }

  .float-actions {
    right: 10px;
    top: 104px;
  }

  .studio-loading {
    inset: 58px 0 270px;
  }

  .toolbar {
    align-content: center;
    background: rgba(255, 252, 247, 0.58);
    border-top: 1px solid rgba(77, 59, 38, 0.08);
    gap: 6px;
    grid-template-columns: minmax(0, 1fr) 42px minmax(0, 1fr);
    min-height: 0;
    padding: 7px 10px;
    z-index: 5;
  }

  .toolbar button {
    border-radius: 14px;
    font-size: 13px;
    min-height: 36px;
    padding-inline: 6px;
  }

  .toolbar .icon-action {
    font-size: 21px;
    min-height: 36px;
  }

  .catalog {
    grid-template-columns: 64px minmax(0, 1fr);
    grid-template-rows: 36px minmax(0, 1fr);
    min-height: 218px;
  }

  .catalog-tabs {
    gap: 5px;
    max-height: 166px;
    padding: 8px 6px 6px 8px;
  }

  .catalog-tabs button {
    border-radius: 999px;
    font-size: 10px;
    min-height: 22px;
    padding: 1px 4px;
  }

  .palette {
    gap: 9px;
    padding: 8px 10px 12px 6px;
  }

  .bead-size-strip {
    padding: 4px 10px 0 6px;
  }

  .bead-size-strip button {
    height: 24px;
    width: 30px;
  }

  .swatch {
    flex-basis: 78px;
    gap: 4px;
    grid-template-rows: 64px 17px auto;
    min-height: 134px;
    min-width: 78px;
    padding: 7px 6px 6px;
  }

  .swatch-dot {
    height: 60px;
    width: 60px;
  }

  .swatch span {
    font-size: 11px;
    max-width: 68px;
  }

  .swatch strong {
    font-size: 10px;
    padding: 4px 7px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  body {
    align-items: center;
    justify-content: center;
  }

  .shell {
    height: var(--app-height, 100svh);
    max-height: var(--app-height, 100svh);
    max-width: min(420px, calc(100svh * 0.58));
    padding: 0;
    width: min(420px, calc(100svh * 0.58));
  }

  .studio {
    border-radius: 0;
    grid-template-rows: 50px minmax(0, 1fr) 44px 150px;
    height: 100%;
  }

  .topbar {
    min-height: 50px;
    padding: 6px 10px 5px;
  }

  .title-stack strong {
    font-size: 15px;
  }

  .title-stack span {
    font-size: 10px;
    letter-spacing: 0;
    text-transform: none;
  }

  .ghost,
  .secondary {
    font-size: 13px;
    padding: 7px 10px;
  }

  .fit-strip {
    font-size: 10px;
    max-width: calc(100% - 78px);
    padding: 5px 8px;
    top: 51px;
  }

  .float-actions {
    right: 8px;
    top: 88px;
  }

  .toolbar {
    gap: 6px;
    grid-template-columns: minmax(0, 1fr) 38px minmax(0, 1fr);
    padding: 5px 8px;
  }

  .toolbar button {
    border-radius: 12px;
    font-size: 12px;
    min-height: 32px;
    padding-inline: 5px;
  }

  .toolbar .icon-action {
    font-size: 19px;
    min-height: 32px;
  }

  .catalog {
    grid-template-columns: 56px minmax(0, 1fr);
    grid-template-rows: 30px minmax(0, 1fr);
    min-height: 150px;
  }

  .catalog-tabs {
    gap: 2px;
    max-height: 106px;
    padding: 4px 4px 4px 5px;
  }

  .catalog-tabs button {
    border-radius: 8px;
    font-size: 9px;
    min-height: 18px;
  }

  .bead-size-strip {
    padding: 3px 8px 0 5px;
  }

  .bead-size-strip button {
    height: 22px;
    width: 26px;
  }

  .palette {
    gap: 8px;
    padding: 5px 8px 8px 5px;
  }

  .swatch {
    flex-basis: 66px;
    grid-template-rows: 46px 15px auto;
    min-height: 108px;
    min-width: 66px;
    padding: 6px 5px 5px;
  }

  .swatch-dot {
    height: 44px;
    width: 44px;
  }

  .swatch span {
    font-size: 9px;
    max-width: 58px;
  }

  .swatch strong {
    font-size: 9px;
    padding: 3px 6px;
  }

  .studio-loading {
    inset: 50px 0 194px;
  }
}
