
:root {
  --bg: #f2efe8;
  --surface: #fffdf8;
  --surface-2: #e7edf0;
  --ink: #142331;
  --muted: #6d7881;
  --line: #d7d4cc;
  --navy: #173b57;
  --navy-2: #235a7e;
  --accent: #b74d39;
  --good: #1f7456;
  --bad: #ad4039;
  --shadow: 0 22px 60px rgba(24, 42, 55, .08);
  --radius: 24px;
}
[data-theme="dark"] {
  --bg: #111820;
  --surface: #18222c;
  --surface-2: #202f3a;
  --ink: #eff4f6;
  --muted: #a7b1b8;
  --line: #30404b;
  --navy: #84b9db;
  --navy-2: #a3cce6;
  --accent: #e27c66;
  --good: #65c49b;
  --bad: #ef8a80;
  --shadow: 0 22px 60px rgba(0, 0, 0, .22);
}
* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 5%, rgba(35, 90, 126, .09), transparent 28%),
    radial-gradient(circle at 90% 90%, rgba(183, 77, 57, .07), transparent 25%),
    var(--bg);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
}
button, select { font: inherit; }
button { color: inherit; }
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand-button {
  border: 0; background: transparent; padding: 0;
  display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px;
  display: grid; place-items: center;
  background: var(--navy); color: var(--surface);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-weight: 700; font-size: 21px;
}
.brand-button strong { display: block; font-size: 15px; letter-spacing: .05em; }
.brand-button small { display: block; color: var(--muted); margin-top: 2px; font-size: 10px; text-align: left; letter-spacing: .12em; }
.top-actions { display: flex; gap: 8px; }
.icon-button {
  border: 1px solid var(--line); background: var(--surface);
  min-width: 44px; height: 40px; border-radius: 12px; cursor: pointer;
  box-shadow: 0 5px 14px rgba(20,35,49,.03);
}
.main-content { width: min(1180px, calc(100% - 40px)); margin: 0 auto; flex: 1; padding: 58px 0 72px; }
.hero { display: grid; grid-template-columns: 1fr auto; gap: 30px; align-items: end; margin-bottom: 44px; }
.eyebrow, .section-label { font-size: 10px; letter-spacing: .2em; font-weight: 800; color: var(--accent); }
.hero h1, .result-card h1, .stats-card h1 {
  margin: 10px 0 14px; font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(40px, 5vw, 64px); line-height: 1.2; font-weight: 600; letter-spacing: -.03em;
}
.hero h1 em { color: var(--navy-2); font-style: normal; }
.hero p { color: var(--muted); max-width: 620px; line-height: 1.9; margin: 0; }
.hero-kpi {
  width: 155px; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(255,255,255,.25);
}
.hero-kpi span, .hero-kpi small { color: var(--muted); font-size: 10px; letter-spacing: .1em; }
.hero-kpi strong { font-family: Georgia, serif; font-size: 40px; color: var(--navy); line-height: 1.1; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .75fr); gap: 24px; align-items: start; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.setup-panel { padding: clamp(24px, 4vw, 42px); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.panel-heading h2 { margin: 7px 0 0; font-family: "Yu Mincho", serif; font-size: 26px; }
.text-button { background: transparent; border: 0; color: var(--navy-2); cursor: pointer; padding: 6px; font-weight: 700; }
.filter-block { margin-bottom: 25px; }
.filter-title { display: block; font-size: 12px; font-weight: 800; margin-bottom: 11px; }
.chip-group { display: flex; flex-wrap: wrap; gap: 9px; }
.filter-chip {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 9px 15px; cursor: pointer; color: var(--muted); transition: .18s ease;
}
.filter-chip.active { background: var(--navy); color: var(--surface); border-color: var(--navy); }
.filter-chip:hover { transform: translateY(-1px); }
select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 12px; padding: 12px 13px; outline: none;
}
select:focus { border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(35,90,126,.12); }
#chapterSelect { min-height: 145px; padding: 8px; }
#chapterSelect option { padding: 7px; border-radius: 6px; }
.select-help, .keyboard-note { margin-top: 8px; font-size: 10px; color: var(--muted); line-height: 1.6; }
.filter-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.available-row {
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 0 16px; padding: 15px 0; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 13px;
}
.available-row strong { color: var(--ink); font-size: 18px; }
.primary-button, .secondary-button, .danger-button {
  border: 0; border-radius: 14px; min-height: 54px; padding: 0 20px; cursor: pointer; font-weight: 800;
}
.primary-button {
  width: 100%; background: var(--navy); color: var(--surface);
  display: flex; align-items: center; justify-content: space-between;
}
.primary-button:hover { background: var(--navy-2); }
.primary-button:disabled { opacity: .45; cursor: not-allowed; }
.secondary-button { border: 1px solid var(--line); background: var(--surface); }
.danger-button { background: transparent; border: 1px solid var(--bad); color: var(--bad); margin-top: 30px; }
.side-stack { display: grid; gap: 18px; }
.progress-panel { padding: 28px; }
.ring-wrap { width: 158px; height: 158px; position: relative; margin: 20px auto; }
.progress-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.progress-ring circle { fill: none; stroke: var(--line); stroke-width: 8; }
.progress-ring .ring-value { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 314; stroke-dashoffset: 314; transition: .5s; }
.ring-text { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-text strong { font-family: Georgia, serif; font-size: 38px; }
.ring-text span { color: var(--muted); font-size: 10px; }
.stat-row { display: flex; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.stat-row strong { color: var(--ink); }
.quick-card {
  text-align: left; width: 100%; padding: 23px 25px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
}
.quick-card h3 { margin: 7px 0 4px; font-family: "Yu Mincho", serif; }
.quick-card p { margin: 0; color: var(--muted); font-size: 12px; }
.quick-arrow { font-size: 25px; color: var(--navy-2); }
footer {
  width: min(1180px, calc(100% - 40px)); margin: 0 auto;
  display: flex; justify-content: space-between; gap: 20px;
  padding: 20px 0 28px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px;
}

/* quiz */
.quiz-layout { max-width: 900px; margin: 0 auto; }
.quiz-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.quiz-progress-text { color: var(--muted); font-family: Georgia, serif; }
.progress-track { height: 4px; background: var(--line); border-radius: 99px; overflow: hidden; margin-bottom: 26px; }
.progress-track span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.question-card { background: var(--surface); border: 1px solid var(--line); border-radius: 30px; padding: clamp(24px, 5vw, 56px); box-shadow: var(--shadow); }
.question-meta { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.meta-pill, .rank-pill { display: inline-block; font-size: 10px; padding: 7px 10px; border-radius: 99px; background: var(--surface-2); margin: 0 5px 5px 0; }
.rank-pill { background: var(--navy); color: var(--surface); font-weight: 800; }
.bookmark-button { border: 0; background: transparent; font-size: 28px; cursor: pointer; color: var(--accent); }
.question-number { margin-top: 35px; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.question-text { margin: 15px 0 42px; font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; font-weight: 500; font-size: clamp(21px, 3.1vw, 31px); line-height: 1.75; white-space: pre-line; }
.answer-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.answer-button {
  min-height: 110px; border-radius: 18px; border: 1px solid var(--line); background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 14px; color: var(--muted); font-weight: 800;
  transition: .15s;
}
.answer-button:hover { transform: translateY(-2px); border-color: var(--navy-2); }
.answer-symbol { font-size: 38px; font-weight: 400; color: var(--navy-2); }
.false-button .answer-symbol { color: var(--accent); }
.answer-button.selected-correct { background: rgba(31,116,86,.1); border-color: var(--good); color: var(--good); }
.answer-button.selected-wrong { background: rgba(173,64,57,.1); border-color: var(--bad); color: var(--bad); }
.answer-button.dimmed { opacity: .38; }
.feedback { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 28px; }
.hidden { display: none !important; }
.feedback-head { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; }
.feedback-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: var(--surface-2); }
.feedback-head span { display: block; color: var(--muted); font-size: 12px; }
.feedback-head strong { display: block; margin-top: 3px; font-size: 19px; }
.explanation { padding: 22px; border-radius: 16px; background: var(--surface-2); }
.explanation p { margin: 10px 0 0; white-space: pre-line; line-height: 1.85; font-size: 14px; }
.next-button { margin-top: 20px; }

/* result */
.result-layout { max-width: 900px; margin: 0 auto; display: grid; gap: 22px; }
.result-card { text-align: center; padding: 50px 30px; }
.result-card h1 { font-size: 42px; }
.score-display { color: var(--navy); margin: 20px 0 2px; }
.score-display strong { font-family: Georgia, serif; font-size: 88px; font-weight: 400; }
.score-display span { font-size: 28px; }
.result-card > p { color: var(--muted); }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; max-width: 520px; margin: 30px auto 0; gap: 12px; }
.review-panel { padding: 30px; }
.review-list { display: grid; gap: 12px; }
.review-item { padding: 18px; border-radius: 14px; background: var(--surface-2); }
.review-item .review-meta { font-size: 10px; color: var(--accent); font-weight: 800; }
.review-item p { margin: 8px 0 6px; line-height: 1.65; }
.review-item small { color: var(--muted); }
.empty-state { color: var(--muted); padding: 30px 0; text-align: center; }

/* stats */
.stats-layout { max-width: 920px; margin: 0 auto; }
.stats-card { padding: clamp(26px,5vw,50px); }
.stats-card h1 { font-size: 42px; }
.stats-kpis { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin: 30px 0; }
.stats-kpis > div { background: var(--surface-2); border-radius: 16px; padding: 20px; }
.stats-kpis span { display: block; color: var(--muted); font-size: 11px; }
.stats-kpis strong { display: block; margin-top: 8px; font-family: Georgia, serif; font-size: 30px; }
.chapter-stats { display: grid; gap: 10px; }
.chapter-stat { display: grid; grid-template-columns: minmax(160px,1fr) 2fr 70px; align-items: center; gap: 15px; font-size: 12px; }
.chapter-bar { height: 7px; background: var(--line); border-radius: 99px; overflow: hidden; }
.chapter-bar span { display: block; height: 100%; background: var(--navy-2); }

@media (max-width: 820px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .side-stack { grid-template-columns: 1fr 1fr; }
  .progress-panel { grid-row: span 2; }
  .hero-kpi { width: 125px; }
  .stats-kpis { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .topbar, .main-content, footer { width: min(100% - 24px, 1180px); }
  .main-content { padding: 38px 0 52px; }
  .hero { grid-template-columns: 1fr; }
  .hero-kpi { display: none; }
  .hero h1 { font-size: 39px; }
  .filter-columns, .answer-buttons, .result-actions { grid-template-columns: 1fr; }
  .side-stack { grid-template-columns: 1fr; }
  .progress-panel { grid-row: auto; }
  .question-card { border-radius: 22px; }
  .question-text { margin-bottom: 28px; }
  .answer-button { min-height: 82px; }
  .stats-kpis { grid-template-columns: 1fr 1fr; }
  .chapter-stat { grid-template-columns: 1fr 70px; }
  .chapter-bar { grid-column: 1 / -1; grid-row: 2; }
  footer { flex-direction: column; gap: 5px; }
}


/* smartphone / PWA enhancements */
html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
button, select, summary, label { touch-action: manipulation; }
.app-shell { min-height: 100dvh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  padding-top: env(safe-area-inset-top);
}
.install-button { display: none; }
.install-button.visible { display: inline-grid; place-items: center; }
.filter-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mini-text-button {
  border: 0; background: transparent; color: var(--navy-2); font-size: 12px;
  font-weight: 800; padding: 8px 0; cursor: pointer;
}
.chapter-picker {
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  overflow: hidden;
}
.chapter-picker summary {
  min-height: 50px; padding: 12px 14px; cursor: pointer; list-style: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-weight: 800; font-size: 14px;
}
.chapter-picker summary::-webkit-details-marker { display: none; }
.summary-arrow { color: var(--muted); transition: transform .18s ease; }
.chapter-picker[open] .summary-arrow { transform: rotate(180deg); }
.chapter-chip-group {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
  max-height: 290px; overflow: auto; padding: 0 12px 12px;
  overscroll-behavior: contain;
}
.chapter-chip {
  min-height: 46px; text-align: left; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); color: var(--ink); padding: 10px 12px; cursor: pointer;
  font-size: 12px; line-height: 1.45; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.chapter-chip .chapter-count { color: var(--muted); font-size: 10px; flex: 0 0 auto; }
.chapter-chip.active { background: var(--navy); border-color: var(--navy); color: var(--surface); }
.chapter-chip.active .chapter-count { color: currentColor; opacity: .8; }
.mobile-note { display: none; }
.backup-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 28px; }
.backup-actions .secondary-button { min-height: 48px; display: grid; place-items: center; text-align: center; }
.file-button { position: relative; overflow: hidden; cursor: pointer; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.answer-button:active, .primary-button:active, .filter-chip:active, .chapter-chip:active { transform: scale(.985); }

@media (display-mode: standalone) {
  .install-button { display: none !important; }
}

@media (max-width: 600px) {
  body { background: var(--bg); }
  .topbar {
    width: 100%; min-height: 64px; padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right)); border-bottom: 1px solid var(--line);
  }
  .brand-mark { width: 38px; height: 38px; border-radius: 11px; font-size: 19px; }
  .brand-button { gap: 9px; min-width: 0; }
  .brand-button strong { font-size: 13px; white-space: nowrap; }
  .brand-button small { display: none; }
  .top-actions { gap: 5px; }
  .icon-button { min-width: 42px; height: 42px; padding: 0 8px; font-size: 12px; }
  .theme-button { min-width: 42px; font-size: 18px; }
  .main-content {
    width: 100%; padding: 24px 12px calc(34px + env(safe-area-inset-bottom));
  }
  .hero { margin-bottom: 22px; }
  .hero h1 { font-size: clamp(31px, 9vw, 39px); line-height: 1.3; margin-top: 7px; }
  .hero p { font-size: 13px; line-height: 1.75; }
  .setup-panel { padding: 22px 16px; border-radius: 20px; }
  .panel-heading { margin-bottom: 24px; }
  .panel-heading h2 { font-size: 23px; }
  .filter-chip { min-height: 44px; padding: 10px 16px; }
  select { min-height: 48px; font-size: 16px; }
  .chapter-chip-group { grid-template-columns: 1fr; max-height: 330px; }
  .chapter-chip { min-height: 50px; font-size: 13px; }
  .primary-button, .secondary-button, .danger-button { min-height: 56px; border-radius: 14px; }
  .keyboard-note { text-align: center; font-size: 11px; }
  .desktop-note { display: none; }
  .mobile-note { display: inline; }
  .quick-card { min-height: 92px; border-radius: 18px; }
  footer { display: none; }

  .quiz-layout { max-width: none; }
  .quiz-top { margin-bottom: 9px; padding: 0 2px; }
  .progress-track { margin-bottom: 14px; }
  .question-card { border-radius: 20px; padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); box-shadow: none; }
  .question-meta { align-items: flex-start; gap: 8px; }
  .meta-pill, .rank-pill { font-size: 9px; padding: 6px 8px; }
  .bookmark-button { min-width: 46px; min-height: 46px; font-size: 30px; margin-top: -5px; }
  .question-number { margin-top: 22px; }
  .question-text { font-size: clamp(19px, 5.2vw, 23px); line-height: 1.72; margin: 12px 0 26px; }
  .answer-buttons { grid-template-columns: 1fr 1fr; gap: 10px; }
  .answer-button { min-height: 86px; border-radius: 16px; flex-direction: column; gap: 1px; font-size: 13px; }
  .answer-symbol { font-size: 35px; line-height: 1; }
  .feedback { margin-top: 22px; padding-top: 22px; }
  .feedback-head { margin-bottom: 18px; }
  .explanation { padding: 18px 16px; border-radius: 14px; }
  .explanation p { font-size: 14px; line-height: 1.8; }
  .next-button { position: sticky; bottom: max(10px, env(safe-area-inset-bottom)); box-shadow: 0 10px 28px rgba(0,0,0,.16); }

  .result-card { padding: 35px 18px; }
  .result-card h1, .stats-card h1 { font-size: 35px; }
  .score-display strong { font-size: 76px; }
  .review-panel { padding: 22px 16px; }
  .stats-card { padding: 24px 16px; }
  .stats-kpis > div { padding: 16px 13px; }
  .stats-kpis strong { font-size: 25px; }
  .backup-actions { grid-template-columns: 1fr; }
}

@media (max-width: 340px) {
  .brand-button strong { font-size: 12px; }
  .install-button { display: none !important; }
  .answer-buttons { grid-template-columns: 1fr; }
  .answer-button { min-height: 68px; flex-direction: row; gap: 10px; }
}

@media (hover: none) {
  .filter-chip:hover, .answer-button:hover { transform: none; }
}
