:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --ink: #172033;
  --muted: #5c677d;
  --line: #dbe3f0;
  --surface: #ffffff;
  --background: #f4f7fb;
  --success: #157347;
  --success-bg: #e9f8ef;
  --danger: #b42318;
  --danger-bg: #fff0ef;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--background);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }

.app-shell {
  width: min(100%, 680px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
}

.screen { animation: appear .2s ease-out; }
.hidden { display: none; }

.eyebrow, .category {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: .86rem;
  font-weight: 700;
  letter-spacing: .04em;
}

h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(1.8rem, 7vw, 2.35rem); line-height: 1.28; }
h2 { margin: 8px 0; font-size: 1.3rem; }

.lead { margin: 16px 0 32px; color: var(--muted); line-height: 1.8; }

.home-card, .question-card, .score-card, .feedback {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(27, 54, 98, .07);
}

.home-card { padding: 28px 24px 24px; text-align: center; }
.home-card p { margin: 0 0 24px; color: var(--muted); line-height: 1.65; }
.card-icon { display: inline-grid; width: 48px; height: 48px; place-items: center; border-radius: 14px; background: #e8efff; color: var(--blue); font-size: 1.45rem; }
.small-note { margin: 24px 0; color: var(--muted); font-size: .9rem; text-align: center; }
.study-summary { margin-top: 22px; padding: 22px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; }
.study-summary h2 { margin: 0 0 16px; font-size: 1.08rem; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary-grid div { padding: 10px 4px; text-align: center; border-right: 1px solid var(--line); }
.summary-grid div:last-child { border-right: 0; }
.summary-grid span { display: block; color: var(--muted); font-size: .72rem; line-height: 1.45; }
.summary-grid strong { display: block; margin-top: 5px; font-size: 1rem; }
.latest-result { margin: 16px 0; color: var(--muted); font-size: .9rem; text-align: center; }
.weakness-summary, .category-analysis { margin-top: 22px; padding: 22px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; }
.difficulty-summary { margin-top: 22px; padding: 22px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; }
.difficulty-summary h2 { margin: 0; font-size: 1.08rem; }
.difficulty-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.difficulty-button { min-height: 54px; padding: 8px 4px; border: 1px solid var(--blue); border-radius: 12px; color: var(--blue); background: #fff; font-weight: 700; cursor: pointer; }
.difficulty-button:disabled { border-color: var(--line); color: #98a2b3; background: #f5f7fa; cursor: not-allowed; }
.weakness-summary h2, .category-analysis h2 { margin: 0; font-size: 1.08rem; }
.section-note { margin: 8px 0 14px; color: var(--muted); font-size: .82rem; line-height: 1.55; }
.weakness-list, .category-analysis-list { display: grid; gap: 10px; }
.weakness-item, .category-stat { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.weakness-name { margin: 0 0 5px; font-weight: 800; }
.weakness-detail, .category-stat p { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.55; }
.learn-category-button { width: 100%; min-height: 42px; margin-top: 10px; border: 0; border-radius: 11px; color: var(--blue); background: #eaf0ff; font-weight: 700; cursor: pointer; }
.category-stat { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.category-stat strong { display: block; margin-bottom: 5px; }
.category-rate { color: var(--blue) !important; font-weight: 700; text-align: right; }

.primary-button, .choice-button, .text-button {
  min-height: 52px;
  border-radius: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.primary-button {
  width: 100%;
  border: 0;
  padding: 12px 18px;
  color: #fff;
  background: var(--blue);
  font-weight: 700;
}
.primary-button:hover { background: var(--blue-dark); }
.primary-button:active { transform: scale(.99); }
.secondary-button { width: 100%; min-height: 48px; border: 1px solid var(--blue); border-radius: 14px; color: var(--blue); background: #fff; font-weight: 700; cursor: pointer; }
.mock-exam-button { margin-top: 10px; }

.progress-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.progress-text { margin: 0; font-weight: 700; }
.category { margin: 0; text-align: right; }
.progress-track { height: 7px; margin: 12px 0 24px; overflow: hidden; border-radius: 999px; background: #dce7ff; }
.progress-bar { width: 10%; height: 100%; border-radius: inherit; background: var(--blue); transition: width .25s ease; }

.question-card { padding: 25px 20px; }
.question-card h1 { font-size: 1.05rem; color: var(--muted); }
.question-text { margin: 14px 0 24px; font-size: 1.15rem; font-weight: 700; line-height: 1.75; }
.choices { display: grid; gap: 12px; }
.choice-button { width: 100%; padding: 14px 16px; border: 1px solid var(--line); color: var(--ink); background: #fff; font-weight: 600; line-height: 1.5; text-align: left; transition: border-color .15s, background .15s; }
.choice-button:hover:not(:disabled) { border-color: var(--blue); background: #f5f8ff; }
.choice-button:disabled { cursor: default; opacity: 1; }
.choice-button.correct { border-color: var(--success); color: var(--success); background: var(--success-bg); }
.choice-button.incorrect { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }

.feedback { margin-top: 18px; padding: 20px; }
.answer-status { margin: 0 0 10px; font-size: 1.2rem; font-weight: 800; }
.answer-status.correct { color: var(--success); }
.answer-status.incorrect { color: var(--danger); }
.explanation-text { margin: 0 0 20px; color: var(--ink); line-height: 1.75; }

#result-screen { text-align: center; }
.score-card { margin: 28px 0 18px; padding: 28px 18px; }
.score-label { margin: 0; color: var(--muted); }
.score-text { margin: 12px 0 6px; font-size: clamp(1.6rem, 7vw, 2.2rem); font-weight: 800; }
.rate-text { margin: 0; color: var(--blue); font-weight: 700; }
.result-message { margin: 20px 0 26px; color: var(--muted); line-height: 1.7; }
.perfect-score-message { margin: 0 0 16px; color: var(--success); font-weight: 700; }
#result-screen .primary-button + .primary-button { margin-top: 10px; }
.text-button { width: 100%; margin-top: 8px; border: 0; color: var(--blue); background: transparent; font-weight: 700; }
.history-list { display: grid; gap: 12px; margin: 24px 0; }
.history-item { padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.history-date { margin: 0 0 12px; color: var(--muted); font-size: .85rem; }
.history-score { margin: 0; font-size: 1.1rem; font-weight: 800; }
.history-detail { margin: 6px 0 0; color: var(--muted); font-size: .9rem; }
.history-empty { margin: 28px 0; padding: 24px; color: var(--muted); text-align: center; border: 1px dashed var(--line); border-radius: 16px; }
.delete-button { width: 100%; min-height: 48px; border: 1px solid #e3a5a0; border-radius: 14px; color: var(--danger); background: #fff; font-weight: 700; cursor: pointer; }

button:focus-visible { outline: 3px solid #93b4ff; outline-offset: 3px; }
.site-footer { max-width: 680px; margin: 4px auto 28px; padding: 0 20px; color: var(--muted); text-align: center; font-size: .75rem; line-height: 1.7; }
.site-footer a { color: var(--blue); font-weight: 700; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.site-footer p { margin: 10px 0 0; }
@keyframes appear { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

@media (min-width: 700px) {
  .app-shell { padding-top: 56px; }
  .question-card { padding: 32px; }
}
