:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #3b82f6;
  --accent-weak: #eff6ff;
  --radius: 12px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Noto Sans JP", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
}

/* ===== ヘッダー ===== */
header {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  color: #fff;
  padding: 24px 24px 22px;
}
.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  position: relative;
}
header h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
header h1 .accent {
  color: #93c5fd;
}
header p {
  margin: 0;
  color: #cbd5e1;
  font-size: 1.05rem;
  max-width: 760px;
}
.lang-switch {
  position: absolute;
  top: 0;
  right: 0;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 0.95rem;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 6px 14px;
  border-radius: 999px;
  transition: all 0.2s;
}
.lang-switch:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* ===== レイアウト ===== */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 8px;
}
.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
  align-items: start;
}

/* ===== プレビュー ===== */
.stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.preview-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 480px;
  margin: 0 auto;
  /* チェッカー背景で切り抜き範囲を可視化 */
  background-image:
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  border-radius: 8px;
}
.clip-box {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 60%, #ec4899 100%);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.clip-box.show-image {
  background-image: var(--clip-image);
}

/* ドラッグ用ハンドル層 */
.handles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.handle {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  transition: transform 0.1s;
}
.handle:hover,
.handle.active {
  transform: scale(1.25);
}
.handle:active {
  cursor: grabbing;
}
.drag-hint {
  margin: 16px 0 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}

/* プレビュー操作バー */
.preview-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.mini-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.mini-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.mini-btn.active {
  background: var(--accent-weak);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== コントロールパネル ===== */
.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 12px;
}
.type-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.type-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.type-btn:hover {
  border-color: var(--accent);
}
.type-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.shape-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.shape-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  padding: 8px 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.shape-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.shape-btn.active {
  background: var(--accent-weak);
  border-color: var(--accent);
  color: var(--accent);
}

.slider-row {
  display: block;
  margin-bottom: 14px;
}
.slider-row:last-child {
  margin-bottom: 0;
}
.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.slider-label em {
  font-style: normal;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  cursor: pointer;
}
.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}
.hint-text {
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

/* ===== 出力 ===== */
.output-section {
  margin-top: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.output-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
}
.output-head h2 {
  margin: 0;
  font-size: 1.15rem;
}
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  font: inherit;
  font-size: 0.95rem;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}
.copy-btn:hover {
  background: #2563eb;
}
.copy-btn.copied {
  background: #16a34a;
}
.output-section textarea,
.code-block {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.6;
  color: #e2e8f0;
  background: #0f172a;
  border: none;
  border-radius: 8px;
  padding: 16px;
}
/* 出力欄はアニメーション出力（11行）も全部見えるよう高めに */
.output-section textarea {
  min-height: 300px;
}
/* プリセットページのコード表示（<pre>） */
pre.code-block {
  margin: 0;
  min-height: 0;
  white-space: pre;
  overflow-x: auto;
}

/* プリセットページのプレビュー枠 */
.demo-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  background-image:
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin: 8px 0 18px;
  min-height: 220px;
}
.demo-fig {
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 60%, #ec4899 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 18px 0 8px;
  gap: 12px;
}
.code-head h3 {
  margin: 0;
  font-size: 1.05rem;
}
.output-note {
  margin: 12px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}
.output-note code {
  font-family: var(--mono);
  background: var(--accent-weak);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ===== 記事・解説 ===== */
.article {
  max-width: 820px;
  margin: 48px auto 0;
  padding: 0 24px;
}
.article h2 {
  font-size: 1.4rem;
  letter-spacing: -0.01em;
  margin: 40px 0 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.article h3 {
  font-size: 1.15rem;
  margin: 28px 0 10px;
}
.article p {
  margin: 0 0 14px;
}
.article ul,
.article ol {
  margin: 0 0 16px;
  padding-left: 1.4em;
}
.article li {
  margin-bottom: 6px;
}
.article code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
}
.answer-box {
  background: var(--accent-weak);
  border: 1px solid #bfdbfe;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 8px;
}
.answer-box p {
  margin: 0;
}
.compare-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 16px;
  font-size: 0.95rem;
}
.compare-table th,
.compare-table td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
}
.compare-table thead th {
  background: #f1f5f9;
}
.faq-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 12px;
  background: var(--surface);
}
.faq-item h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}
.faq-item p {
  margin: 0;
  color: #334155;
}

/* 関連ツール */
.related {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 12px 0 8px;
}
.related a {
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  transition: all 0.2s;
}
.related a:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.12);
}
.related a strong {
  display: block;
  color: var(--accent);
  margin-bottom: 4px;
}
.related a span {
  font-size: 0.9rem;
  color: var(--muted);
}

/* ===== フッター ===== */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 40px;
  color: #64748b;
  font-size: 1rem;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  margin-top: 48px;
}
footer a {
  color: #1e293b;
  text-decoration: none;
  transition: color 0.2s;
}
footer a:hover {
  color: #3b82f6;
}
.footer-links {
  display: flex;
  gap: 16px;
}
.footer-links a {
  border: 1px solid #e2e8f0;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 1rem;
  transition: all 0.2s;
}
.footer-links a:hover {
  border-color: #3b82f6;
  color: #3b82f6;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .panel {
    order: 2;
  }
}
@media (max-width: 768px) {
  header {
    padding: 18px 20px 16px;
  }
  header h1 {
    font-size: 1.5rem;
  }
  .lang-switch {
    position: static;
    display: inline-block;
    margin-bottom: 16px;
  }
  footer {
    flex-direction: column;
    gap: 16px;
    padding: 24px 16px;
    text-align: center;
  }
  .footer-links {
    flex-wrap: wrap;
    justify-content: center;
  }
}
