:root {
  /* Tulle white app background with a faint pink tint, one light look on every device */
  --bg: #FDF7F8;
  --panel: #ffffff;
  --ink: #2a1f20;
  --muted: #6b5a60;
  --line: #efdfe3;
  --accent: #e2552d;
  --accent-ink: #ffffff;
  --stage: #f8edf0;
  --checker: #f3e5e9;
  --radius: 12px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  overflow: hidden;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  -webkit-tap-highlight-color: transparent;
}
button { -webkit-user-select: none; user-select: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Touch vs mouse wording */
.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  .touch-only { display: inline; }
  p.touch-only { display: block; }
  .mouse-only { display: none; }
}

.topbar {
  flex: none;
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }

/* Symbol picker */
.sym-toggle { margin: 0 0 10px !important; }
.symbols { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin: 0 0 10px; background: var(--bg); }
.sym-cats { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.sym-cats::-webkit-scrollbar { display: none; }
.sym-cat {
  flex: none; border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer;
}
.sym-cat.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sym-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 4px;
  max-height: 180px; overflow-y: auto; overscroll-behavior: contain;
}
.sym {
  height: 38px; border: 0; border-radius: 6px; background: var(--panel); color: var(--ink);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 0;
  font-family: system-ui, "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols", "Noto Sans Egyptian Hieroglyphs", sans-serif;
}
.sym:hover, .sym:focus-visible { background: color-mix(in srgb, var(--accent) 16%, var(--panel)); }
.remember { margin: 14px 0 0; font-size: 13px; color: var(--muted); }

.layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 340px 1fr;
}
.panel {
  min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 14px;
}
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.card h2 {
  margin: 0 0 12px; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.step {
  display: inline-grid; place-items: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 11px;
}

.seg { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; margin-bottom: 12px; }
.seg-btn {
  flex: 1; border: 0; background: none; color: var(--muted);
  padding: 7px; border-radius: 6px; cursor: pointer; font: inherit;
}
.seg-btn.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.drop {
  display: grid; place-items: center; text-align: center; gap: 8px;
  min-height: 96px; padding: 12px;
  border: 1.5px dashed var(--line); border-radius: 10px;
  color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.drop small { opacity: .8; }
/* Logo library */
.logo-hint { margin: 4px 0 8px; }
/* Once there are logos, the add box shrinks to a slim button so the logos stay in view */
#wm-image-opts.has-logos .drop { min-height: 0; padding: 10px; }
#wm-image-opts.has-logos .drop small, #wm-image-opts.has-logos .drop br { display: none; }
.per-photo { margin: 12px 0 2px; font-weight: 500; color: var(--ink); }
#img-drop.compact { min-height: 0; padding: 10px; }
#img-drop.compact small, #img-drop.compact br { display: none; }
/* Photo list with a logo picker on each row */
.thumbs.assign { display: flex; flex-direction: column; gap: 8px; }
.thumbs.assign li.row {
  aspect-ratio: auto; overflow: visible; cursor: default;
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 10px; outline: 0;
  background: var(--panel); border: 1px solid var(--line);
}
.thumbs.assign li.row.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.row-photo { position: relative; flex: none; width: 64px; height: 64px; border-radius: 6px; overflow: hidden; cursor: pointer; }
.row-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.row-label { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-label b { color: var(--ink); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  width: 40px; height: 40px; padding: 4px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line);
  background: repeating-conic-gradient(#e4e1e2 0 25%, #fff 0 50%) 0 0 / 10px 10px;
}
.chip img { width: 100%; height: 100%; object-fit: contain; display: block; }
.chip.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* Which logo each photo uses, shown on the photo strip */
.thumbs .badge-logo {
  position: absolute; left: 3px; bottom: 3px; width: 26px; height: 26px;
  border-radius: 6px; padding: 2px; object-fit: contain;
  background: rgba(255,255,255,.92); box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.logos {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px;
}
.logos li {
  position: relative; aspect-ratio: 1; max-width: 100%;
  border-radius: 8px; overflow: hidden; cursor: pointer;
  border: 1px solid var(--line);
  background: repeating-conic-gradient(#e4e1e2 0 25%, #fff 0 50%) 0 0 / 12px 12px;
}
.logos li.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.logos li.active::after {
  content: "✓"; position: absolute; left: 4px; bottom: 4px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font-size: 12px; line-height: 20px; text-align: center;
}
.logos img { width: 100%; height: 100%; object-fit: contain; padding: 8px; display: block; }
.logos .x {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px;
  border: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff;
  font-size: 14px; line-height: 22px; cursor: pointer; padding: 0;
}

.thumbs {
  list-style: none; margin: 10px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
}
.thumbs li { position: relative; aspect-ratio: 1; max-width: 100%; border-radius: 6px; overflow: hidden; cursor: pointer; outline: 2px solid transparent; outline-offset: -2px; }
.thumbs li.active { outline-color: var(--accent); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs .x {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px;
  border: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff;
  font-size: 14px; line-height: 22px; cursor: pointer; padding: 0;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); flex: 1; min-width: 0; }
.field.narrow { flex: 0 0 84px; }
.field { position: relative; }
.field output { position: absolute; top: 0; right: 0; color: var(--ink); font-variant-numeric: tabular-nums; }
.field input[type="text"], .field select, .field input[type="number"] {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%;
}
.field input[type="color"] { width: 100%; height: 35px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 2px; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }
.row { display: flex; gap: 10px; }
.row.checks { gap: 20px; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }

.pos-grid {
  display: grid; grid-template-columns: repeat(3, 28px); gap: 4px;
  padding: 6px; background: var(--bg); border-radius: 8px; width: max-content;
}
.pos-grid button {
  width: 28px; height: 22px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--panel); cursor: pointer; padding: 0;
}
.pos-grid button.active { background: var(--accent); border-color: var(--accent); }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 12px; }

.patterns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.pattern {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px 6px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--muted); font: inherit; font-size: 12px; cursor: pointer;
}
.pattern svg { width: 40px; height: 28px; }
.pattern.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--ink); }
.pattern.active svg { color: var(--accent); }

button.primary, button.secondary {
  width: 100%; font: inherit; font-weight: 600; padding: 10px;
  border-radius: 8px; cursor: pointer; margin-top: 4px;
}
button.primary { background: var(--accent); color: var(--accent-ink); border: 0; }
button.secondary { background: none; color: var(--ink); border: 1px solid var(--line); margin-top: 8px; }
button.secondary.small { width: auto; padding: 6px 12px; margin: 0 0 10px; font-weight: 500; }
button:disabled { opacity: .45; cursor: not-allowed; }
.save-hint { margin-top: 12px; }

/* Preview stage */
.stage {
  position: relative; min-height: 0; min-width: 0; overflow: hidden;
  background: var(--stage)
    repeating-conic-gradient(var(--checker) 0 25%, transparent 0 50%) 0 0 / 24px 24px;
}
#preview {
  position: absolute; top: 24px; left: 24px;
  width: calc(100% - 48px); height: calc(100% - 48px);
  object-fit: contain;
  filter: drop-shadow(0 10px 30px rgba(0,0,0,.45));
  touch-action: none;
}
#preview.draggable { cursor: grab; }
#preview.dragging { cursor: grabbing; }
.empty {
  position: absolute; inset: 0; display: grid; place-content: center;
  text-align: center; color: var(--muted); padding: 16px;
}
.empty p { margin: 4px 0 0; }
.empty-art { font-size: 56px; opacity: .5; line-height: 1; }
.stage-nav {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.6); color: #fff; border-radius: 999px; padding: 2px 6px;
}
.stage-nav button { background: none; border: 0; color: #fff; font-size: 24px; width: 40px; height: 36px; cursor: pointer; line-height: 1; }
.stage-nav span { font-variant-numeric: tabular-nums; font-size: 13px; min-width: 3.5em; text-align: center; }

.tabs { display: none; }

.credit {
  flex: none; text-align: center;
  padding: 6px 16px; font-size: 11.5px; color: var(--muted);
  border-top: 1px solid var(--line); background: var(--bg);
}
.credit p { margin: 0; }
.credit p + p { margin-top: 1px; }
.credit a { color: inherit; font-weight: 600; text-decoration: none; }
.credit a:hover, .credit a:focus-visible { color: var(--accent); text-decoration: underline; }

.toast {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  max-width: calc(100% - 32px); width: max-content;
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}

/* ---------- Phones and small tablets ---------- */
@media (max-width: 820px) {
  .topbar { padding: 10px 16px; }
  .topbar h1 { font-size: 16px; }

  .layout { display: flex; flex-direction: column; }

  .stage { order: 1; flex: 0 0 auto; height: 44dvh; min-height: 220px; }
  #preview { top: 12px; left: 12px; width: calc(100% - 24px); height: calc(100% - 24px); }
  .stage-nav { bottom: 8px; }

  .tabs {
    order: 2; flex: none;
    display: grid; grid-template-columns: repeat(4, 1fr);
    background: var(--panel); border-bottom: 1px solid var(--line);
  }
  .tab {
    position: relative;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 2px 7px; border: 0; background: none; cursor: pointer;
    font: inherit; font-size: 11.5px; color: var(--muted);
    border-bottom: 2px solid transparent;
  }
  .tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .tab.active { color: var(--accent); border-bottom-color: var(--accent); }
  .badge {
    position: absolute; top: 4px; left: calc(50% + 8px);
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    background: var(--accent); color: var(--accent-ink);
    font-size: 11px; line-height: 18px; font-variant-numeric: tabular-nums;
  }

  .panel { order: 3; flex: 1; border-right: 0; padding: 14px 16px 24px; display: block; }
  .panel > .card { display: none; border: 0; padding: 0; background: none; border-radius: 0; }
  .panel > .card.tab-active { display: block; }
  .card h2 { display: none; }

  .drop { min-height: 84px; }
  .thumbs { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }

  .pos-grid { margin: 0 auto; }
  #single-opts .hint { text-align: center; }
}

/* Bigger tap targets for fingers */
@media (pointer: coarse) {
  .field input[type="text"], .field select, .field input[type="number"] { font-size: 16px; padding: 10px; } /* 16px stops iOS zoom */
  .field input[type="color"] { height: 44px; }
  .field input[type="range"] { height: 32px; }
  .field { margin-bottom: 8px; font-size: 14px; }
  .seg-btn { padding: 11px 7px; font-size: 15px; }
  .pos-grid { grid-template-columns: repeat(3, 52px); gap: 6px; padding: 8px; }
  .pos-grid button { width: 52px; height: 38px; border-radius: 6px; }
  .pattern { padding: 10px 4px 8px; font-size: 13px; }
  .pattern svg { width: 48px; height: 32px; }
  button.primary, button.secondary { padding: 14px; font-size: 15px; }
  button.secondary.small { padding: 10px 14px; }
  .thumbs .x, .logos .x { width: 28px; height: 28px; line-height: 28px; font-size: 16px; }
  .check { margin: 8px 0 12px; font-size: 15px; }
  .check input { width: 22px; height: 22px; }
  .sym { height: 44px; font-size: 22px; }
  .sym-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
  .sym-cat { padding: 7px 12px; font-size: 13px; }
}

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