:root {
  --bg: #0b0f1a;
  --bg-2: #111726;
  --panel: rgba(255, 255, 255, 0.035);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #eef2f9;
  --muted: #8a97ad;
  --accent: #4f8cff;
  --accent-2: #19d3c5;
  --a-color: #4f8cff;
  --b-color: #ffb020;
  --danger: #ff2d78;
  --radius: 16px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Hiragino Sans", "Segoe UI", system-ui, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  touch-action: manipulation; /* ダブルタップによる意図しないページ拡大を抑制 */
}

.bg-grid {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(79,140,255,0.18), transparent 60%),
    radial-gradient(800px 500px at 95% 0%, rgba(25,211,197,0.14), transparent 55%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
}
.bg-grid::after {
  content: ""; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at 50% 30%, black, transparent 75%);
}

/* ---------- header ---------- */
.app-header { text-align: center; padding: 34px 20px 12px; }
.brand { display: inline-flex; align-items: center; gap: 12px; }
.logo-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--danger), var(--accent));
  box-shadow: 0 0 18px rgba(79,140,255,0.6);
}
.app-header h1 {
  font-size: clamp(1.5rem, 3.4vw, 2.2rem); font-weight: 800; letter-spacing: -0.02em;
  background: linear-gradient(90deg, #fff, #b9cdff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--muted); margin-top: 6px; font-size: 0.95rem; }

.app { max-width: 1180px; margin: 0 auto; padding: 16px 20px 40px; }

/* ---------- uploads ---------- */
.uploads {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: center;
}
.drop-card {
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--radius); padding: 10px;
}
.drop-inner {
  position: relative; border: 2px dashed rgba(255,255,255,0.14);
  border-radius: 12px; min-height: 200px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden; transition: border-color .2s, background .2s;
}
.drop-inner:hover { border-color: rgba(79,140,255,0.5); background: rgba(79,140,255,0.05); }
.drop-inner.dragover { border-color: var(--accent-2); background: rgba(25,211,197,0.08); }
.drop-inner.has-img { border-style: solid; border-color: rgba(255,255,255,0.1); }
.thumb-wrap { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: #0008; }
.thumb-wrap img { max-width: 100%; max-height: 320px; object-fit: contain; }
.has-img .thumb-wrap { display: flex; }
.has-img .drop-prompt { opacity: 0; }
.drop-prompt { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 16px; transition: opacity .2s; }
.drop-prompt strong { font-size: 1.05rem; }
.drop-prompt .hint { color: var(--muted); font-size: 0.82rem; }
.badge { font-weight: 800; font-size: 0.85rem; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #0a0e17; }
.badge-a { background: var(--a-color); }
.badge-b { background: var(--b-color); }
.clear-btn {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  width: 30px; height: 30px; border-radius: 50%; border: none;
  background: rgba(0,0,0,0.6); color: #fff; font-size: 1.1rem; cursor: pointer; line-height: 1;
}
.clear-btn:hover { background: var(--danger); }
.meta { color: var(--muted); font-size: 0.78rem; text-align: center; min-height: 18px; margin-top: 8px; }
.swap-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--panel-border);
  background: var(--panel); color: var(--text); font-size: 1.3rem; cursor: pointer; transition: .2s;
}
.swap-btn:hover { background: var(--accent); color: #0a0e17; transform: rotate(180deg); }

/* ---------- workspace ---------- */
.workspace {
  margin-top: 24px;
  display: grid; grid-template-columns: 1fr 300px; grid-template-rows: auto 1fr;
  grid-template-areas: "tabs tabs" "stage panel";
  gap: 16px;
}
.mode-tabs { grid-area: tabs; display: flex; gap: 6px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--panel-border); padding: 6px; border-radius: 12px; }
.tab {
  flex: 1; min-width: 110px; padding: 10px 12px; border: none; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: .15s;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.tab.active { background: linear-gradient(135deg, var(--accent), #2f6fe0); color: #fff; box-shadow: 0 4px 14px rgba(79,140,255,0.35); }

.stage-wrap { grid-area: stage; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.stats { display: flex; gap: 10px; }
.stat {
  flex: 1; background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 12px; padding: 10px 14px; text-align: center;
}
.stat-val { display: block; font-size: 1.3rem; font-weight: 800; color: var(--accent-2); }
.stat-label { font-size: 0.72rem; color: var(--muted); }

.stage {
  position: relative; background:
    repeating-conic-gradient(#1a2336 0% 25%, #141b2b 0% 50%) 0 0 / 24px 24px;
  border: 1px solid var(--panel-border); border-radius: var(--radius);
  overflow: hidden;
  /* 縦長画像にも優しい、正方形に近い表示エリア（上下の領域を確保） */
  width: 100%; aspect-ratio: 1 / 1; min-height: 480px; max-height: 80vh;
  cursor: grab;
  touch-action: none; /* 自前でパン/ピンチを扱うためブラウザのスクロール/ズームを抑制 */
}
.stage.panning { cursor: grabbing; }
.canvas-pan { position: absolute; left: 50%; top: 50%; transform-origin: center center; will-change: transform; }
.view-side { display: flex; gap: 10px; }
.side-col { position: relative; }
.side-col canvas { display: block; box-shadow: var(--shadow); border-radius: 6px; }
.side-tag {
  position: absolute; top: 8px; left: 8px; background: #000a; color: #fff;
  font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 6px;
}
.view-single { position: relative; }
.view-single canvas { display: block; box-shadow: var(--shadow); border-radius: 6px; }
.swipe-handle { position: absolute; top: 0; bottom: 0; width: 48px; transform: translateX(-50%); cursor: ew-resize; z-index: 5; touch-action: none; }
.swipe-line { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 8px #000; }
.swipe-grip {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 38px; height: 38px; border-radius: 50%; background: #fff; color: #0a0e17;
  display: grid; place-items: center; font-size: 1rem; box-shadow: 0 2px 10px #000a;
}
.zoom-readout {
  position: absolute; bottom: 10px; right: 12px; background: #000a; color: #fff;
  font-size: 0.75rem; padding: 3px 9px; border-radius: 20px; pointer-events: none;
}

.stage-toolbar { display: flex; align-items: center; gap: 6px; }
.mini {
  min-width: 38px; height: 38px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--panel-border); background: var(--panel); color: var(--text);
  font-size: 1rem; cursor: pointer; transition: .15s;
}
.mini:hover { background: rgba(255,255,255,0.08); border-color: var(--accent); }
.stage-toolbar .sep { flex: 1; }
#downloadBtn { background: linear-gradient(135deg, var(--accent-2), #11a89c); color: #042; border: none; font-weight: 700; }

/* ---------- アイコン（絵文字の代替・SVG） ---------- */
svg.icon {
  width: 18px; height: 18px; flex: none; display: block;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
svg.icon.fill { fill: currentColor; stroke: none; }
.mini, .swap-btn, .clear-btn { display: inline-flex; align-items: center; justify-content: center; }
.btn-ghost, #downloadBtn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }

/* ---------- panel ---------- */
.panel { grid-area: panel; display: flex; flex-direction: column; gap: 14px; }
.panel-group {
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 14px; padding: 14px;
}
.panel-title { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent-2); margin-bottom: 12px; }
.ctl { display: block; margin-bottom: 14px; }
.ctl:last-child { margin-bottom: 0; }
.ctl > span { display: flex; justify-content: space-between; font-size: 0.86rem; margin-bottom: 7px; color: var(--text); }
.ctl > span b { color: var(--accent); font-variant-numeric: tabular-nums; }
.ctl-note { display: block; color: var(--muted); font-size: 0.72rem; margin-top: 4px; }
.ctl-check { display: flex; align-items: center; gap: 8px; font-size: 0.86rem; cursor: pointer; margin-bottom: 12px; }
.ctl-check input { width: 16px; height: 16px; accent-color: var(--accent); }
.ctl-check.inline { margin-bottom: 0; }
.color-row { display: flex; align-items: center; gap: 12px; }
.color-row input[type=color] { width: 44px; height: 32px; border: none; border-radius: 8px; background: none; cursor: pointer; }
.align-grid { display: flex; flex-direction: column; gap: 12px; }
.align-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.align-actions .btn-ghost { width: 100%; }
#alignNote { margin-top: 14px; line-height: 1.55; }
.btn-ghost {
  flex: 1; padding: 9px; border-radius: 9px; border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.03); color: var(--text); font-size: 0.84rem; cursor: pointer; transition: .15s;
}
.btn-ghost:hover { background: rgba(79,140,255,0.12); border-color: var(--accent); }

/* range */
input[type=range] { width: 100%; -webkit-appearance: none; appearance: none; height: 5px; border-radius: 5px;
  background: rgba(255,255,255,0.12); outline: none; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 17px; height: 17px; border-radius: 50%;
  background: var(--accent); cursor: pointer; box-shadow: 0 0 0 4px rgba(79,140,255,0.2); transition: .1s; }
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.15); }

/* ---------- SEO / 説明コンテンツ ---------- */
.info { margin-top: 56px; padding-top: 36px; border-top: 1px solid var(--panel-border); }
.info-title {
  font-size: clamp(1.25rem, 2.6vw, 1.7rem); font-weight: 800; text-align: center;
  margin: 40px 0 22px; letter-spacing: -0.01em;
}
.info-title:first-child { margin-top: 0; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.step {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px;
  padding: 22px 20px; position: relative;
}
.step-no {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #2f6fe0); color: #fff; font-weight: 800;
  margin-bottom: 12px; box-shadow: 0 4px 14px rgba(79,140,255,0.35);
}
.step h3 { font-size: 1.05rem; margin-bottom: 8px; }
.step p { color: var(--muted); font-size: 0.88rem; }

.feature-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.feature-card {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px; padding: 20px 22px;
  transition: border-color .2s, transform .2s;
}
.feature-card:hover { border-color: rgba(79,140,255,0.4); transform: translateY(-2px); }
.feature-card h3 { font-size: 1.05rem; margin-bottom: 8px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.feature-card h3::before {
  content: ""; flex: none; width: 15px; height: 15px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2319d3c5' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 6l6 6-6 6'/%3E%3C/svg%3E") center / contain no-repeat;
}
.feature-card p { color: var(--muted); font-size: 0.88rem; }
.feature-card strong { color: var(--text); font-weight: 700; }

.scene-list {
  max-width: 760px; margin: 0 auto; list-style: none;
  display: grid; gap: 10px;
}
.scene-list li {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 12px 16px 12px 40px; position: relative; color: var(--muted); font-size: 0.9rem;
}
.scene-list li::before {
  content: ""; position: absolute; left: 16px; top: 15px; width: 15px; height: 15px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2319d3c5' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 13l4 4 10-12'/%3E%3C/svg%3E") center / contain no-repeat;
}

.faq-list { max-width: 900px; margin: 0 auto; display: grid; gap: 12px; }
.faq-item {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px;
  padding: 18px 20px;
}
.faq-item h3 { font-size: 0.98rem; margin-bottom: 8px; color: var(--text); }
.faq-item p { color: var(--muted); font-size: 0.88rem; line-height: 1.8; }

.related-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.related-card {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px; padding: 18px;
  text-decoration: none; color: var(--text); transition: border-color .2s, transform .2s;
}
.related-card:hover { border-color: rgba(25,211,197,0.5); transform: translateY(-2px); }
.related-card h3 { font-size: 0.98rem; margin-bottom: 6px; }
.related-card p { color: var(--muted); font-size: 0.82rem; }

/* 旧版との比較 */
.compare-lead, .compare-note { max-width: 820px; margin: 0 auto 16px; text-align: center; color: var(--muted); font-size: 0.9rem; }
.compare-note { margin-top: 16px; }
.compare-lead a, .compare-note a { color: var(--accent); text-decoration: none; font-weight: 600; }
.compare-lead a:hover, .compare-note a:hover { text-decoration: underline; }
.compare-wrap { max-width: 900px; margin: 0 auto; overflow-x: auto; border-radius: 14px; border: 1px solid var(--panel-border); }
.compare-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; min-width: 560px; }
.compare-table th, .compare-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--panel-border); vertical-align: top; }
.compare-table thead th { background: rgba(255,255,255,0.04); font-weight: 700; color: var(--text); }
.compare-table thead th:last-child { color: var(--accent-2); }
.compare-table tbody td:first-child { color: var(--text); font-weight: 600; white-space: nowrap; }
.compare-table tbody td { color: var(--muted); }
.compare-table tbody tr:last-child td { border-bottom: none; }
.compare-table tbody td:last-child { background: rgba(79,140,255,0.05); }
.compare-table strong { color: var(--text); }

/* ---------- footer ---------- */
.footer {
  text-align: center; color: var(--muted); font-size: 0.84rem; line-height: 2;
  padding: 30px 20px 40px; margin-top: 40px; border-top: 1px solid var(--panel-border);
}
.footer p { margin: 2px 0; }
.footer-privacy { color: var(--text); font-size: 0.82rem; margin-bottom: 10px !important; }
.footer-links { margin-top: 8px !important; }
.footer a { color: #9fb2cf; text-decoration: none; transition: color .2s; }
.footer a:hover { color: #fff; text-decoration: underline; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1c2740; border: 1px solid var(--panel-border); color: var(--text);
  padding: 11px 20px; border-radius: 12px; font-size: 0.88rem; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: .25s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* スマホ用 保存モーダル */
.save-modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px; }
.save-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.78); backdrop-filter: blur(2px); }
.save-modal-body {
  position: relative; z-index: 1; width: 100%; max-width: 460px;
  background: var(--bg-2); border: 1px solid var(--panel-border); border-radius: 16px;
  padding: 18px; text-align: center; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto;
}
.save-modal-close {
  position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 50%;
  border: none; background: rgba(255,255,255,0.08); color: var(--text); font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.save-modal-close:hover { background: var(--danger); }
.save-modal-hint { color: var(--text); font-size: 0.92rem; margin: 6px 0 14px; line-height: 1.5; }
.save-modal-imgwrap {
  background: repeating-conic-gradient(#1a2336 0% 25%, #141b2b 0% 50%) 0 0 / 18px 18px;
  border-radius: 10px; padding: 8px; margin-bottom: 14px;
}
.save-modal-imgwrap img { display: block; max-width: 100%; max-height: 60vh; margin: 0 auto; border-radius: 6px; }
.save-modal-dl {
  display: inline-block; padding: 11px 22px; border-radius: 10px; text-decoration: none; font-weight: 700;
  background: linear-gradient(135deg, var(--accent-2), #11a89c); color: #042;
}
.save-modal-dl:hover { filter: brightness(1.08); }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; grid-template-areas: "tabs" "stage" "panel"; }
  .uploads { grid-template-columns: 1fr; }
  .swap-btn { justify-self: center; transform: rotate(90deg); }
  .swap-btn:hover { transform: rotate(270deg); }
  .align-actions { flex-direction: row; }
  /* スマホは「並べて」を縦積みにして各画像を大きく表示 */
  .view-side { flex-direction: column; }
  .steps { grid-template-columns: 1fr; }
  .feature-grid { grid-template-columns: 1fr; }
  .related-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .align-actions { flex-direction: column; }
  .related-grid { grid-template-columns: 1fr; }
  .stat { padding: 8px 6px; }
  .stat-val { font-size: 1.05rem; }
  .stat-label { font-size: 0.66rem; white-space: nowrap; }
  .mode-tabs { gap: 4px; }
  .tab { min-width: 0; flex-basis: calc(50% - 4px); padding: 9px 6px; font-size: 0.82rem; }
}
