:root {
  --bg: #EEF3FD;
  --card: #FFFFFF;
  --ink: #1C2333;
  --muted: #6B7385;
  --blue: #3B7BEA;
  --blue-2: #5B9BF5;
  --term: #1E40AF;
  --ring-track: #E6E9F0;
  --correct: #96E07E;
  --wrong: #F07A78;
  --shadow: 0 6px 22px rgba(40, 70, 140, .10);
  --radius: 28px;
  --gutter: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  min-height: 100dvh; overflow-x: hidden;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--blue-2); outline-offset: 2px; }
.defs { position: absolute; }
.boot { text-align: center; padding-top: 40vh; color: var(--muted); }

main {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) var(--gutter) calc(env(safe-area-inset-bottom) + 20px);
}

/* 共通ボタン */
.pill-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 999px;
  background: linear-gradient(135deg, var(--blue), var(--blue-2)); color: #fff; font-weight: 600;
  box-shadow: 0 4px 14px rgba(59, 123, 234, .30);
}
.pill-btn.small { padding: 8px 14px; font-size: 14px; }
.pill-btn.danger { background: linear-gradient(135deg, #E25B5B, #F08A7A); box-shadow: 0 4px 14px rgba(226, 91, 91, .25); }
.text-btn { display: block; margin: 14px auto 0; padding: 10px 20px; color: var(--muted); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; color: var(--ink); }

/* ホーム */
.home-top { display: flex; align-items: center; gap: 14px; }
.home-top .pill-btn { margin-left: auto; }
.stat { display: flex; align-items: center; gap: 4px; font-size: 15px; white-space: nowrap; }
.stat b { font-size: 20px; }
.home-title { font-size: 22px; margin: 18px 4px 8px; letter-spacing: .02em; }
.notice { background: #FFF6DB; border-radius: 14px; padding: 10px 14px; font-size: 14px; margin: 8px 0; }
.levels { display: grid; gap: 30px; margin-top: 30px; }
.level-card {
  position: relative; display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto;
  align-items: center; column-gap: 18px; row-gap: 6px; text-align: left;
  background: var(--card); border-radius: var(--radius); padding: 26px 20px 16px; box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.level-card:active { transform: scale(.98); }
.level-card:disabled { opacity: .55; }
.step-tab {
  position: absolute; top: -16px; left: 22px; background: var(--card); border-radius: 14px;
  padding: 4px 18px; font-weight: 700; font-size: 16px; box-shadow: 0 2px 8px rgba(40, 70, 140, .08);
}
.level-ring { grid-row: 1; grid-column: 1; }
.level-text { display: grid; gap: 2px; }
.level-text strong { font-size: 20px; }
.level-text span { color: var(--muted); font-size: 15px; }
.chev { font-size: 30px; color: var(--muted); line-height: 1; }
.level-foot { grid-column: 1 / -1; display: flex; justify-content: space-between; color: var(--muted); font-size: 15px; }
.mastered { font-size: 13px; }
.ring-label { font-weight: 700; font-size: 17px; fill: var(--ink); }
.meta { text-align: center; color: var(--muted); font-size: 13px; margin-top: 26px; }

/* 下から出るシート（レッスンの長さ・設定） */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(20, 30, 60, 0); display: flex; align-items: flex-end; justify-content: center;
  transition: background .2s ease; z-index: 10;
}
.sheet-backdrop.open { background: rgba(20, 30, 60, .35); }
.sheet {
  width: 100%; max-width: 560px; background: var(--card); border-radius: 28px 28px 0 0;
  padding: 10px var(--gutter) calc(env(safe-area-inset-bottom) + 16px);
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2, .8, .3, 1);
  max-height: 88dvh; overflow-y: auto;
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: #D8DCE5; margin: 0 auto 12px; }
.sheet h2 { margin: 4px 4px 2px; font-size: 20px; }
.sheet-sub { margin: 0 4px 16px; color: var(--muted); font-size: 14px; }
.length-list { display: grid; gap: 12px; }
.length-btn {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 20px; border-radius: 20px;
  background: linear-gradient(135deg, var(--blue), var(--blue-2)); color: #fff; box-shadow: 0 4px 14px rgba(59, 123, 234, .28);
}
.length-btn strong { font-size: 19px; }
.length-btn span { font-size: 14px; opacity: .95; }
.length-btn:disabled { background: #EEF0F4; color: var(--muted); box-shadow: none; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 4px; border-bottom: 1px solid #EEF0F4; }
.row.col { flex-direction: column; align-items: stretch; }
.row small { display: block; color: var(--muted); font-size: 12px; }
.row input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--blue); flex: none; }
.row input[type="range"] { width: 100%; accent-color: var(--blue); }

/* 出題 */
.quiz { display: flex; flex-direction: column; min-height: 100dvh; }
.quiz-top { display: flex; align-items: center; gap: 10px; }
.quiz-top .pill-btn { margin-left: auto; }
.quiz-count { font-size: 14px; color: var(--muted); }
.q-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  margin-top: 14px; padding: 22px 22px 26px; min-height: 38dvh; display: flex; flex-direction: column;
}
.detail { flex: 1; }
.detail p { margin: 0 0 14px; font-size: 17px; line-height: 1.55; }
.detail .ex { font-size: 18px; }
.detail .note { color: var(--muted); font-size: 15px; }
.retry { color: var(--blue); font-weight: 600; }
.term { margin: 12px 0 0; text-align: center; color: var(--term); font-size: clamp(24px, 7vw, 34px); line-height: 1.3; font-weight: 800; overflow-wrap: anywhere; }
.answer-meaning { margin: 6px 0 0; text-align: center; font-size: 16px; font-weight: 600; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.choice {
  min-height: 96px; padding: 14px 12px; border-radius: 24px; background: var(--card); box-shadow: var(--shadow);
  font-size: 16px; line-height: 1.4; overflow-wrap: anywhere; transition: background .15s ease, transform .1s ease;
}
.choice:active { transform: scale(.97); }
.choice.correct { background: var(--correct); }
.choice.wrong { background: var(--wrong); }
.quiz-foot { display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; gap: 12px; margin-top: 16px; }
.lv-badge {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700;
  background: var(--lv, var(--blue)); box-shadow: 0 4px 14px rgba(40, 70, 140, .18);
}
.lv-A1 { --lv: #3B9BE8; } .lv-A2 { --lv: #34B37A; } .lv-B1 { --lv: #E0A21B; } .lv-B2 { --lv: #E87A3B; } .lv-C1 { --lv: #D9547A; }
.main-btn { height: 64px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-size: 17px; font-weight: 500; }
.main-btn.primary { background: linear-gradient(135deg, var(--blue), var(--blue-2)); color: #fff; }
.round-btn {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue-2)); box-shadow: 0 4px 14px rgba(59, 123, 234, .30);
}
.round-btn:disabled { opacity: .4; }
.foot-note { text-align: center; color: var(--muted); font-size: 14px; min-height: 21px; margin: 8px 0 0; }

.similar { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.similar-label { width: 100%; font-size: 12px; font-weight: 700; color: var(--blue); letter-spacing: .04em; }
.sim { display: inline-flex; flex-direction: column; background: #EEF3FD; border-radius: 12px; padding: 6px 10px; line-height: 1.35; }
.sim b { color: var(--term); font-size: 15px; font-weight: 600; }
.sim small { color: var(--muted); font-size: 12px; }

/* 結果 */
.result-card { align-items: center; justify-content: center; text-align: center; gap: 8px; }
.result-card h2 { margin: 10px 0 0; font-size: 20px; }
.missed { background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 16px 18px; margin-top: 16px; }
.missed h3 { margin: 0 0 8px; font-size: 15px; color: var(--muted); }
.missed-row { display: grid; gap: 2px; padding: 8px 0; border-top: 1px solid #EEF0F4; }
.missed-row b { color: var(--term); }
.result-actions { display: grid; gap: 12px; margin-top: 18px; }

@media (max-width: 360px) {
  .home-top { gap: 8px; }
  .stat { font-size: 13px; }
  .choice { font-size: 15px; min-height: 88px; }
}
