/* 実験装置（lab/）の共通レイアウト
   色は styles/tokens.css のトークンだけを参照する。ここにも各ページにも
   生の hex / rgba を書かないこと（唯一の例外は theme-color 属性）。

   トップページ (index.html) と違い、lab/ は Web Animations API を使わない。
   数値に追従して描き替えるだけなので、値の反映は素の代入か CSS transition、
   連続的な動きだけ requestAnimationFrame で回す。 */

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  /* iOS で横向きにしたときの自動拡大を抑える */
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
               "Noto Sans JP", "Yu Gothic UI", sans-serif;
  line-height: 1.9;
  /* 左右の余白はここで一度だけ持たせる */
  padding: 0 1.25rem;
}

.wrap {
  width: 100%;
  max-width: 56rem;
  margin: 0 auto;
  padding-block: 2.5rem 4rem;
}

/* ---- ヘッダー ---- */
.site-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.site-head .home {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--fg);
  text-decoration: none;
}
.site-head .home .accent {
  background: linear-gradient(100deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.site-head .crumb {
  font-size: .8rem;
  letter-spacing: .08em;
  color: var(--muted);
}
.site-head .crumb a { color: var(--muted); }

a { color: var(--accent); }
a:focus-visible,
button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---- ページ見出し ---- */
.page-head { margin: 2.5rem 0 2rem; }
.page-head .eyebrow {
  margin: 0;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .18em;
  color: var(--accent);
}
.page-head h1 {
  margin: .4rem 0 .6rem;
  font-size: clamp(1.5rem, 5.5vw, 2.1rem);
  line-height: 1.4;
  letter-spacing: .01em;
}
.page-head .lede {
  margin: 0;
  max-width: 38rem;
  color: var(--muted);
}

/* ---- カード ---- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem 1.25rem;
  margin-bottom: 1.25rem;
}
.card > h2 {
  margin: 0 0 1rem;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .14em;
  color: var(--muted);
}
.card.stage { padding: 1.25rem 1rem; }

/* ---- 操作パネル ---- */
.controls {
  display: grid;
  gap: 1.25rem;
}
@media (min-width: 40rem) {
  .controls.two { grid-template-columns: 1fr 1fr; gap: 1.25rem 2rem; }
}

.ctl > .ctl-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .1rem;
}
.ctl .ctl-label {
  font-size: .85rem;
  color: var(--muted);
  letter-spacing: .04em;
}
.ctl .ctl-value {
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--fg);
}
.ctl .ctl-value .unit {
  margin-left: .15em;
  font-size: .72em;
  font-weight: 600;
  color: var(--muted);
}

/* range。見た目を揃えるため両ベンダー分を書く */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  margin: .35rem 0 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--track);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--track);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -8px;              /* トラック 4px との差の半分 */
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px -2px var(--shadow);
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px -2px var(--shadow);
}

/* 選択式（路面など） */
.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .45rem;
}
.segmented button {
  flex: 1 1 auto;
  padding: .45rem .8rem;
  font: inherit;
  font-size: .85rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.segmented button[aria-pressed="true"] {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

/* 汎用ボタン */
.btn {
  padding: .55rem 1.15rem;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: center;
}

/* ---- 数値の読み取り ---- */
.readouts {
  display: grid;
  /* min() を挟まないと、画面より広い最小幅を要求して横スクロールが出る */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr));
  gap: 1px;
  margin-top: 1.25rem;
  background: var(--border);          /* 1px の隙間が仕切りになる */
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.readout {
  padding: .85rem 1rem;
  background: var(--bg);
}
.readout .rd-label {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .75rem;
  letter-spacing: .06em;
  color: var(--muted);
}
.readout .rd-value {
  font-variant-numeric: tabular-nums;
  /* 桁が増えても「1315.2万/円」と折り返さないよう、狭い画面では縮める */
  font-size: clamp(1.15rem, 4.6vw, 1.45rem);
  font-weight: 700;
  line-height: 1.4;
}
.readout .rd-value .unit {
  margin-left: .12em;
  font-size: .62em;
  font-weight: 600;
  color: var(--muted);
}
.readout.hero .rd-value { font-size: clamp(1.3rem, 5.4vw, 1.8rem); }

/* 系列の色見本。色だけに意味を持たせず、必ずラベルと並べる */
.swatch {
  flex: 0 0 auto;
  width: .7rem;
  height: .7rem;
  border-radius: 3px;
  background: var(--c, var(--muted));
}
.swatch.line {
  width: 1.1rem;
  height: 3px;
  border-radius: 2px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 1.1rem;
  margin: 0 0 .9rem;
  padding: 0;
  list-style: none;
  font-size: .8rem;
  color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: .45rem; }

/* ---- 図 ---- */
figure { margin: 0; }
svg.plot { display: block; width: 100%; height: auto; overflow: visible; }

/* 図の中の文字は viewBox ごと縮むので、放っておくと狭い画面で読めなくなる。
   JS が実際の描画幅を測って --fs に「見た目 11px になるユーザー単位」を入れる。
   個々の文字要素は em で指定し、この 1 箇所に追従させること。 */
svg.plot { font-size: var(--fs, 11px); }
svg.plot text { fill: var(--muted); font-size: 1em; }
/* hidden 属性の既定スタイルは HTML 要素にしか当たらない。
   SVG の中で hidden を使うと隠れないので、ここで明示しておく */
svg [hidden] { display: none; }
/* HTML 側も、display を指定したクラス（.legend の flex など）に hidden が負けないようにする */
[hidden] { display: none !important; }
svg.plot .grid-line { stroke: var(--grid); stroke-width: 1; }
svg.plot .axis-line { stroke: var(--axis); stroke-width: 1; }
/* 系列の線。細く、端は丸く */
svg.plot .series { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- 気づき / 注記 ---- */
.insight {
  margin: 1.25rem 0 0;
  padding: .9rem 1.1rem;
  background: var(--surface-2);
  border-left: 2px solid var(--accent);
  border-radius: 0 10px 10px 0;
  font-size: .92rem;
}
.insight strong { color: var(--accent); }
.note {
  margin: .9rem 0 0;
  font-size: .78rem;
  line-height: 1.8;
  color: var(--muted);
}
.note code, code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .92em;
}

/* ---- 表（グラフを色以外でも読めるようにする） ---- */
details.dataview { margin-top: 1rem; }
details.dataview summary {
  font-size: .8rem;
  color: var(--muted);
  cursor: pointer;
}
.table-scroll { overflow-x: auto; margin-top: .75rem; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}
th, td {
  padding: .4rem .7rem;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 600; }
th:first-child, td:first-child { text-align: left; }

/* ---- つづけて動かす（関連する実験への導線）---- */
.more {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 1.1rem;
}
@media (min-width: 40rem) {
  .more { grid-template-columns: 1fr 1fr; gap: 1.25rem 2rem; }
}
.more a {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .55rem;
  color: var(--fg);
  text-decoration: none;
}
.more .n {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .18em;
  color: var(--accent);
}
.more b { font-size: 1.02rem; }
.more a:hover b,
.more a:focus-visible b { color: var(--accent); }
.more p { margin: .2rem 0 0; font-size: .85rem; color: var(--muted); }

/* ---- フッター ---- */
.site-foot {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: .78rem;
  letter-spacing: .06em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem 1rem;
}
.site-foot b { color: var(--fg); font-weight: 600; }

/* ---- 一覧（ハブ）---- */
.deck {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
}
.deck a {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 1.35rem 1.25rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--fg);
  text-decoration: none;
  transition: border-color .2s ease, transform .2s ease;
}
.deck a:hover { border-color: var(--accent); transform: translateY(-3px); }
.deck .n {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .18em;
  color: var(--accent);
}
.deck h2 { margin: .5rem 0 .4rem; font-size: 1.12rem; line-height: 1.5; }
.deck p { margin: 0; font-size: .86rem; color: var(--muted); }
.deck .thumb { margin: .35rem 0 .9rem; display: block; width: 100%; height: auto; }
.deck .go {
  margin-top: auto;
  padding-top: 1rem;
  font-size: .8rem;
  color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .deck a:hover { transform: none; }
  * { transition-duration: .01ms !important; }
}
