:root {
  color-scheme: dark;
  --ink: #f8fafc;
  --muted: #9aa8ba;
  --line: rgba(255,255,255,.14);
  --paper: #0f1722;
  --soft: #111c29;
  --teal: #12c8b2;
  --blue: #3b82f6;
  --orange: #ff9f43;
  --green: #22c55e;
  --danger: #ff5a67;
  --shadow: 0 20px 50px rgba(0,0,0,.34);
  --sheet-h: 190px;
  --hud-safe: 146px;
  --work-bias: .18;
}

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

html,
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(90deg, rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,.035) 1px, transparent 1px),
    #08111b;
  background-size: 28px 28px;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

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

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  width: min(100%, 540px);
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: #0b1520;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 28px 80px rgba(0,0,0,.45);
}

.topbar {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  z-index: 80;
  width: min(calc(100% - 18px), 520px);
  height: 50px;
  transform: translateX(-50%);
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 18px;
  background: rgba(10, 18, 28, .78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

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

.brand-lockup img {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.18);
}

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

.brand-lockup strong {
  color: #fff;
  font-size: 14px;
  line-height: 1.05;
}

.brand-lockup span {
  margin-top: 2px;
  color: #8ee9dd;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

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

.icon-btn,
.tool-icon,
.round-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 14px;
  background: rgba(255,255,255,.08);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.10);
}

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

.editor-shell,
.stage {
  position: relative;
  width: 100%;
  height: 100dvh;
}

.stage {
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, rgba(18,200,178,.11), transparent 38%),
    linear-gradient(180deg, #0d1926 0%, #08111b 100%);
}

.stage-title {
  position: absolute;
  left: 10px;
  right: 10px;
  top: calc(66px + env(safe-area-inset-top));
  z-index: 30;
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  padding: 10px 10px 9px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 20px;
  background: rgba(8, 17, 27, .68);
  box-shadow: 0 16px 38px rgba(0,0,0,.24);
  backdrop-filter: blur(16px);
}

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

h1 {
  margin: 2px 0 0;
  color: #fff;
  font-size: 20px;
  line-height: 1.05;
}

.stage-title p {
  margin: 4px 0 0;
  max-width: min(340px, calc(100vw - 125px));
  color: #cbd5e1;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.25;
}

.mode-toggle {
  min-height: 38px;
  border: 0;
  border-radius: 999px;
  padding: 9px 13px;
  background: linear-gradient(135deg, #f59e0b, #12c8b2 54%, #3b82f6);
  color: #fff;
  font-weight: 950;
  box-shadow: 0 14px 32px rgba(18,200,178,.24);
}

.canvas-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  background:
    linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,.05) 1px, transparent 1px),
    #101a26;
  background-size: 22px 22px;
}

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

.selection-chip {
  position: absolute;
  left: 12px;
  top: calc(150px + env(safe-area-inset-top));
  z-index: 34;
  max-width: calc(100% - 92px);
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  background: rgba(8, 17, 27, .74);
  color: #fff;
  font-size: 12px;
  font-weight: 950;
  box-shadow: 0 12px 28px rgba(0,0,0,.30);
  backdrop-filter: blur(14px);
}

.quick-stack {
  position: absolute;
  top: calc(150px + env(safe-area-inset-top));
  right: 10px;
  z-index: 34;
  display: grid;
  gap: 7px;
  padding: 6px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 22px;
  background: rgba(8,17,27,.74);
  box-shadow: 0 16px 34px rgba(0,0,0,.34);
  backdrop-filter: blur(14px);
}

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

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

.tool-sheet {
  position: fixed;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 70;
  width: min(calc(100% - 16px), 520px);
  height: var(--sheet-h);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 26px;
  background: rgba(8, 17, 27, .82);
  box-shadow: 0 -12px 60px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.10);
  backdrop-filter: blur(20px);
}

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

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

.tool-tab {
  flex: 0 0 66px;
  min-height: 48px;
  display: grid;
  grid-template-rows: 21px auto;
  place-items: center;
  gap: 2px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 18px;
  background: rgba(255,255,255,.055);
  color: #d2d9e5;
  font-size: 10px;
  font-weight: 950;
}

.tool-tab.active {
  color: #07111c;
  border-color: rgba(255,255,255,.42);
  background: linear-gradient(135deg, #14f1d6, #7dd3fc);
  box-shadow: 0 12px 26px rgba(18,200,178,.24);
}

.tool-panels {
  flex: 1 1 auto;
  overflow: auto;
  padding: 0 10px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.35) transparent;
}

.tool-panel {
  display: none;
  color: #e6edf6;
}

.tool-panel.active {
  display: block;
  animation: panel-in .16s ease-out both;
}

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

label,
.microcopy {
  display: block;
  color: #aeb9c8;
  font-size: 10px;
  font-weight: 850;
}

label {
  margin: 6px 0 4px;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 14px;
  padding: 0 12px;
  outline: none;
  background: rgba(255,255,255,.08);
  color: #fff;
}

select option {
  color: #111827;
}

input::placeholder {
  color: #98a6b8;
}

input:focus,
select:focus {
  border-color: rgba(20,241,214,.75);
  box-shadow: 0 0 0 3px rgba(20,241,214,.16);
}

input[type="range"] {
  height: 30px;
  padding: 0;
  accent-color: var(--teal);
}

.mode-grid,
.button-row,
.custom-grid,
.quick-links,
.range-line {
  display: grid;
  gap: 8px;
}

.mode-grid {
  grid-template-columns: 1fr 1fr;
}

.choice-card,
.secondary-btn,
.primary-btn,
.store-btn,
.whatsapp-mini,
.whatsapp-btn,
.file-chip,
.upload-main,
.preset-btn,
.category-chip,
.pattern-card {
  min-height: 42px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 16px;
  text-decoration: none;
  color: #eaf2ff;
  background: rgba(255,255,255,.075);
}

.choice-card {
  padding: 8px 10px;
  text-align: left;
}

.choice-card strong,
.choice-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 {
  font-size: 13px;
  font-weight: 950;
}

.choice-card span,
.selected-card span,
.export-card span,
.upload-panel span {
  margin-top: 2px;
  color: #aeb9c8;
  font-size: 10px;
  font-weight: 700;
}

.choice-card.active,
.category-chip.active,
.pattern-card.active {
  border-color: rgba(20,241,214,.70);
  background: rgba(20,241,214,.18);
}

.input-with-unit {
  position: relative;
}

.input-with-unit span {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #d7e2f2;
  font-size: 11px;
  font-weight: 900;
}

.assist-card,
.selected-card,
.export-card,
.upload-panel {
  margin-top: 8px;
  padding: 9px 10px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 16px;
  background: rgba(255,255,255,.065);
}

.assist-card strong,
.selected-card strong,
.export-card strong,
.upload-panel strong {
  color: #fff;
  font-size: 13px;
}

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

.button-row {
  grid-template-columns: 1fr 1fr;
}

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

.primary-btn,
.secondary-btn,
.store-btn,
.whatsapp-mini,
.whatsapp-btn,
.upload-main,
.file-chip {
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
  font-weight: 950;
  text-align: center;
}

.primary-btn {
  border: 0;
  background: linear-gradient(135deg, #14f1d6, #3b82f6);
  color: #06111d;
}

.secondary-btn {
  background: rgba(148,163,184,.15);
}

.secondary-btn.danger,
.danger {
  color: var(--danger);
}

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

.range-line {
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.range-line label {
  margin: 0;
}

.round-btn {
  width: 40px;
  height: 40px;
}

output {
  min-width: 42px;
  color: var(--orange);
  font-size: 11px;
  font-weight: 950;
  text-align: right;
}

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

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

.category-strip {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  margin: 8px 0;
  scrollbar-width: none;
}

.category-chip {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 11px;
  color: #eaf2ff;
  font-size: 11px;
  font-weight: 950;
}

.pattern-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-bottom: 8px;
}

.pattern-card {
  overflow: hidden;
  min-height: 86px;
  padding: 0;
  background: rgba(255,255,255,.08);
}

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

.pattern-card span {
  display: block;
  padding: 5px 6px;
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-list {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.preset-btn {
  padding: 8px 10px;
  text-align: left;
}

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

.preset-btn strong {
  color: #fff;
}

.preset-btn span {
  margin-top: 2px;
  color: #aeb9c8;
  font-size: 10px;
}

.custom-grid {
  grid-template-columns: 1fr 1fr 1fr auto;
  margin-top: 8px;
}

.swatch-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0;
}

.swatch-row button {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 2px solid rgba(255,255,255,.24);
  border-radius: 50%;
}

.swatch-row button.active {
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(20,241,214,.32);
}

.upload-main {
  min-height: 70px;
  border-style: dashed;
  color: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sheet-h) + 24px + env(safe-area-inset-bottom));
  z-index: 120;
  transform: translate(-50%, 20px);
  max-width: min(90vw, 390px);
  padding: 11px 14px;
  border-radius: 999px;
  background: rgba(8,17,27,.88);
  color: #fff;
  font-size: 12px;
  font-weight: 950;
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  transition: opacity .18s ease, transform .18s ease;
}

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

.done-layer {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: rgba(3,7,12,.72);
  backdrop-filter: blur(12px);
}

.done-card {
  width: min(86vw, 360px);
  padding: 18px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 24px;
  background: #0e1824;
  color: #fff;
  text-align: center;
  box-shadow: var(--shadow);
}

.done-card canvas {
  width: 100%;
  height: auto;
}

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

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

.done-card span {
  margin: 8px 0 14px;
  color: #b7c3d2;
  font-size: 13px;
}

@media (max-width: 390px) {
  :root {
    --sheet-h: 178px;
    --hud-safe: 140px;
    --work-bias: .16;
  }
  .stage-title {
    min-height: 70px;
  }
  h1 { font-size: 18px; }
  .stage-title p { font-size: 9.5px; }
  .tool-tab { flex-basis: 61px; }
  .pattern-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 900px) {
  .app-shell {
    border-radius: 28px;
  }
}
