:root {
  color-scheme: light;
  --ink: #28222c;
  --muted: #746a76;
  --paper: #fffdf8;
  --line: rgba(40, 34, 44, 0.14);
  --pink: #f85f8d;
  --coral: #ff8f6b;
  --teal: #10a7a7;
  --mint: #c8f4e7;
  --lemon: #ffe56e;
  --violet: #8868ff;
  --shadow: 0 18px 44px rgba(42, 29, 47, 0.18);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  background:
    linear-gradient(150deg, #fff8fb 0%, #eefdf8 48%, #fff8d7 100%);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app {
  width: 100%;
  max-width: none;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.2)),
    radial-gradient(circle at top left, rgba(255, 229, 110, 0.34), transparent 36%),
    radial-gradient(circle at bottom right, rgba(16, 167, 167, 0.2), transparent 34%);
}

main {
  display: block;
  width: 100%;
}

.topbar {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: calc(env(safe-area-inset-top) + 4px) 10px 4px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.brand {
  min-width: 0;
  display: grid;
  gap: 1px;
  line-height: 1.05;
}

.brand span {
  color: var(--teal);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0;
}

.brand strong {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  gap: 5px;
}

.icon-button,
.pill-button,
.small-button,
.download-button {
  min-height: 32px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 6px 14px rgba(42, 29, 47, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  user-select: none;
}

.icon-button {
  width: 34px;
  border-radius: 6px;
  font-size: 20px;
  font-weight: 800;
}

.icon-button.compact {
  width: 28px;
  min-height: 28px;
  font-size: 18px;
}

.pill-button,
.small-button,
.download-button {
  border-radius: 6px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.pill-button.primary,
.download-button {
  border-color: rgba(248, 95, 141, 0.2);
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--coral));
}

.stage-shell {
  position: relative;
  flex: 2;
  min-height: 0;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#dollCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: #fff;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(10px);
  max-width: calc(100% - 40px);
  padding: 9px 12px;
  border-radius: 8px;
  color: #fff;
  background: rgba(40, 34, 44, 0.86);
  font-size: 13px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.control-panel {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 5px 8px calc(env(safe-area-inset-bottom) + 6px);
  border-top: 1px solid rgba(40, 34, 44, 0.1);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
}

.category-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.tab-button {
  height: 34px;
  border-radius: 6px;
  color: var(--muted);
  background: #f7f4f1;
  border: 1px solid transparent;
  display: grid;
  place-items: center;
  gap: 0;
}

.tab-button .tab-icon {
  width: 17px;
  height: 17px;
}

.tab-button span {
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
}

.tab-button.active {
  color: #fff;
  background: linear-gradient(135deg, #f85f8d, #10a7a7);
  box-shadow: 0 8px 18px rgba(248, 95, 141, 0.22);
}

.category-row {
  height: 28px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.category-row h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 900;
}

.small-button {
  min-height: 26px;
  padding-inline: 7px;
  font-size: 10px;
  box-shadow: none;
  border-radius: 6px;
}

.item-strip {
  min-width: 0;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 62px;
  gap: 5px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 1px 1px 2px;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.item-strip::-webkit-scrollbar {
  display: none;
}

.item-card {
  height: 64px;
  padding: 4px;
  border-radius: 6px;
  border: 2px solid transparent;
  background: #fff;
  box-shadow: 0 6px 16px rgba(42, 29, 47, 0.08);
  display: grid;
  grid-template-rows: 34px 1fr;
  gap: 3px;
  align-items: center;
  justify-items: center;
  scroll-snap-align: start;
}

.item-card.active {
  border-color: var(--pink);
  box-shadow: 0 8px 18px rgba(248, 95, 141, 0.22);
}

.item-card.toggled {
  border-color: var(--teal);
}

.item-preview {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid rgba(40, 34, 44, 0.12);
  background: var(--preview, #f4f0ef);
  display: grid;
  place-items: center;
  color: var(--ink);
  overflow: hidden;
}

.item-preview svg {
  width: 24px;
  height: 24px;
  display: block;
}

.item-name {
  width: 100%;
  color: var(--ink);
  font-size: 9px;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(40, 34, 44, 0.44);
}

.modal-panel {
  position: relative;
  width: min(100%, 420px);
  max-height: calc(100dvh - 32px);
  padding: 12px;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 900;
}

#savedPreview {
  width: 100%;
  max-height: 64dvh;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

@media (max-height: 700px) {
  .topbar {
    min-height: 38px;
    padding-top: calc(env(safe-area-inset-top) + 2px);
    padding-bottom: 2px;
  }

  .brand span {
    font-size: 8px;
  }

  .brand strong {
    font-size: 13px;
  }

  .tab-button {
    height: 30px;
  }

  .tab-button .tab-icon {
    width: 14px;
    height: 14px;
  }

  .tab-button span {
    font-size: 8px;
  }

  .category-row {
    height: 24px;
    margin-top: 3px;
  }

  .item-card {
    height: 56px;
    grid-template-rows: 28px 1fr;
    padding: 3px;
  }

  .item-preview {
    width: 28px;
    height: 28px;
  }

  .item-preview svg {
    width: 20px;
    height: 20px;
  }

  .item-name {
    font-size: 8px;
  }

  .item-strip {
    grid-auto-columns: 52px;
    gap: 4px;
  }

  .stage-shell {
    padding: 0 4px;
  }
}

@media (max-height: 560px) {
  .topbar {
    min-height: 34px;
  }

  .tab-button {
    height: 28px;
    border-radius: 5px;
  }

  .tab-button .tab-icon {
    width: 12px;
    height: 12px;
  }

  .tab-button span {
    font-size: 7px;
  }

  .item-card {
    height: 48px;
    grid-template-rows: 24px 1fr;
    padding: 2px;
    border-radius: 5px;
  }

  .item-preview {
    width: 24px;
    height: 24px;
    border-radius: 4px;
  }

  .item-preview svg {
    width: 16px;
    height: 16px;
  }

  .item-strip {
    grid-auto-columns: 44px;
    gap: 3px;
  }
}

/* 手机桌面模式: 窄屏 + 短屏 */
@media (max-width: 520px) and (max-height: 750px) {
  .top-actions {
    gap: 5px;
  }

  .pill-button {
    padding: 0 8px;
    font-size: 12px;
  }

  .control-panel {
    padding: 6px 8px calc(env(safe-area-inset-bottom) + 8px);
  }
}

/* 宽屏放大: 600px以上文字和组件统一放大 */
@media (min-width: 600px) {
  .topbar {
    min-height: 60px;
    padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    gap: 12px;
  }

  .brand span {
    font-size: 13px;
  }

  .brand strong {
    font-size: 22px;
  }

  .top-actions {
    gap: 8px;
  }

  .icon-button {
    width: 48px;
    font-size: 26px;
  }

  .icon-button.compact {
    width: 38px;
    min-height: 38px;
    font-size: 24px;
  }

  .pill-button,
  .small-button,
  .download-button {
    min-height: 44px;
    padding: 0 16px;
    font-size: 16px;
  }

  .stage-shell {
    padding: 0 16px;
  }

  .control-panel {
    padding: 8px 14px calc(env(safe-area-inset-bottom) + 10px);
  }

  .category-tabs {
    gap: 6px;
  }

  .tab-button {
    height: 48px;
    border-radius: 8px;
  }

  .tab-button .tab-icon {
    width: 24px;
    height: 24px;
  }

  .tab-button span {
    font-size: 13px;
  }

  .category-row {
    height: 38px;
    margin-top: 8px;
  }

  .category-row h2 {
    font-size: 18px;
  }

  .small-button {
    min-height: 36px;
    padding-inline: 12px;
    font-size: 14px;
  }

  .item-strip {
    grid-auto-columns: 100px;
    gap: 10px;
  }

  .item-card {
    height: 100px;
    padding: 8px;
    grid-template-rows: 54px 1fr;
    gap: 6px;
    border-radius: 8px;
  }

  .item-preview {
    width: 54px;
    height: 54px;
    border-radius: 8px;
  }

  .item-preview svg {
    width: 38px;
    height: 38px;
  }

  .item-name {
    font-size: 13px;
  }

  .toast {
    font-size: 16px;
    padding: 12px 18px;
  }

  .modal-panel {
    width: min(100%, 600px);
  }

  .modal-head h2 {
    font-size: 22px;
  }
}

@media (min-width: 700px) and (max-width: 1200px) {
  .app {
    width: 100vw;
  }

  #dollCanvas {
    max-width: 550px;
  }
}

@media (min-width: 1201px) {
  body {
    overflow: auto;
  }

  .app {
    width: min(100%, 800px);
    margin: 0 auto;
    border-inline: 1px solid rgba(40, 34, 44, 0.08);
    min-height: 100vh;
  }
}
