/* ============================================================
   社労士・宅建士 用語集アプリ - メインスタイル
   Mobile-first design
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --color-sr: #1565C0;       /* 社労士カラー（ディープブルー） */
  --color-sr-light: #E3F2FD;
  --color-sr-mid: #42A5F5;
  --color-tk: #2E7D32;       /* 宅建士カラー（ディープグリーン） */
  --color-tk-light: #E8F5E9;
  --color-tk-mid: #66BB6A;
  --color-both: #6A1B9A;     /* 両方カラー（パープル） */
  --color-both-light: #F3E5F5;

  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --surface-2: #F8F9FA;
  --border: #E0E0E0;
  --text-primary: #1A1A2E;
  --text-secondary: #6B7280;
  --text-hint: #9CA3AF;

  --accent: #FF6F00;
  --accent-light: #FFF3E0;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.14), 0 4px 8px rgba(0,0,0,0.08);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --header-h: 120px;
  --bottom-nav-h: 64px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN',
               'Noto Sans JP', 'Yu Gothic', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden; /* スクロールは #main-wrap で管理 */
}

/* ---------- Main Wrap（スクロール容器）---------- */
#main-wrap {
  position: fixed;
  top: 0;        /* JS で header 高さに更新 */
  bottom: var(--bottom-nav-h);
  left: 0;
  right: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input { font-family: inherit; }
ul { list-style: none; }

/* ---------- Header ---------- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 12px 16px 0;
}

.header-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.app-logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--color-sr), var(--color-tk));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.app-title {
  flex: 1;
}
.app-title h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.app-title p {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 1px;
}

/* ---------- Search Bar ---------- */
.search-wrap {
  position: relative;
  margin-bottom: 10px;
}
.search-icon {
  position: absolute;
  left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-hint);
  font-size: 16px;
  pointer-events: none;
}
#search-input {
  width: 100%;
  padding: 10px 36px 10px 38px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 15px;
  color: var(--text-primary);
  background: var(--surface-2);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#search-input:focus {
  border-color: var(--color-sr);
  box-shadow: 0 0 0 3px rgba(21,101,192,0.12);
  background: var(--surface);
}
#search-input::placeholder { color: var(--text-hint); }
.search-clear {
  position: absolute;
  right: 10px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--text-hint);
  color: white;
  font-size: 13px;
  display: none;
  align-items: center; justify-content: center;
}
.search-clear.visible { display: flex; }

/* ---------- Category Tabs ---------- */
.category-tabs {
  display: flex;
  gap: 6px;
  padding-bottom: 1px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.category-tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex-shrink: 0;
  padding: 6px 16px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  transition: all var(--transition);
  white-space: nowrap;
}
.tab-btn.active-all {
  background: var(--text-primary);
  color: white;
  border-color: var(--text-primary);
}
.tab-btn.active-sr {
  background: var(--color-sr);
  color: white;
  border-color: var(--color-sr);
}
.tab-btn.active-tk {
  background: var(--color-tk);
  color: white;
  border-color: var(--color-tk);
}

/* ---------- Law Filter Chips ---------- */
.filter-bar {
  padding: 8px 16px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  margin-top: 8px;
  min-height: 0;
}
.filter-bar::-webkit-scrollbar { display: none; }

.law-chip {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1.5px solid var(--border);
  transition: all var(--transition);
  white-space: nowrap;
}
.law-chip.active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

/* ---------- Main Content ---------- */
.main-content {
  padding: 0 12px 80px;
}

/* ---------- Section Header ---------- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px 8px;
}
.result-count {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ---------- View Toggle ---------- */
.view-toggle {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}
.view-toggle-btn {
  width: 30px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-hint);
  transition: all var(--transition);
}
.view-toggle-btn.active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ---------- Section View（法令別横スクロール）---------- */
.section-group {
  margin-bottom: 20px;
}
.section-law-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 6px 6px 0 0;
  border-left: 4px solid var(--border);
  background: var(--surface-2);
  margin-bottom: 8px;
}
.section-law-header.cat-sr { border-color: var(--color-sr); background: var(--color-sr-light); }
.section-law-header.cat-tk { border-color: var(--color-tk); background: var(--color-tk-light); }
.section-law-header.cat-both { border-color: var(--color-both); background: var(--color-both-light); }
.section-law-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}
.section-law-count {
  font-size: 11px;
  color: var(--text-secondary);
}

.section-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0 0 8px 2px;
  scroll-snap-type: x proximity;
}
.section-row::-webkit-scrollbar { display: none; }

.term-card-mini {
  flex-shrink: 0;
  width: 148px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 10px 12px 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  border-left: 4px solid transparent;
  scroll-snap-align: start;
  transition: transform var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.term-card-mini:active {
  transform: scale(0.96);
  box-shadow: var(--shadow-md);
}
.term-card-mini.cat-sr   { border-color: var(--color-sr); }
.term-card-mini.cat-tk   { border-color: var(--color-tk); }
.term-card-mini.cat-both { border-color: var(--color-both); }

.mini-badges { line-height: 1; margin-bottom: 2px; }
.mini-term {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  word-break: break-all;
}
.mini-reading {
  font-size: 10px;
  color: var(--text-secondary);
}
.mini-article {
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
  align-self: flex-start;
}

/* ---------- Term Card ---------- */
.term-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  border-left: 4px solid transparent;
  position: relative;
  overflow: hidden;
}
.term-card:active {
  transform: scale(0.98);
  box-shadow: none;
}
.term-card.cat-sr { border-left-color: var(--color-sr); }
.term-card.cat-tk { border-left-color: var(--color-tk); }
.term-card.cat-both { border-left-color: var(--color-both); }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.card-term-wrap {
  flex: 1;
  min-width: 0;
}
.card-term {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.card-reading {
  font-size: 11px;
  color: var(--text-hint);
  margin-top: 2px;
}

.card-badges {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.badge {
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.badge-sr {
  background: var(--color-sr-light);
  color: var(--color-sr);
}
.badge-tk {
  background: var(--color-tk-light);
  color: var(--color-tk);
}

.card-law {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.card-law-name { font-weight: 600; }
.card-article { color: var(--text-hint); }

.card-short {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}
.card-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
}
.tag {
  padding: 2px 7px;
  background: var(--surface-2);
  border-radius: 4px;
  font-size: 10px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.card-fav-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: transform var(--transition);
}
.card-fav-btn:active { transform: scale(0.85); }
.card-fav-btn.fav { color: var(--accent); }
.card-fav-btn:not(.fav) { color: var(--text-hint); }

/* ---------- Empty State ---------- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  display: block;
}
.empty-state p {
  font-size: 14px;
  line-height: 1.6;
}

/* ---------- Bottom Navigation ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-hint);
  transition: color var(--transition);
  padding: 8px 0;
}
.nav-btn .nav-icon { font-size: 22px; }
.nav-btn.active { color: var(--color-sr); }

/* ---------- Detail Sheet ---------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  backdrop-filter: blur(2px);
}
.sheet-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.detail-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 201;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: env(safe-area-inset-bottom, 16px);
}
.detail-sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 0;
  flex-shrink: 0;
}

.sheet-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sheet-badges {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.sheet-term {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}
.sheet-reading {
  font-size: 13px;
  color: var(--text-hint);
  margin-top: 3px;
}
.sheet-law-info {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
.sheet-law-badge {
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-light);
  color: var(--accent);
}
.sheet-article {
  font-size: 12px;
  color: var(--text-secondary);
}

.sheet-body {
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.sheet-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-hint);
  margin-bottom: 8px;
  margin-top: 20px;
}
.sheet-section-title:first-child { margin-top: 0; }

.sheet-detail-text {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-primary);
  white-space: pre-wrap;
}

/* Markdown-like table rendering */
.sheet-detail-text table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 8px 0;
}
.sheet-detail-text th,
.sheet-detail-text td {
  padding: 6px 8px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.sheet-detail-text th {
  background: var(--surface-2);
  font-weight: 700;
  font-size: 11px;
}

.sheet-related {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.related-chip {
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 13px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  color: var(--text-primary);
  font-weight: 500;
  transition: all var(--transition);
}
.related-chip:active {
  background: var(--color-sr-light);
  border-color: var(--color-sr);
  color: var(--color-sr);
}

.sheet-fav-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  position: absolute;
  right: 20px;
  top: 58px;
  transition: all var(--transition);
}
.sheet-fav-btn.fav {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}
.sheet-fav-btn:not(.fav) { color: var(--text-hint); }

/* ---------- Favorites View ---------- */
.view { display: none; }
.view.active { display: block; }

/* ---------- Highlight matched text ---------- */
mark {
  background: #FFF176;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 16px);
  left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text-primary);
  color: white;
  padding: 8px 18px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: all 0.25s;
  white-space: nowrap;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Scroll padding ---------- */
.scroll-spacer { height: 16px; }

/* ---------- Tag clickable ---------- */
.tag-clickable {
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.tag-clickable:active,
.tag-clickable:hover {
  background: var(--color-sr-light);
  color: var(--color-sr);
  border-color: var(--color-sr);
}

/* ============================================================
   Quiz View
   ============================================================ */

/* --- Home --- */
.quiz-home-header {
  text-align: center;
  padding: 32px 20px 20px;
}
.quiz-home-icon {
  font-size: 48px;
  margin-bottom: 10px;
}
.quiz-home-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.quiz-home-sub {
  font-size: 13px;
  color: var(--text-secondary);
}
.quiz-home-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-hint);
  margin: 12px 16px 24px;
}

.quiz-cat-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px;
}
.quiz-cat-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 2px solid var(--border);
  transition: all var(--transition);
  width: 100%;
  text-align: left;
}
.quiz-cat-btn:active {
  transform: scale(0.97);
  box-shadow: none;
}
.quiz-cat-btn-sr { border-color: var(--color-sr-light); }
.quiz-cat-btn-sr:active { border-color: var(--color-sr); background: var(--color-sr-light); }
.quiz-cat-btn-tk { border-color: var(--color-tk-light); }
.quiz-cat-btn-tk:active { border-color: var(--color-tk); background: var(--color-tk-light); }

.quiz-cat-icon { font-size: 28px; flex-shrink: 0; }
.quiz-cat-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}
.quiz-cat-count {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
  flex-shrink: 0;
}

/* --- Playing --- */
.quiz-progress-bar {
  height: 4px;
  background: var(--border);
  margin: 0 0 12px;
  border-radius: 2px;
  overflow: hidden;
}
.quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-sr), var(--color-tk));
  border-radius: 2px;
  transition: width 0.3s ease;
}

.quiz-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px 10px;
}
.quiz-counter {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.quiz-score-disp {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-tk);
}

.quiz-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px 16px 16px;
  box-shadow: var(--shadow-md);
  margin-bottom: 16px;
}

.quiz-law-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.quiz-cat-badge {
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
}
.quiz-cat-badge-sr {
  background: var(--color-sr-light);
  color: var(--color-sr);
}
.quiz-cat-badge-tk {
  background: var(--color-tk-light);
  color: var(--color-tk);
}
.quiz-law-name-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 99px;
}
.quiz-past-exam-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid var(--accent);
  padding: 3px 8px;
  border-radius: 99px;
}

/* --- Per-question stats --- */
.quiz-question-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 11px;
  color: var(--text-secondary);
}
.qstat-label   { font-weight: 600; }
.qstat-first   { color: var(--color-tk); font-weight: 700; }
.qstat-pct strong { color: var(--color-sr); font-weight: 700; font-size: 13px; }
.qstat-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  flex-wrap: wrap;
}
.hist-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
}
.hist-correct { background: #2E7D32; }
.hist-wrong   { background: #C62828; }

.quiz-question {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.65;
  margin-bottom: 20px;
}

.quiz-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quiz-choice-btn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--surface-2);
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
  transition: all var(--transition);
}
.quiz-choice-btn:not(:disabled):active {
  background: var(--color-sr-light);
  border-color: var(--color-sr);
}
.quiz-choice-num {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-sr);
  flex-shrink: 0;
  min-width: 20px;
}
.quiz-choice-btn.correct {
  background: #E8F5E9;
  border-color: #2E7D32;
  color: #1B5E20;
}
.quiz-choice-btn.correct .quiz-choice-num { color: #2E7D32; }
.quiz-choice-btn.wrong {
  background: #FFEBEE;
  border-color: #C62828;
  color: #B71C1C;
}
.quiz-choice-btn.wrong .quiz-choice-num { color: #C62828; }
.quiz-choice-btn.dimmed {
  opacity: 0.45;
}

/* --- Result --- */
.quiz-result {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.quiz-result-label {
  font-size: 17px;
  font-weight: 800;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.quiz-result-correct { color: #2E7D32; }
.quiz-result-wrong   { color: #C62828; }
.quiz-correct-ans {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 99px;
}

.quiz-explanation {
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-primary);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}
.quiz-explanation strong {
  color: var(--color-sr);
  font-weight: 700;
}

.quiz-related { margin-top: 4px; }
.quiz-related-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-hint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}
.quiz-related-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* --- Actions --- */
.quiz-actions {
  padding: 0 0 8px;
}
.quiz-next-btn {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, var(--color-sr), #1976D2);
  color: white;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  box-shadow: var(--shadow-md);
  transition: all var(--transition);
}
.quiz-next-btn:active {
  transform: scale(0.97);
  box-shadow: none;
}

/* --- Finish --- */
.quiz-finish-card {
  text-align: center;
  padding: 48px 24px 40px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  margin: 20px 0;
  box-shadow: var(--shadow-md);
}
.quiz-finish-emoji {
  font-size: 64px;
  margin-bottom: 12px;
}
.quiz-finish-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 20px;
}
.quiz-finish-score {
  margin-bottom: 12px;
}
.score-big {
  font-size: 56px;
  font-weight: 900;
  color: var(--color-sr);
  line-height: 1;
}
.score-sep  { font-size: 28px; color: var(--text-secondary); }
.score-total { font-size: 28px; font-weight: 700; color: var(--text-secondary); }
.score-pct  {
  display: block;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-top: 4px;
}
.quiz-finish-comment {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 28px;
}
.quiz-retry-btn {
  display: block;
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, var(--color-sr), #1976D2);
  color: white;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
  box-shadow: var(--shadow-md);
  transition: all var(--transition);
}
.quiz-retry-btn:active { transform: scale(0.97); }
.quiz-change-btn {
  display: block;
  width: 100%;
  padding: 13px;
  background: var(--surface-2);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  transition: all var(--transition);
}
.quiz-change-btn:active { background: var(--border); }

/* ---------- Quiz History ---------- */
.quiz-history-link-btn {
  display: block;
  width: calc(100% - 32px);
  margin: 16px;
  padding: 13px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition);
}
.quiz-history-link-btn:active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.quiz-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px 12px;
  gap: 8px;
}
.quiz-history-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
  text-align: center;
}
.quiz-back-btn {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-sr);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 99px;
  white-space: nowrap;
}
.quiz-back-btn:active { background: var(--color-sr-light); }
.quiz-history-clear-btn {
  width: 36px;
  height: 36px;
  font-size: 17px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  transition: all var(--transition);
}
.quiz-history-clear-btn:active {
  background: #FFEBEE;
  border-color: #C62828;
}

.quiz-history-summary {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.hsum-row {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.hsum-label {
  display: block;
  font-size: 10px;
  color: var(--text-hint);
  margin-bottom: 4px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.hsum-val { font-size: 13px; color: var(--text-secondary); }
.hsum-val strong { font-size: 20px; color: var(--text-primary); font-weight: 800; }
.hsum-pct strong { color: var(--color-sr); }

.quiz-history-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid var(--border);
}
.quiz-history-card:active {
  transform: scale(0.98);
  box-shadow: none;
}
.qh-card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.qh-pct {
  margin-left: auto;
  font-size: 14px;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 99px;
}
.pct-good { background: #E8F5E9; color: #2E7D32; }
.pct-mid  { background: #FFF8E1; color: #F57F17; }
.pct-low  { background: #FFEBEE; color: #C62828; }

.qh-q {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}
.qh-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.qh-count {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
}

/* Detail view */
.qh-detail-card { margin-top: 4px; }
.qh-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.qh-choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
}
.qh-choice-text { flex: 1; }
.qh-choice-correct {
  background: #E8F5E9;
  border-color: #2E7D32;
  color: #1B5E20;
}
.qh-choice-correct .quiz-choice-num { color: #2E7D32; }
.qh-correct-mark {
  font-size: 11px;
  font-weight: 700;
  background: #2E7D32;
  color: white;
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---------- Loading skeleton ---------- */
@keyframes shimmer {
  0% { background-position: -300px 0; }
  100% { background-position: 300px 0; }
}
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 600px 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 6px;
}

/* ---------- Responsive (tablet以上) ---------- */
@media (min-width: 600px) {
  .main-content {
    max-width: 640px;
    margin: 0 auto;
    padding-left: 20px;
    padding-right: 20px;
  }
  .app-header { max-width: none; }
  .bottom-nav { max-width: 640px; left: 50%; transform: translateX(-50%); }
  .detail-sheet { max-width: 640px; left: 50%; transform: translateX(-50%) translateY(100%); }
  .detail-sheet.open { transform: translateX(-50%) translateY(0); }
}
