/* ============================================================
   reset.css — ブラウザ差の吸収と視認性の下限

   【このファイルの役割】AI も人も触らない（check.py が雛形との違いを検出する）
     前半  Reset  ブラウザごとの初期表示の違いをそろえる
     後半  Base   視認性の下限（誰が見ても読める・操作できる状態）
   色・サイズ・角丸などデザインの判断は持たない。デザインは DESIGN.md → style.css で決まる。
   Base が使う変数（--color-* 等）は style.css「1. Tokens」が定義する。

   【書き方の約束】
   - 全セレクタを :where() で包み、詳細度 0 にする。style.css はクラス 1 つで必ずこのファイルに勝つ
   - !important は [hidden] / 閉じた dialog・popover / .visually-hidden だけ
     （どんな指定より強くないと機能しないため。check.py の検査対象外）

   【対象ブラウザ】Chrome / Edge / Safari / iOS Safari の直近2メジャー + Firefox 最新
   新しいプロパティは、対応していないブラウザでは無視されるだけで表示は崩れない。
============================================================ */

/* 重なり順の宣言（最初に読み込まれるこのファイルで決める）
   reset < library（library/ から足す CSS）< page（style.css） */
@layer reset, library, page;

@layer reset {

/* ============================================================
   Reset — 箱と文書
============================================================ */

  /* 幅・高さに枠線と内側の余白を含める（レイアウトの計算を単純にする） */
  *,
  ::before,
  ::after {
    box-sizing: border-box;
  }

  :where(html) {
    /* 書体未指定のときに明朝体で表示されるブラウザがあるため */
    font-family: sans-serif;

    /* 行間 1.5 以上（WCAG 1.4.12） */
    line-height: 1.5;

    /* 横向き表示で文字が勝手に拡大されないように */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;

    /* 長い英単語・URL がはみ出さないように折り返す
       （anywhere は flex / grid の列を縮めすぎるため break-word） */
    overflow-wrap: break-word;

    /* --- 日本語組版（継承する。クラス 1 つで解除できる） ----- */
    line-break: strict;              /* 小書き仮名・長音などを行頭に置かない */
    text-spacing-trim: trim-start;   /* 行頭の括弧の空きを詰める（Chrome / Edge 123+） */
    text-autospace: normal;          /* 和文と英数字の間に小さな空き（Firefox 145+ / Safari 27+） */

    /* スクロールバーの出入りで横幅が揺れないように（溝の色は Base の背景色） */
    scrollbar-gutter: stable;

    /* タップ時の灰色の四角を消す（押下表現は style.css「Touch feedback」） */
    -webkit-tap-highlight-color: transparent;
  }

  /* height: auto への変化をアニメーションできるようにする（Chrome / Edge。他は無視） */
  @media (prefers-reduced-motion: no-preference) {
    :where(html) {
      interpolate-size: allow-keywords;
    }

    /* ページ内リンクをなめらかにスクロールする。動きを減らす設定では瞬時に移動 */
    :where(html:focus-within) {
      scroll-behavior: smooth;
    }
  }

  :where(body) {
    margin: 0;
    /* モバイルのアドレスバーが出ている状態の高さ（伸縮のたびに再計算しない svb） */
    min-block-size: 100svb;
  }

  /* 固定ヘッダーの裏にジャンプ先が隠れないように（値は Base で上書き） */
  :where(:target) {
    scroll-margin-block-start: 5rem;
  }


/* ============================================================
   Reset — 余白・見出し・リスト
   余白はすべて style.css で明示する前提なので、ブラウザ既定の余白を消す
============================================================ */

  :where(h1, h2, h3, h4, h5, h6, p, blockquote, figure, pre, address, dl, dd, ul, ol, menu) {
    margin: 0;
  }

  /* section の中の h1 が小さくなるブラウザの挙動をそろえる */
  :where(h1) {
    font-size: 2em;
  }

  :where(ul, ol, menu) {
    padding-inline-start: 0;
    /* list-style: none にすると Safari の読み上げがリストとして扱わない */
    list-style-type: "";
  }

  :where(dt) {
    font-weight: bolder;
  }

  /* 英文だけ、最終行が1語だけになるのを防ぐ（日本語は SP で不自然な改行になるため対象外） */
  :where(:is(h1, h2, h3, h4, h5, h6, p, figcaption):lang(en)) {
    text-wrap: pretty;
  }

  /* 区切り線。色は文字色に合わせる（Base で調整） */
  :where(hr) {
    block-size: 0;
    margin: 0;
    border: 0;
    border-block-start: 1px solid;
    color: inherit;
    overflow: visible;
  }

  :where(search) {
    display: block;
  }


/* ============================================================
   Reset — 文字の意味づけ
============================================================ */

  /* 日本語に斜体はなじまない。強調は太字で表す */
  :where(em:lang(ja)) {
    font-weight: bolder;
  }

  :where(:is(i, cite, em, dfn, address, var):lang(ja)) {
    font-style: normal;
  }

  /* 等幅の書体。ブラウザ既定の「等幅だけ小さくなる」挙動を打ち消す */
  :where(code, kbd, samp, pre) {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 1em;
  }

  :where(pre) {
    overflow-x: auto;
    /* コードの中には和欧間の空き・括弧の詰めを入れない */
    text-spacing-trim: space-all;
    text-autospace: no-autospace;
  }

  :where(abbr[title]) {
    text-decoration: underline dotted;
    cursor: help;
  }

  /* 日付・時刻の数字の間に空きを入れない */
  :where(time) {
    text-autospace: no-autospace;
  }

  :where(sub, sup) {
    line-height: 0;
  }


/* ============================================================
   Reset — リンク
   本文中のリンクの下線は Base が付ける（ナビ・ボタンは style.css で外してよい）
============================================================ */

  :where(a) {
    color: inherit;
  }

  :where(a:any-link) {
    text-decoration-line: none;
    text-decoration-thickness: from-font;
    text-underline-offset: 0.2em;
  }


/* ============================================================
   Reset — 画像・埋め込み
============================================================ */

  /* 親の幅からはみ出さない。下にできる謎の隙間（ベースライン分）を消す */
  :where(img, svg, picture, video, audio, canvas, iframe, embed, object) {
    max-inline-size: 100%;
    vertical-align: bottom;
  }

  /* 縦横比を保つ（audio は高さ auto で消えるため除く） */
  :where(img, svg, picture, video, canvas, iframe, embed, object) {
    block-size: auto;
  }

  :where(iframe) {
    border: 0;
  }


/* ============================================================
   Reset — 表
============================================================ */

  :where(table) {
    border-collapse: collapse;
  }

  :where(caption, th) {
    text-align: start;
  }


/* ============================================================
   Reset — フォーム
   ブラウザ独自の見た目をやめ、周りの文字の書体・色を引き継ぐ。
   未スタイルでも操作できる場所だと分かるよう、枠線は 1px で残す。
   枠を消すときは border: none ではなく border-color: transparent
   （強制カラーモードで輪郭が消えないように）
============================================================ */

  :where(button, input, select, textarea),
  ::file-selector-button {
    margin: 0;
    border: 1px solid;
    border-radius: 0;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-align: inherit;
  }

  :where(button, input:is([type="button" i], [type="submit" i], [type="reset" i])),
  ::file-selector-button {
    background-color: transparent;
  }

  :where(input[type="file" i]) {
    border: 0;
  }

  :where(input[type="search" i]) {
    -webkit-appearance: textfield;
  }

  :where(textarea) {
    /* 横方向に伸ばすとレイアウトが崩れるため縦だけ */
    resize: block;
  }

  /* 入力中に和欧間の空きが入ると、カーソル位置がずれて見える */
  :where(input:not([type="button" i], [type="submit" i], [type="reset" i]), textarea, [contenteditable]) {
    text-autospace: no-autospace;
  }

  /* 押せるものは指カーソル */
  :where(button:enabled, label[for], select:enabled, summary,
         input:is([type="button" i], [type="submit" i], [type="reset" i], [type="checkbox" i], [type="radio" i]):enabled,
         [role="button" i], [role="tab" i], [role="option" i]),
  :where(:enabled)::file-selector-button {
    cursor: pointer;
  }

  :where(:disabled) {
    cursor: not-allowed;
  }

  /* ダブルタップでの拡大を止め、押した瞬間に反応させる */
  :where(button, input:is([type="button" i], [type="submit" i], [type="reset" i]),
         [role="button" i], [role="tab" i], [role="option" i]),
  ::file-selector-button {
    touch-action: manipulation;
  }

  :where(fieldset) {
    min-inline-size: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }

  :where(legend) {
    padding: 0;
  }

  /* プレースホルダーを薄くしすぎるブラウザがあるため。色は Base */
  ::placeholder {
    opacity: 1;
  }


/* ============================================================
   Reset — 非表示
   どんな指定より強くないと機能しないものだけ !important を使う
============================================================ */

  /* hidden 属性は必ず隠す（until-found はページ内検索で開くため除く） */
  :where([hidden]:not([hidden="until-found" i])) {
    display: none !important;
  }

  /* 閉じている dialog / popover は必ず隠す（display を上書きして開きっぱなしになる事故を防ぐ）
     popover として開く dialog は open 属性が付かないため、dialog 側の条件から除く */
  :where(dialog:not([open], [popover]), [popover]:not(:popover-open)) {
    display: none !important;
  }

  :where(dialog, [popover]) {
    color: inherit;
  }

  /* 見た目は隠し、読み上げには残す（フォームのラベル等）。フォーカスしたら表示する */
  :where(.visually-hidden:not(:focus, :active, :focus-within)) {
    position: absolute !important;
    inline-size: 1px !important;
    block-size: 1px !important;
    overflow: hidden !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }

/* ============================================================
   Base — 視認性の下限（触らない）
   デザインが決まっていない要素にも「人が読める・操作できる」状態を保証する。
   全セレクタ :where()（詳細度 0）。部品や style.css のクラス 1 つで上書きできる。
   上書きしてよいのは、デザインとして別の手段で同じ目的を満たす場合だけ。
   例: 本文リンクの下線を消すなら、色＋太さ等で 3:1 の差をつける（WCAG 1.4.1）
============================================================ */

  /* ----------------------------------------------------------
     ページ
     html にも背景色を置く（scrollbar-gutter の溝と
     オーバースクロール時の余白が白抜けしないように）
  ---------------------------------------------------------- */
  /* 横スクロールの防止
     横からのスライドイン演出（data-animate-x 等）の待機位置がはみ出しても横に揺れないように。
     html と body の両方に clip を置く（body だけだと viewport に伝播して hidden 扱いになり、
     フォーカス移動などで横にずれる）。clip はスクロールコンテナを作らないので sticky を壊さない */
  :where(html) {
    overflow-x: clip;
    background-color: var(--color-surface);
    color: var(--color-text);
  }

  :where(body) {
    font-family: var(--font-sans-ja);
    font-size:   var(--text-md);
    line-height: var(--lh-normal);
    color:       var(--color-text);
    background-color: var(--color-surface);
    overflow-x: clip;
  }

  :where(h1, h2, h3, h4, h5, h6) {
    font-weight:    var(--font-weight-bold);
    line-height:    var(--lh-tight);
    letter-spacing: var(--tracking-tight);
  }

  :where(code, kbd, samp, pre) {
    font-family: var(--font-mono);
  }

  :where(hr) {
    color: var(--color-border-subtle);
  }

  /* 固定ヘッダーの裏にジャンプ先が隠れないように */
  :where(:target) {
    scroll-margin-block-start: calc(var(--header-height) + var(--spacing-4));
  }


  /* ----------------------------------------------------------
     リンク
     本文中のリンクは下線を残す。色だけでリンクを示すと
     色覚特性によっては判別できない（WCAG 1.4.1）。
     ナビ・ボタン・カードなどクラスを持つリンクは components 側で下線を外してよい。
  ---------------------------------------------------------- */
  :where(p, li, dd, td, th, figcaption, blockquote, address, small) :where(a:any-link) {
    text-decoration-line: underline;
  }

  :where(a:any-link) {
    color: var(--color-primary);
  }


  /* ----------------------------------------------------------
     フォーカス
     キーボード操作の現在地を必ず見せる（WCAG 2.4.7 / 2.4.13）。
     消すときは代わりのフォーカス表現を components 側に書く。
  ---------------------------------------------------------- */
  :where(:focus-visible) {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
  }

  /* 強制カラーモードではシステム色に任せる */
  @media (forced-colors: active) {
    :where(:focus-visible) {
      outline-color: Highlight;
    }
  }


  /* ----------------------------------------------------------
     フォーム
     未スタイルでも入力欄の境界が見える（UI境界 3:1 は --color-border で担保）
  ---------------------------------------------------------- */
  :where(input:not([type="checkbox" i], [type="radio" i], [type="range" i], [type="color" i], [type="file" i]), select, textarea) {
    border-color: var(--color-border);
    background-color: var(--color-surface);
    /* iOS は 16px 未満の入力欄にフォーカスすると画面を拡大する */
    font-size: max(1rem, 1em);
  }

  ::placeholder {
    /* 既定のプレースホルダーは薄すぎてコントラスト不足になりやすい */
    color: var(--color-text-muted);
  }

  :where(:disabled, [aria-disabled="true" i]) {
    opacity: var(--state-disabled);
  }


  /* ----------------------------------------------------------
     選択色
  ---------------------------------------------------------- */
  ::selection {
    background-color: color-mix(in srgb, var(--color-primary) 25%, transparent);
  }

} /* end @layer reset */
