:root{
  --bg1:#f7fbff;
  --bg2:#fff7fb;
  --card:#ffffffcc;
  --line:#00000012;
  --text:#0b1220;
  --muted:#3a4a62;
  --shadow: 0 12px 30px #00000012;
  --r:18px;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  color:var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  background:
    radial-gradient(1200px 600px at 20% 10%, #dff1ff 0%, transparent 60%),
    radial-gradient(900px 500px at 80% 10%, #ffe3f2 0%, transparent 60%),
    radial-gradient(1000px 700px at 50% 90%, #e8ffe8 0%, transparent 65%),
    linear-gradient(180deg, var(--bg1), var(--bg2));
}

.topbar{
  position:sticky; top:0; z-index:20;
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 16px;
  backdrop-filter: blur(10px);
  background:#ffffffaa;
  border-bottom:1px solid var(--line);
}

.brand{display:flex; gap:10px; align-items:center}
.logo{font-size:24px}
.ttl{font-weight:800; letter-spacing:0.02em}
.sub{font-size:12px; color:var(--muted)}

.top-actions{display:flex; gap:8px; flex-wrap:wrap}

.btn{
  border:1px solid var(--line);
  background:#fff;
  padding:10px 12px;
  border-radius:14px;
  box-shadow: 0 8px 18px #00000010;
  cursor:pointer;
  transition: transform .06s ease, box-shadow .2s ease;
  user-select:none;
}
.btn:active{ transform: translateY(1px); box-shadow: 0 4px 10px #00000010; }
.btn.primary{ background: #2b6cff; color:#fff; border-color:#2b6cff; }
.btn.danger{ background:#ff3b5c; color:#fff; border-color:#ff3b5c; }
.btn.mini{ padding:7px 10px; border-radius:12px; font-size:12px; box-shadow:none; }

.layout{
  display:grid;
  grid-template-columns: 380px 1fr;
  gap:14px;
  padding:14px;
}

.panel{min-width:0}
.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--r);
  box-shadow: var(--shadow);
  padding:14px;
  margin-bottom:12px;
}
.cardTitle{
  font-weight:800;
  margin-bottom:10px;
  display:flex; align-items:center; justify-content:space-between;
}

.row{
  display:flex; align-items:center; gap:10px;
  margin:10px 0;
}
.label{
  width:92px;
  color:var(--muted);
  font-size:13px;
  flex:0 0 auto;
}
.select,.range,.color{
  flex:1 1 auto;
  min-width:0;
}
.select{
  padding:10px 10px;
  border-radius:14px;
  border:1px solid var(--line);
  background:#fff;
}
.range{ width:100% }
.color{
  width:56px; height:40px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
  padding:4px;
}
.val{
  width:64px;
  text-align:right;
  color:var(--muted);
  font-variant-numeric: tabular-nums;
}

.chk{font-size:13px; color:var(--muted); display:flex; gap:8px; align-items:center; white-space:nowrap}

.seg{display:flex; gap:8px}
.segBtn{
  padding:8px 10px;
  border-radius:12px;
  border:1px solid var(--line);
  background:#fff;
  cursor:pointer;
}
.segBtn.isOn{
  background:#111827;
  border-color:#111827;
  color:#fff;
}

.hint{
  margin-top:10px;
  font-size:12px;
  color:var(--muted);
  line-height:1.55;
}

.stageCard{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--r);
  box-shadow: var(--shadow);
  padding:14px;
}

.stageTop{
  display:flex; align-items:end; justify-content:space-between;
  margin-bottom:10px;
}
.stageTitle{font-weight:900}
.stageMeta{font-size:12px; color:var(--muted)}
.dot{padding:0 6px}

.stage{
  border-radius: 22px;
  background: linear-gradient(135deg, #ffffffaa, #ffffff55);
  border:1px solid var(--line);
  padding:12px;
}

.canvasWrap{
  position:relative;
  width:100%;
  aspect-ratio: 16 / 10;
  border-radius: 18px;
  overflow:hidden;
  background:
    radial-gradient(800px 400px at 40% 10%, #fff 0%, #f4fbff 60%),
    radial-gradient(700px 500px at 70% 90%, #fff 0%, #fff7fb 65%),
    linear-gradient(180deg, #f8fbff, #fff);
  box-shadow: inset 0 0 0 1px #00000010;
}

/* IMPORTANT: ズレ防止（pointer用） */
.mainCanvas, .overlayCanvas, .pCanvas{
  display:block;
  width:100%;
  height:100%;
  touch-action:none; /* ←これが無いとスクロール/ズーム介入で座標が狂う */
  user-select:none;
}

.mainCanvas{
  position:absolute; inset:0;
}
.overlayCanvas{
  position:absolute; inset:0;
  pointer-events:none; /* プレビュー用。描くときはJSで切り替える */
}

/* パターン */
.patternGrid{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap:10px;
}
.pBox{
  border:1px solid var(--line);
  border-radius:16px;
  background:#fff;
  overflow:hidden;
}
.pHead{
  display:flex; align-items:center; justify-content:space-between;
  padding:8px 10px;
  border-bottom:1px solid var(--line);
  font-size:12px;
  color:var(--muted);
}
.pCanvas{
  width:100%;
  height:92px;
  background: linear-gradient(180deg, #fbfdff, #ffffff);
}

/* footer */
.footer{
  padding:12px 16px;
  color:var(--muted);
  font-size:12px;
  opacity:.9;
}

/* responsive */
@media (max-width: 980px){
  .layout{ grid-template-columns: 1fr; }
  .label{ width:88px; }
}

/* SP: メインが上 / オーバーレイが下（縦並び） */
@media (max-width: 700px){
  .canvasWrap{
    aspect-ratio: 4 / 5;
    padding:0;
    background: transparent;
    box-shadow:none;
    overflow:visible;
    border:none;
  }
  .mainCanvas, .overlayCanvas{
    position:relative;
    width:100%;
    height:auto;
    aspect-ratio: 4 / 5;
    border-radius: 18px;
    overflow:hidden;
    border:1px solid var(--line);
    background:
      radial-gradient(800px 400px at 40% 10%, #fff 0%, #f4fbff 60%),
      radial-gradient(700px 500px at 70% 90%, #fff 0%, #fff7fb 65%),
      linear-gradient(180deg, #f8fbff, #fff);
    margin-bottom:10px;
  }
  .overlayCanvas{
    background: linear-gradient(180deg, #ffffff, #f5fbff);
  }
}
