:root {
  --bg: #14161a;
  --bg2: #1c1f25;
  --bg3: #24282f;
  --edge: #32363e;
  --text: #e8eaed;
  --muted: #9aa0a8;
  --accent: #4da3ff;
  --accent2: #2f7fdb;
  --danger: #ff5d5d;
  --ok: #4ade80;
  --warn: #fbbf24;
  --cut: #ff2d7a;
  --radius: 8px;
  font-size: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 16px; height: 48px; flex: 0 0 auto;
  background: var(--bg2); border-bottom: 1px solid var(--edge);
}
.brand { font-size: 15px; white-space: nowrap; }
.brand .tagline { color: var(--muted); font-size: 11px; margin-left: 8px; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: none; border: none; color: var(--muted); padding: 8px 14px;
  border-radius: var(--radius); cursor: pointer; font-size: 13px;
}
.tab:hover { color: var(--text); background: var(--bg3); }
.tab.active { color: var(--text); background: var(--bg3); box-shadow: inset 0 -2px 0 var(--accent); }
.topbar-right { margin-left: auto; color: var(--muted); font-size: 11px; }

/* ---------- layout ---------- */
.tool { display: none; flex: 1 1 auto; min-height: 0; }
.tool.active { display: flex; }
.sidebar {
  width: 300px; flex: 0 0 auto; overflow-y: auto;
  background: var(--bg2); border-right: 1px solid var(--edge); padding: 10px;
}
.workspace { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }

.panel { border: 1px solid var(--edge); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; background: var(--bg); }
.panel h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }

.row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; min-width: 0; }
.row label { flex: 0 0 auto; color: var(--muted); font-size: 12px; min-width: 62px; }
.row input[type=number], .row select, .row input[type=text] {
  flex: 1 1 auto; min-width: 0; background: var(--bg3); color: var(--text);
  border: 1px solid var(--edge); border-radius: 6px; padding: 5px 7px; font-size: 12px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid2 .row label { min-width: 46px; }
.slider-row input[type=range] { flex: 1 1 auto; min-width: 0; accent-color: var(--accent); }
.slider-row output { flex: 0 0 30px; text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.slider-inline { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.slider-inline input[type=range] { width: 90px; accent-color: var(--accent); }

.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 12px; cursor: pointer; min-width: 0 !important; }
.chk input { accent-color: var(--accent); }

.btn {
  background: var(--bg3); color: var(--text); border: 1px solid var(--edge);
  border-radius: 6px; padding: 7px 12px; cursor: pointer; font-size: 12.5px; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent2); border-color: var(--accent2); }
.btn.primary:hover:not(:disabled) { background: var(--accent); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.wide { width: 100%; margin-top: 4px; }
.btn.mode.active { background: var(--accent2); border-color: var(--accent2); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btngroup { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.btngroup.right { justify-content: flex-end; margin-top: 12px; }

select.sm { background: var(--bg3); color: var(--text); border: 1px solid var(--edge); border-radius: 6px; padding: 4px 6px; font-size: 12px; }

/* ---------- dropzones ---------- */
.dropzone {
  border: 2px dashed var(--edge); border-radius: var(--radius); padding: 22px 10px;
  text-align: center; cursor: pointer; color: var(--muted); transition: border-color .15s, background .15s;
  margin-bottom: 8px;
}
.dropzone.small { padding: 12px 10px; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: rgba(77,163,255,.06); color: var(--text); }
.dz-sub { font-size: 11px; color: var(--muted); }

/* ---------- sticker list ---------- */
.sticker-list { display: flex; flex-direction: column; gap: 8px; max-height: 44vh; overflow-y: auto; }
.sticker-card { border: 1px solid var(--edge); border-radius: var(--radius); background: var(--bg2); padding: 8px; }
.sticker-card.detecting { opacity: .6; }
.sc-head { display: flex; gap: 8px; align-items: center; }
.sc-thumb {
  width: 44px; height: 44px; flex: 0 0 auto; border-radius: 6px; border: 1px solid var(--edge);
  background: repeating-conic-gradient(#2e323a 0% 25%, #262a31 0% 50%) 0 0/12px 12px; object-fit: contain;
}
.sc-name { flex: 1 1 auto; min-width: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-name .dims { display: block; color: var(--muted); font-size: 10.5px; }
.sc-qty { width: 52px !important; flex: 0 0 auto !important; }
.sc-x { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 2px 5px; }
.sc-x:hover { color: var(--danger); }
.sc-more { margin-top: 6px; display: none; border-top: 1px dashed var(--edge); padding-top: 6px; }
.sticker-card.open .sc-more { display: block; }
.sc-toggle { background: none; border: none; color: var(--muted); font-size: 11px; cursor: pointer; padding: 2px 0; }
.sc-toggle:hover { color: var(--accent); }

/* ---------- canvas area ---------- */
.canvas-toolbar, .layerbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; flex: 0 0 auto;
  background: var(--bg2); border-bottom: 1px solid var(--edge); flex-wrap: wrap;
}
.layerbar { gap: 14px; padding: 4px 10px; }
.sep { width: 1px; height: 20px; background: var(--edge); margin: 0 4px; }
.spacer { flex: 1 1 auto; }
.canvas-wrap { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: #101216; }
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.canvas-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); pointer-events: none; font-size: 15px;
}
.canvas-empty.hidden { display: none; }

.sheettabs { display: flex; gap: 4px; flex-wrap: wrap; }
.sheettab {
  background: var(--bg3); border: 1px solid var(--edge); color: var(--muted);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.sheettab.active { color: var(--text); border-color: var(--accent); background: rgba(77,163,255,.12); }

/* ---------- status bar ---------- */
.statusbar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border-top: 1px solid var(--edge); padding: 5px 10px;
  font-size: 12px; color: var(--muted); min-height: 30px;
}
.progress { width: 160px; height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; display: none; }
.progress.on { display: block; }
.progress > div { height: 100%; width: 0%; background: var(--accent); transition: width .12s; }

/* ---------- misc ---------- */
.mini { font-size: 11.5px; margin: 4px 0; }
.muted { color: var(--muted); }
.warn { color: var(--warn); font-size: 12px; padding: 6px 0; }
.hidden { display: none !important; }
.swatch { width: 22px; height: 22px; border-radius: 5px; border: 1px solid var(--edge); display: inline-block; background: #fff; }

#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
#modal {
  background: var(--bg2); border: 1px solid var(--edge); border-radius: 12px;
  width: min(520px, 92vw); max-height: 84vh; overflow-y: auto; padding: 18px;
}
#modal h3 { margin-bottom: 12px; font-size: 15px; }
#modal-body { font-size: 13px; }
.vresult { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; border-bottom: 1px solid var(--edge); }
.vresult:last-child { border-bottom: none; }
.vicon { flex: 0 0 auto; }
.vres-ok .vicon { color: var(--ok); }
.vres-fail .vicon { color: var(--danger); }
.vres-warn .vicon { color: var(--warn); }

#toast {
  position: fixed; bottom: 44px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--edge); color: var(--text);
  padding: 9px 16px; border-radius: 8px; z-index: 60; font-size: 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.4); max-width: 80vw;
}
#restore-banner {
  position: fixed; top: 56px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--accent); border-radius: 8px;
  padding: 8px 14px; z-index: 40; display: flex; gap: 10px; align-items: center; font-size: 13px;
}

@media (max-width: 900px) {
  .tool.active { flex-direction: column; overflow-y: auto; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--edge); max-height: 45vh; }
  .workspace { min-height: 55vh; }
}

/* Per-size sticker controls */
.sc-size { margin-top: 8px; gap: 8px; }
.sc-size label { min-width: 0; color: var(--muted); font-size: 11px; }
.sc-size input { display: block; box-sizing: border-box; width: 100%; margin-top: 4px; background: var(--bg3); color: var(--text); border: 1px solid var(--edge); border-radius: 6px; padding: 5px 7px; }
.sc-count { margin-top: 8px; }
.sc-link { margin-bottom: 8px; }
.sc-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; }

.sc-shape { margin-top: 8px; }

/* Sub-sheet list (tool 1) */
.region-list:empty { display: none; }
.region-row { display: flex; align-items: center; gap: 6px; padding: 4px 6px; margin-bottom: 4px; border: 1px solid var(--edge); border-radius: 6px; cursor: pointer; font-size: 12px; }
.region-row.active { border-color: var(--accent); }
.region-row .swatch { width: 18px; height: 18px; flex: 0 0 auto; }
.region-row .rname { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.region-row .btn.sm { padding: 2px 7px; }
