/* 理科の動く図：共通の見た目。図のファイルはここにある変数・クラスだけを使い、新しい色を足さない。 */
:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --fg: #1d2330;
  --muted: #6a7180;
  --line: #d9d6cc;
  --accent: #2f6fd6;
  --accent-soft: #e3ecfb;
  --radius: 12px;
  --tap: 44px;

  /* 図の色（理科の慣習に合わせる） */
  --c-red: #d6453d;      /* ＋極・N極・酸性・動脈血・力1 */
  --c-blue: #2f6fd6;     /* S極・アルカリ性・静脈血・力2 */
  --c-black: #1d2330;    /* −極 */
  --c-green: #2e9c5a;    /* 中性・植物 */
  --c-orange: #e38a1c;   /* 合力・結果・強調 */
  --c-purple: #7a4fc4;
  --c-gray: #8a909c;
  --c-light: #f2c230;    /* 光・太陽 */
  --c-sky: #12182a;      /* 宇宙・夜 */
  --c-dark: #3a4256;     /* 天体の影の部分 */
  --c-lit: #f7f1d8;      /* 天体の光っている部分 */
  --c-earth: #3d8bd9;
  --c-grid: #e6e3da;
  --c-grid-strong: #cfcabd;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 17px; line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }

/* ---------- トップ ---------- */
.top { max-width: 960px; margin: 0 auto; padding: 16px 16px 48px; }
.top h1 { font-size: 24px; margin: 8px 0 4px; }
.top .lead { color: var(--muted); margin: 0 0 16px; font-size: 15px; }
.top .crumb { display: inline-flex; align-items: center; min-height: var(--tap); color: var(--muted); text-decoration: none; font-size: 15px; }
.grade-filter { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.grade-filter button {
  min-height: var(--tap); padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer;
}
.grade-filter button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.field-title { font-size: 15px; color: var(--muted); margin: 24px 0 4px; font-weight: 600; letter-spacing: .05em; }
.unit { margin: 12px 0 20px; }
.unit h2 { font-size: 17px; margin: 0 0 8px; display: flex; gap: 8px; align-items: baseline; }
.unit h2 .grade { font-size: 13px; color: var(--muted); font-weight: normal; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.card {
  display: flex; align-items: center; min-height: 64px; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--fg); text-decoration: none; font-weight: 600;
}
.card:hover { border-color: var(--accent); }
.card.soon { color: var(--muted); font-weight: normal; background: transparent; border-style: dashed; }
.card.soon::after { content: "準備中"; margin-left: auto; font-size: 12px; }

/* ---------- 図のページ ---------- */
.fig-page { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.fig-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.fig-head .back {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: var(--tap); min-height: var(--tap); text-decoration: none; font-size: 22px; color: var(--fg);
}
.fig-head .titles { flex: 1; min-width: 0; }
.fig-head h1 { font-size: 18px; margin: 0; line-height: 1.3; }
.fig-head .unit-name { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn {
  min-height: var(--tap); min-width: var(--tap); padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); cursor: pointer;
  touch-action: manipulation;
}
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.fig-body { flex: 1; display: flex; flex-direction: column; }
.stage { background: var(--panel); border-bottom: 1px solid var(--line); }
.stage svg {
  display: block; width: 100%; height: auto; max-height: 62vh; margin: 0 auto;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.side { padding: 10px 14px 24px; max-width: 720px; width: 100%; margin: 0 auto; }

/* 横持ち（またはタブレット横）：図の右に操作 */
@media (orientation: landscape) and (min-width: 640px) {
  .fig-body { flex-direction: row; align-items: stretch; }
  .stage { flex: 1; border-bottom: 0; border-right: 1px solid var(--line); display: flex; align-items: center; }
  .stage svg { max-height: calc(100vh - 60px); max-height: calc(100dvh - 60px); }
  .side { width: 320px; flex: none; overflow-y: auto; max-height: calc(100dvh - 58px); }
}

/* 操作部品 */
.ctl { margin: 10px 0; }
.ctl[hidden] { display: none; }
.ctl-label { display: flex; justify-content: space-between; font-size: 15px; color: var(--muted); }
.ctl-label b { color: var(--fg); font-variant-numeric: tabular-nums; }
.ctl input[type="range"] { width: 100%; height: var(--tap); margin: 0; accent-color: var(--accent); }
.ctl-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { min-height: var(--tap); padding: 0 14px; border: 0; background: var(--panel); cursor: pointer; touch-action: manipulation; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets .btn { padding: 0 12px; }
.ctl-title { font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.explain {
  margin-top: 14px; padding: 12px 14px; background: var(--accent-soft);
  border-radius: var(--radius); font-size: 16px;
}
.explain[hidden] { display: none; }
.explain p { margin: 0 0 8px; }
.explain p:last-child { margin-bottom: 0; }
.explain h3 { font-size: 14px; margin: 10px 0 2px; color: var(--accent); }
.explain h3:first-child { margin-top: 0; }

/* SVG の中の文字（論理座標 800×500 に対する大きさ） */
svg text { font-family: inherit; fill: var(--fg); }
svg .t   { font-size: 22px; }
svg .t-s { font-size: 18px; }
svg .t-l { font-size: 30px; font-weight: 700; }
svg .t-muted { fill: var(--muted); }
/* スマホ縦持ち：図が縮むので文字だけ 1.35 倍にする（図のファイルは文字のまわりに余白を取っておく） */
@media (max-width: 560px) {
  svg .t   { font-size: 30px; }
  svg .t-s { font-size: 24px; }
  svg .t-l { font-size: 40px; }
}
svg .halo { paint-order: stroke; stroke: var(--panel); stroke-width: 5px; stroke-linejoin: round; }
svg .handle { cursor: grab; }
svg .hit { fill: transparent; stroke: none; }
