:root {
  --main: #0b3d91;
  --main-light: #e8eefb;
  --ok: #1a8a4a;
  --ok-bg: #e5f6ec;
  --ng: #c62828;
  --ng-bg: #fdecec;
  --text: #1d1d1f;
  --sub: #666;
  --bg: #f4f6fa;
  --card: #fff;
  --border: #d9dee8;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; cursor: pointer; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  background: var(--main); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  min-height: 52px;
}
.topbar h1 { font-size: 17px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: none; color: #fff; font-size: 30px; line-height: 1; padding: 0 8px 4px 0; }
.progress-text { font-size: 14px; opacity: .9; white-space: nowrap; }
.progress-bar { height: 4px; background: #c9d6f2; position: absolute; left: 0; right: 0; bottom: 0; }
.progress-bar[hidden] { display: none; }
.progress-bar div { height: 100%; background: #f2a900; width: 0; transition: width .3s; }

main { max-width: 760px; margin: 0 auto; padding: 16px 14px 40px; }

.card { background: var(--card); border-radius: 14px; padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.card h2 { font-size: 16px; margin: 0 0 10px; color: var(--main); }

/* home */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats .num { font-size: 24px; font-weight: 700; color: var(--main); line-height: 1.2; }
.stats .lbl { font-size: 12px; color: var(--sub); }
.meter { height: 8px; background: #e6e9f0; border-radius: 4px; overflow: hidden; margin-top: 12px; display: flex; }
.meter .ok { background: var(--ok); }
.meter .ng { background: var(--ng); }

.menu { display: grid; gap: 10px; }
.menu button {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; width: 100%;
}
.menu button:active { background: var(--main-light); }
.menu button[disabled] { opacity: .45; }
.menu .ico { font-size: 24px; width: 32px; text-align: center; }
.menu .t { font-weight: 700; display: block; }
.menu .d { font-size: 13px; color: var(--sub); display: block; }

.ranges { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.ranges button { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px; text-align: center; }
.ranges button .r { font-weight: 700; display: block; }
.ranges button .s { font-size: 12px; color: var(--sub); }

.link-btn { background: none; border: none; color: var(--sub); text-decoration: underline; font-size: 13px; padding: 8px; }

/* quiz */
.qhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.qno { font-weight: 700; color: var(--main); font-size: 18px; }
.qdate { font-size: 12px; color: var(--sub); margin-left: 6px; font-weight: 400; }
.bm { background: none; border: 1px solid var(--border); border-radius: 20px; padding: 2px 12px; font-size: 14px; color: var(--sub); }
.bm.on { color: #b77900; border-color: #f2a900; background: #fff7e0; }
.qtext { white-space: pre-wrap; font-size: 17px; }
.figs img { display: block; max-width: 100%; margin: 12px auto 0; border: 1px solid var(--border); border-radius: 6px; cursor: zoom-in; background: #fff; }
.figs .hint { font-size: 12px; color: var(--sub); text-align: center; }

.choices { display: grid; gap: 10px; }
.choice {
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  width: 100%; padding: 14px; border-radius: 12px;
  background: var(--card); border: 2px solid var(--border);
  font-size: 16px; line-height: 1.6;
}
.choice .mk { font-weight: 700; color: var(--main); font-size: 18px; line-height: 1.4; flex-shrink: 0; }
.choice:not([disabled]):active { background: var(--main-light); }
.choice.correct { border-color: var(--ok); background: var(--ok-bg); }
.choice.wrong { border-color: var(--ng); background: var(--ng-bg); }
.choice[disabled] { cursor: default; }
.choice.dim { opacity: .55; }
.choices.compact { grid-template-columns: repeat(4, 1fr); }
.choices.compact .choice { justify-content: center; }
.choices.compact .mk { font-size: 24px; }

.verdict { font-size: 22px; font-weight: 800; text-align: center; padding: 6px 0 2px; }
.verdict.ok { color: var(--ok); }
.verdict.ng { color: var(--ng); }
.answer-line { text-align: center; font-weight: 700; margin-bottom: 4px; }
.expl { white-space: pre-wrap; font-size: 15px; }
.note { white-space: pre-wrap; font-size: 14px; background: #f7f7f2; border-left: 4px solid #f2a900; padding: 8px 10px; margin-top: 12px; border-radius: 4px; }

.actions { display: flex; gap: 10px; margin-top: 4px; }
.btn {
  flex: 1; padding: 14px; border-radius: 12px; border: none;
  background: var(--main); color: #fff; font-weight: 700; font-size: 16px;
}
.btn.sub { background: #fff; color: var(--main); border: 1px solid var(--main); }
.btn:active { opacity: .85; }

/* result */
.score { text-align: center; }
.score .big { font-size: 48px; font-weight: 800; color: var(--main); line-height: 1.2; }
.score .pct { font-size: 18px; color: var(--sub); }

/* list */
.qlist { list-style: none; margin: 0; padding: 0; }
.qlist li { border-bottom: 1px solid #eef0f4; }
.qlist li:last-child { border-bottom: none; }
.qlist button { display: flex; gap: 10px; width: 100%; background: none; border: none; text-align: left; padding: 10px 2px; align-items: flex-start; }
.qlist .n { font-weight: 700; color: var(--main); width: 44px; flex-shrink: 0; }
.qlist .tx { flex: 1; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.qlist .st { width: 28px; text-align: center; flex-shrink: 0; font-weight: 700; }
.st.ok { color: var(--ok); }
.st.ng { color: var(--ng); }
.st.none { color: #bbb; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.filters button { border: 1px solid var(--border); background: #fff; border-radius: 16px; padding: 4px 12px; font-size: 13px; }
.filters button.on { background: var(--main); color: #fff; border-color: var(--main); }

.zoom { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 100; display: flex; align-items: center; justify-content: center; overflow: auto; touch-action: pinch-zoom; }
.zoom img { max-width: 100%; max-height: 100%; background: #fff; }
.zoom[hidden] { display: none; }

.install { font-size: 13px; color: var(--sub); }
.install b { color: var(--text); }
details.install summary { cursor: pointer; color: var(--main); }
details.install p { margin: 8px 0; }
.empty { text-align: center; color: var(--sub); padding: 24px 0; }

@media (prefers-color-scheme: dark) {
  :root { --text: #eceef3; --sub: #a5abb8; --bg: #12151c; --card: #1d222c; --border: #343b4a; --main-light: #22304d; --ok-bg: #173323; --ng-bg: #3a1c1c; }
  .card h2, .qno, .choice .mk, .stats .num, .qlist .n, .score .big { color: #8fb1ff; }
  .btn.sub { background: transparent; color: #8fb1ff; border-color: #8fb1ff; }
  .note { background: #26261f; }
  .bm.on { background: #3a3120; }
  .filters button { background: var(--card); }
  .filters button.on { background: var(--main); }
  .qlist li { border-color: #2a303c; }
}
