:root {
  --bg: #fff8f0;
  --surface: #ffffff;
  --ink: #1c1c1e;
  --muted: #8e8e93;
  --accent: #ff3b30;
  --border: #e5e5ea;
  --radius: 16px;
  --touch: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  overscroll-behavior-x: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 10px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: padding 0.18s ease;
}

body.scrolled header {
  padding: 4px 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  max-height: 40px;
  overflow: hidden;
  transition: max-height 0.18s ease, opacity 0.18s ease, margin 0.18s ease;
}

body.scrolled h1 {
  max-height: 0;
  opacity: 0;
  margin: 0;
}

body.scrolled .tab {
  height: 36px;
  font-size: 14px;
  padding: 0 14px;
}

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

.pan-fab {
  margin-left: auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: #fff;
  font-size: 22px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}

.pan-fab.visible { display: inline-flex; }

.pan-fab.active {
  background: var(--accent);
  border-color: var(--accent);
}

.tab {
  flex: 0 0 auto;
  height: 44px;
  padding: 0 20px;
  border: none;
  border-radius: 22px;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: var(--ink);
  color: #fff;
}

main {
  /* natural height — body scrolls */
}

.panel {
  display: none;
  flex-direction: column;
  padding: 12px 20px 20px;
  gap: 12px;
}

.panel.active {
  display: flex;
}

.toolbar-collapse {
  align-self: flex-end;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  margin: -4px -4px -8px 0;
  cursor: pointer;
}

.toolbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  padding: 8px 12px;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.toolbar.collapsed { display: none; }

.toolbar::-webkit-scrollbar {
  -webkit-appearance: none;
  height: 8px;
}
.toolbar::-webkit-scrollbar-track { background: transparent; }
.toolbar::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.25);
  border-radius: 4px;
}

.tool-group {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.tool-group + .tool-group {
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.toolbar .swatch,
.toolbar .size {
  width: 44px;
  height: 44px;
}

.toolbar .swatch-picker {
  width: 44px;
  height: 44px;
}

.toolbar .swatch.active,
.toolbar .swatch-picker.active {
  transform: scale(1.05);
}

.toolbar .btn,
.toolbar .zoom-label,
.toolbar .style-toggle {
  height: 44px;
  padding: 0 12px;
  font-size: 14px;
}

.toolbar .zoom-btn {
  width: 44px;
  padding: 0;
}

.toolbar .style-opt {
  height: 38px;
  padding: 0 10px;
  font-size: 13px;
}

.toolbar .swatch.eraser {
  padding: 0 12px;
  font-size: 13px;
}

.swatch {
  width: var(--touch);
  height: var(--touch);
  border-radius: 50%;
  border: 3px solid transparent;
  background: var(--c);
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s;
}

.swatch.swatch-white {
  border: 1px solid var(--border);
}

.swatch-picker {
  width: var(--touch);
  height: var(--touch);
  border-radius: 50%;
  border: 3px solid transparent;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
  overflow: hidden;
}

.swatch-picker.active {
  border-color: var(--ink);
  transform: scale(1.08);
}

.swatch-picker::-webkit-color-swatch-wrapper {
  padding: 0;
  border-radius: 50%;
}

.swatch-picker::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

.swatch-picker::-moz-color-swatch {
  border: none;
  border-radius: 50%;
}

.swatch.active {
  border-color: var(--ink);
  transform: scale(1.08);
}

.swatch.eraser {
  width: auto;
  padding: 0 18px;
  background: #f2f2f7;
  color: var(--ink);
  border-radius: 28px;
  font-weight: 600;
  font-size: 15px;
}

.swatch.eraser.active {
  background: var(--ink);
  color: #fff;
}

.size {
  width: var(--touch);
  height: var(--touch);
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.size span {
  display: block;
  background: var(--ink);
  border-radius: 50%;
}

.size.active {
  border-color: var(--ink);
  background: #f2f2f7;
}

.btn {
  height: var(--touch);
  padding: 0 20px;
  border: none;
  border-radius: 28px;
  background: #f2f2f7;
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.canvas-wrap {
  background: #e5e5ea;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  padding: 12px;
  display: flex;
}

#canvas {
  touch-action: none;
  background: #fff;
  border-radius: 8px;
  display: block;
  margin: auto;
  flex: 0 0 auto;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.zoom-group {
  gap: 4px !important;
}

.slot-row {
  display: flex;
  gap: 8px;
  padding: 0 4px;
}

.slot {
  flex: 1;
  height: 68px;
  border-radius: 12px;
  border: 3px solid transparent;
  background: #f2f2f7;
  position: relative;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.slot.active {
  border-color: var(--ink);
  background: #fff;
}

.slot-num {
  font-size: 22px;
  font-weight: 700;
  color: var(--muted);
}

.slot.active .slot-num {
  color: var(--ink);
}

.slot-thumb {
  position: absolute;
  inset: 4px;
  width: calc(100% - 8px);
  height: calc(100% - 8px);
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
}

.style-toggle {
  display: inline-flex;
  background: #e5e5ea;
  border-radius: 24px;
  padding: 3px;
  gap: 0;
  height: var(--touch);
}

.style-opt {
  min-width: 60px;
  padding: 0 14px;
  border: none;
  background: transparent;
  border-radius: 22px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.style-opt.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}

.zoom-btn {
  width: var(--touch);
  padding: 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.zoom-label {
  min-width: 64px;
  height: var(--touch);
  padding: 0 10px;
  border: none;
  border-radius: 28px;
  background: #f2f2f7;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.coming-soon {
  margin: auto;
  max-width: 440px;
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.coming-soon h2 {
  margin: 0 0 12px;
}

.coming-soon p {
  margin: 8px 0;
  line-height: 1.5;
  color: var(--muted);
}

.coming-soon strong {
  color: var(--ink);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  padding: 20px;
  z-index: 10;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
}

.modal[hidden] { display: none; }

.modal::-webkit-scrollbar,
.canvas-wrap::-webkit-scrollbar,
.mix-parts::-webkit-scrollbar {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
}
.modal::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.2);
  border-radius: 6px;
}
.canvas-wrap::-webkit-scrollbar-track,
.mix-parts::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.08);
  border-radius: 6px;
}
.modal::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.75);
  border-radius: 6px;
  min-height: 40px;
}
.canvas-wrap::-webkit-scrollbar-thumb,
.mix-parts::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.4);
  border-radius: 6px;
  min-height: 40px;
}

.modal-card {
  margin: 0 auto 20px;
  max-width: 520px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  position: relative;
}

.modal-card::after {
  content: '';
  position: sticky;
  bottom: -24px;
  display: block;
  margin: 16px -24px -24px;
  height: 40px;
  background: linear-gradient(to bottom, transparent, rgba(0,0,0,0.12));
  border-radius: 0 0 var(--radius) var(--radius);
  pointer-events: none;
}

.modal-card h2 {
  margin: 0 0 16px;
  text-align: center;
}

.emoji-preview-grid {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.checker {
  width: 220px;
  height: 220px;
  border-radius: 12px;
  background:
    linear-gradient(45deg, #e5e5ea 25%, transparent 25%),
    linear-gradient(-45deg, #e5e5ea 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e5ea 75%),
    linear-gradient(-45deg, transparent 75%, #e5e5ea 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #f2f2f7;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.checker img {
  max-width: 100%;
  max-height: 100%;
}

.emoji-sizes {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.emoji-sizes > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.emoji-sizes span {
  font-size: 12px;
  color: var(--muted);
}

#emoji-img-lg { width: 80px; height: 80px; }
#emoji-img-md { width: 48px; height: 48px; }
#emoji-img-sm { width: 28px; height: 28px; }

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Mix & Match */

.mix-layout {
  display: flex;
  gap: 20px;
  flex: 1;
  min-height: 0;
  flex-wrap: wrap;
}

.mix-preview {
  flex: 0 0 auto;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

#mix-svg-wrap {
  width: 180px;
  height: 180px;
  background: #fff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#mix-svg-wrap svg {
  width: 100%;
  height: 100%;
}

.mix-preview .btn {
  height: 44px;
  padding: 0 16px;
  font-size: 15px;
}

.mix-preview-buttons {
  display: flex;
  gap: 8px;
}

.mix-parts {
  flex: 1 1 280px;
  min-width: 280px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.mix-category {
  margin-bottom: 10px;
}

.mix-category:last-child { margin-bottom: 0; }

.mix-category-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.mix-options {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mix-option {
  width: 48px;
  height: 48px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #f2f2f7;
  padding: 2px;
  cursor: pointer;
  overflow: hidden;
}

.mix-option svg {
  width: 100%;
  height: 100%;
  display: block;
}

.mix-option.active {
  border-color: var(--ink);
  background: #fff;
}

.tune-category {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.tune-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.tune-row label {
  flex: 0 0 78px;
  font-size: 13px;
  color: var(--muted);
}

.tune-row input[type="range"] {
  flex: 1;
  min-width: 0;
}

/* Describe */

.describe-layout {
  margin: auto;
  max-width: 520px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.describe-hint {
  margin: 0;
  text-align: center;
  color: var(--muted);
  line-height: 1.5;
}

.mic-btn {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform 0.15s, background 0.15s;
}

.mic-btn:active { transform: scale(0.96); }

.mic-btn.recording {
  background: #1f1f1f;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.6); }
  50% { box-shadow: 0 0 0 18px rgba(255, 59, 48, 0); }
}

.mic-icon {
  font-size: 44px;
  line-height: 1;
}

.mic-label {
  font-size: 14px;
  font-weight: 600;
}

.transcript-wrap {
  width: 100%;
}

#transcript {
  width: 100%;
  font: inherit;
  font-size: 17px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #fff;
  resize: vertical;
  min-height: 80px;
}

.describe-go {
  align-self: stretch;
}

.batch-divider {
  width: 100%;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 18px;
  margin-top: 8px;
}

.batch-inputs {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.batch-input {
  font: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: #fff;
  min-height: 44px;
}

.batch-modal-card {
  max-width: 640px;
}

.batch-results {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.batch-result {
  background: #f2f2f7;
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.batch-result img {
  width: 100%;
  max-width: 220px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
}

.batch-result .btn {
  height: 36px;
  padding: 0 14px;
  font-size: 14px;
}
