:root {
  color-scheme: light;
  --page: #EEF1E6;
  --surface: #FFFFFF;
  --surface-2: #E7EBDC;
  --ink: #262B21;
  --ink-2: #545C49;
  --muted: #83897A;
  --border: rgba(38,43,33,0.16);
  --border-strong: #33392C;

  --accent: #4E8C2F;
  --accent-dark: #396A20;
  --accent-ink: #FFFFFF;
  --accent-wash: #DCEECB;

  --pop: #E85D82;
  --pop-dark: #CE4468;
  --pop-wash: #FBDEE6;

  --gold: #C68A1E;
  --gold-wash: #F6E4C0;

  --good: #1E8A4C;
  --good-wash: #DCEEDF;
  --bad: #C94A40;
  --bad-wash: #F5DEDB;

  --diff-easy: #1E8A4C;
  --diff-easy-wash: #DCEEDF;
  --diff-medium: #B47A12;
  --diff-medium-wash: #F3E3BE;
  --diff-hard: #C94A40;
  --diff-hard-wash: #F5DEDB;

  --radius: 18px;
  --radius-sm: 11px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Segoe UI", sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(22px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(64px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

@media (min-width: 900px) {
  .app {
    justify-content: center;
  }
}

/* --- header --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-kechu {
  width: 54px;
  height: 54px;
  object-fit: contain;
  flex: 0 0 auto;
}
.brand-text h1 {
  font-size: 22px;
  font-weight: 900;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--accent-dark);
}
.brand-dot { color: var(--pop); }
.tagline {
  margin: 2px 0 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--surface);
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
}

.score-box {
  display: flex;
  align-items: center;
  gap: 8px;
}
.score {
  display: flex;
  align-items: baseline;
  gap: 3px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-variant-numeric: tabular-nums;
}
.score-num { font-size: 17px; font-weight: 800; }
.score-sep { color: var(--muted); font-size: 14px; }
.score-label {
  font-size: 11px;
  color: var(--muted);
  margin-left: 5px;
  align-self: center;
  font-weight: 700;
}
.streak {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--gold-wash);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-weight: 800;
  font-size: 14px;
  color: var(--ink);
}
.streak-fire { font-size: 15px; }
.streak-label { font-size: 10px; color: var(--muted); font-weight: 700; }

.mistake-nav-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-2);
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s;
}
.mistake-nav-btn:hover { background: var(--surface-2); }
.mistake-nav-btn span {
  font-variant-numeric: tabular-nums;
}

/* --- filters --- */
.filters {
  padding: 12px 16px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
}
.filters-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.filters-summary::-webkit-details-marker { display: none; }
.filters-summary::before {
  content: "▶";
  font-size: 10px;
  color: var(--muted);
}
.filters[open] .filters-summary::before { content: "▼"; }
.filters[open] .filters-summary { margin-bottom: 12px; }
.filters-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.filter-group { display: flex; flex-direction: column; gap: 6px; }
.filter-label {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--muted);
  text-transform: uppercase;
  white-space: nowrap;
}
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.pill:hover { background: var(--surface-2); }
.pill.is-active {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: var(--accent-ink);
}
.filter-count {
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* --- card --- */
.card {
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 3px 14px rgba(38,43,33,0.08);
  padding: 26px 22px 22px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* iPad等、縦に余裕のある広い画面では画面いっぱいに間延びさせず、
   自然な高さのまま.appごと縦方向に中央寄せする(.appのjustify-centerは別途) */
@media (min-width: 900px) {
  .card {
    flex: none;
  }
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.badge {
  font-size: 11.5px;
  font-weight: 800;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
}
.badge-diff.diff-易 { color: var(--diff-easy); background: var(--diff-easy-wash); border-color: var(--diff-easy); }
.badge-diff.diff-中 { color: var(--diff-medium); background: var(--diff-medium-wash); border-color: var(--diff-medium); }
.badge-diff.diff-難 { color: var(--diff-hard); background: var(--diff-hard-wash); border-color: var(--diff-hard); }
.badge-cat {
  color: var(--ink-2);
  background: var(--surface-2);
  border-color: var(--border);
}
.badge-acc {
  color: var(--accent-dark);
  background: var(--surface-2);
  border-color: var(--border);
}
.qid {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.question-text {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.75;
  margin: 0 0 22px;
  text-wrap: balance;
}
.question-text .blank {
  white-space: nowrap;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 6px;
}
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 15.5px;
  font-weight: 600;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.choice:hover:not(:disabled) { background: var(--surface-2); }
.choice:disabled { cursor: default; }
.choice-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink-2);
  font-weight: 800;
  font-size: 13px;
  flex: 0 0 auto;
  border: 1.5px solid var(--border-strong);
}
.choice.is-correct {
  border-color: var(--good);
  background: var(--good-wash);
}
.choice.is-correct .choice-letter { background: var(--good); color: #fff; border-color: var(--good); }
.choice.is-wrong {
  border-color: var(--bad);
  background: var(--bad-wash);
}
.choice.is-wrong .choice-letter { background: var(--bad); color: #fff; border-color: var(--bad); }

/* --- feedback --- */
.feedback {
  margin-top: 4px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1.5px dashed var(--border);
}
.feedback-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.feedback-kechu {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex: 0 0 auto;
}
.feedback-bubble { flex: 1; min-width: 0; }
.feedback-top {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 14.5px;
}
.kechu-line {
  margin: 3px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
}
.tested-point {
  margin: 8px 0 0;
  font-size: 13.5px;
  color: var(--ink-2);
}

.explain {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1.5px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.explain-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  align-items: start;
}
.explain-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--muted);
  padding-top: 2px;
}
.explain-text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink);
}
.distractor-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.distractor-list li {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-2);
}
.distractor-list .d-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 800;
  margin-right: 6px;
}

/* --- actions --- */
.actions {
  margin-top: auto;
  padding-top: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.btn {
  font: inherit;
  font-size: 14.5px;
  font-weight: 800;
  padding: 11px 22px;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  cursor: pointer;
  transition: background 0.12s, opacity 0.12s;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost {
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 9px 14px;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--ink-2); }

/* --- footer --- */
.foot {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.8;
}
.foot-sep {
  margin: 0 2px;
}
.foot-privacy {
  color: var(--muted);
  text-decoration: underline;
}
/* --- modal (report / mistakes) --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,20,10,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(20,20,10,0.18);
  width: 100%;
  max-width: 420px;
  padding: 24px 22px 22px;
}
.modal.modal-wide { max-width: 540px; }
.modal h2 {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 900;
}
.modal-sub {
  margin: 0 0 18px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.field label {
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-2);
}
.field select,
.field textarea {
  font: inherit;
  font-size: 13.5px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  resize: vertical;
}
.modal-error {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--bad);
  margin: 0 0 10px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal-done {
  text-align: center;
  padding: 10px 0 0;
}
.modal-done p {
  color: var(--good);
  font-weight: 800;
  margin: 0 0 14px;
}

/* --- mistake list --- */
.modal-head-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.mistake-list {
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
  padding-right: 2px;
}
.mistake-empty {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  padding: 30px 10px;
}
.mistake-item {
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
}
.mistake-item-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: none;
  border: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}
.mistake-item-q {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.mistake-item-count {
  font-size: 11px;
  font-weight: 800;
  color: var(--bad);
  background: var(--bad-wash);
  border-radius: 999px;
  padding: 2px 8px;
  flex: 0 0 auto;
}
.mistake-item-body {
  padding: 4px 14px 14px;
  border-top: 1.5px dashed var(--border);
  font-size: 13px;
}
.mistake-item-body .mistake-question-full {
  margin: 10px 0 10px;
  font-weight: 600;
  color: var(--ink);
}
.mistake-item-body .choice-line {
  padding: 4px 0;
}
.mistake-item-body .choice-line.correct { color: var(--good); font-weight: 700; }
.mistake-item-body .mistake-translation {
  margin: 8px 0 0;
  color: var(--ink-2);
}
.mistake-remove {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
  padding: 2px 4px;
}
.mistake-remove:hover { color: var(--bad); }

@media (max-width: 480px) {
  .question-text { font-size: 16.5px; }
  .card { padding: 20px 16px 18px; }
  .brand-kechu { width: 46px; height: 46px; }
  .brand-text h1 { font-size: 19px; }
}

/* --- settings modal --- */
.settings-nav-btn {
  font-size: 18px;
  padding: 8px 10px;
  line-height: 1;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
}
.settings-label {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-2);
}
.settings-toggle {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.settings-divider {
  border: none;
  border-top: 1.5px solid var(--border-strong);
  margin: 6px 0 12px;
}
.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
#downloadProgress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}
#downloadProgress progress {
  flex: 1;
  height: 10px;
  accent-color: var(--accent);
}
#downloadProgressLabel {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
