    /* ── テーマ変数（ライト＝デフォルト） ── */
    :root {
      --bg-page:      #f4f4f8;
      --bg-card:      #ffffff;
      --bg-card2:     #f8f8fc;
      --bg-deep:      #eef4fb;
      --bg-formula:   #e8f0f8;
      --bg-dark:      #e0e0e8;
      --bg-tooltip:   #1a3050;
      --border:       #d0d0e0;
      --border-soft:  #d0d0e8;
      --border-blue:  #9ab8d8;
      --border-tip:   #3a6a9a;
      --border-def:   #ddddf0;
      --text:         #1a1a30;
      --text-muted:   #666;
      --text-dim:     #aaa;
      --accent:       #2255bb;
      --accent2:      #1a66cc;
      --accent3:      #1155bb;
      --highlight:    #b36a00;
      --text-chart:   #555;
      --text-math:    #335577;
      --text-def:     #446688;
      --text-easy:    #334466;
      --text-tip:     #d0e8ff;
      --link:         #2255bb;
      --link-hover-bg:#e0eeff;
      --link-hover:   #113399;
      --overlay-bg:   rgba(240,240,248,0.92);
      --reset-bg:     #ddd;
      --reset-color:  #444;
      --tog-track:    #ccc;
      --tog-thumb:    #999;
      --tog-sep:      #ccc;
      --chart-tick:   #555;
      --chart-grid:   #ddd;
    }
    body.dark {
      --bg-page:      #0f0f1a;
      --bg-card:      #1a1a2e;
      --bg-card2:     #131325;
      --bg-deep:      #0d1b2a;
      --bg-formula:   #0a1520;
      --bg-dark:      #222;
      --bg-tooltip:   #0d2035;
      --border:       #333;
      --border-soft:  #2a2a4a;
      --border-blue:  #2c4a6e;
      --border-tip:   #3a6a9a;
      --border-def:   #1e1e3a;
      --text:         #e0e0ff;
      --text-muted:   #888;
      --text-dim:     #555;
      --accent:       #a0c4ff;
      --accent2:      #7eb8f7;
      --accent3:      #a0d4ff;
      --highlight:    #ffd166;
      --text-chart:   #aaa;
      --text-math:    #aac4e0;
      --text-def:     #99b8d4;
      --text-easy:    #b0cce0;
      --text-tip:     #d0e8ff;
      --link:         #5b8fd4;
      --link-hover-bg:#1a2a3e;
      --link-hover:   #90c0ff;
      --overlay-bg:   rgba(10,10,20,0.88);
      --reset-bg:     #444;
      --reset-color:  #ccc;
      --tog-track:    #333;
      --tog-thumb:    #888;
      --tog-sep:      #555;
      --chart-tick:   #aaa;
      --chart-grid:   #222;
    }

    * { box-sizing: border-box; margin: 0; padding: 0; }
    body {
      font-family: 'Segoe UI', sans-serif;
      background: var(--bg-page);
      color: var(--text);
      min-height: 100vh;
      transition: background 0.3s, color 0.3s;
    }
    h1 {
      text-align: center;
      padding: 20px;
      font-size: 1.6rem;
      color: var(--accent);
      letter-spacing: 0.05em;
    }
    /* ── テーマ切り替えボタン ── */
    #btnTheme {
      background: transparent;
      color: #fff;
      border: 1px solid #fff;
      border-radius: 20px;
      padding: 4px 12px;
      font-size: 0.82rem;
      cursor: pointer;
      transition: opacity 0.2s;
      white-space: nowrap;
    }
    #btnTheme:hover { opacity: 0.8; }
    .controls {
      display: flex;
      flex-wrap: wrap;
      gap: 16px;
      justify-content: center;
      padding: 10px 20px 20px;
    }
    .ctrl-group {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 14px 20px;
      display: flex;
      flex-direction: column;
      gap: 8px;
      min-width: 200px;
    }
    .ctrl-group label {
      font-size: 0.85rem;
      color: var(--text-muted);
    }
    .range-labels {
      display: flex;
      justify-content: space-between;
      font-size: 0.72rem;
      color: var(--text-dim);
    }
    #progress-bar { height: 100%; background: #20c997; border-radius: 6px; transition: width 0.1s; }
    .ctrl-group .val-display {
      font-size: 1.5rem;
      font-weight: bold;
      color: var(--accent);
      text-align: center;
    }
    input[type=range] {
      width: 100%;
      accent-color: var(--accent);
    }
    .btn-row {
      display: flex;
      justify-content: center;
      gap: 12px;
      padding-bottom: 20px;
      flex-wrap: wrap;
    }
    button {
      padding: 10px 28px;
      border: none;
      border-radius: 8px;
      font-size: 1rem;
      cursor: pointer;
      transition: opacity 0.2s, transform 0.1s;
    }
    button:hover { opacity: 0.85; transform: scale(1.03); }
    button:active { transform: scale(0.97); }
    #btnRoll { background: #4c6ef5; color: #fff; }
    #btnAuto { background: #20c997; color: #fff; }
    #btnReset { background: var(--reset-bg); color: var(--reset-color); }
    #progress-bar-wrap {
      width: 90%; max-width: 800px; margin: 0 auto 8px;
      background: var(--bg-dark); border-radius: 6px; height: 8px; display: none;
    }
    #progress-bar {
      height: 100%; background: #20c997; border-radius: 6px;
      transition: width 0.1s;
    }
    .stats-row {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 10px;
      padding: 0 20px 18px;
    }
    .stat-card {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 10px 18px;
      text-align: center;
      min-width: 140px;
    }
    .stat-card .stat-label { font-size: 0.75rem; color: var(--text-muted); }
    .stat-card .stat-val { font-size: 1.2rem; font-weight: bold; color: var(--highlight); }
    .charts-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
      gap: 20px;
      padding: 0 20px 30px;
      max-width: 1400px;
      margin: 0 auto;
    }
    .chart-card {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 16px;
    }
    .chart-card h2 {
      font-size: 0.9rem;
      color: var(--accent);
      margin-bottom: 4px;
    }
    .chart-card .chart-note {
      font-size: 0.72rem;
      color: var(--text-muted);
      margin-bottom: 10px;
    }
    .chart-card canvas { width: 100% !important; }
    .math-box {
      background: var(--bg-deep);
      border: 1px solid var(--border-blue);
      border-radius: 10px;
      padding: 16px 22px;
      margin: 0 20px 30px;
      max-width: 1360px;
      margin-left: auto;
      margin-right: auto;
      font-size: 0.82rem;
      line-height: 1.8;
      color: var(--text-math);
    }
    .math-box h3 { color: var(--accent2); margin-bottom: 8px; font-size: 0.95rem; }
    .math-box span.formula { color: var(--highlight); font-family: monospace; }

    /* ── 用語ツールチップ ── */
    .term {
      border-bottom: 1px dashed var(--accent2);
      color: var(--accent3);
      cursor: help;
      position: relative;
      white-space: nowrap;
    }
    .term::after {
      content: attr(data-tip);
      position: absolute;
      bottom: calc(100% + 6px);
      left: 50%;
      transform: translateX(-50%);
      background: var(--bg-tooltip);
      border: 1px solid var(--border-tip);
      color: var(--text-tip);
      font-size: 0.74rem;
      line-height: 1.5;
      padding: 8px 12px;
      border-radius: 6px;
      white-space: normal;
      width: 260px;
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.15s;
      z-index: 100;
    }
    .term:hover::after { opacity: 1; }

    /* ── 用語集セクション ── */
    .glossary {
      max-width: 1360px;
      margin: 0 auto 40px;
      padding: 0 20px;
    }
    .glossary h3 {
      color: var(--accent2);
      font-size: 1rem;
      margin-bottom: 14px;
    }
    .glossary-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
      gap: 12px;
    }
    details.gitem {
      background: var(--bg-card2);
      border: 1px solid var(--border-soft);
      border-radius: 8px;
      padding: 0;
    }
    details.gitem summary {
      padding: 10px 14px;
      cursor: pointer;
      font-size: 0.88rem;
      color: var(--accent);
      list-style: none;
      display: flex;
      align-items: center;
      gap: 8px;
      -webkit-user-select: none;
      user-select: none;
    }
    details.gitem summary::before {
      content: '▶';
      font-size: 0.6rem;
      transition: transform 0.15s;
      color: var(--text-dim);
    }
    details.gitem[open] summary::before { transform: rotate(90deg); }
    details.gitem .gdef {
      padding: 0 14px 12px;
      font-size: 0.8rem;
      color: var(--text-def);
      line-height: 1.7;
      border-top: 1px solid var(--border-def);
      margin-top: 4px;
    }
    details.gitem .gdef .gformula {
      display: block;
      margin-top: 6px;
      font-family: monospace;
      color: var(--highlight);
      background: var(--bg-formula);
      padding: 4px 8px;
      border-radius: 4px;
      font-size: 0.78rem;
    }
    #dice-display {
      display: flex;
      flex-wrap: wrap;
      gap: 5px;
      justify-content: center;
      padding: 0 20px 16px;
      max-width: 940px;
      margin: 0 auto;
      min-height: 150px;
    }
    .die {
      width: 32px; height: 32px;
      background: #fff;
      color: #111;
      border-radius: 6px;
      font-size: 1rem;
      font-weight: bold;
      display: flex;
      align-items: center;
      justify-content: center;
      animation: pop 0.2s ease;
    }
    @keyframes pop {
      0% { transform: scale(0.6); opacity: 0.3; }
      60% { transform: scale(1.2); }
      100% { transform: scale(1); opacity: 1; }
    }
    .die-1 { background: #ff6b6b; color: #fff; }
    .die-2 { background: #ffa94d; color: #fff; }
    .die-3 { background: #ffe066; color: #111; }
    .die-4 { background: #69db7c; color: #111; }
    .die-5 { background: #74c0fc; color: #111; }
    .die-6 { background: #cc5de8; color: #fff; }

    /* ── サイコロエリア＋オーバーレイ ── */
    #dice-area {
      position: relative;
      max-width: 940px;
      margin: 0 auto;
    }
    #dice-overlay {
      position: absolute;
      inset: -8px;
      background: var(--overlay-bg);
      -webkit-backdrop-filter: blur(6px);
      backdrop-filter: blur(6px);
      border-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 10;
      animation: fadeInOverlay 0.4s ease;
    }
    #dice-overlay[hidden] { display: none; }
    @keyframes fadeInOverlay {
      from { opacity: 0; }
      to   { opacity: 1; }
    }
    .overlay-inner {
      text-align: center;
      padding: 20px 24px;
      max-width: 340px;
    }
    .overlay-icon { font-size: 2rem; line-height: 1; margin-bottom: 8px; }
    .overlay-title {
      font-size: 0.95rem;
      font-weight: bold;
      color: var(--highlight);
      margin-bottom: 10px;
    }
    .overlay-body {
      font-size: 0.78rem;
      color: var(--text-math);
      line-height: 1.7;
      margin-bottom: 16px;
    }

    /* ── 表示モード切り替えトグル ── */
    .mode-toggle-row {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 10px;
      padding-bottom: 10px;
      font-size: 0.85rem;
      color: var(--text-muted);
    }
    .toggle-label {
      display: flex;
      align-items: center;
      gap: 8px;
      cursor: pointer;
    }
    .toggle-label input[type=checkbox] { display: none; }
    .toggle-track {
      width: 44px; height: 24px;
      background: var(--tog-track);
      border-radius: 12px;
      position: relative;
      transition: background 0.2s;
    }
    .toggle-track::after {
      content: '';
      position: absolute;
      top: 3px; left: 3px;
      width: 18px; height: 18px;
      background: var(--tog-thumb);
      border-radius: 50%;
      transition: transform 0.2s, background 0.2s;
    }
    .toggle-label input:checked + .toggle-track { background: #4c6ef5; }
    .toggle-label input:checked + .toggle-track::after {
      transform: translateX(20px);
      background: #fff;
    }
    .mode-name { min-width: 60px; color: var(--accent); font-weight: bold; }
    .toggle-sep { margin-left: 16px; color: var(--tog-sep); }

    /* ── やさしい解説セクション ── */
    .easy-glossary {
      margin-bottom: 60px;
    }
    .easy-list {
      display: flex;
      flex-direction: column;
      gap: 16px;
      font-size: 0.9rem;
      line-height: 1.9;
      color: var(--text-easy);
    }
    .easy-item {
      background: var(--bg-card2);
      border: 1px solid var(--border-soft);
      border-radius: 10px;
      padding: 16px 20px;
    }
    .easy-item-title {
      color: var(--highlight);
      font-weight: bold;
      margin-bottom: 6px;
    }
    .easy-formula {
      display: inline-block;
      margin: 6px 0 2px;
      font-family: monospace;
      background: var(--bg-formula);
      color: var(--highlight);
      padding: 5px 10px;
      border-radius: 4px;
      font-size: 0.85rem;
    }
    .easy-link {
      display: inline-block;
      margin-top: 10px;
      font-size: 0.78rem;
      color: var(--link);
      text-decoration: none;
      border: 1px solid var(--border-blue);
      border-radius: 4px;
      padding: 2px 8px;
    }
    .easy-link:hover { background: var(--link-hover-bg); color: var(--link-hover); }
    .chi-table {
      border-collapse: collapse;
      margin: 8px 0;
      font-size: 0.92em;
    }
    .chi-table th {
      border: 1px solid var(--border);
      padding: 4px 10px;
      background: var(--bg-dark);
    }
    .chi-table td {
      border: 1px solid var(--border);
      padding: 3px 10px;
      text-align: center;
    }
    .card-link {
      display: block;
      margin-top: 8px;
      font-size: 0.75rem;
      color: var(--link);
      text-decoration: none;
    }
    .card-link:hover { color: var(--link-hover); }

/* ── header / footer ── */
header.header {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #000;
  color: #fff;
  padding: 8px 16px;
}
header.header .title {
  flex: 1;
  font-size: 1.1rem;
  margin: 0;
  color: #fff;
}
header.header .header-image {
  border-radius: 6px;
}
header.header .header-link {
  color: #fff;
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}
header.header .header-link:hover {
  text-decoration: underline;
}
footer {
  background: #000;
  color: #fff;
  text-align: center;
  padding: 12px 16px;
  margin-top: 32px;
  font-size: 0.85rem;
}
footer a {
  color: #ccc;
  text-decoration: none;
}
footer a:hover {
  text-decoration: underline;
}
