/* Collage Studio — clean, light UI with a coral accent */
:root {
  --bg: #fff7f3; --panel: #ffffff; --ink: #2a2433; --muted: #7c7486; --line: #efe5e1; --soft: #fbf1ed;
  --accent: #ff6b5b; --accent-ink: #fff; --accent-soft: #ffe3de; --teal: #3fb1ae; --stage: #f1e8e4;
  --r: 14px; --shadow: 0 6px 24px rgba(80, 40, 30, .08);
  --top-h: 56px; --tabs-w: 76px; --dock-w: 290px; --side-w: 300px;
  font-family: 'Inter', system-ui, -apple-system, sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); overflow: hidden; overscroll-behavior: none; }
body { font-size: 14px; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 12px; font-weight: 600; transition: background .15s, border-color .15s, transform .1s; }
button:hover { border-color: #e2d3cd; background: var(--soft); }
button:active { transform: scale(.97); }
button:disabled { opacity: .35; pointer-events: none; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { background: #f45a4a; }
button.small { padding: 5px 10px; font-size: 13px; }
button.wide { width: 100%; margin-top: 10px; }
button.danger { color: #d43d2f; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h2 { font-size: 16px; margin: 2px 0 12px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.45; margin: 8px 0; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
#top button { white-space: nowrap; }
.fmt-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
#top { height: calc(var(--top-h) + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) 14px 0; display: flex; align-items: center; gap: 8px; background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 5; }
.brand { display: flex; align-items: center; gap: 9px; font-size: 16px; white-space: nowrap; }
.logo { display: grid; grid-template-columns: 11px 7px; grid-template-rows: 9px 9px; gap: 2px; }
.logo i { border-radius: 3px; background: var(--accent); }
.logo i:first-child { grid-row: span 2; }
.logo i:nth-child(2) { background: #ffb35c; } .logo i:nth-child(3) { background: var(--teal); }
.fmt-btn { margin-left: 10px; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; padding: 5px 12px; }
.fmt-btn small { color: var(--muted); font-weight: 500; font-size: 11.5px; }
.spacer { flex: 1; }
.icon-btn { padding: 7px; display: grid; place-items: center; }

/* ---------- main grid ---------- */
#app { height: calc(100% - var(--top-h) - env(safe-area-inset-top, 0px)); display: grid; grid-template-columns: var(--tabs-w) var(--dock-w) 1fr var(--side-w); grid-template-areas: "tabs dock stage side"; }
#tabs { grid-area: tabs; display: flex; flex-direction: column; gap: 4px; padding: 10px 6px; background: var(--panel); border-right: 1px solid var(--line); }
#tabs button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 9px 2px; font-size: 11px; font-weight: 600; color: var(--muted); border-radius: 12px; }
#tabs button.on { background: var(--accent-soft); color: var(--accent); }
#tabs svg { width: 22px; height: 22px; }
.mobile-only { display: none !important; }
#dock, #side { background: var(--panel); overflow-y: auto; overscroll-behavior: contain; }
#dock { grid-area: dock; border-right: 1px solid var(--line); }
#side { grid-area: side; border-left: 1px solid var(--line); }
.panel { display: none; padding: 16px; }
.panel.on, #inspector { display: block; }
#stageWrap { grid-area: stage; position: relative; background: var(--stage); min-width: 0; min-height: 0; }
#stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#view, #overlay { position: absolute; left: 0; top: 0; }
#view { box-shadow: 0 10px 40px rgba(60, 30, 20, .18); background: #fff; }
#overlay { touch-action: none; }

/* ---------- empty state ---------- */
.empty { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.empty-card { pointer-events: auto; background: rgba(255, 255, 255, .92); backdrop-filter: blur(6px); border-radius: 20px; padding: 26px 30px; text-align: center; box-shadow: var(--shadow); max-width: 300px; }
.empty-card h1 { font-size: 20px; margin: 14px 0 2px; }
.empty-card p { margin: 6px 0; color: var(--muted); }
.empty-art { display: inline-grid; grid-template-columns: 30px 20px; grid-template-rows: 22px 22px; gap: 5px; }
.empty-art i { border-radius: 7px; background: var(--accent); }
.empty-art i:first-child { grid-row: span 2; } .empty-art i:nth-child(2) { background: #ffb35c; } .empty-art i:nth-child(3) { background: var(--teal); }
.drop-hint { position: absolute; inset: 12px; border: 3px dashed var(--accent); border-radius: 18px; background: rgba(255, 107, 91, .08); display: grid; place-items: center; pointer-events: none; z-index: 4; }
.drop-hint div { background: var(--accent); color: #fff; font-weight: 700; padding: 10px 18px; border-radius: 999px; }

/* ---------- brush bar ---------- */
.brush-bar { position: absolute; left: 0; right: 0; margin: 0 auto; width: max-content; bottom: 14px; display: flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: 10px 14px; background: var(--panel); padding: 9px 14px; border-radius: 16px; box-shadow: var(--shadow); z-index: 3; max-width: calc(100% - 24px); }
.brush-bar label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.brush-bar input[type=range] { width: 90px; }

/* ---------- controls ---------- */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.custom-size label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 600; }
.custom-size input { width: 76px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--soft); }
.check { display: flex; gap: 8px; align-items: center; margin-top: 16px; color: var(--muted); font-size: 13px; }
.slider { display: grid; grid-template-columns: 82px 1fr 38px; align-items: center; gap: 8px; margin: 9px 0; color: var(--muted); font-size: 13px; font-weight: 500; }
.slider output { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.slider:not(:has(output)) { grid-template-columns: 82px 1fr; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=color] { width: 34px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer; }
select, textarea, input[type=text] { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft); }
textarea { resize: vertical; min-height: 64px; font-size: 15px; }
.seg { display: flex; background: var(--soft); border-radius: 11px; padding: 3px; gap: 2px; border: 1px solid var(--line); }
.seg button { flex: 1; border: 0; background: none; padding: 7px 6px; font-size: 12.5px; color: var(--muted); border-radius: 8px; }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, .08); }
.seg.small button { padding: 4px 8px; }
.color-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; margin: 10px 0; }
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 12px 0; }
.swatches button { aspect-ratio: 1; padding: 0; border-radius: 50%; border: 2px solid rgba(0, 0, 0, .08); }
.swatches button.on { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.swatches.grads { grid-template-columns: repeat(5, 1fr); }
.swatches.grads button { border-radius: 10px; }
.bg-sub { display: none; } .bg-sub.on { display: block; }

/* size list */
.fmt-group { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; font-weight: 700; }
.fmt-group:first-child { margin-top: 0; }
.fmt-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 9px; margin: 3px 0; text-align: left; border-color: transparent; background: none; font-weight: 500; }
.fmt-item.on { background: var(--accent-soft); border-color: #ffc9c1; }
.fmt-item .shape { width: 34px; height: 34px; display: grid; place-items: center; flex: none; }
.fmt-item .shape i { display: block; border: 2px solid currentColor; border-radius: 3px; opacity: .55; }
.fmt-item.on .shape i { color: var(--accent); opacity: 1; }
.fmt-item b { display: block; font-weight: 600; } .fmt-item small { color: var(--muted); font-size: 11.5px; }

/* layouts */
.tpl-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tpl-list button { padding: 6px; display: grid; place-items: center; aspect-ratio: 1; }
.tpl-list button.on { border-color: var(--accent); background: var(--accent-soft); }
.tpl-list svg { width: 100%; height: 100%; stroke: none; }
.tpl-list svg rect { fill: #e9ddd8; } .tpl-list button.on svg rect { fill: #ff9d91; }
.tpl-list svg .free { fill: none; stroke: #c9b8b1; stroke-width: 2; stroke-dasharray: 4 3; }

/* photos */
.photo-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.photo-list.small { grid-template-columns: repeat(4, 1fr); }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--soft) center/cover no-repeat; cursor: grab; border: 2px solid transparent; padding: 0; }
.thumb.on { border-color: var(--accent); }
.thumb .x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .55); color: #fff; font-size: 13px; line-height: 22px; display: none; }
.thumb:hover .x, .thumb:focus-within .x { display: block; }
.thumb .used { position: absolute; left: 4px; bottom: 4px; background: rgba(255, 255, 255, .9); border-radius: 99px; font-size: 10.5px; padding: 1px 6px; font-weight: 700; color: var(--accent); }

/* text presets */
.text-presets { display: grid; gap: 8px; }
.text-presets button { text-align: left; padding: 12px 14px; font-weight: 400; line-height: 1.1; }

/* layers list */
.layer-list { display: flex; flex-direction: column; gap: 4px; }
.layer { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; }
.layer:hover { background: var(--soft); }
.layer.on { background: var(--accent-soft); border-color: #ffc9c1; }
.layer .lt { width: 38px; height: 38px; border-radius: 7px; background: var(--soft) center/cover no-repeat; display: grid; place-items: center; font-weight: 800; color: var(--muted); flex: none; border: 1px solid var(--line); }
.layer .ln { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .ln small { display: block; color: var(--muted); font-size: 11px; }
.layer button { padding: 4px 6px; border: 0; background: none; color: var(--muted); }
.layer.hid .lt, .layer.hid .ln { opacity: .4; }

/* inspector */
.insp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.insp-head h2 { margin: 0; flex: 1; }
.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; }
.tools button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px; font-size: 10.5px; font-weight: 600; color: var(--muted); }
.tools button svg { width: 18px; height: 18px; color: var(--ink); }
.tools button.on { background: var(--accent-soft); border-color: #ffc9c1; color: var(--accent); }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.presets button { font-size: 12.5px; padding: 8px 6px; }
.presets button.hero { grid-column: span 2; background: linear-gradient(120deg, #2a2433, #5a4870); color: #fff; border: 0; }
.blend-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.blend-grid button { font-size: 11px; padding: 6px 2px; font-weight: 600; }
.blend-grid button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.font-list { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.font-list button { font-weight: 400; font-size: 15px; padding: 7px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-list button.on { border-color: var(--accent); background: var(--accent-soft); }
.nosel { text-align: center; color: var(--muted); padding: 20px 6px; }
.nosel .big { font-size: 34px; }
.tip-list { text-align: left; font-size: 12.5px; line-height: 1.55; padding-left: 18px; }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(30, 20, 30, .42); display: grid; place-items: center; z-index: 20; padding: 16px; }
.sheet { background: var(--panel); border-radius: 20px; padding: 20px; width: min(440px, 100%); max-height: calc(100% - 20px); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.sheet h2 { font-size: 19px; }
.sheet .preview { width: auto; max-width: 100%; max-height: 260px; margin-inline: auto !important; background: repeating-conic-gradient(#f2eaea 0 25%, #fff 0 50%) 0 0/16px 16px; border-radius: 12px; display: block; margin: 6px 0 12px; }
.sheet .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.sheet .field { margin: 12px 0; }
.sheet .field > span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .05em; }
.toast { position: fixed; left: 50%; top: calc(var(--top-h) + 14px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 30; font-weight: 500; box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center; }

/* ---------- narrower desktops ---------- */
@media (max-width: 1180px) { :root { --dock-w: 250px; --side-w: 270px; } }

/* ---------- phones & small tablets: stage on top, sheet + tab bar below ---------- */
@media (max-width: 860px) {
  :root { --top-h: 52px; }
  .brand b { display: none; }
  .fmt-btn { margin-left: 2px; }
  #exportBtn { padding: 8px 12px; }
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr minmax(0, 40%) calc(62px + env(safe-area-inset-bottom, 0px)); grid-template-areas: "stage" "sheet" "tabs"; }
  #tabs { flex-direction: row; justify-content: space-around; padding: 4px 4px env(safe-area-inset-bottom, 0px); border-right: 0; border-top: 1px solid var(--line); overflow-x: auto; }
  #tabs button { flex: 1; min-width: 52px; padding: 6px 2px; font-size: 10.5px; }
  .mobile-only { display: flex !important; }
  #dock, #side { grid-area: sheet; border: 0; border-top: 1px solid var(--line); }
  #side { display: none; }
  body.tab-edit #side { display: block; }
  body.tab-edit #dock { display: none; }
  .panel { padding: 12px 16px 20px; }
  .tpl-list { grid-template-columns: repeat(6, 1fr); }
  .photo-list { grid-template-columns: repeat(5, 1fr); }
  .swatches { grid-template-columns: repeat(14, 1fr); gap: 4px; }
  .swatches.grads { grid-template-columns: repeat(10, 1fr); }
  .tools { grid-template-columns: repeat(8, 1fr); }
  .tools button span { display: none; }
  .brush-bar { bottom: 8px; gap: 6px 10px; padding: 7px 10px; }
  .brush-bar input[type=range] { width: 70px; }
}
@media (max-width: 520px) {
  .tpl-list { grid-template-columns: repeat(4, 1fr); }
  .photo-list { grid-template-columns: repeat(4, 1fr); }
  .swatches { grid-template-columns: repeat(10, 1fr); }
  .swatches.grads { grid-template-columns: repeat(5, 1fr); }
  .tools { grid-template-columns: repeat(4, 1fr); }
  .tools button span { display: block; }
  #fmtDims { display: none; }
  .wide-only { display: none; }
  .fmt-btn { min-width: 0; flex: 0 1 auto; max-width: 46vw; font-size: 13px; }
  #top { gap: 6px; padding-inline: 10px; }
}
