/* Layout: square stage on the left, a tall control column on the right; stacks on phones.
   One committed dark look (a photo-editing room), pixel display type for the "chrome". */
:root {
  --ink: #140f19;        /* page */
  --well: #1c1622;       /* panels */
  --well-2: #251d2d;     /* raised controls */
  --line: #3a2e44;       /* hairlines */
  --text: #f4ecf3;
  --muted: #ab9cb2;
  --pink: #ff7ab8;
  --pink-deep: #c2367a;
  --cyan: #7ff0e6;
  --shadow: #07050a;
  --font-display: "Silkscreen", ui-monospace, monospace;
  --font-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 10px;
  color-scheme: dark;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--ink);
  color: var(--text);
  font: 15px/1.45 var(--font-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ---------- top bar ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 22px; height: 20px; image-rendering: pixelated;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 11 10' shape-rendering='crispEdges'%3E%3Cpath fill='%23ff6fa5' d='M1 1h3v1h1v1h1V2h1V1h3v1h1v3h-1v1H9v1H8v1H7v1H4V8H3V7H2V6H1V5H0V2h1z'/%3E%3Cpath fill='%23fff' d='M2 2h1v2H2z'/%3E%3C/svg%3E") center/contain no-repeat;
}
.brand-name { font: 700 20px/1 var(--font-display); letter-spacing: .02em; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 8px; cursor: pointer;
  background: var(--well-2); border: 1px solid var(--line);
  font-weight: 600; font-size: 14px; user-select: none;
  box-shadow: 0 3px 0 var(--shadow);
  transition: transform .08s ease, box-shadow .08s ease, background .15s ease;
}
.btn:hover { background: #2e2437; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.btn.primary { background: var(--pink); border-color: var(--pink); color: #2a0b1b; }
.btn.primary:hover { background: #ff92c6; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--well-2); }
.btn.small { min-height: 32px; font-size: 13px; padding: 0 10px; }
.btn[disabled] { opacity: .4; pointer-events: none; }

/* ---------- main layout ---------- */
.app {
  display: grid; gap: 20px;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  align-items: start;
  padding-block: 20px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  max-width: 1400px; margin: 0 auto;
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
}

.stage-col { display: flex; flex-direction: column; gap: 12px; align-items: center; min-width: 0; position: sticky; top: 12px; }
@media (max-width: 860px) { .stage-col { position: static; } }
.stage {
  position: relative; width: min(100%, calc(100vh - 190px)); min-width: 260px; max-width: 100%;
  aspect-ratio: 1 / 1; border-radius: 6px; overflow: hidden;
  background: repeating-conic-gradient(#221a29 0 25%, #1a141f 0 50%) 0 0 / 24px 24px;
  box-shadow: 0 0 0 1px var(--line), 0 18px 40px -18px #000;
}
@media (max-width: 860px) { .stage { width: 100%; min-width: 0; } }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#ui { touch-action: none; cursor: default; }
.drop-veil {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(20, 15, 25, .72); border: 3px dashed var(--pink); border-radius: 6px;
  font: 700 18px var(--font-display); color: var(--pink);
}

.toolrow { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; width: 100%; }
.seg { display: inline-flex; background: var(--well); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--well-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.brush-size { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.brush-size input { width: 120px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); text-align: center; max-width: 60ch; }

/* ---------- side column ---------- */
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.tabs {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px;
  background: var(--well); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px;
}
.tabs button {
  border: 0; background: transparent; cursor: pointer; border-radius: 7px; min-width: 0;
  padding: 10px 4px; font: 400 12px/1 var(--font-display); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tabs button[aria-selected="true"] { background: var(--pink); color: #2a0b1b; }
.panels { min-width: 0; }
.panel { display: flex; flex-direction: column; gap: 14px; background: var(--well); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel h3 {
  margin: 6px 0 -4px; font: 400 12px/1.2 var(--font-display); letter-spacing: .06em; color: var(--cyan); text-transform: uppercase;
}
.panel h3:first-child { margin-top: 0; }
.note { margin: -4px 0 0; font-size: 13px; color: var(--muted); }

/* controls */
.ctl { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ctl > .lab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; font-weight: 600; }
.ctl > .lab output { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 500; }
.ctl input[type="range"] { width: 100%; accent-color: var(--pink); margin: 0; }
.ctl select, .ctl input[type="text"], .ctl textarea {
  width: 100%; background: var(--well-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 14px;
}
.ctl textarea { resize: vertical; min-height: 72px; line-height: 1.35; }
.ctl-color { flex-direction: row; align-items: center; justify-content: space-between; }
.ctl-color input { width: 44px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
.ctl-toggle { flex-direction: row; align-items: center; justify-content: space-between; }
.ctl-toggle input { width: 18px; height: 18px; accent-color: var(--pink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 1px solid var(--line); background: var(--well-2); border-radius: 999px; padding: 5px 11px;
  font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted);
}
.chips button[aria-pressed="true"] { border-color: var(--pink); color: var(--text); background: #3a2131; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* looks */
.looks { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.look {
  border: 1px solid var(--line); background: var(--well-2); border-radius: 9px; padding: 6px; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-align: left;
}
.look i { display: block; height: 26px; border-radius: 5px; }
.look[aria-pressed="true"] { border-color: var(--pink); color: var(--text); box-shadow: 0 0 0 1px var(--pink); }

/* recipe cards */
.recipes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.recipe {
  border: 1px solid var(--line); background: var(--well-2); border-radius: 10px; padding: 0; overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; text-align: left;
  transition: transform .12s ease, border-color .12s ease;
}
.recipe:hover { transform: translateY(-2px); border-color: var(--pink); }
.recipe canvas { width: 100%; aspect-ratio: 1; display: block; background: #0e0b12; }
.recipe span { padding: 7px 8px 8px; font-size: 12px; font-weight: 600; line-height: 1.2; }
@media (max-width: 420px) { .recipes { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* sticker grid */
.stickers { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.sticker {
  border: 1px solid var(--line); background: var(--well-2); border-radius: 9px; padding: 6px 4px 5px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; color: var(--muted);
  line-height: 1.15; text-align: center;
}
.sticker:hover { border-color: var(--pink); color: var(--text); }
.sticker canvas { width: 56px; height: 56px; display: block; }

/* inspector */
.inspector {
  background: var(--well); border: 1px solid var(--pink-deep); border-radius: var(--radius); padding: 14px 16px 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.insp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.insp-head strong { font: 400 13px/1 var(--font-display); color: var(--pink); letter-spacing: .04em; }
.insp-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.insp-actions .btn { min-height: 30px; font-size: 12px; padding: 0 9px; box-shadow: none; }
.insp-actions .danger { color: #ff8a9b; }
.insp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.insp-grid .wide { grid-column: 1 / -1; }
details.more { border-top: 1px solid var(--line); padding-top: 10px; }
details.more summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
details.more[open] summary { margin-bottom: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--ink); padding: 9px 16px; border-radius: 999px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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