:root {
  --bg: #f4f1ee;
  --surface: #ffffff;
  --ink: #23201e;
  --muted: #7a736d;
  --line: #e2dcd6;
  --brand: #7b1e26;      /* 落ち着いた血液色 */
  --brand-ink: #5c151b;
  --accent: #2f6d6a;     /* 深いティール */
  --ok: #1f7a4d;
  --ok-bg: #e6f4ec;
  --ng: #b23a3a;
  --ng-bg: #fbeaea;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 6px 18px rgba(0,0,0,.05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", Meiryo, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  /* 下部固定バーの高さぶん余白を確保 */
  padding-bottom: calc(76px + var(--safe-b));
}

/* ---- ヘッダー ---- */
.header {
  background: linear-gradient(135deg, var(--brand), var(--brand-ink));
  color: #fff;
  padding: calc(12px + var(--safe-t)) 16px 14px;
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.header h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: .01em;
}
.tagline {
  margin: 6px 0 0;
  font-size: .82rem;
  color: rgba(255,255,255,.9);
}
.disclaimer { color: #ffdede; }
.header .disclaimer { display: inline-block; }

.net {
  font-size: .7rem;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  white-space: nowrap;
}
.net.online { background: rgba(255,255,255,.22); }
.net.offline { background: #4a1015; color: #ffd9d9; }

/* ---- レイアウト ---- */
.main {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 14px 24px;
}
section { margin-bottom: 16px; }
h2 {
  font-size: 1rem;
  margin: 0 0 10px;
  color: var(--brand-ink);
}
.muted { color: var(--muted); font-size: .85rem; }

/* ---- 統計 ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 6px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-num {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--brand);
  line-height: 1.1;
}
.stat-label { font-size: .68rem; color: var(--muted); }

/* ---- フィルタ ---- */
.filters-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.filters { display: flex; gap: 6px; }
.filters button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: .85rem;
  cursor: pointer;
}
.filters button.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.text-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: .78rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}

/* ---- 問題エリア ---- */
.quiz {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
}
.image-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #111;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
#cell-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity .25s ease;
  background: #111;
}
#cell-image.loaded { opacity: 1; }
.image-wrap.error { background: #2a2a2a; }
.image-fallback[hidden] { display: none; }
.image-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #ddd;
  padding: 16px;
  font-size: .85rem;
}
.image-fallback .muted { color: #aaa; }
.specimen-badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: .72rem;
  padding: 3px 9px;
  border-radius: 999px;
  backdrop-filter: blur(2px);
}

.meta-row {
  display: flex;
  justify-content: flex-end;
  padding: 8px 2px 4px;
}
.source-link {
  font-size: .75rem;
  color: var(--accent);
  text-decoration: none;
}
.source-link:hover { text-decoration: underline; }

.prompt {
  font-weight: 700;
  margin: 6px 2px 10px;
  font-size: 1rem;
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 58px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: border-color .12s, background .12s, transform .05s;
}
.option:active { transform: scale(.99); }
.option:hover:not(:disabled) { border-color: var(--brand); }
.opt-ja { font-size: 1rem; font-weight: 600; }
.opt-en { font-size: .72rem; color: var(--muted); }
.option:disabled { cursor: default; }
.option.correct {
  border-color: var(--ok);
  background: var(--ok-bg);
}
.option.correct .opt-ja { color: var(--ok); }
.option.wrong {
  border-color: var(--ng);
  background: var(--ng-bg);
}
.option.wrong .opt-ja { color: var(--ng); }

/* ---- 解説 ---- */
#explain {
  margin-top: 14px;
  border-radius: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: #faf8f6;
}
#explain.ok { background: var(--ok-bg); border-color: #bfe3cd; }
#explain.ng { background: var(--ng-bg); border-color: #f0c9c9; }
#explain.reveal { background: #f1eff7; border-color: #ddd7ea; }
.verdict { margin: 0 0 6px; font-weight: 700; font-size: .95rem; }
.verdict.ok { color: var(--ok); }
.verdict.ng { color: var(--ng); }
.verdict.reveal { color: #5a4d86; }
#explain h3 { margin: 2px 0 6px; font-size: 1.1rem; }
#explain h3 .en { font-size: .8rem; color: var(--muted); font-weight: 500; }
.explain-text { margin: 0 0 10px; font-size: .9rem; }
.clues {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: .86rem;
}
.clues dt { font-weight: 700; color: var(--brand-ink); white-space: nowrap; }
.clues dd { margin: 0; }

/* ---- 復習 ---- */
.review-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: .85rem;
  cursor: pointer;
}
.chip:hover { border-color: var(--brand); }
.chip-count {
  background: var(--ng-bg);
  color: var(--ng);
  font-size: .72rem;
  padding: 1px 7px;
  border-radius: 999px;
}

/* ---- 細胞一覧 ---- */
.catalog-list { display: flex; flex-direction: column; gap: 8px; }
.cat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.cat-info { display: flex; flex-direction: column; gap: 1px; }
.cat-name { font-weight: 600; }
.cat-en { font-size: .75rem; color: var(--muted); }
.cat-meta { font-size: .72rem; color: var(--accent); }
.cat-btn {
  flex-shrink: 0;
  border: 1px solid var(--brand);
  color: var(--brand);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .8rem;
  cursor: pointer;
  white-space: nowrap;
}
.cat-btn:hover { background: var(--brand); color: #fff; }

/* ---- フッター ---- */
.footer { margin-top: 20px; }
.footer p { font-size: .74rem; color: var(--muted); margin: 6px 0; }

/* ---- 操作バー（下部固定） ---- */
.actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 10px;
  padding: 10px 14px calc(10px + var(--safe-b));
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  z-index: 20;
}
.btn {
  flex: 1;
  min-height: 48px;
  border-radius: 12px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid transparent;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:disabled { background: #cbb9ba; cursor: default; }
.btn.secondary {
  background: var(--surface);
  color: var(--brand);
  border-color: var(--brand);
}
.btn.secondary:disabled { color: #b7aeae; border-color: var(--line); cursor: default; }

.actionbar { max-width: 720px; margin: 0 auto; }

@media (min-width: 560px) {
  .actionbar {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 100%;
    border-radius: 14px 14px 0 0;
  }
}
