:root {
  --navy: #152238;
  --blue: #3569e8;
  --blue-dark: #2453c2;
  --pale-blue: #edf3ff;
  --cream: #fbfaf7;
  --white: #ffffff;
  --text: #182235;
  --muted: #687386;
  --line: #dfe5ee;
  --green: #16865c;
  --green-bg: #e8f7f0;
  --red: #c84242;
  --red-bg: #fff0f0;
  --shadow: 0 18px 50px rgba(24, 34, 53, 0.10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 8%, rgba(53, 105, 232, .09), transparent 25rem),
    var(--cream);
  font-family: "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
}

button { font: inherit; }

.site-header {
  height: 68px;
  padding: 0 max(24px, calc((100vw - 960px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(24, 34, 53, .08);
  background: rgba(251, 250, 247, .88);
  backdrop-filter: blur(12px);
}

.brand { color: var(--navy); font-weight: 800; text-decoration: none; letter-spacing: .02em; }
.subject-chip { padding: 7px 12px; border-radius: 99px; color: var(--blue-dark); background: var(--pale-blue); font-size: 13px; font-weight: 700; }
.site-nav { display: flex; align-items: center; gap: 6px; }
.site-nav a { padding: 8px 11px; border-radius: 9px; color: var(--muted); font-size: 13px; font-weight: 800; text-decoration: none; }
.site-nav a:hover, .site-nav a.active { color: var(--blue-dark); background: var(--pale-blue); }

.page-shell { width: min(720px, calc(100% - 32px)); margin: 52px auto 40px; }
.panel { background: var(--white); border: 1px solid rgba(24, 34, 53, .08); border-radius: 24px; box-shadow: var(--shadow); }
.hidden { display: none !important; }

.start-panel { padding: 56px; text-align: center; }
.eyebrow { margin: 0 0 14px; color: var(--blue); font-size: 13px; font-weight: 900; letter-spacing: .15em; }
h1 { margin: 0; font-size: clamp(34px, 7vw, 54px); line-height: 1.25; letter-spacing: -.04em; }
h1 span { color: var(--blue); }
.lead { max-width: 520px; margin: 24px auto 30px; color: var(--muted); font-size: 16px; line-height: 1.9; }
.course-selectors { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 24px; text-align: left; }
.course-selectors label { display: flex; flex-direction: column; gap: 7px; }
.course-selectors label > span { color: var(--muted); font-size: 12px; font-weight: 800; }
.course-selectors select { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); background: var(--white); font: inherit; font-weight: 700; }
.course-selectors select:focus { border-color: var(--blue); outline: 3px solid rgba(53, 105, 232, .12); }
.feature-row { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 0 34px; padding: 22px 0; border-block: 1px solid var(--line); }
.feature-row div { display: flex; flex-direction: column; gap: 5px; }
.feature-row div + div { border-left: 1px solid var(--line); }
.feature-row strong { font-size: 20px; }
.feature-row span { color: var(--muted); font-size: 12px; }

.primary-button { width: 100%; padding: 16px 24px; border: 0; border-radius: 13px; color: white; background: var(--blue); box-shadow: 0 8px 20px rgba(53, 105, 232, .24); font-weight: 800; cursor: pointer; transition: .18s ease; }
.primary-button:hover { background: var(--blue-dark); transform: translateY(-1px); }
.primary-button:disabled { opacity: .65; cursor: wait; transform: none; }

.quiz-panel { padding: 36px 42px 42px; }
.progress-header { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; font-weight: 700; }
.progress-track { height: 7px; margin: 12px 0 28px; overflow: hidden; border-radius: 99px; background: var(--line); }
#progress-bar { height: 100%; width: 0; border-radius: inherit; background: var(--blue); transition: width .3s ease; }
.question-meta { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
#question-type { padding: 5px 9px; border-radius: 7px; color: var(--blue-dark); background: var(--pale-blue); font-size: 12px; font-weight: 800; }
#difficulty { color: #e3a323; font-size: 13px; letter-spacing: .1em; }
.question-text { min-height: 68px; margin: 0 0 28px; font-size: clamp(20px, 4vw, 25px); line-height: 1.65; }
.choices { display: grid; gap: 12px; }
.choice-button { width: 100%; min-height: 58px; padding: 10px 16px; display: flex; align-items: center; gap: 14px; border: 1px solid var(--line); border-radius: 13px; color: var(--text); background: var(--white); text-align: left; cursor: pointer; transition: .16s ease; }
.choice-button:hover:not(:disabled) { border-color: var(--blue); background: var(--pale-blue); transform: translateX(3px); }
.choice-letter { flex: 0 0 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; color: var(--blue-dark); background: var(--pale-blue); font-weight: 900; }
.choice-text { font-weight: 700; }
.choice-button.correct { border-color: var(--green); background: var(--green-bg); }
.choice-button.correct .choice-letter { color: white; background: var(--green); }
.choice-button.incorrect { border-color: var(--red); background: var(--red-bg); }
.choice-button.incorrect .choice-letter { color: white; background: var(--red); }

.feedback { margin-top: 24px; padding: 22px; border-radius: 15px; background: #f7f9fc; border: 1px solid var(--line); }
.feedback-title { margin-bottom: 12px; font-size: 20px; font-weight: 900; }
.feedback-title.is-correct { color: var(--green); }
.feedback-title.is-incorrect { color: var(--red); }
.formula-label { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.formula-label strong { color: var(--text); }
.explanation { margin-bottom: 20px; line-height: 1.8; }
.feedback .primary-button { padding: 13px 20px; }

.result-panel { padding: 48px; text-align: center; }
.result-panel h2 { margin: 0 0 26px; font-size: 30px; }
.score-circle { width: 150px; height: 150px; margin: 0 auto 22px; display: grid; place-content: center; border: 10px solid var(--pale-blue); border-radius: 50%; color: var(--blue); }
.score-circle strong { font-size: 50px; line-height: 1; }
.score-circle span { margin-top: 4px; font-weight: 800; }
.score-message { color: var(--muted); line-height: 1.8; }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 26px 0; }
.result-stats div { padding: 18px; display: flex; flex-direction: column; gap: 7px; border-radius: 12px; background: #f7f9fc; }
.result-stats span { color: var(--muted); font-size: 12px; }
.result-stats strong { font-size: 18px; }

footer { padding: 20px; color: var(--muted); text-align: center; font-size: 12px; }

.library-shell { width: min(960px, calc(100% - 32px)); margin: 42px auto 60px; }
.library-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 28px; }
.library-heading h1 { margin: 0 0 10px; font-size: clamp(30px, 6vw, 46px); }
.library-heading p:not(.eyebrow) { margin: 0; color: var(--muted); }
.compact-button { width: auto; flex: 0 0 auto; padding: 13px 20px; color: white; text-decoration: none; }
.library-filters { padding: 24px; display: grid; gap: 18px; border: 1px solid rgba(24, 34, 53, .08); border-radius: 18px; background: var(--white); box-shadow: 0 10px 30px rgba(24, 34, 53, .06); }
.filter-group { display: grid; grid-template-columns: 64px 1fr; align-items: start; gap: 12px; }
.filter-group > span { padding-top: 7px; color: var(--muted); font-size: 12px; font-weight: 900; }
.filter-links { display: flex; flex-wrap: wrap; gap: 7px; }
.filter-links a { padding: 7px 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--white); font-size: 13px; font-weight: 700; text-decoration: none; }
.filter-links a:hover { border-color: var(--blue); }
.filter-links a.selected { border-color: var(--blue); color: var(--blue-dark); background: var(--pale-blue); }
.filter-links small { margin-left: 4px; color: var(--muted); font-size: 10px; }
.unit-overview { margin-top: 24px; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.unit-card { min-height: 150px; padding: 24px; display: flex; flex-direction: column; justify-content: center; gap: 8px; border: 1px solid rgba(24, 34, 53, .09); border-radius: 18px; color: var(--text); background: var(--white); box-shadow: 0 8px 24px rgba(24, 34, 53, .055); text-decoration: none; transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease; }
.unit-card:hover { transform: translateY(-2px); border-color: var(--blue); box-shadow: 0 12px 28px rgba(43, 101, 217, .12); }
.unit-card-label { color: var(--blue); font-size: 12px; font-weight: 900; }
.unit-card strong { font-size: 25px; }
.unit-card > span:last-child { color: var(--muted); font-size: 13px; font-weight: 700; }
.library-toolbar { margin: 28px 0 14px; display: flex; align-items: center; justify-content: space-between; }
.library-toolbar > strong { font-size: 18px; }
.library-toolbar div { display: flex; gap: 8px; }
.library-toolbar button { padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: var(--white); font-size: 12px; font-weight: 800; cursor: pointer; }
.library-toolbar button:hover { border-color: var(--blue); color: var(--blue-dark); }
.question-list { display: grid; gap: 16px; }
.library-question { padding: 26px 30px; border: 1px solid rgba(24, 34, 53, .09); border-radius: 18px; background: var(--white); box-shadow: 0 8px 24px rgba(24, 34, 53, .055); }
.library-question-header { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; }
.question-number { color: var(--blue); font-size: 13px; font-weight: 900; }
.question-tag { padding: 4px 8px; border-radius: 6px; color: var(--blue-dark); background: var(--pale-blue); font-size: 11px; font-weight: 800; }
.question-difficulty { margin-left: auto; color: #e3a323; font-size: 12px; letter-spacing: .08em; }
.library-question h2 { margin: 0 0 18px; font-size: 19px; line-height: 1.7; }
.library-choices { margin: 0 0 20px; padding-left: 34px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 28px; }
.library-choices li { padding-left: 5px; line-height: 1.6; }
.answer-details { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #f8fafc; }
.answer-details summary { padding: 13px 16px; color: var(--blue-dark); font-size: 13px; font-weight: 900; cursor: pointer; list-style-position: inside; }
.answer-details[open] summary { border-bottom: 1px solid var(--line); }
.answer-content { padding: 18px; }
.answer-line { margin: 0 0 10px; display: flex; align-items: baseline; gap: 10px; }
.answer-line > span { padding: 3px 7px; border-radius: 5px; color: white; background: var(--green); font-size: 11px; font-weight: 900; }
.point-line { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.point-line strong { color: var(--text); }
.library-explanation { line-height: 1.9; }
.diagram-figure { margin: 18px 0 0; }
.math-diagram { width: min(100%, 680px); height: auto; display: block; margin: 16px auto 0; border: 1px solid var(--line); border-radius: 12px; background: white; }
.diagram-figure figcaption { margin-top: 8px; color: var(--muted); font-size: 12px; text-align: center; }
.empty-library { padding: 50px; color: var(--muted); text-align: center; }

@media (max-width: 600px) {
  .site-header { height: 60px; padding-inline: 16px; }
  .brand { font-size: 14px; }
  .subject-chip { display: none; }
  .site-nav { gap: 2px; }
  .site-nav a { padding: 7px 8px; font-size: 11px; }
  .page-shell { margin-top: 24px; }
  .start-panel, .quiz-panel, .result-panel { padding: 28px 20px; border-radius: 18px; }
  .feature-row { margin-bottom: 26px; }
  .course-selectors { grid-template-columns: 1fr; }
  .feature-row strong { font-size: 16px; }
  .question-text { min-height: auto; }
  .choice-button { padding-inline: 12px; }
  .library-shell { margin-top: 24px; }
  .library-heading { align-items: stretch; flex-direction: column; gap: 18px; }
  .compact-button { width: 100%; text-align: center; }
  .library-filters { padding: 18px; }
  .filter-group { grid-template-columns: 1fr; gap: 7px; }
  .filter-group > span { padding-top: 0; }
  .library-toolbar { align-items: flex-start; gap: 12px; }
  .library-toolbar div { flex-direction: column; }
  .library-question { padding: 21px 18px; }
  .library-choices { grid-template-columns: 1fr; }
}
