:root {
  color-scheme: light;
  --ink: #101828;
  --muted: #667085;
  --line: #dde5ef;
  --paper: #ffffff;
  --soft: #f6f8fb;
  --teal: #0f9f8f;
  --blue: #2563eb;
  --orange: #e56b2f;
  --green: #22c55e;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(16, 24, 40, .16);
  --sheet-h: 244px;
}

* { box-sizing: border-box; }
[hidden], .hidden { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  overflow: hidden;
  font-family: Montserrat, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #edf8f6 0%, #f9fbff 52%, #fff6ef 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);
  height: 100dvh;
  margin: 0 auto;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 0 0 1px rgba(16, 24, 40, .06);
}

.topbar {
  height: calc(58px + env(safe-area-inset-top));
  padding: max(9px, env(safe-area-inset-top)) 10px 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid rgba(16, 24, 40, .08);
  backdrop-filter: blur(18px);
}

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

.brand-lockup img {
  width: 39px;
  height: 39px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

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

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

.brand-lockup span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

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

.icon-btn,
.tool-icon,
.round-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 8px 20px rgba(16, 24, 40, .08);
}

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

.editor-shell {
  position: relative;
  height: calc(100dvh - 58px - env(safe-area-inset-top));
  overflow: hidden;
}

.stage {
  height: 100%;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(135deg, rgba(15, 159, 143, .13), rgba(37, 99, 235, .07), rgba(229, 107, 47, .10)),
    #f8fbff;
}

.stage-title {
  flex: 0 0 auto;
  min-height: 90px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px 8px;
}

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

h1 {
  margin: 3px 0 0;
  font-size: 22px;
  line-height: 1.05;
}

.stage-title p {
  margin: 5px 0 0;
  max-width: min(320px, calc(100vw - 120px));
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.28;
}

.mode-toggle {
  flex: 0 0 auto;
  min-height: 38px;
  border: 0;
  border-radius: 999px;
  padding: 9px 14px;
  background: linear-gradient(135deg, var(--teal), var(--blue));
  color: #fff;
  font-weight: 900;
  box-shadow: 0 12px 26px rgba(15, 159, 143, .24);
}

.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding-bottom: calc(var(--sheet-h) + env(safe-area-inset-bottom));
  background:
    linear-gradient(90deg, rgba(16, 24, 40, .055) 1px, transparent 1px),
    linear-gradient(0deg, rgba(16, 24, 40, .055) 1px, transparent 1px),
    #fbfdff;
  background-size: 22px 22px;
  touch-action: none;
}

#designCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.selection-chip {
  position: absolute;
  left: 12px;
  top: 10px;
  max-width: calc(100% - 86px);
  padding: 7px 11px;
  border: 1px solid rgba(16, 24, 40, .08);
  border-radius: 999px;
  background: rgba(255, 255, 255, .9);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 10px 28px rgba(16, 24, 40, .12);
  backdrop-filter: blur(12px);
}

.quick-stack {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  gap: 7px;
  padding: 6px;
  border: 1px solid rgba(16, 24, 40, .08);
  border-radius: 20px;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 16px 34px rgba(16, 24, 40, .14);
  backdrop-filter: blur(12px);
}

.tool-icon {
  width: 40px;
  height: 40px;
  box-shadow: none;
}

.tool-icon.danger {
  color: var(--danger);
}

.tool-sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 50;
  width: min(100%, 520px);
  height: calc(var(--sheet-h) + env(safe-area-inset-bottom));
  border: 1px solid rgba(16, 24, 40, .10);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 -18px 54px rgba(16, 24, 40, .18);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tool-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 9px 8px 7px;
  scrollbar-width: none;
}

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

.tool-tab {
  flex: 0 0 76px;
  min-height: 50px;
  display: grid;
  grid-template-rows: 20px auto;
  place-items: center;
  gap: 3px;
  border: 1px solid transparent;
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.tool-tab.active {
  border-color: rgba(15, 159, 143, .24);
  background: linear-gradient(135deg, rgba(15, 159, 143, .16), rgba(37, 99, 235, .12));
  color: var(--ink);
  box-shadow: 0 8px 20px rgba(15, 159, 143, .13);
}

.tool-panels {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.tool-panel {
  display: none;
  height: 100%;
  overflow: auto;
  padding: 8px 13px calc(12px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}

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

label {
  display: block;
  margin: 8px 0 5px;
  color: #344054;
  font-size: 12px;
  font-weight: 900;
}

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

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 159, 143, .14);
}

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

.mode-grid,
.button-row,
.quick-links,
.custom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.button-row.compact {
  grid-template-columns: repeat(3, 1fr);
}

.choice-card,
.assist-card,
.selected-card,
.export-card,
.upload-panel {
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--soft);
  padding: 10px;
}

.choice-card {
  min-height: 62px;
  text-align: left;
}

.choice-card strong,
.choice-card span,
.assist-card strong,
.assist-card span,
.selected-card strong,
.selected-card span,
.export-card strong,
.export-card span,
.upload-panel strong,
.upload-panel span {
  display: block;
}

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

.choice-card span,
.assist-card span,
.selected-card span,
.export-card span,
.upload-panel span,
.microcopy {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.choice-card.active {
  border-color: var(--teal);
  background: #e9fbf8;
  box-shadow: 0 0 0 3px rgba(15, 159, 143, .12);
}

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

.range-line:has(.round-btn) {
  grid-template-columns: 42px 1fr 42px;
}

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

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

.primary-btn {
  background: linear-gradient(135deg, var(--teal), var(--blue));
  color: #fff;
}

.secondary-btn,
.store-btn,
.file-chip,
.upload-main {
  background: #eef6ff;
  color: #1e3a8a;
}

.secondary-btn.danger {
  background: #fff1f0;
  color: var(--danger);
}

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

.full {
  width: 100%;
  margin-top: 8px;
}

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

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

.category-strip,
.swatch-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 9px -13px 8px;
  padding: 0 13px 4px;
}

.category-chip {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 8px 11px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 900;
}

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

.pattern-grid,
.preset-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.pattern-card,
.preset-btn {
  position: relative;
  min-height: 82px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 0;
}

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

.pattern-card span,
.preset-btn span,
.preset-btn strong {
  display: block;
  padding: 5px 7px;
  font-size: 10.5px;
  font-weight: 900;
}

.pattern-card span {
  position: absolute;
  left: 5px;
  right: 5px;
  bottom: 5px;
  border-radius: 9px;
  background: rgba(255, 255, 255, .88);
  color: var(--ink);
}

.pattern-card.active,
.preset-btn.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 159, 143, .16);
}

.swatch {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(16, 24, 40, .16);
  border-radius: 999px;
  background: var(--swatch);
}

.swatch.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 159, 143, .18);
}

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

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

.done-layer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 24, 40, .52);
  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(16, 24, 40, .28);
}

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

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

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

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

button:active,
a:active {
  transform: scale(.98);
}

@media (max-width: 390px) {
  :root { --sheet-h: 232px; }
  .tool-tab { flex-basis: 68px; font-size: 10px; }
  h1 { font-size: 20px; }
  .stage-title p { font-size: 10px; }
  .pattern-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

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

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

  .tool-sheet {
    bottom: 18px;
    border-radius: 24px;
    border-bottom: 1px solid rgba(16, 24, 40, .10);
  }
}
