* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1a1d23; --muted: #6b7280;
  --accent: #c8501e; --line: #e2e4e9;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--ink);
  overscroll-behavior: none;
}
.layout { display: flex; flex-direction: column; min-height: 100dvh; }
#stage-col { position: sticky; top: 0; z-index: 5; background: var(--bg); }
#stage {
  position: relative; margin: 0 auto; touch-action: none;
  width: min(92vw, 55dvh, 560px); aspect-ratio: 2164 / 2150;
}
#design-canvas, #overlay-img { position: absolute; inset: 0; }
#select-box { position: absolute; }
#design-canvas { width: 100%; height: 100%; }
#overlay-img { width: 100%; height: 100%; pointer-events: none; user-select: none; }
#select-box { pointer-events: none; }
#empty-state {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; z-index: 3;
}
#empty-state h1 { font-size: 20px; font-weight: 700; margin-bottom: 6px; color: #fff; }
.big-btn {
  font-size: 16px; font-weight: 600; padding: 14px 28px; min-width: 220px;
  border: none; border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer;
}
.big-btn:active { transform: scale(0.98); }
#layer-toggle {
  display: flex; gap: 6px; justify-content: center; padding: 10px 0;
}
#layer-toggle button {
  font-size: 13px; font-weight: 600; padding: 8px 20px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted); cursor: pointer;
}
#layer-toggle button.active { background: var(--ink); border-color: var(--ink); color: #fff; }
#controls {
  display: flex; gap: 10px; padding: 12px 16px; flex-wrap: wrap; justify-content: center;
}
.tool-btn {
  font-size: 14px; font-weight: 600; padding: 12px 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer;
  min-height: 44px;
}
.tool-btn.subtle { color: var(--muted); }
#sheet {
  position: fixed; inset: auto 0 0 0; z-index: 20; background: var(--panel);
  border-radius: 16px 16px 0 0; padding: 20px; box-shadow: 0 -8px 30px rgba(0,0,0,0.18);
  max-height: 70dvh; overflow-y: auto;
}
#select-box { border: 2px solid var(--accent); pointer-events: none; z-index: 4; }
.handle {
  position: absolute; width: 28px; height: 28px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent); pointer-events: auto;
  touch-action: none; box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
.handle.tl { left: -14px; top: -14px; }  .handle.tr { right: -14px; top: -14px; }
.handle.bl { left: -14px; bottom: -14px; } .handle.br { right: -14px; bottom: -14px; }
.handle.rot { left: calc(50% - 14px); top: -50px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-head h2 { font-size: 16px; }
.sheet-close { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.swatch-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.swatch {
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer;
}
.swatch.custom { overflow: hidden; position: relative; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.swatch.custom input { position: absolute; inset: -8px; opacity: 0; cursor: pointer; }
.preview-overlay {
  position: fixed; inset: 0; z-index: 30; background: rgba(20, 22, 28, 0.92);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.pv-frame { width: min(88vw, 80dvh); }
.pv-stack { position: relative; width: 100%; aspect-ratio: 1; background: #fff; border-radius: 12px; overflow: hidden; }
.pv-stack img { position: absolute; left: 0; top: 0; }
.pv-shot { width: 100%; height: 100%; }
.pv-close, .pv-prev, .pv-next {
  border: none; background: rgba(255,255,255,0.12); color: #fff; font-size: 22px;
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
}
.pv-close { position: absolute; top: 18px; right: 18px; }
@media (min-width: 701px) {
  .layout { flex-direction: row; align-items: flex-start; justify-content: center; gap: 28px; padding: 28px; }
  #stage { width: min(58vw, 78dvh, 640px); }
  #controls { flex-direction: column; width: 300px; position: sticky; top: 28px; }
  .tool-btn { width: 100%; }
  #sheet { inset: 0 auto 0 auto; left: 50%; top: 50%; transform: translate(-50%, -50%);
           bottom: auto; border-radius: 16px; width: 420px; max-height: 80dvh; }
}
