/* ---------- Tokens ---------- */
:root {
  --font-display: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Noto Sans JP', sans-serif;
  --font-body: 'Noto Sans JP', 'Hiragino Sans', 'Yu Gothic', sans-serif;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: clamp(1.25rem, 1.1rem + 0.8vw, 1.5rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;

  --color-bg: oklch(0.975 0.008 230);
  --color-surface: oklch(1 0 0);
  --color-surface-2: oklch(0.965 0.01 230);
  --color-border: oklch(0.9 0.012 230);
  --color-text: oklch(0.25 0.02 240);
  --color-text-muted: oklch(0.5 0.02 240);
  --color-text-faint: oklch(0.65 0.015 240);
  --color-accent: oklch(0.62 0.15 232);
  --color-accent-strong: oklch(0.54 0.15 235);
  --color-accent-soft: oklch(0.94 0.04 232);
  --color-warn-bg: oklch(0.96 0.05 80);
  --color-warn-text: oklch(0.45 0.1 60);
  --color-error-bg: oklch(0.95 0.04 20);
  --color-error-text: oklch(0.45 0.15 20);
  --color-ok-bg: oklch(0.95 0.05 160);
  --color-ok-text: oklch(0.4 0.1 160);

  --radius-md: 0.625rem;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;
  --shadow-sm: 0 1px 2px oklch(0.3 0.03 240 / 0.06);
  --shadow-md: 0 6px 20px oklch(0.3 0.03 240 / 0.08);
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* IRIAM layout constants (relative to header width 1125) */
  --icon-d: 40%;                 /* 450 / 1125 */
  --ring-d: 42.1333%;            /* 474 / 1125 (幅) */
  --ring-h: 98.75%;              /* 474 / 480  (高さ) */
  --ring-pad: 1.06667%;          /* 12 / 1125  */
  --icon-cy: 65.5208%;           /* 314.5 / 480 */
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, p, ul { margin: 0; }
button { font: inherit; color: inherit; }
a { color: var(--color-accent-strong); }
canvas { display: block; }

/* ---------- Header ---------- */
.site-header {
  padding: calc(env(safe-area-inset-top) + var(--space-6)) var(--space-5) var(--space-4);
  max-width: 640px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: var(--space-3); color: var(--color-accent-strong); }
.logo { flex: none; }
.brand-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: 1.25;
  color: var(--color-text);
  word-break: keep-all; /* 「メーカー」の途中で折り返さない（IRIAM の後の空白で折り返す） */
}
.brand-sub { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; }

/* ---------- Layout ---------- */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 var(--space-4) var(--space-10);
  display: grid;
  gap: var(--space-4);
}
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.card-muted { background: var(--color-surface-2); box-shadow: none; }
.card-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.card-title-sub { font-family: var(--font-body); font-size: var(--text-xs); font-weight: 500; color: var(--color-text-muted); margin-left: var(--space-1); }
.step-num {
  display: inline-grid; place-items: center;
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: var(--color-accent); color: #fff;
  font-size: var(--text-sm); font-weight: 700;
}

/* ---------- Dropzone ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-1);
  min-height: 120px;
  padding: var(--space-5);
  border: 2px dashed var(--color-accent);
  border-radius: var(--radius-lg);
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
  cursor: pointer;
  text-align: center;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.dropzone:hover, .dropzone:focus-visible { background: oklch(0.92 0.05 232); outline: none; }
.dropzone.is-over { border-style: solid; transform: scale(1.01); }
.dropzone-main { font-weight: 700; font-size: var(--text-base); }
.dropzone-sub { font-size: var(--text-xs); color: var(--color-text-muted); }
.file-meta { margin-top: var(--space-3); font-size: var(--text-sm); color: var(--color-text-muted); }

.notice {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.notice-warn { background: var(--color-warn-bg); color: var(--color-warn-text); }
.notice-error { background: var(--color-error-bg); color: var(--color-error-text); }
.notice-ok { background: var(--color-ok-bg); color: var(--color-ok-text); }

/* ---------- Phone mock / preview ---------- */
.phone {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-md);
}
.phone-bar {
  height: 44px;
  display: grid; place-items: center;
  font-size: var(--text-sm); font-weight: 700; color: #333;
  background: #fff;
}
.header-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1125 / 480;
  background: #e9eef3;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.header-stage.is-draggable { cursor: grab; }
.header-stage.is-dragging { cursor: grabbing; }
.header-canvas { width: 100%; height: 100%; }
.header-placeholder {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: var(--text-sm); color: var(--color-text-faint);
  background: repeating-linear-gradient(135deg, #e6ecf2 0 12px, #edf2f7 12px 24px);
}
.header-placeholder[hidden] { display: none; }

.icon-ring {
  /* 白縁(12px)を含む外枠。iOS Safari 26.3 以前は position:absolute + aspect-ratio + padding/border で
     高さを誤計算する（WebKit 272527 / Safari 26.4 で修正）。そのため aspect-ratio と padding を使わず、
     幅・高さともステージに対する % で指定する（ステージは 1125:480 固定なので高さ % = 474/480） */
  position: absolute;
  left: 50%;
  top: var(--icon-cy);
  width: var(--ring-d);
  height: var(--ring-h);
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 50%;
  z-index: 2;
  pointer-events: none;
}
.icon-canvas {
  /* 白縁ぶん内側に配置：12/474 = 2.53165%、450/474 = 94.9367% */
  position: absolute; left: 2.53165%; top: 2.53165%; width: 94.9367%; height: 94.9367%;
  border-radius: 50%; background: #fff;
}

.drag-hint {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  padding: 2px 10px; border-radius: 999px;
  background: oklch(0.2 0.02 240 / 0.6); color: #fff; font-size: var(--text-xs);
  z-index: 3; pointer-events: none;
}
.drag-hint[hidden] { display: none; }

.phone-body { padding: calc(var(--ring-d) * 0.16 + 12px) var(--space-4) var(--space-5); text-align: center; }
.phone-name { font-weight: 700; font-size: var(--text-base); color: #222; }
.phone-stats { font-size: var(--text-xs); color: #777; margin-top: 2px; }
.phone-stats strong { color: #333; font-weight: 700; margin-right: 2px; }

.adjust-row {
  margin-top: var(--space-4);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-accent-soft);
  border-radius: var(--radius-md);
}
.adjust-row[hidden] { display: none; }
.adjust-text { font-size: var(--text-sm); color: var(--color-text); flex: 1 1 100%; }
.adjust-controls { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex: 1 1 100%; }
.zoom-label { font-size: var(--text-sm); color: var(--color-text-muted); }
.zoom-label strong { color: var(--color-text); font-variant-numeric: tabular-nums; }

.below-row {
  margin-top: var(--space-3);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.below-row[hidden] { display: none; }
.below-label { font-size: var(--text-sm); font-weight: 700; color: var(--color-text); }
.seg { display: inline-flex; border: 1px solid var(--color-border); border-radius: 999px; padding: 2px; background: #fff; }
.seg-btn {
  min-height: 36px; padding: 0 var(--space-4); border: 0; border-radius: 999px; background: transparent;
  font-size: var(--text-sm); font-weight: 700; color: var(--color-text-muted); cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.seg-btn.is-active { background: var(--color-accent); color: #fff; }
.seg-btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.below-note { flex: 1 1 100%; font-size: var(--text-xs); color: var(--color-text-muted); }
.below-note[hidden] { display: none; }

.hints {
  margin-top: var(--space-4);
  padding-left: 1.2em;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  display: grid; gap: var(--space-1);
}

/* ---------- How to / example (collapsible) ---------- */
.howto { padding: 0; overflow: hidden; }
.howto-summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm); font-weight: 700; color: var(--color-accent-strong);
}
.howto-summary::-webkit-details-marker { display: none; }
.howto-summary:hover { background: var(--color-accent-soft); }
.howto-summary:focus-visible { outline: 2px solid var(--color-accent); outline-offset: -2px; }
.howto-chevron { width: 10px; height: 10px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform var(--transition); margin-right: 4px; }
.howto[open] .howto-chevron { transform: rotate(-135deg); }
.howto-body { padding: 0 var(--space-4) var(--space-4); display: grid; gap: var(--space-3); }
.howto-steps { margin: 0; padding-left: 1.4em; font-size: var(--text-sm); color: var(--color-text); display: grid; gap: 2px; }
.howto-fig { margin: 0; }
.howto-fig img { display: block; width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--color-border); background: #fff; }
.howto-fig figcaption { margin-top: 4px; font-size: var(--text-xs); color: var(--color-text-muted); line-height: 1.4; }
.howto-fig figcaption strong { color: var(--color-text); }
.howto-fig-wide img { max-width: 420px; margin-inline: auto; }
.howto-fig-wide figcaption { text-align: center; }
.howto-lead { font-size: var(--text-sm); color: var(--color-text); }
.howto-lead strong { color: var(--color-accent-strong); }
.cmp-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-3); }
.cmp-img { position: relative; }
/* 拡大画像内の位置（%）：ヘッダー下端 76.5%、アイコン下端 86.7%、円の左右 13.8%〜86.2% */
.cmp-mark {
  position: absolute; left: 10%; width: 80%; top: 74.5%; height: 14.5%;
  border: 2px dashed; border-radius: 0 0 40px 40px / 0 0 28px 28px; pointer-events: none;
}
.cmp-mark.is-white { border-color: oklch(0.6 0.19 25); }
.cmp-mark.is-image { border-color: oklch(0.55 0.17 250); }
.cmp-tag {
  position: absolute; left: 50%; top: 90%; transform: translateX(-50%);
  padding: 1px 8px; border-radius: 999px; font-size: var(--text-xs); font-weight: 700; color: #fff; white-space: nowrap; line-height: 1.5;
}
.cmp-tag.is-white { background: oklch(0.6 0.19 25); }
.cmp-tag.is-image { background: oklch(0.55 0.17 250); }
.howto-credit { font-size: var(--text-xs); color: var(--color-text-muted); display: flex; flex-wrap: wrap; gap: 2px var(--space-4); }
.howto-credit span { white-space: nowrap; }
.howto-credit a { color: var(--color-accent-strong); text-decoration: none; }
.howto-credit a:hover { text-decoration: underline; }

/* ---------- Buttons ---------- */
.btn-stack { display: grid; gap: var(--space-3); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 52px;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:hover { background: var(--color-accent-strong); }
.btn-primary:disabled { background: var(--color-border); color: var(--color-text-faint); cursor: not-allowed; }
.btn-meta { font-size: var(--text-xs); font-weight: 500; opacity: 0.9; }
.btn-ghost { background: #fff; border-color: var(--color-border); min-height: 40px; font-size: var(--text-sm); color: var(--color-accent-strong); }
.btn-ghost:hover { background: var(--color-accent-soft); }
.save-note { margin-top: var(--space-3); font-size: var(--text-sm); color: var(--color-text-muted); }

/* ---------- Reference ---------- */
.ref-wrap { display: grid; place-items: center; }
.ref-canvas {
  width: min(240px, 60%);
  height: auto;
  border: 1px solid var(--color-border);
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.ref-note { margin-top: var(--space-3); font-size: var(--text-xs); color: var(--color-text-muted); text-align: center; }

details summary { cursor: pointer; font-weight: 700; font-size: var(--text-sm); }
details .hints { margin-top: var(--space-3); }

.site-footer {
  max-width: 640px; margin: 0 auto;
  padding: 0 var(--space-5) calc(env(safe-area-inset-bottom) + var(--space-8));
  font-size: var(--text-xs); color: var(--color-text-faint); text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
