:root {
  --ink: #211b16;
  --muted: #756b60;
  --cream: #fbf7ed;
  --paper: #fffdf8;
  --gold: #f5b800;
  --gold-dark: #d89b00;
  --green: #147a57;
  --red: #c44738;
  --line: #e8dece;
  --shadow: 0 18px 45px rgba(72, 49, 13, .12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 5%, rgba(245,184,0,.16), transparent 30rem),
    linear-gradient(180deg, #fffaf0 0, var(--cream) 34rem);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  min-height: 100vh;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  max-width: 980px;
  margin: auto;
  padding: 24px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  border-radius: 12px; background: var(--gold); font: 900 24px Georgia, serif;
  box-shadow: 4px 4px 0 var(--ink);
}
.brand strong, .brand span { display: block; }
.brand div > span { font-size: 12px; color: var(--muted); margin-top: 2px; }
.text-button { border: 0; background: transparent; color: var(--muted); padding: 8px; }
.text-button:hover { color: var(--ink); }

main { max-width: 850px; margin: 0 auto; padding: 20px 22px 60px; }
.screen { display: none; }
.screen.active { display: block; animation: rise .28s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.hero { text-align: center; padding: 46px 0 36px; }
.eyebrow { color: var(--gold-dark); font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.hero h1 { font-size: clamp(38px, 7vw, 70px); line-height: 1.08; letter-spacing: -.04em; margin: 12px 0 18px; }
.hero > p:last-child { max-width: 570px; margin: auto; color: var(--muted); line-height: 1.8; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stats-grid article { background: rgba(255,255,255,.75); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.stats-grid span { display: block; font-size: 27px; font-weight: 900; }
.stats-grid small { color: var(--muted); }
.stats-grid .wrong-stat span { color: var(--red); }

.panel, .question-card, .summary-card { background: var(--paper); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.controls { padding: 28px; }
fieldset { padding: 0; margin: 0 0 22px; border: 0; }
legend, .control-row label { font-weight: 800; margin-bottom: 10px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 12px 8px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); }
.segmented input:checked + span { color: var(--ink); border-color: var(--gold-dark); background: #fff3c4; font-weight: 800; }
.control-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.control-row label { display: flex; flex-direction: column; gap: 8px; }
select, #answerInput { width: 100%; border: 1px solid #d8cbb9; border-radius: 12px; background: white; color: var(--ink); padding: 13px 14px; }
.check-row { display: flex; gap: 10px; align-items: center; margin: 10px 0 22px; color: var(--muted); }
.check-row input { width: 18px; height: 18px; accent-color: var(--gold-dark); }
.primary, .secondary { width: 100%; border-radius: 14px; padding: 15px 18px; font-weight: 900; border: 1px solid var(--ink); }
.primary { background: var(--gold); color: var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.primary:hover { background: #ffc81c; transform: translate(-1px,-1px); box-shadow: 5px 5px 0 var(--ink); }
.primary:active { transform: translate(3px,3px); box-shadow: 1px 1px 0 var(--ink); }
.secondary { background: white; color: var(--ink); }
.message { color: var(--red); min-height: 1.5em; }

.quiz-head { display: flex; justify-content: space-between; align-items: center; margin-top: 24px; font-weight: 800; }
.back { padding-left: 0; }
.progress { height: 7px; border-radius: 99px; background: #eadfcd; overflow: hidden; margin: 10px 0 26px; }
.progress span { display: block; width: 0; height: 100%; background: var(--gold); transition: width .25s ease; }
.question-card { padding: clamp(24px, 6vw, 52px); }
.question-card h2 { font-size: clamp(25px, 4.5vw, 38px); line-height: 1.55; margin: 12px 0 36px; }
.term-with-reading { white-space: nowrap; }
.term-with-reading strong { font-weight: 900; }
.question-card h2 .term-with-reading { white-space: normal; }
#answerForm label { display: block; font-weight: 800; margin-bottom: 8px; }
#answerInput { font-size: 20px; padding: 16px; margin-bottom: 14px; }
#answerInput:focus { outline: 3px solid rgba(245,184,0,.3); border-color: var(--gold-dark); }

.feedback { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 26px; }
.result-badge { display: inline-block; border-radius: 99px; padding: 8px 14px; font-weight: 900; margin-bottom: 20px; }
.result-badge.correct { color: var(--green); background: #e3f5ed; }
.result-badge.wrong { color: var(--red); background: #fae9e5; }
.answer-block, .explanation-block { margin-bottom: 19px; }
.answer-block span, .explanation-block span { display: block; color: var(--muted); font-size: 13px; font-weight: 800; margin-bottom: 6px; }
.answer-block strong { font-size: 25px; }
.explanation-block p { line-height: 1.8; margin: 0; }
.memory-tip {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 13px;
  align-items: start;
  margin: 22px 0;
  padding: 16px;
  border-left: 5px solid var(--gold-dark);
  border-radius: 10px 16px 16px 10px;
  background: #fff2bf;
}
.memory-tip[hidden] { display: none; }
.memory-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ink);
  color: white;
  font-weight: 900;
}
.memory-tip div > span { display: block; color: #8b6200; font-size: 12px; font-weight: 900; margin: 2px 0 4px; }
.memory-tip p { margin: 0; line-height: 1.7; font-weight: 700; }
.related-block {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 16px;
  align-items: center;
  margin: 24px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffaf0;
}
.related-visual {
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  border-radius: 15px;
  background: linear-gradient(145deg, #ffe58a, var(--gold));
  font-size: 39px;
  box-shadow: inset 0 0 0 1px rgba(33,27,22,.08);
}
.related-content > span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; margin-bottom: 4px; }
.related-content > strong { display: block; margin-bottom: 10px; line-height: 1.45; }
.related-links { display: flex; flex-wrap: wrap; gap: 8px; }
.related-links a {
  color: var(--ink);
  background: white;
  border: 1px solid #d8cbb9;
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}
.related-links a:hover { border-color: var(--gold-dark); background: #fff3c4; }
.override { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; margin: 22px 0; }
.override button { border: 1px solid var(--line); border-radius: 9px; background: white; padding: 7px 10px; }
.override button.active { border-color: var(--ink); background: var(--ink); color: white; }

.summary-card { max-width: 620px; margin: 70px auto 0; padding: 48px; text-align: center; }
.summary-icon { display: grid; place-items: center; width: 70px; height: 70px; border-radius: 50%; background: #e3f5ed; color: var(--green); font-size: 38px; font-weight: 900; margin: 0 auto 24px; }
.summary-card h2 { font-size: 36px; margin: 8px 0 12px; }
.summary-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.7; }
.summary-actions { display: grid; gap: 12px; margin-top: 30px; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }

@media (max-width: 600px) {
  .topbar { padding: 18px 16px; }
  .topbar #resetHistory { font-size: 12px; }
  main { padding: 0 14px 44px; }
  .hero { padding: 30px 0 26px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .controls { padding: 20px; }
  .segmented { grid-template-columns: 1fr; }
  .control-row { grid-template-columns: 1fr; }
  .question-card { border-radius: 18px; }
  .summary-card { margin-top: 35px; padding: 30px 22px; }
  .override { flex-wrap: wrap; }
  .related-block { grid-template-columns: 58px 1fr; padding: 13px; }
  .related-visual { width: 58px; height: 58px; font-size: 30px; }
}

#learningPanel label{display:block;margin:12px 0} #learningPanel select,#learningPanel textarea,#learningPanel input{width:100%;box-sizing:border-box;margin-top:6px} #learningPanel textarea{min-height:70px;padding:10px} #learningPanel details{margin:16px 0} #learningPanel .practice{border-top:1px solid #ddd;padding:16px 0} #learningPanel .learning-status{font-weight:bold;padding:12px;background:#f1f1f1} #learningPanel button{margin:8px 8px 8px 0} #learningPanel .notice{font-size:13px;color:#555}

/* Small screens and installed iPhone layout. */
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.install-help { max-width: 720px; margin: 16px auto; padding: 20px; line-height: 1.7; }
#learningPanel { min-width: 0; padding: 16px; }
#learningPanel input, #learningPanel textarea, #learningPanel select { font-size: 16px; min-width: 0; }
#learningPanel button, #learningPanel summary, .related-links a { min-height: 44px; }
#learningPanel button { padding: 10px; }
.question-card, .related-content, .practice { min-width: 0; overflow-wrap: anywhere; }
@media (display-mode: standalone) { .install-help > p:first-of-type { display: none; } }

.sync-panel{margin:18px 0;padding:16px;background:#fff;border:1px solid var(--line);border-radius:14px}.sync-panel p{margin:0 0 8px;font-size:15px}.sync-panel button{padding:10px 14px;min-height:44px;border:1px solid var(--line);border-radius:8px;background:#fff2bf}.sync-panel a{font-size:14px;margin-left:12px}.sync-panel small{display:block;margin-top:8px;line-height:1.6;font-size:13px;color:var(--muted)}

.format-options{grid-template-columns:1fr 1fr}.format-options small{display:block;font-size:12px;margin-top:5px;font-weight:400}.level-label{display:block;font-weight:800;margin-bottom:10px}.menu-note{font-size:13px;line-height:1.7;color:var(--muted)}.menu-count{font-weight:700;margin:16px 0 24px}.segmented input:focus-visible+span{outline:3px solid var(--green);outline-offset:2px}#choiceAnswers[hidden]{display:none}#choiceList{display:grid;gap:12px}.choice-option{display:flex!important;align-items:center;gap:10px;border:1px solid var(--line);border-radius:12px;padding:16px;min-height:52px;cursor:pointer}.choice-option:has(input:checked){background:#fff3c4;border-color:var(--gold-dark)}.choice-option:focus-within{outline:2px solid var(--green)}.choice-option input{flex-shrink:0;width:20px;height:20px;accent-color:var(--gold-dark)}.choice-option span{overflow-wrap:anywhere}#answerLabel[hidden]{display:none}

.review-record{display:grid;grid-template-columns:minmax(110px,1fr) 2fr;gap:12px;margin:18px 0}.review-record dt{color:var(--muted)}.review-record dd{margin:0;font-weight:700}#learningPanel{margin-top:24px;border-top:1px solid var(--line)}@media(max-width:450px){.review-record{grid-template-columns:1fr;gap:6px}.review-record dd{margin-bottom:10px}}
.import-panel{margin-top:10px;font-size:14px}.import-panel summary{cursor:pointer;color:var(--muted)}.import-panel textarea{width:100%;box-sizing:border-box;margin:6px 0;font:12px/1.4 ui-monospace,monospace}

/* 公開版の問題文は改行を含む（並べ替え・組み合わせの選択肢など） */
#questionText { white-space: pre-line; }

/* 公開版だけで使う部品（public-edition.js・privacy.html・terms.html） */
body.age-gate-open { overflow: hidden; }
.age-gate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(33, 27, 22, .55); }
.age-gate-card { max-width: 420px; padding: 28px; border-radius: 22px; background: var(--paper); box-shadow: var(--shadow); }
.age-gate-card h2 { margin-top: 0; }
.age-gate-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.report-row { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); }
.account-panel { margin-top: 10px; font-size: 14px; }
.text-button.danger { color: var(--red); }
.legal { max-width: 720px; margin: 0 auto; padding: 24px 20px 60px; line-height: 1.9; }
.legal h1 { font-size: 26px; }
.legal h2 { font-size: 19px; margin-top: 2em; }
.legal-links { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; }
.legal-links a { color: var(--muted); }
.age-gate-actions[hidden] { display: none; }
