* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  height: 100%;
  overflow: hidden;
  background: #f0f0f0;
  color: #222;
  font-family: 'Segoe UI', 'Meiryo', sans-serif;
}
body { display: flex; flex-direction: column; }

#header {
  flex: none;
  background: rgba(236, 236, 242, 0.97);
  border-bottom: 1px solid #bbc;
  padding: 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 10;
}
#header .row {
  display: flex;
  align-items: center;
  gap: 6px 14px;
  flex-wrap: wrap;
  min-height: 28px;
}
h1 { font-size: 13px; color: #2255cc; white-space: nowrap; margin-right: 4px; }

.education-back {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-height: 24px; padding: 2px 10px; border: 1px solid #b8c4d4; border-radius: 6px;
  background: #fff; color: #36556f; font-size: 12px; font-weight: 600; line-height: 1.2;
  text-decoration: none; white-space: nowrap;
}
.education-back:hover, .education-back:focus-visible {
  border-color: #2b6cb0; background: #eef4fb; color: #2b6cb0;
}

.ctrl { display: flex; align-items: center; gap: 5px; font-size: 11px; white-space: nowrap; }
.ctrl label { color: #444; }
.ctrl input[type=range] { width: 92px; cursor: pointer; accent-color: #3366cc; }
.ctrl .v { font-family: Consolas, monospace; color: #116611; min-width: 52px; font-size: 11px; }
.ctrl select { font-size: 11px; padding: 1px 2px; border: 1px solid #aab; border-radius: 3px; background: #fff; color: #222; cursor: pointer; }
button {
  background: #e4e8f4; color: #2255cc; border: 1px solid #aab;
  padding: 3px 9px; cursor: pointer; border-radius: 3px; font-size: 11px; white-space: nowrap;
}
button:hover { background: #d6ddf0; }
.chk { display: flex; align-items: center; gap: 3px; font-size: 11px; color: #444; white-space: nowrap; cursor: pointer; }
.chk input { cursor: pointer; accent-color: #3366cc; }

#main { flex: 1; display: flex; min-height: 0; }
#viewport { flex: 1; position: relative; min-width: 0; }
/* canvas の描画サイズが親の高さに影響しないよう、絶対配置で親いっぱいに広げる */
#c3d { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }

#sidebar {
  width: 300px; flex-shrink: 0;
  background: rgba(236, 236, 242, 0.97);
  border-left: 1px solid #bbc;
  display: flex; flex-direction: column;
  padding: 8px; gap: 6px; overflow-y: auto;
}
.pt { font-size: 11px; color: #2255cc; border-bottom: 1px solid #ccd; padding-bottom: 3px; margin-top: 2px; }
.chart { width: 100%; height: 130px; border: 1px solid #ccd; border-radius: 3px; background: #fff; flex: none; }
.ig { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.ii { background: rgba(0, 0, 0, 0.06); padding: 3px 6px; border-radius: 3px; }
.ii .lb { font-size: 9px; color: #555; margin-bottom: 1px; }
.ii .vl { font-size: 11px; font-family: Consolas, monospace; color: #116611; }
.hint { font-size: 10px; color: #555; line-height: 1.7; }
.legend { font-size: 10px; color: #555; line-height: 2; }
.legend .lrow { display: flex; flex-wrap: wrap; gap: 0 14px; } /* 似た項目は横に並べる */
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }
.legend .ln { display: inline-block; width: 16px; height: 0; border-top: 1.5px solid #444; vertical-align: 3px; }
.legend .lg { display: grid; grid-template-columns: 30px 1fr; padding: 2px 0; border-top: 1px dotted #ccd; } /* 物理量ごとのまとまり */
.legend .lg:first-child { border-top: none; }
.legend .lgt { font-weight: bold; color: #2255cc; }
.tool-links a { color: #2255cc; }

/* 狭い画面: 3D ビューの下にサイドバーを並べ、ページ全体をスクロールする */
@media (max-width: 860px) {
  html, body { overflow: auto; height: auto; }
  body { display: block; }
  #header { padding: 4px 8px; }
  #header .row { gap: 4px 12px; }
  #main { flex-direction: column; }
  #viewport { flex: none; height: min(70vh, 125vw); min-height: 300px; } /* 縦長のスマホでは余白を減らす */
  #sidebar { width: 100%; border-left: none; border-top: 1px solid #bbc; overflow-y: visible; }
  .ig { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
@media (max-width: 480px) {
  h1 { white-space: normal; font-size: 12px; }
  .ctrl input[type=range] { width: 80px; }
}
