/* =========================================================
   軌道6要素ビューア — スタイル
   色は要素ごとに固定：a 黄 / e 朱 / i 緑 / Ω 紫 / ω 青 / ν 黄緑
   ========================================================= */

:root {
  --bg: #0A0F1C; --panel: #0F1727; --panel2: #16213A; --line: #24324D;
  --text: #E7ECF4; --text2: #C9D2E1; --muted: #8C99B0; --faint: #5A6883;
  --c-a: #F2B84B; --c-e: #F0795A; --c-i: #3CC7B3; --c-O: #A38BF6; --c-w: #5AA9F2; --c-n: #B9DB67; --c-j2: #E58BD0;
  --warn: #F2B84B; --bad: #FF6B6B;
  --sans: "IBM Plex Sans JP", "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --math: "STIX Two Text", "Times New Roman", serif;
  color-scheme: dark;
}

/* ---------- ベース ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 14px; line-height: 1.55;
}
button, input, select { font: inherit; }

/* ---------- レイアウト ---------- */
.app { display: grid; grid-template-columns: minmax(0, 1fr) 400px; height: 100%; }
.view { position: relative; min-width: 0; min-height: 0; }
.stage { position: absolute; inset: 0; overflow: hidden; }
#cv { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#cv:active { cursor: grabbing; }

/* ---------- 3D 上のラベル ---------- */
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl {
  position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 12px; font-weight: 500;
  text-shadow: 0 0 3px var(--bg), 0 0 6px var(--bg), 0 0 10px var(--bg);
  transition: opacity .2s; will-change: transform;
}
.lbl.ang { font-family: var(--mono); font-size: 12.5px; }
.lbl i { font-family: var(--math); font-size: 15px; margin-right: 2px; }
.lbl.tick { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.lbl.plane { font-size: 11px; letter-spacing: .08em; color: var(--muted); }

/* ---------- 上部ツールバー ---------- */
.bar {
  position: absolute; top: 12px; left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap;
  pointer-events: none;
}
.bar > * { pointer-events: auto; }
.seg {
  display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px;
  background: rgba(15, 23, 39, .88); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 9px;
}
.seg button { background: none; border: 0; color: var(--muted); font-size: 12px; padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel2); color: var(--text); }
.seg button:focus-visible, .chip:focus-visible, .el-head:focus-visible, .x:focus-visible, .gl .t:focus-visible {
  outline: 2px solid var(--c-w); outline-offset: 1px;
}
.play { display: flex; gap: 6px; align-items: center; }
.pbtn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 9px; padding: 7px 12px;
  background: var(--text); color: var(--bg); font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.pbtn svg { width: 10px; height: 10px; fill: currentColor; }

/* ---------- 解説カード ---------- */
.explain {
  position: absolute; left: 16px; bottom: 16px; width: min(460px, calc(100% - 32px));
  display: grid; gap: 6px; padding: 12px 14px 13px;
  background: rgba(15, 23, 39, .9); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 12px;
}
.ex-h { display: flex; align-items: baseline; gap: 10px; }
.ex-h .s { font-family: var(--math); font-style: italic; font-size: 26px; line-height: 1; }
.ex-h b { font-size: 15px; }
.ex-h .k { color: var(--muted); font-size: 12px; }
.ex-h .x { margin-left: auto; background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; font-size: 11.5px; padding: 2px 8px; cursor: pointer; }
.explain p { margin: 0; font-size: 13px; color: var(--text2); text-wrap: pretty; }
.explain .now { font-family: var(--mono); font-size: 12.5px; color: var(--text); }
.explain .ex-en { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.explain .order { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; font-size: 12.5px; }
.explain .order span { white-space: nowrap; }
.explain .order i { font-family: var(--math); font-size: 16px; }
.explain .arrow { color: var(--faint); }
.explain .tech { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

/* ---------- 右パネル ---------- */
.panel {
  background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto;
  padding: 18px 16px 28px; display: flex; flex-direction: column; gap: 18px;
}
header h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .02em; text-wrap: balance; }
header p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.sec-t { font-size: 11px; letter-spacing: .12em; color: var(--muted); margin: 0 0 8px; font-weight: 500; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 5px 11px; font-size: 12.5px; cursor: pointer; }
.chip:hover { border-color: var(--faint); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* 要素スライダー */
.elements { display: grid; gap: 14px; }
.grp { display: grid; gap: 4px; }
.grp h3 { display: flex; align-items: baseline; gap: 8px; margin: 0 0 2px; font-size: 13px; font-weight: 700; }
.grp h3 .step { font-family: var(--mono); font-size: 11px; color: var(--bg); background: var(--muted); border-radius: 4px; padding: 0 5px; font-weight: 500; }
.grp h3 em { font-style: normal; font-weight: 400; color: var(--muted); font-size: 12px; }
.el { --p: 0%; display: grid; gap: 4px; padding: 8px 10px 6px; border-radius: 10px; border: 1px solid transparent; transition: opacity .2s, background .2s, border-color .2s; }
.el:hover, .el.on { background: var(--panel2); }
.el.pin { border-color: color-mix(in srgb, var(--c) 50%, transparent); }
.el.dim { opacity: .42; }
.el-head { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; align-items: center; gap: 8px; cursor: pointer; border-radius: 6px; }
.sym { font-family: var(--math); font-style: italic; font-size: 25px; color: var(--c); line-height: 1; text-align: center; }
.nm b { font-weight: 700; font-size: 13.5px; }
.nm small { display: block; color: var(--muted); font-size: 12px; line-height: 1.35; }
.val { display: flex; align-items: baseline; gap: 4px; }
.num { width: 84px; background: var(--bg); border: 1px solid var(--line); color: var(--text); font-family: var(--mono); font-size: 13px; padding: 3px 6px; border-radius: 6px; text-align: right; font-variant-numeric: tabular-nums; }
.num:focus { outline: none; border-color: var(--c); }
.unit { font-family: var(--mono); font-size: 12px; color: var(--muted); width: 18px; }
.el .warn { font-size: 11.5px; color: var(--warn); padding-left: 38px; line-height: 1.4; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; margin: 0; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(var(--c), var(--c)) 0 0 / var(--p) 100% no-repeat, var(--line); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--c); margin-top: -6px; border: 3px solid var(--panel); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--c); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--c); border: 3px solid var(--panel); }
input[type=range]:focus-visible { outline: 2px solid var(--c); outline-offset: 2px; border-radius: 4px; }

/* 諸元 */
.ro { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.ro > div { background: var(--panel); padding: 7px 10px; }
.ro small { display: block; color: var(--muted); font-size: 11.5px; }
.ro span { font-family: var(--mono); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.sv { margin-top: 8px; font-family: var(--mono); font-size: 12px; color: var(--text2); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; overflow-x: auto; white-space: pre; font-variant-numeric: tabular-nums; }
.alert { margin-top: 8px; font-size: 12.5px; border-radius: 8px; padding: 7px 10px; border: 1px solid; }
.alert.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: color-mix(in srgb, var(--bad) 8%, transparent); }
.alert.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 7%, transparent); }

/* 用語集 */
.gl { display: grid; gap: 2px; margin: 0; }
.gl .t { padding: 8px 10px; border-radius: 10px; cursor: pointer; transition: background .2s; }
.gl .t:hover, .gl .t.on { background: var(--panel2); }
.gl .t.pin { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 55%, transparent); }
.gl dt { font-weight: 700; font-size: 13.5px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.gl dt .en { font-family: var(--mono); font-weight: 400; font-size: 11.5px; color: var(--muted); }
.gl dt .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); align-self: center; }
.gl dd { margin: 3px 0 0; font-size: 12.5px; color: var(--text2); text-wrap: pretty; }
.gl dd b { color: var(--text); font-weight: 500; }
.fig { margin: 6px 0 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; }
.fig svg { display: block; width: 100%; min-width: 300px; height: auto; }

/* 言語切り替え */
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg.lang { background: var(--bg); backdrop-filter: none; }
.seg.lang button { padding: 4px 9px; font-size: 11.5px; }

/* J2 摂動 */
.j2 { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: color-mix(in srgb, var(--c-j2) 4%, var(--panel)); }
.j2.on { border-color: color-mix(in srgb, var(--c-j2) 45%, var(--line)); }
.switch { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 10px; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 38px; height: 22px; border-radius: 11px; background: var(--line); position: relative; transition: background .2s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--text); transition: transform .2s; }
.switch input:checked + .track { background: var(--c-j2); }
.switch input:checked + .track::after { transform: translateX(16px); background: var(--bg); }
.switch input:focus-visible + .track { outline: 2px solid var(--c-j2); outline-offset: 2px; }
.switch-text b { display: block; font-size: 13.5px; }
.switch-text small { display: block; color: var(--muted); font-size: 12px; }
.j2-hint, .j2-note { margin: 0; font-size: 12.5px; color: var(--text2); text-wrap: pretty; }
.j2-note.muted { color: var(--muted); font-size: 12px; }
.j2-note:empty { display: none; }
.j2-body { display: grid; gap: 8px; }
.ro > .wide { grid-column: 1 / -1; }
.ghost-btn { justify-self: start; background: none; border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 5px 11px; font-size: 12.5px; cursor: pointer; }
.ghost-btn:hover { border-color: var(--faint); }
.ghost-btn:focus-visible { outline: 2px solid var(--c-j2); outline-offset: 1px; }

footer { color: var(--faint); font-size: 11.5px; font-family: var(--mono); line-height: 1.6; }
footer a { color: var(--muted); }

/* ---------- 狭い画面：縦積み ---------- */
@media (max-width: 860px) {
  html, body { height: auto; }
  .app { grid-template-columns: 1fr; height: auto; }
  .view { display: flex; flex-direction: column; }
  .stage { position: relative; inset: auto; height: 60vh; min-height: 340px; }
  .explain { position: static; width: auto; margin: 12px 16px 0; }
  .panel { border-left: 0; overflow: visible; }
}
@media (prefers-reduced-motion: reduce) { .lbl, .el, .gl .t, .switch .track, .switch .track::after { transition: none; } }
