* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0c1512;
  --card: #142420;
  --card-light: #1d332c;
  --text: #eafaf3;
  --text-dim: #93b7ab;
  --primary: #2dd4bf;
  --primary-dark: #14a08a;
  --accent: #a3e635;
  --correct: #34d399;
  --wrong: #fb7185;
  --gold: #facc15;
}

html, body { height: 100%; }

body {
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  background: linear-gradient(160deg, #0c1512 0%, #0f2320 55%, #0d1f2b 100%);
  color: var(--text);
  line-height: 1.6;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.screen { display: none; }
.screen.active { display: block; animation: fadeIn .3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== ヒーロー ===== */
.hero { text-align: center; padding: 24px 0 12px; }
.hero-badge {
  display: inline-block;
  background: var(--accent);
  color: #17250a;
  font-weight: 700;
  font-size: 12px;
  padding: 4px 14px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.hero h1 { font-size: 30px; letter-spacing: 1px; }
.hero-sub { color: var(--text-dim); font-size: 14px; margin-top: 6px; }

/* ===== 科学者ロード（遷移図） ===== */
.title-path-card { padding: 16px 16px 12px; }
.title-path-card h2 { margin-bottom: 10px; }
.title-path-wrap { overflow-x: auto; padding-bottom: 6px; }
.title-path {
  position: relative;
  display: flex;
  justify-content: space-between;
  min-width: 560px;
  padding-top: 4px;
}
.tp-track {
  position: absolute;
  top: 17px;
  left: 32px;
  right: 32px;
  height: 6px;
  background: #24463c;
  border-radius: 999px;
}
.tp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  border-radius: 999px;
  transition: width .6s ease;
}
.tp-node {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 66px;
  text-align: center;
  flex-shrink: 0;
}
.tp-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--card-light);
  border: 3px solid #2f5347;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: #fff;
}
.tp-node.done .tp-dot {
  background: var(--gold);
  border-color: var(--gold);
  color: #3a2a00;
  font-weight: 700;
}
.tp-node.current .tp-dot {
  border-color: var(--gold);
  background: #35331c;
  animation: tp-pulse 1.6s ease-in-out infinite;
}
@keyframes tp-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(250,204,21,.55); }
  50%      { box-shadow: 0 0 0 7px rgba(250,204,21,0); }
}
.tp-name {
  font-size: 10px;
  margin-top: 5px;
  color: var(--text-dim);
  line-height: 1.3;
}
.tp-node.current .tp-name { color: var(--gold); font-weight: 700; }
.tp-node.done .tp-name { color: var(--text); }
.tp-need { font-size: 9px; color: #5a7c70; }
.title-next {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
  margin-top: 8px;
}

/* ===== 統計バー ===== */
.stats-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 14px 0 4px;
}
.stat-chip {
  background: var(--card);
  border: 1px solid #2a4a40;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-dim);
}
.stat-chip b { color: var(--gold); font-size: 14px; }

/* ===== カード ===== */
.card {
  background: var(--card);
  border: 1px solid #2a4a40;
  border-radius: 16px;
  padding: 20px;
  margin: 16px 0;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.card h2 { font-size: 17px; margin-bottom: 6px; }
.hint { color: var(--text-dim); font-size: 13px; margin-bottom: 12px; }

/* ===== ボタン ===== */
.btn {
  display: inline-block;
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
  background: var(--card-light);
  transition: transform .1s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #052a24; }
.btn-accent { background: linear-gradient(135deg, #a3e635, #65a30d); color: #17250a; }
.btn-big { width: 100%; padding: 16px; font-size: 18px; margin-top: 4px; }
.btn-small { padding: 8px 14px; font-size: 13px; }
.btn-ghost { background: transparent; border: 1px solid #2f5347; color: var(--text-dim); }

.error-msg { color: var(--wrong); text-align: center; font-size: 14px; margin-top: 10px; min-height: 1.4em; }

/* ===== 分野別の成績 ===== */
.subject-stats-card { padding: 16px 18px 14px; }
.subject-stats-card h2 { margin-bottom: 10px; }
.ss-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
}
.ss-name {
  width: 74px;
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 700;
}
.ss-bar {
  flex: 1;
  height: 12px;
  background: var(--card-light);
  border-radius: 999px;
  overflow: hidden;
}
.ss-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .6s ease;
}
.ss-fill.ss-physics   { background: linear-gradient(90deg, #0891b2, #38bdf8); }
.ss-fill.ss-chemistry { background: linear-gradient(90deg, #7c3aed, #c792ea); }
.ss-fill.ss-biology   { background: linear-gradient(90deg, #16a34a, var(--accent)); }
.ss-fill.ss-earth     { background: linear-gradient(90deg, #c2560c, #fb923c); }
.ss-num {
  width: 118px;
  flex-shrink: 0;
  text-align: right;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}
.ss-num small { font-weight: 400; font-size: 10px; color: var(--text-dim); }
.ss-weak {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--wrong);
  background: #3d2029;
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}
.ss-weak.clear { color: var(--correct); background: #123829; }

@media (max-width: 480px) {
  .ss-row { flex-wrap: wrap; gap: 6px; }
  .ss-bar { order: 3; flex-basis: 100%; }
}

/* ===== 分野タブ ===== */
.subject-tabs {
  display: flex;
  gap: 8px;
  margin: 10px 0 12px;
}
.subject-tab {
  flex: 1;
  position: relative;
  background: var(--card-light);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 11px 4px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.subject-tab:hover { color: var(--text); }
.subject-tab.active {
  border-color: var(--accent);
  background: #26331a;
  color: var(--text);
}
.tab-badge {
  display: inline-block;
  margin-left: 5px;
  background: var(--primary);
  color: #052a24;
  font-size: 11px;
  border-radius: 999px;
  padding: 1px 7px;
  vertical-align: middle;
}

/* ===== 範囲選択 ===== */
.range-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

.era-group { margin-bottom: 10px; }
.era-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin: 10px 0 6px;
  letter-spacing: 1px;
}
.unit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.unit-check {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-light);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  transition: border-color .15s ease, background .15s ease;
}
.unit-check input { display: none; }
.unit-check .box {
  width: 18px; height: 18px;
  border: 2px solid #3f6357;
  border-radius: 5px;
  flex-shrink: 0;
  display: grid; place-items: center;
  font-size: 12px;
  color: transparent;
}
.unit-check.checked { border-color: var(--primary); background: #16453c; }
.unit-check.checked .box { background: var(--primary); border-color: var(--primary); color: #052a24; }
.unit-check .qcount { margin-left: auto; font-size: 11px; color: var(--text-dim); }

/* ===== 問題数 ===== */
.count-options { display: flex; gap: 10px; }
.count-btn {
  flex: 1;
  background: var(--card-light);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 12px 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.count-btn span { display: block; font-size: 11px; font-weight: 400; color: var(--text-dim); }
.count-btn.selected { border-color: var(--accent); background: #26331a; }

/* ===== クイズ画面 ===== */
.quiz-header { display: flex; align-items: center; gap: 12px; padding: 12px 0 4px; }
.progress-wrap { flex: 1; display: flex; align-items: center; gap: 10px; }
.progress-bar {
  flex: 1; height: 10px;
  background: var(--card);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 999px;
  transition: width .3s ease;
}
.progress-text { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.combo { font-size: 14px; font-weight: 700; color: var(--gold); min-width: 70px; text-align: right; }

.quiz-card { min-height: 320px; }
.q-meta { font-size: 12px; color: var(--accent); font-weight: 700; margin-bottom: 8px; }
.q-text { font-size: 17px; font-weight: 600; margin-bottom: 18px; }

.choices { display: flex; flex-direction: column; gap: 10px; }
.choice-btn {
  text-align: left;
  background: var(--card-light);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.choice-btn:hover { border-color: #3f6357; }
.choice-btn.correct { border-color: var(--correct); background: #123829; }
.choice-btn.wrong { border-color: var(--wrong); background: #3d2029; }
.choice-btn:disabled { cursor: default; opacity: .85; }
.choice-btn .mark { font-weight: 700; margin-right: 8px; color: var(--accent); }

/* ===== 並べ替え ===== */
.order-picked {
  min-height: 44px;
  border: 2px dashed #2f5347;
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.order-picked .picked-item {
  background: #16453c;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 14px;
}
.order-picked .picked-item .num { color: var(--gold); font-weight: 700; margin-right: 8px; }
.order-items { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.order-item-btn {
  background: var(--card-light);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.order-item-btn:hover { border-color: #3f6357; }
.order-item-btn.used { opacity: .25; pointer-events: none; }

/* ===== 記述問題 ===== */
.input-row { display: flex; gap: 8px; }
.input-answer {
  flex: 1;
  background: var(--card-light);
  border: 2px solid #2f5347;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
}
.input-answer:focus { outline: none; border-color: var(--primary); }
.input-answer:disabled { opacity: .6; }

.essay-answer {
  width: 100%;
  background: var(--card-light);
  border: 2px solid #2f5347;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  resize: vertical;
  margin-bottom: 10px;
}
.essay-answer:focus { outline: none; border-color: var(--primary); }
.essay-answer:disabled { opacity: .6; }

.essay-model {
  margin-top: 14px;
  background: var(--card-light);
  border-left: 4px solid var(--correct);
  border-radius: 8px;
  padding: 12px 14px;
}
.essay-model-label { font-size: 12px; font-weight: 700; color: var(--correct); margin-bottom: 4px; }
.essay-model p { font-size: 14px; }
.essay-keywords { margin-top: 8px; font-size: 12px; color: var(--text-dim); }
.essay-keywords .kw {
  display: inline-block;
  background: #26331a;
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 10px;
  margin: 2px 4px 2px 0;
  font-weight: 700;
}
.essay-judge-row { display: flex; gap: 10px; margin-top: 8px; }
.essay-judge { flex: 1; }
.judge-ok { background: #123829; border: 2px solid var(--correct); }
.judge-ng { background: #3d2029; border: 2px solid var(--wrong); }

/* ===== フィードバック ===== */
.feedback { margin-top: 18px; border-top: 1px solid #2a4a40; padding-top: 14px; }
.feedback-result { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.feedback-result.ok { color: var(--correct); }
.feedback-result.ng { color: var(--wrong); }
.feedback-exp {
  background: var(--card-light);
  border-left: 4px solid var(--gold);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: #d6ece2;
  margin-bottom: 14px;
}

#btn-quit { margin-top: 14px; }

/* ===== 結果 ===== */
.result-card { text-align: center; padding: 32px 20px; }
.result-emoji { font-size: 52px; }
.score-circle {
  width: 150px; height: 150px;
  margin: 16px auto;
  border-radius: 50%;
  background: var(--card-light);
  border: 6px solid var(--primary);
  display: grid;
  place-content: center;
}
.score-circle.perfect { border-color: var(--gold); box-shadow: 0 0 30px rgba(250,204,21,.45); }
.score-circle #score-value { font-size: 48px; font-weight: 800; line-height: 1; }
.score-circle small { color: var(--text-dim); }
.result-message { font-size: 16px; font-weight: 600; margin-bottom: 8px; white-space: pre-line; }
.title-up { color: var(--gold); font-weight: 700; font-size: 14px; min-height: 1.4em; margin-bottom: 8px; }

.wrong-review { text-align: left; margin: 18px 0; }
.wrong-review h3 { font-size: 14px; color: var(--wrong); margin-bottom: 8px; }
.wrong-review .wrong-item {
  background: var(--card-light);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 8px;
}
.wrong-review .wrong-item .wq { font-weight: 600; }
.wrong-review .wrong-item .wa { color: var(--correct); margin-top: 2px; }

.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

/* ===== 紙吹雪 ===== */
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 99;
}

@media (max-width: 480px) {
  .unit-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 24px; }
  .subject-tab { font-size: 13px; }
}
