:root {
  --bg: #f4efe7;
  --panel: #fffdf9;
  --ink: #2b2622;
  --muted: #7a7066;
  --line: #e4dccf;
  --accent: #e0573b;
  --primary: #2b2622;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.top {
  display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between;
  gap: .5rem 1.5rem; padding: 1rem 1.25rem .5rem;
}
.brand h1 { margin: 0; font-size: clamp(1.25rem, 3.5vw, 1.8rem); letter-spacing: -.01em; }
.brand p { margin: .1rem 0 0; color: var(--muted); }
.privacy { margin: 0; font-size: .9rem; color: var(--muted); }

.app {
  display: grid; gap: 1rem; padding: .5rem 1.25rem 1.25rem;
  grid-template-columns: minmax(0, 1fr) 340px; align-items: start;
}
.preview-wrap { position: sticky; top: .75rem; }
.preview {
  position: relative; background: #3a3633; border-radius: var(--radius);
  height: min(72vh, 760px); display: grid; place-items: center; overflow: hidden;
}
.preview.dragging { outline: 3px dashed var(--accent); outline-offset: -8px; }
#preview { max-width: 100%; max-height: 100%; display: block; }
.empty { position: absolute; text-align: center; color: #eee; padding: 1rem; pointer-events: none; }
.empty .muted { color: #bbb; }
.status { min-height: 1.2em; margin: .4rem 0 0; font-size: .85rem; }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 999px; padding: .65rem 1.1rem; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem;
  min-height: 44px; /* touch target */
}
.btn:hover { border-color: #cbbfae; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: progress; }
.small-btn { padding: .4rem .8rem; min-height: 36px; font-size: .85rem; font-weight: 500; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }

.controls { display: grid; gap: .75rem; }
details {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .75rem 1rem;
}
summary { font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: .5rem; }
details[open] summary { margin-bottom: .6rem; }
.pill { background: var(--bg); border-radius: 999px; padding: 0 .55rem; font-size: .8rem; font-weight: 600; }

.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: .5rem; margin-bottom: .6rem; max-height: 340px; overflow: auto; }
.item { background: var(--bg); border-radius: 8px; padding: .3rem; display: grid; gap: .25rem; }
.item canvas { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 4px; display: block; }
.item input { width: 100%; font: inherit; font-size: .75rem; padding: .25rem .3rem; border: 1px solid var(--line); border-radius: 4px; }
.item .tools { display: flex; justify-content: space-between; }
.item button { border: 0; background: none; cursor: pointer; font-size: .9rem; padding: .15rem .35rem; border-radius: 4px; }
.item button:hover { background: var(--line); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin-bottom: .5rem; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-block; padding: .45rem 1rem; cursor: pointer; }
.seg input:checked + span { background: var(--primary); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.check { display: flex; align-items: center; gap: .5rem; margin: .4rem 0; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.range { display: grid; grid-template-columns: 1fr auto; align-items: center; margin: .45rem 0; }
.range label { font-size: .9rem; }
.range em { color: var(--muted); font-style: normal; font-size: .8rem; }
.range output { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--muted); }
.range input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); height: 28px; }

.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin: .4rem 0; }
.color { display: flex; align-items: center; gap: .4rem; font-size: .9rem; }
.color input { width: 40px; height: 32px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: #fff; }
.field { display: grid; gap: .25rem; font-size: .9rem; margin: .4rem 0; flex: 1; }
.field select, .field input { font: inherit; padding: .5rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 10; padding: 1rem; }
.overlay[hidden] { display: none; }
.sheet { background: var(--panel); border-radius: var(--radius); padding: 1rem; max-width: 720px; width: 100%; max-height: 92vh; overflow: auto; }
.sheet p { margin: .2rem 0; }
.sheet img {
  width: 100%; margin: .6rem 0; border-radius: 6px;
  background: repeating-conic-gradient(#ddd 0 25%, #f6f6f6 0 50%) 0 0 / 20px 20px;
  -webkit-touch-callout: default;
}

.foot { text-align: center; padding: 1rem; font-size: .85rem; color: var(--muted); }

/* Phones & small tablets: stack, preview on top */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; padding: .25rem .75rem 1rem; }
  .top { padding: .75rem .75rem .25rem; }
  .preview-wrap { position: static; }
  .preview { height: min(56vh, 520px); }
  .actions .btn { flex: 1 1 auto; justify-content: center; }
}
