/*
  幅で切り替える（機種では分岐しない）。
  - 〜40rem: iPhone・iPhone Duo の外側画面。一列。
  - 40rem〜: iPhone Duo の内側画面（約 669px）・iPad 縦。本文を2段組み。
  - 60rem〜: iPad 横・Mac・PC。左に見出しと目次、右に本文の段組み。
  - Safari が画面の折り目を知らせたとき（viewport segments）は、折り目をまたがない配置にする。
*/

:root {
  color-scheme: light dark;
  --bg: #fbfbfa;
  --fg: #1d1d1f;
  --muted: #6e6e73;
  --line: #e2e2e0;
  --card: #ffffff;
  --accent: #0a66c2;
  --gap: 2.5rem;
  --section: 2.5rem;
  --pad-x: 1.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141415;
    --fg: #f2f2f2;
    --muted: #a1a1a6;
    --line: #2f2f32;
    --card: #1c1c1e;
    --accent: #6cb4ff;
  }
}

/* iPhone・iPad では iOS の「文字サイズ」設定に追従する（rem で指定した大きさがすべて連動する）。 */
@supports (font: -apple-system-body) and (-webkit-touch-callout: none) {
  html { font: -apple-system-body; }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.9;
  letter-spacing: 0.04em;
  -webkit-text-size-adjust: 100%;
  line-break: strict;
  overflow-wrap: anywhere;
}

a { color: var(--accent); }

p, ol, ul, dl { margin: 0 0 1em; }
ol, ul { padding-left: 1.5rem; }
li + li { margin-top: 0.5em; }

h1 { font-size: 1.5rem; line-height: 1.35; margin: 0; }
h2 { font-size: 1.1rem; line-height: 1.5; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; line-height: 1.5; margin: 1.5rem 0 0.5rem; color: var(--muted); }
dt { font-weight: 600; margin-bottom: 0.25em; }
dd { margin: 0 0 1.25em; }

/* 全体の枠。左右はノッチ・ホームバーのセーフエリアを避ける（viewport-fit=cover と対）。 */
.wrap {
  max-width: 82rem;
  margin: 0 auto;
  padding:
    max(1.25rem, env(safe-area-inset-top))
    max(var(--pad-x), env(safe-area-inset-right))
    max(2rem, env(safe-area-inset-bottom))
    max(var(--pad-x), env(safe-area-inset-left));
  display: grid;
  gap: 1.75rem var(--gap);
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "crumbs" "side" "main" "foot";
}

.crumbs { grid-area: crumbs; }
.side { grid-area: side; }
main { grid-area: main; min-width: 0; }
footer { grid-area: foot; color: var(--muted); font-size: 0.8rem; }

.crumbs ol {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  /* 指で押す環境ではリンクだけに上下の余白が付くので、文字の下端で揃える */
  align-items: baseline;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.crumbs li + li { margin: 0; }
.crumbs li + li::before { content: "›"; margin-right: 0.25rem; }
.crumbs a { color: inherit; }

/* アイコンと名前 */
.ident { display: flex; gap: 1rem; align-items: center; }
.ident p { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.9rem; line-height: 1.7; }
.kicker { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 600; }

.icon {
  width: 64px;
  height: 64px;
  border-radius: 22.5%;
  flex: none;
}

.lead { color: var(--muted); margin-top: 0.75rem; }
.links { margin: 0.5rem 0 0; font-size: 0.9rem; }
.catch { font-size: 1.35rem; font-weight: 700; line-height: 1.5; margin-bottom: 1rem; }

/* しないことの一覧: 幅があれば格子状に並べる */
.nots ul {
  list-style: none;
  padding: 0;
  display: grid;
  gap: 1rem var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  font-size: 0.95rem;
  line-height: 1.8;
}
.nots li { margin: 0; padding-left: 1.3em; text-indent: -1.3em; }
.nots li::before { content: "✓"; display: inline-block; width: 1.3em; text-indent: 0; color: var(--accent); font-weight: 700; }

/* 目次とサイドのリンクは広い画面だけ */
.toc, .side-links { display: none; }

/* 本文の節 */
.cols > * { padding-bottom: var(--section); }
.cols > .cont { margin-top: calc(1.5rem - var(--section)); }
.cont > h3:first-child { margin-top: 0; }
.cols > :last-child { padding-bottom: 0; }
.home section + section { margin-top: var(--section); }
.intro p:last-child, section > :last-child, .cont > :last-child, dd:last-child { margin-bottom: 0; }

/* 画面紹介: 画像は切り抜かず、縦長の2枚を左右に並べ、横長の1枚をその下に置く。 */
.screenshots { container-type: inline-size; }
.screenshot-grid { display: grid; grid-template-columns: minmax(0, 0.687fr) minmax(0, 0.703fr); gap: 1.75rem 1rem; align-items: start; }
.screenshot-wide { grid-column: 1 / -1; }
.screenshot-grid figure { margin: 0; min-width: 0; }
.shot { display: block; width: 100%; padding: 0; border: 0; background: none; border-radius: 0.75rem; cursor: zoom-in; }
.shot:focus-visible { outline: 3px solid var(--accent); outline-offset: 5px; }
.screenshot-grid img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
}
/* 幅に余裕があれば3枚を横一列に。列の幅を画像の縦横比（800×1164、1000×1422、1600×1126）に合わせて高さをそろえる。 */
@container (min-width: 44rem) {
  .screenshot-grid { grid-template-columns: minmax(0, 0.687fr) minmax(0, 0.703fr) minmax(0, 1.421fr); column-gap: 1.5rem; }
  .screenshot-wide { grid-column: auto; }
}
.screenshot-grid figcaption { margin-top: 0.75rem; color: var(--muted); font-size: 0.8rem; line-height: 1.7; }
.screenshot-grid strong { display: block; color: var(--fg); font-size: 0.9rem; margin-bottom: 0.2rem; }
.screenshots .screenshot-note { margin-top: 1.25rem; color: var(--muted); font-size: 0.8rem; }

/* 拡大表示: popover 属性で開閉する（JS なし）。
   画面全体を覆う閉じるボタン（.shot-dismiss）の中に画像を置くので、画像の上でも外でも、タップすると閉じる。
   タップがポップオーバーの中で止まるため、後ろにある別のサムネイルが押されて次の拡大表示が開くこともない。 */
.shot-preview {
  --edge: 1rem;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  /* overlay に対応していないブラウザでも、閉じる途中のタップを後ろのページに通さないよう前面に置く */
  z-index: 100;
  padding: 0;
  border: 0;
  background: none;
  overflow: visible;
  /* 閉じたあとの状態。開くときは @starting-style からこの値へ、閉じるときはこの値へ戻る */
  opacity: 0;
  scale: 0.96;
  /* display と overlay を allow-discrete で遅らせ、閉じるときも最後まで表示したまま動かす */
  transition:
    opacity 0.2s ease-out,
    scale 0.2s ease-out,
    display 0.2s allow-discrete,
    overlay 0.2s allow-discrete;
}
.shot-preview:popover-open { opacity: 1; scale: 1; }
@starting-style {
  .shot-preview:popover-open { opacity: 0; scale: 0.96; }
}
.shot-dismiss {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding:
    max(var(--edge), env(safe-area-inset-top))
    max(var(--edge), env(safe-area-inset-right))
    max(var(--edge), env(safe-area-inset-bottom))
    max(var(--edge), env(safe-area-inset-left));
  border: 0;
  background: none;
  cursor: zoom-out;
  -webkit-tap-highlight-color: transparent;
}
.shot-preview img {
  display: block;
  width: auto;
  height: auto;
  max-width: calc(100vw - 2 * var(--edge) - env(safe-area-inset-left) - env(safe-area-inset-right));
  max-height: calc(100dvh - 2 * var(--edge) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  border-radius: 0.75rem;
  /* 暗い画面の画像でも、暗い背景との境目が分かるように */
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.18);
}
.shot-preview::backdrop {
  background: rgb(0 0 0 / 0);
  transition:
    background-color 0.2s ease-out,
    display 0.2s allow-discrete,
    overlay 0.2s allow-discrete;
}
.shot-preview:popover-open::backdrop { background: rgb(0 0 0 / 0.85); }
@starting-style {
  .shot-preview:popover-open::backdrop { background: rgb(0 0 0 / 0); }
}
/* 動きを減らす設定では、拡大縮小をやめてフェードだけにする */
@media (prefers-reduced-motion: reduce) {
  .shot-preview,
  .shot-preview:popover-open { scale: none; }
}
.shot-close {
  position: absolute;
  top: max(0.75rem, env(safe-area-inset-top));
  right: max(0.75rem, env(safe-area-inset-right));
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.6);
  color: #fff;
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.shot-close:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
/* 開いている間は後ろのページをスクロールさせない */
html:has(.shot-preview:popover-open) { overflow: hidden; }
/* 閉じる途中の拡大表示はタップを受け止めない。続けてタップしたときに後ろのサムネイルが押されて
   次の拡大表示が開かないよう、開いている間と閉じてから 0.4 秒はサムネイルを押せなくする。 */
.shot { transition: pointer-events 0s 0.4s allow-discrete; }
html:has(.shot-preview:popover-open) .shot { pointer-events: none; transition: none; }

/* トップのアプリ一覧 */
.apps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
}
.apps li + li { margin: 0; }
.app {
  display: flex;
  gap: 0.875rem;
  align-items: center;
  padding: 1rem 1.125rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 1rem;
  text-decoration: none;
  color: inherit;
}
.app strong { display: block; margin-bottom: 0.2rem; }
.app span { color: var(--muted); font-size: 0.875rem; line-height: 1.7; }
.app .icon { width: 56px; height: 56px; }
.app .store { display: block; margin-top: 0.35rem; color: var(--accent); font-size: 0.8rem; }

/* App Store のバッジ。Apple の規定で画面上の高さは 40px 以上にする。 */
.store-badge { display: inline-block; vertical-align: top; }
.store-badge img { display: block; width: auto; height: 48px; }
.apps .store-badge { margin-top: 0.75rem; }
.intro .store-badge { margin-top: 1.25rem; }

/* マウスのある環境だけホバー表示 */
@media (hover: hover) {
  .app:hover { border-color: var(--muted); }
  .toc a:hover { color: var(--accent); }
}

/* 指で押す環境ではリンクを押しやすく */
@media (pointer: coarse) {
  .crumbs a, .toc a { display: inline-block; padding: 0.4rem 0; }
}

/* 中くらいの幅: 本文を2段組み */
@media (min-width: 40rem) {
  :root { --pad-x: 2rem; }
  main.cols { columns: 15rem 2; column-gap: var(--gap); }
  .cols > * { break-inside: avoid; }
  /* 段組みでは節を分割しない塊にする。Safari は段の境目の余白を次の段の先頭へ持ち越すため。
     長い節は小見出しごとの .cont に分けて、段の高さがそろうようにする。 */
  .cols > :not(.intro) { display: inline-block; width: 100%; vertical-align: top; }
  .cols > .cont { margin-top: 0; }
  .cols .intro { column-span: all; max-width: 48rem; }
  .cols .nots { column-span: all; display: block; }
  .cols .screenshots { column-span: all; display: block; }
  .icon { width: 72px; height: 72px; }
}

/* 広い幅: 左に見出しと目次を固定、右に本文 */
@media (min-width: 60rem) {
  .wrap {
    grid-template-columns: 15rem minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "crumbs crumbs" "side main" "foot main";
    column-gap: 3.5rem;
    padding-top: max(2rem, env(safe-area-inset-top));
  }
  .side { position: sticky; top: 2rem; align-self: start; }
  .ident { flex-direction: column; align-items: flex-start; }
  .icon { width: 88px; height: 88px; }
  .toc, .side-links { display: block; }
  .toc ul, .side-links {
    list-style: none;
    padding: 1rem 0 0;
    margin: 1.25rem 0 0;
    border-top: 1px solid var(--line);
    font-size: 0.9rem;
  }
  .toc li + li { margin-top: 0.35rem; }
  .toc a { color: var(--fg); text-decoration: none; }
  .side-links { line-height: 2.2; }
  /* 1段が狭くなりすぎないよう、段の最小幅を広めにとる（Mac の一般的な幅では2段） */
  main.cols { columns: 20rem 3; }
  .wrap:not(.home) footer { align-self: end; }
}

/* 文字の少ないトップは中央にまとめる */
.home { max-width: 44rem; grid-template-columns: minmax(0, 1fr); grid-template-areas: "side" "main" "foot"; }
.home main { display: block; }
@media (min-width: 60rem) {
  .home { padding-top: max(4rem, env(safe-area-inset-top)); }
}

/* 折り目のある画面で Safari が2つの領域を知らせたとき: 左に見出しと目次、右に本文（折り目をまたがない） */
@media (horizontal-viewport-segments: 2) {
  .wrap {
    max-width: none;
    padding-left: max(var(--pad-x), env(safe-area-inset-left));
    padding-right: max(var(--pad-x), env(safe-area-inset-right));
    grid-template-columns:
      calc(env(viewport-segment-width 0 0) - max(var(--pad-x), env(safe-area-inset-left)) - var(--pad-x))
      minmax(0, 1fr);
    column-gap: calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0) + 2 * var(--pad-x));
    grid-template-areas: "crumbs main" "side main" "foot main";
    align-content: start;
  }
  main.cols { columns: auto 1; }
  .toc, .side-links { display: block; }
  .toc ul, .side-links { list-style: none; padding: 0.75rem 0 0; margin: 0.75rem 0 0; border-top: 1px solid var(--line); }
}

@media print {
  :root { --bg: #fff; --fg: #000; --muted: #444; --accent: #000; }
  .wrap { display: block; max-width: none; padding: 0; }
  .toc, .side-links, .crumbs { display: none; }
  main.cols { columns: auto 1; }
  .cols > * { padding-bottom: 1.25rem; }
}
