:root {
  color-scheme: light;
  --bg: #f4f7f2;
  --paper: #ffffff;
  --panel: #fbfcf8;
  --ink: #111827;
  --muted: #667085;
  --line: #dbe2d4;
  --accent: #a76432;
  --teal: #11756d;
  --green: #25d366;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(17, 24, 39, .13);
  --radius: 18px;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% -10%, rgba(17, 117, 109, .12), transparent 28%),
    linear-gradient(180deg, #eef5ef 0%, var(--bg) 48%, #f7f0e8 100%);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button { cursor: pointer; }

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  overflow-x: hidden;
  background: rgba(255, 255, 255, .64);
  box-shadow: 0 0 0 1px rgba(17, 24, 39, .06);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(17, 24, 39, .08);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-lockup img {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: #fff;
}

.brand-lockup strong,
.brand-lockup span {
  display: block;
}

.brand-lockup strong {
  font-size: 15px;
  line-height: 1.1;
}

.brand-lockup span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.icon-btn,
.tool-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  box-shadow: none;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.icon-btn svg,
.tool-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn:active,
.tool-btn:active,
.mode-toggle:active,
.choice-card:active,
.pattern-card:active,
.primary-btn:active,
.secondary-btn:active,
.whatsapp-btn:active {
  transform: scale(.97);
}

main {
  display: grid;
  gap: 14px;
  padding: 12px 12px calc(18px + env(safe-area-inset-bottom));
}

.stage-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(17, 24, 39, .08);
  border-radius: 0 0 22px 22px;
  background: #edf2ed;
  box-shadow: var(--shadow);
}

.stage-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 15px 8px;
}

.stage-head > div {
  min-width: 0;
}

.eyebrow {
  display: block;
  color: var(--teal);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

h1 {
  margin: 4px 0 0;
  font-size: 25px;
  line-height: 1.05;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.stage-note {
  margin: 7px 0 0;
  max-width: 260px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
}

.mode-toggle {
  flex: 0 0 auto;
  min-height: 38px;
  border: 0;
  border-radius: 999px;
  padding: 9px 13px;
  background: var(--ink);
  color: #fff;
  font-weight: 900;
}

.canvas-viewport {
  position: relative;
  height: clamp(320px, 55vh, 560px);
  display: grid;
  place-items: center;
  padding: 20px 14px 44px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(17, 24, 39, .05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(17, 24, 39, .05) 1px, transparent 1px),
    #f9faf7;
  background-size: 26px 26px;
  touch-action: none;
}

#designCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 24px 58px rgba(17, 24, 39, .22);
  transition: transform .26s ease, box-shadow .26s ease;
}

#designCanvas.pop {
  animation: canvasPop .34s ease;
}

#designCanvas.spark {
  animation: canvasSpark .72s ease;
}

body.previewing #designCanvas {
  transform: none;
  box-shadow: 0 34px 78px rgba(17, 24, 39, .30);
}

.spark-particle {
  position: absolute;
  z-index: 4;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #f8c15f;
  box-shadow: 0 0 18px rgba(248, 193, 95, .8);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: sparkParticle .68s ease var(--delay, 0ms) forwards;
}

.spark-particle:nth-child(3n) {
  background: #25d366;
  box-shadow: 0 0 18px rgba(37, 211, 102, .65);
}

.spark-particle:nth-child(3n + 1) {
  background: #14b8a6;
  box-shadow: 0 0 18px rgba(20, 184, 166, .7);
}

.view-zoom-panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 14px;
  z-index: 14;
  display: none;
  grid-template-columns: 40px 1fr 86px 62px;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid rgba(17, 24, 39, .1);
  border-radius: 16px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 18px 42px rgba(17, 24, 39, .16);
  backdrop-filter: blur(12px);
}

body.previewing .view-zoom-panel {
  display: grid;
}

.zoom-btn,
.zoom-reset-btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.zoom-reset-btn {
  font-size: 12px;
}

#viewZoomRange {
  min-height: 38px;
  padding: 0;
}

#viewZoomValue {
  min-width: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.gesture-hint {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 10px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(17, 24, 39, .86);
  color: #fff;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

.floating-tools {
  position: absolute;
  left: 50%;
  bottom: 52px;
  display: flex;
  gap: 8px;
  padding: 7px;
  border: 1px solid rgba(17, 24, 39, .08);
  border-radius: 16px;
  background: rgba(255, 255, 255, .88);
  box-shadow: 0 14px 32px rgba(17, 24, 39, .16);
  transform: translateX(-50%);
}

.workflow-card {
  overflow: hidden;
  border: 1px solid rgba(17, 24, 39, .08);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.step-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  padding: 8px;
  border-bottom: 1px solid rgba(17, 24, 39, .08);
  background: #f9faf7;
}

.step-tab {
  min-width: 0;
  min-height: 39px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.step-tab.active {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 10px 22px rgba(17, 24, 39, .16);
}

.step-panel {
  display: none;
  padding: 15px;
  animation: panelIn .2s ease;
}

.step-panel.active { display: block; }

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choice-card {
  min-width: 0;
  min-height: 80px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  text-align: left;
  padding: 12px;
}

.choice-card strong,
.choice-card span {
  display: block;
}

.choice-card strong { font-size: 17px; }

.choice-card span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.choice-card.active {
  border-color: var(--teal);
  background: #ebf7f5;
  box-shadow: 0 0 0 3px rgba(17, 117, 109, .13);
}

label {
  display: block;
  margin: 14px 0 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 900;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(17, 117, 109, .13);
}

.hidden { display: none !important; }

.input-with-unit,
.range-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.input-with-unit span,
output {
  min-width: 52px;
  color: var(--accent);
  font-weight: 900;
  text-align: right;
}

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

.microcopy {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.assist-card {
  display: grid;
  gap: 7px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #bfe7c7;
  border-radius: 16px;
  background: #f0fff4;
}

.assist-card strong {
  color: #14532d;
  font-size: 13px;
}

.assist-card span {
  color: #315443;
  font-size: 12px;
  line-height: 1.35;
}

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

.preset-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-height: 228px;
  overflow: auto;
  padding-right: 2px;
}

.preset-btn {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 10px;
  text-align: left;
}

.preset-btn strong,
.preset-btn span {
  display: block;
}

.preset-btn span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.preset-btn.active {
  border-color: var(--teal);
  background: #ebf7f5;
  box-shadow: 0 0 0 3px rgba(17, 117, 109, .13);
}

.custom-size {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.custom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.custom-grid select,
.custom-grid button {
  grid-column: span 2;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.file-chip,
.secondary-file,
.upload-main {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 14px;
  padding: 11px 12px;
  background: #f3eee8;
  color: #69411f;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.file-chip input,
.secondary-file input,
.upload-main input {
  display: none;
}

.category-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 12px -15px 10px;
  padding: 0 15px 6px;
  scrollbar-width: thin;
}

.category-chip {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 8px 12px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

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

.pattern-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-height: 430px;
  overflow: auto;
  padding-right: 2px;
}

.pattern-card {
  position: relative;
  min-height: 106px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #e9eee5;
  padding: 0;
}

.pattern-card img {
  width: 100%;
  height: 100%;
  min-height: 106px;
  object-fit: cover;
  display: block;
}

.pattern-card span {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .88);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.pattern-card.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(17, 117, 109, .16);
}

.upload-panel,
.selected-card,
.export-card {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.upload-panel strong,
.selected-card strong,
.export-card strong {
  font-size: 17px;
}

.upload-panel span,
.selected-card span,
.export-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 12px;
}

.primary-btn,
.secondary-btn,
.whatsapp-btn,
.store-btn,
.whatsapp-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
}

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

.secondary-btn {
  background: #eef2ee;
  color: var(--ink);
}

.secondary-btn.full,
.whatsapp-btn,
.store-btn.full {
  width: 100%;
  margin-top: 10px;
}

.whatsapp-btn {
  background: var(--green);
  color: #073b1d;
}

.whatsapp-mini {
  min-height: 44px;
  background: var(--green);
  color: #073b1d;
}

.store-btn {
  min-height: 44px;
  background: #fff7ed;
  color: #7c2d12;
  border: 1px solid #fed7aa;
}

.swatch-row {
  display: flex;
  gap: 9px;
  margin-top: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.swatch {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--swatch);
}

.swatch.active {
  box-shadow: 0 0 0 3px rgba(17, 117, 109, .2);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 100;
  max-width: min(440px, calc(100vw - 28px));
  padding: 12px 15px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px) scale(.98);
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.done-layer {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 24, 39, .5);
  backdrop-filter: blur(10px);
}

.done-card {
  width: min(100%, 360px);
  overflow: hidden;
  border-radius: 22px;
  background: #fff;
  padding: 0 16px 16px;
  text-align: center;
  box-shadow: 0 26px 70px rgba(17, 24, 39, .28);
  animation: modalIn .25s ease;
}

.done-card canvas {
  display: block;
  width: 100%;
  height: 170px;
}

.done-card strong,
.done-card span {
  display: block;
}

.done-card strong {
  font-size: 24px;
}

.done-card span {
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

body.previewing .workflow-card,
body.previewing .floating-tools,
body.previewing .gesture-hint {
  opacity: 0;
  pointer-events: none;
}

body.previewing .stage-head {
  display: none;
}

body.previewing .canvas-viewport {
  height: calc(100dvh - 104px);
  padding-bottom: 76px;
}

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

@keyframes modalIn {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes canvasPop {
  0% { transform: scale(.985); }
  65% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

@keyframes canvasSpark {
  0% { filter: saturate(1); box-shadow: 0 24px 58px rgba(17, 24, 39, .22); }
  35% { filter: saturate(1.25) brightness(1.04); box-shadow: 0 28px 76px rgba(17, 117, 109, .34); }
  100% { filter: saturate(1); box-shadow: 0 24px 58px rgba(17, 24, 39, .22); }
}

@keyframes sparkParticle {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(.4);
  }
  22% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.08);
  }
}

@media (min-width: 900px) {
  body {
    display: grid;
    place-items: center;
    padding: 24px;
  }

  .app-shell {
    min-height: min(900px, calc(100vh - 48px));
    border-radius: 28px;
    overflow: hidden;
  }
}

@media (max-width: 420px) {
  main {
    padding-inline: 8px;
  }

  .stage-head {
    gap: 8px;
    padding-inline: 14px;
  }

  h1 {
    font-size: 23px;
  }

  .stage-note {
    max-width: 230px;
    font-size: 10.5px;
  }

  .mode-toggle {
    padding-inline: 10px;
    font-size: 14px;
  }

  .top-actions {
    gap: 4px;
  }

  .view-zoom-panel {
    grid-template-columns: 36px 1fr 78px 58px;
    gap: 6px;
  }

  .step-tab {
    padding-inline: 2px;
    font-size: 11px;
  }

  .mode-grid {
    gap: 8px;
  }
}

@media (max-width: 380px) {
  .step-tabs {
    gap: 3px;
    padding: 6px;
  }

  .step-tab {
    font-size: 11px;
  }

  .floating-tools {
    gap: 5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
