:root { color: #1b2434; background: #f7f9fd; font-family: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; line-height: 1.6; }
* { box-sizing: border-box; }
body { margin: 0; }
.lab { max-width: 1180px; margin: 0 auto; padding: 22px 20px 28px; }
header { margin-bottom: 14px; }
.eyebrow { margin: 0; color: #8a6212; font-size: 11px; font-weight: 800; letter-spacing: .13em; }
h1 { margin: 4px 0 6px; font-size: 24px; }
header > p:last-child { margin: 0; color: #56627a; }
h3 { margin: 0 0 8px; font-size: 15px; color: #8a6212; }
button { min-height: 44px; padding: 9px 13px; border: 1px solid #c3cddd; border-radius: 10px; background: #fff; color: #1b2434; font: inherit; font-weight: 650; cursor: pointer; }
button:hover { border-color: #c39432; }
button.primary, button.active { border-color: #c39432; background: #c39432; color: #fff; }
button:disabled { cursor: default; opacity: .85; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 18px; align-items: start; }

.scene { position: relative; height: 500px; min-height: 500px; overflow: hidden; border: 1px solid #d6dded; border-radius: 14px; background: #f4f6fb; touch-action: none; }
.scene canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.scene canvas:active { cursor: grabbing; }
.scene-message { position: absolute; inset: 0; display: grid; margin: 0; padding: 20px; place-content: center; color: #56627a; font-size: 14px; text-align: center; }
.scene-footer { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 8px; }
.scene-hint { margin: 0; color: #56627a; font-size: 12px; }
.scene-footer button { min-height: 38px; padding: 6px 12px; font-size: 13px; }
.legend-row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-top: 10px; line-height: 1.3; }
.legend { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 6px; white-space: nowrap; color: #56627a; font-size: 12px; }
.legend::before { flex: 0 0 auto; width: 13px; height: 13px; border-radius: 50%; content: ""; }
.legend-dominant::before { background: #d9a441; }
.legend-recessive::before { background: #6a8fbf; }
.legend-round::before { background: #d9a441; }
.legend-wrinkled::before { background: #8a9a6b; }

.panel-body { display: grid; gap: 13px; }
.controls-row { display: flex; flex-wrap: wrap; gap: 8px; }
.selectors { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.field { display: grid; gap: 5px; font-size: 14px; font-weight: 650; }
.field select { min-height: 44px; padding: 9px 11px; border: 1px solid #c3cddd; border-radius: 10px; background: #fff; color: #1b2434; font: inherit; font-weight: 650; }

.readout { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 9px; }
.readout > div { display: grid; gap: 2px; padding: 10px 12px; border-radius: 11px; background: #fdf3e0; }
.readout small { color: #56627a; font-size: 12px; }
.readout b { font-size: 17px; color: #8a6212; }

.answer-box { display: grid; gap: 3px; padding: 14px 16px; border-radius: 12px; background: #fdf3e0; border-left: 4px solid #c39432; }
.answer-box small { color: #56627a; font-size: 12px; }
.answer-box b { font-size: 22px; color: #8a6212; }

.rule-card { padding: 14px 16px; border-radius: 12px; background: #f1f4fa; }
.rule-card p { margin: 0 0 8px; font-size: 14px; }
.rule-card p:last-child { margin-bottom: 0; }

.hint { padding: 13px 15px; border-left: 4px solid #3f7fd6; border-radius: 0 10px 10px 0; background: #eef3fb; }
.hint b { display: block; margin-bottom: 4px; color: #2c62ad; }
.hint p { margin: 0; font-size: 14px; }
.hint.warn { border-left-color: #e0a33a; background: #fdf5e6; }
.hint.warn b { color: #a8741a; }
.note { margin: 6px 0 0; color: #56627a; font-size: 13px; }

/* --- かけ合わせの表 --- */
.grid-table { padding: 14px 16px; border-radius: 12px; background: #f1f4fa; }
.grid-table table { width: 100%; border-collapse: separate; border-spacing: 6px; }
.grid-table th { width: 52px; padding: 8px; border-radius: 9px; background: #e3e9f3; font-size: 17px; font-weight: 800; }
.grid-table th.allele-A { background: #d9a441; color: #fff; }
.grid-table th.allele-a { background: #6a8fbf; color: #fff; }
.cell { padding: 11px 8px; border-radius: 10px; text-align: center; cursor: pointer; transition: transform .15s ease; }
.cell:hover { transform: translateY(-2px); }
.cell b { display: block; font-size: 18px; }
.cell small { display: block; margin-top: 2px; font-size: 12px; }
.cell.dominant { background: #faf0dc; color: #8a6212; }
.cell.recessive { background: #e7ecdd; color: #4c5c38; }

.counts { padding: 14px 16px; border-radius: 12px; background: #f1f4fa; }
.count-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.count-cell { display: grid; gap: 2px; justify-items: center; padding: 10px; border-radius: 10px; background: #fff; }
.count-cell.zero { opacity: .45; }
.count-cell .tag { padding: 2px 9px; border-radius: 999px; background: #eef2f8; font-size: 12px; font-weight: 700; }
.count-cell b { font-size: 21px; color: #8a6212; }
.count-cell small { color: #56627a; font-size: 11px; }

/* --- 3世代 --- */
.generation-flow { display: grid; gap: 7px; }
.gen { padding: 13px 15px; border-radius: 12px; background: #f1f4fa; }
.gen.highlight { background: #fdf3e0; }
.gen-tag { display: inline-block; margin-bottom: 4px; padding: 2px 10px; border-radius: 999px; background: #e3e9f3; color: #56627a; font-size: 12px; font-weight: 700; }
.gen.highlight .gen-tag { background: #f0dcb4; color: #8a6212; }
.gen b { display: block; font-size: 18px; }
.gen p { margin: 5px 0 0; font-size: 14px; }
.gen-arrow { color: #9aa5ba; font-size: 13px; text-align: center; }

.laws { display: grid; gap: 9px; padding: 14px 16px; border-radius: 12px; background: #f1f4fa; }
.law { padding: 11px 13px; border-radius: 10px; background: #fff; }
.law.advanced { opacity: .82; }
.law-head { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.law-head b { font-size: 15px; }
.law-head span { padding: 1px 8px; border-radius: 999px; background: #eef2f8; color: #56627a; font-size: 11px; font-weight: 700; }
.law.advanced .law-head span { background: #f3e6d2; color: #8a6212; }
.statement { margin: 6px 0 0; font-size: 14px; font-weight: 650; }

.terms { display: grid; gap: 7px; padding: 14px 16px; border-radius: 12px; background: #f1f4fa; }
.term { padding: 9px 11px; border-radius: 9px; background: #fff; }
.term b { font-size: 14px; }
.term p { margin: 2px 0 0; color: #56627a; font-size: 13px; }

/* --- メンデルの実験 --- */
.compare-table, .traits { padding: 14px 16px; border-radius: 12px; background: #f1f4fa; overflow-x: auto; }
.compare-table table, .traits table { width: 100%; border-collapse: collapse; font-size: 14px; }
.compare-table th, .compare-table td, .traits th, .traits td { padding: 8px 10px; border-bottom: 1px solid #d6dded; text-align: right; }
.compare-table thead th, .traits thead th { background: transparent; color: #56627a; font-size: 13px; }
.compare-table tbody th, .traits tbody th { color: #56627a; font-weight: 650; text-align: left; }
.compare-table tr.diff td { color: #8a6212; font-weight: 700; }
.traits td { text-align: center; }
.traits td.dominant { color: #8a6212; font-weight: 700; }
.traits td.recessive { color: #4c5c38; }

/* --- 問題演習 --- */
.level { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; margin: 0; color: #8a6212; font-weight: 700; }
.topic { padding: 2px 9px; border-radius: 999px; background: #fdf3e0; font-size: 12px; }
.question { margin: 0; font-size: 17px; font-weight: 700; }
.choices { display: grid; gap: 9px; }
.choice { min-height: 50px; font-size: 14px; text-align: left; }
.choice.correct { border-color: #138a62; background: #e6f7ef; }
.choice.incorrect { border-color: #c64141; background: #fff0f0; }
.result { padding: 13px; border-left: 5px solid #8090aa; border-radius: 8px; background: #edf1f8; }
.result.correct { border-color: #138a62; background: #e6f7ef; }
.result.incorrect { border-color: #c64141; background: #fff0f0; }
.result b { display: block; margin-bottom: 3px; }
.result p { margin: 0; font-size: 14px; }
.steps { display: grid; gap: 11px; padding: 14px 16px; border-radius: 12px; background: #f1f4fa; }
.steps ol { margin: 0; padding-left: 1.3em; }
.steps li { margin-bottom: 6px; font-size: 14px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .scene { height: 420px; min-height: 420px; }
}
@media (max-width: 600px) {
  .lab { padding: 17px 13px; }
  .tabs button { flex: 1 1 44%; }
  .scene { height: 340px; min-height: 340px; }
  .selectors { grid-template-columns: 1fr; }
  .count-row { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .cell { transition: none; } }

@media (prefers-color-scheme: dark) {
  :root { color: #edf2ff; background: #101522; }
  header > p:last-child, .note, .scene-hint, .scene-message, .readout small, .answer-box small, .legend, .term p, .count-cell small, .gen-tag, .compare-table tbody th, .traits tbody th, .compare-table thead th, .traits thead th, .law-head span { color: #b4bfd4; }
  button, .field select { color: #edf2ff; background: #1a2232; border-color: #46536b; }
  .scene { background: #141b2b; border-color: #46536b; }
  .readout > div, .answer-box, .gen.highlight { background: #2b2415; }
  .readout b, .answer-box b, h3, .level, .count-cell b, .compare-table tr.diff td, .traits td.dominant { color: #e8c483; }
  .rule-card, .hint, .grid-table, .counts, .laws, .terms, .gen, .steps, .result, .compare-table, .traits { background: #1a2232; }
  .hint.warn { background: #2b2415; }
  .law, .term, .count-cell { background: #212a3d; }
  .grid-table th { background: #2a3348; }
  .cell.dominant { background: #33291a; color: #e8c483; }
  .cell.recessive { background: #1f2a1c; color: #b8c9a0; }
  .gen-tag, .topic, .count-cell .tag, .law-head span { background: #2a3348; }
  .compare-table th, .compare-table td, .traits th, .traits td { border-color: #46536b; }
  .traits td.recessive { color: #b8c9a0; }
  .result.correct, .choice.correct { background: #12392f; }
  .result.incorrect, .choice.incorrect { background: #431f25; }
}
