/* 剛体消失 — 共通スタイル */
:root {
  --bg: #0b0e12;
  --bg2: #12171e;
  --panel: #171d25;
  --panel2: #1c232d;
  --line: #262f3b;
  --line2: #334050;
  --fg: #e8edf3;
  --muted: #8b98a9;
  --accent: #ff7a45;      /* 崩壊・非剛体 */
  --rigid: #5cc8ff;       /* 剛体 */
  --good: #6fdc8c;
  --warn: #ffd166;
  --bad: #ff5d73;
  --radius: 12px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 6px 20px rgba(0,0,0,.25);
  --mono: "Cascadia Mono", "Consolas", "Menlo", monospace;
  --sans: "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--rigid); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--rigid); outline-offset: 2px; border-radius: 6px; }
::selection { background: rgba(255,122,69,.35); }

/* スクロールバー */
* { scrollbar-width: thin; scrollbar-color: #33404f transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2c3744; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #3a4757; }
::-webkit-scrollbar-track { background: transparent; }

/* ヘッダ */
.rv-header {
  position: relative;
  display: flex; align-items: center; gap: 14px;
  padding: 9px 18px; min-height: 49px;
  background: linear-gradient(180deg, #141a22, #10151b);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.rv-header::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, var(--accent), transparent 35%, transparent 65%, var(--rigid));
  opacity: .55;
}
.rv-header .back {
  text-decoration: none; color: var(--muted); font-size: 12.5px;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  transition: color .15s, border-color .15s, background .15s;
}
.rv-header .back:hover { color: var(--fg); border-color: var(--line2); background: #1a212a; }
.rv-header h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: .03em; }
.rv-header .chap {
  color: var(--accent); font-family: var(--mono); font-size: 11.5px;
  padding: 2px 8px; border-radius: 6px; background: rgba(255,122,69,.1);
}
.rv-header .libs { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.lib-badge {
  font-family: var(--mono); font-size: 10.5px; padding: 2px 9px;
  border: 1px solid var(--line); border-radius: 999px; color: var(--muted);
  transition: color .3s, border-color .3s;
}
.lib-badge.ok { color: var(--good); border-color: #2a4d35; background: rgba(111,220,140,.05); }
.lib-badge.ok::before { content: "● "; font-size: 8px; vertical-align: 1px; }
.lib-badge.err { color: var(--bad); border-color: #6b2a35; }
.stars { font-size: 15px; letter-spacing: 2px; color: var(--warn); text-shadow: 0 0 10px rgba(255,209,102,.35); }

/* レイアウト */
.rv-main {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px;
  height: calc(100vh - 49px);
}
.rv-stage {
  position: relative; overflow: hidden;
  background: radial-gradient(ellipse at 50% 35%, #10161d 0%, #090c0f 75%);
}
.rv-stage canvas { display: block; width: 100%; height: 100%; }
.rv-side {
  border-left: 1px solid var(--line); background: var(--bg2);
  overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px;
}
@media (max-width: 860px) {
  .rv-main { grid-template-columns: 1fr; height: auto; }
  .rv-stage { height: 62vh; }
  .rv-side { border-left: 0; border-top: 1px solid var(--line); }
  .rv-header .libs { margin-left: 0; width: 100%; }
}

/* パネル */
.panel {
  position: relative;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.panel h2 {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; margin: 0 0 8px; color: var(--muted); font-weight: 700; letter-spacing: .08em;
}
.panel h2::before {
  content: ""; width: 6px; height: 6px; border-radius: 2px; background: var(--line2); flex: none;
}
.panel p { margin: 5px 0; }
/* ミッション：いちばん目立たせる */
.mission { border-color: #5a3a2a; background: linear-gradient(180deg, #24191a, #1b1a1f); }
.mission::before, .easy::before {
  content: ""; position: absolute; left: -1px; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.mission h2 { color: var(--accent); }
.mission h2::before { background: var(--accent); }

.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.row label { min-width: 84px; color: var(--muted); font-size: 12px; }
.row .val { font-family: var(--mono); min-width: 64px; text-align: right; font-size: 12px; color: var(--fg); }

/* スライダー */
input[type=range] {
  -webkit-appearance: none; appearance: none; flex: 1; min-width: 60px;
  height: 22px; background: transparent; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 6px;
  background: linear-gradient(90deg, var(--accent) var(--p, 50%), #2a333f var(--p, 50%));
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
}
input[type=range]::-moz-range-track { height: 6px; border-radius: 6px; background: #2a333f; }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -5px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(0,0,0,.45);
  transition: transform .12s;
}
input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--accent);
}
input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.15); }
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.25); }
input[type=range]:disabled { opacity: .45; cursor: default; }

/* ボタン */
.btn {
  background: #222b36; border: 1px solid #364352; border-radius: 8px;
  padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 13px;
  transition: background .15s, border-color .15s, transform .08s, box-shadow .15s;
}
.btn:hover { background: #2a3542; border-color: #46566a; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, #ff8c5c, var(--accent)); border-color: #ff8c5c; color: #1a0d06; font-weight: 700;
  box-shadow: 0 4px 14px rgba(255,122,69,.28);
}
.btn.primary:hover { filter: brightness(1.06); box-shadow: 0 6px 18px rgba(255,122,69,.38); }
.btn:disabled { opacity: .45; cursor: default; box-shadow: none; transform: none; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

.seg {
  display: inline-flex; gap: 2px; padding: 3px;
  background: #10151b; border: 1px solid var(--line); border-radius: 10px; flex-wrap: wrap;
}
.seg button {
  background: transparent; border: 0; padding: 5px 11px; cursor: pointer; border-radius: 7px;
  color: var(--muted); font-size: 12.5px; transition: background .15s, color .15s;
}
.seg button:hover { color: var(--fg); background: #1c242e; }
.seg button.on { background: #2c3846; color: var(--fg); box-shadow: 0 1px 4px rgba(0,0,0,.35); }

/* 計測値 */
.meters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.meter {
  background: #0f141a; border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px;
}
.meter .k { font-size: 11px; color: var(--muted); }
.meter .v { font-family: var(--mono); font-size: 17px; font-weight: 600; letter-spacing: .01em; }

/* 因果ログ（溝口ら 2016 の因果推論） */
.causal {
  font-family: var(--mono); font-size: 12px; max-height: 220px; overflow-y: auto;
  background: #0d1217; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px;
}
.causal:empty::before { content: "（まだ何も起きていない）"; color: #5b6878; font-family: var(--sans); }
.causal .ln { padding: 3px 0; border-bottom: 1px dashed #222c38; animation: rv-in .25s ease-out; }
.causal .ln:last-child { border-bottom: 0; }
.causal .ln .t { color: #5f6d7e; margin-right: 6px; }
.causal .ln .p {
  color: var(--warn); margin-left: 6px; font-size: 10.5px; padding: 0 5px;
  border: 1px solid rgba(255,209,102,.3); border-radius: 4px; cursor: help;
}
.causal .ln.arrow::before { content: "→ "; color: var(--accent); }

/* やさしい解説（高校生向け） */
.easy { border-color: #24425a; background: linear-gradient(180deg, #172430, #161e27); }
.easy::before { background: var(--rigid); }
.easy h2 { color: var(--rigid); }
.easy h2::before { background: var(--rigid); }
.easy dl { margin: 0; }
.easy dt { font-weight: 700; font-size: 13px; margin-top: 8px; color: #cfe9fb; }
.easy dt:first-child { margin-top: 0; }
.easy dd { margin: 2px 0 0; font-size: 13px; color: #d5dde6; }
.word { border-bottom: 1px dotted var(--muted); cursor: help; }
details.adv { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 6px; }
details.adv summary { cursor: pointer; color: var(--muted); font-size: 12px; list-style: none; }
details.adv summary::-webkit-details-marker { display: none; }
details.adv summary::before { content: "▸ "; display: inline-block; transition: transform .15s; }
details.adv[open] summary::before { transform: rotate(90deg); }
details.adv summary:hover { color: var(--fg); }
details.adv[open] summary { margin-bottom: 6px; }

/* ルール一覧（因果ログの番号の意味） */
.rules { font-size: 12px; margin: 0; padding-left: 0; list-style: none; }
.rules li { padding: 3px 0; display: flex; gap: 6px; align-items: baseline; }
.rules b {
  flex: none; color: var(--warn); font-family: var(--mono); font-weight: 400; font-size: 10.5px;
  padding: 0 5px; border: 1px solid rgba(255,209,102,.3); border-radius: 4px;
}

.formula {
  font-family: var(--mono); font-size: 12.5px; background: #0d1217; padding: 8px 10px;
  border-radius: 8px; border: 1px solid var(--line); white-space: pre-wrap;
}
.note { color: var(--muted); font-size: 12px; }
.ref { color: var(--muted); font-size: 11px; }

/* κ（剛性）メーター */
.kappa {
  position: absolute; left: 14px; top: 14px; z-index: 5;
  background: rgba(13,17,22,.78); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 12px; font-family: var(--mono); font-size: 12px; pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.35);
}
.kappa b { font-size: 14px; }
.kappa .bar { width: 150px; height: 6px; background: #252e39; border-radius: 3px; margin-top: 5px; overflow: hidden; }
.kappa .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--rigid)); transition: width .25s; }

.toast {
  position: absolute; left: 50%; top: 18px; transform: translateX(-50%); z-index: 6;
  background: rgba(23,29,37,.92); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--line2); border-radius: 999px;
  padding: 8px 18px; font-weight: 700; pointer-events: none; transition: opacity .3s;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: rv-drop .25s ease-out;
}

/* モーダル */
.rv-modal-bg {
  position: fixed; inset: 0; background: rgba(5,7,10,.66); z-index: 50;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: rv-fade .2s ease-out;
}
.rv-modal {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, #1e2630, var(--panel)); border: 1px solid var(--line2); border-radius: 16px;
  max-width: 560px; width: 100%; padding: 22px 24px 18px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,.55); animation: rv-pop .28s cubic-bezier(.2,.9,.3,1.2);
  line-height: 1.75;
}
.rv-modal::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--rigid));
}
.rv-modal h3 { margin: 0 0 10px; font-size: 19px; letter-spacing: .02em; }
.rv-modal p { margin: 8px 0; }
.rv-modal .btns { margin-top: 16px; justify-content: flex-end; }
.rv-modal .btn { padding: 8px 18px; }

@keyframes rv-fade { from { opacity: 0; } }
@keyframes rv-pop { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes rv-drop { from { opacity: 0; transform: translate(-50%, -8px); } }
@keyframes rv-in { from { opacity: 0; transform: translateX(-4px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
