:root {
  --primary: #2d6a9f;
  --primary-dark: #1e4d73;
  --primary-mid: #3a82c4;
  --primary-light: #dceef8;
  --bg: #eef4f9;
  --card-bg: #fff;
  --text: #1a2533;
  --text-secondary: #5a7390;
  --border: #c8dcea;
  --accent: #e05c4a;
  --section-ch1: #2d6a9f;
  --section-ch2: #1a7a4a;
  --section-ch3: #c07a00;
  --section-ch4: #7b3fad;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 55%, var(--primary-mid) 100%);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(30,77,115,.3);
}
.header-logo {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
}
.header h1 {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}
.header .count {
  font-size: 12px;
  opacity: .8;
}
.version-select {
  font-size: 12px;
  padding: 3px 8px;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 14px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.version-select option {
  color: #333;
  background: #fff;
}
.header-link {
  color: #fff;
  text-decoration: none;
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 14px;
  white-space: nowrap;
  transition: background .15s;
}
.header-link:active {
  background: rgba(255,255,255,.15);
}

/* Filter tabs */
.filter-bar {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #dceef8 0%, #eef4f9 100%);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.filter-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: #fff;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Question list */
.question-list {
  padding: 8px 12px 120px;
}

.section-group {
  margin-bottom: 16px;
}
.section-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 4px 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 6px;
}
.section-header.ch1 { border-color: var(--section-ch1); color: var(--section-ch1); }
.section-header.ch2 { border-color: var(--section-ch2); color: var(--section-ch2); }
.section-header.ch3 { border-color: var(--section-ch3); color: var(--section-ch3); }
.section-header.ch4 { border-color: var(--section-ch4); color: var(--section-ch4); }

.q-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: var(--card-bg);
  border-radius: 8px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: background .15s;
  border: 1px solid var(--border);
  gap: 10px;
}
.q-item:active {
  background: var(--primary-light);
}
.q-item .q-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.q-item .q-text {
  flex: 1;
  font-size: 14px;
  line-height: 1.4;
  min-width: 0;
}
.q-item .q-breadcrumb {
  font-size: 10px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}
.q-item .q-title {
  font-weight: 500;
}
.q-item .q-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}
.q-item .q-view-count {
  font-size: 9px;
  color: var(--text-secondary);
}
.q-item .q-assess-mark {
  font-size: 11px;
  font-weight: 700;
}
.q-assess-mark.mark-good { color: #1a7a4a; }
.q-assess-mark.mark-shaky { color: #c07a00; }
.q-assess-mark.mark-bad { color: #e05c4a; }
.q-item .q-arrow {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.q-item .q-arrow svg {
  width: 18px;
  height: 18px;
}

.q-item.viewed .q-num {
  background: #e0eaf2;
  color: #8aa5bc;
}

/* Answer overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform .3s ease;
  pointer-events: none;
}
.overlay.open {
  transform: translateY(0);
  pointer-events: auto;
}
.overlay-backdrop {
  flex-shrink: 0;
  height: 20%;
  background: rgba(0,0,0,.4);
}
.overlay-panel {
  flex: 1;
  background: linear-gradient(180deg, #f5faff 0%, #fff 80px);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Drag handle to close overlay */
.drag-handle {
  flex-shrink: 0;
  padding: 10px 0 6px;
  display: flex;
  justify-content: center;
  cursor: grab;
  user-select: none;
}
.drag-handle-bar {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  transition: background .15s;
}
.drag-handle:active .drag-handle-bar {
  background: var(--primary);
}

.overlay-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.overlay-header-text {
  flex: 1;
  min-width: 0;
}
.overlay-breadcrumb {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.overlay-header .q-label {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
}
.close-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--primary-light);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 18px;
  transition: background .15s;
}
.close-btn:active { background: var(--border); }

.overlay-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}
.answer-text {
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
  color: var(--text);
}

/* Assessment bar */
.assessment-bar {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  justify-content: center;
  background: linear-gradient(180deg, #fff 0%, #f5faff 100%);
}
.assess-btn {
  width: 52px;
  height: 36px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
}
.assess-btn:active { transform: scale(.95); }
.assess-btn[data-mark="○"] { color: #1a7a4a; }
.assess-btn[data-mark="△"] { color: #c07a00; }
.assess-btn[data-mark="×"] { color: #e05c4a; }
.assess-btn.selected[data-mark="○"] { background: #e3f5ec; border-color: #1a7a4a; }
.assess-btn.selected[data-mark="△"] { background: #fef7e0; border-color: #c07a00; }
.assess-btn.selected[data-mark="×"] { background: #fce8e6; border-color: #e05c4a; }

/* Navigation within overlay */
.overlay-nav {
  display: flex;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding: 8px 16px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  gap: 8px;
}
.nav-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  color: var(--primary);
  font-weight: 500;
  transition: background .15s;
}
.nav-btn:active { background: var(--primary-light); }
.nav-btn:disabled {
  color: #bccfdd;
  border-color: #dde9f2;
}

/* Slides section */
.slides-section {
  margin-top: 20px;
}
.slides-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.slides-counter {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
}
.slide-carousel {
  position: relative;
}
.slide-img-wrapper {
  overflow: hidden;
  border-radius: 8px;
  background: var(--primary-light);
  border: 1px solid var(--border);
}
.slide-img-wrapper img {
  width: 100%;
  display: block;
  cursor: zoom-in;
}
.slide-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 8px;
}
.slide-nav-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 16px;
  transition: background .15s;
}
.slide-nav-btn:active { background: var(--primary-light); }
.slide-nav-btn:disabled { color: #bccfdd; border-color: #dde9f2; }
.slide-page {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 50px;
  text-align: center;
}
.slide-source {
  font-size: 10px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 4px;
}
.no-slides {
  padding: 16px;
  background: var(--primary-light);
  border-radius: 8px;
  border: 1px dashed var(--border);
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
}

/* Content swiper (薬価算定の基準 ←→ Q&A) */
.content-swiper {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.content-swiper::-webkit-scrollbar { display: none; }
.content-page {
  flex: 0 0 100%;
  scroll-snap-align: start;
  min-width: 0;
}
#qaTextPage {
  padding-left: 0;
}

/* Content tabs indicator */
.content-tabs {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 4px 0 10px;
}
.content-tabs.hidden { display: none; }
.content-tab {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 2px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all .2s;
}
.content-tab.active {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-mid) 100%);
  color: #fff;
}

/* Q&A text content */
.qa-text-content {
  font-size: 13px;
  line-height: 1.8;
  color: var(--text);
}
.qa-text-content .qa-q-line {
  font-weight: 700;
  color: var(--primary-dark);
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  padding: 8px 12px;
  border-radius: 0 6px 6px 0;
  margin-top: 20px;
}
.qa-text-content .qa-q-line:first-child {
  margin-top: 0;
}
.qa-text-content .qa-a-line {
  margin-top: 6px;
  padding-left: 4px;
}
.qa-text-content .qa-ex-line {
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 4px;
  padding-left: 4px;
  border-left: 2px solid var(--border);
}
.qa-text-content .qa-section-line {
  font-weight: 700;
  font-size: 14px;
  margin-top: 20px;
  color: var(--text);
}
.qa-text-content .qa-subheader-line {
  font-weight: 700;
  font-size: 13px;
  margin-top: 20px;
  padding: 5px 0 4px;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
}
.qa-text-content .qa-normal-line {
  margin-top: 2px;
}
.qa-text-content .qa-q-body {
  color: var(--primary-dark);
  background: var(--primary-light);
  padding: 2px 12px 2px 12px;
  margin-top: 0;
}
.qa-text-content .qa-ex-body {
  color: var(--text-secondary);
  font-size: 12px;
  padding-left: 4px;
  border-left: 2px solid var(--border);
  margin-top: 2px;
}
.qa-text-content .qa-example-line {
  margin-top: 4px;
  padding-left: 24px;
  font-size: 12px;
  color: var(--text-secondary);
}
/* Q&A tables */
.qa-text-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 11px;
  line-height: 1.4;
}
.qa-text-content th,
.qa-text-content td {
  border: 1px solid var(--border);
  padding: 4px 6px;
  text-align: left;
}
.qa-text-content th {
  background: var(--primary-light);
  font-weight: 600;
  white-space: nowrap;
}

/* Slide badge on question list */
.q-badge {
  flex-shrink: 0;
  font-size: 9px;
  background: #fff3e0;
  color: #c07a00;
  padding: 2px 5px;
  border-radius: 4px;
  font-weight: 600;
}

/* Fullscreen image viewer */
.img-viewer {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0,0,0,.9);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.img-viewer.open { display: flex; }
.img-viewer img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  touch-action: none;
  will-change: transform;
  transition: none;
}
.img-viewer-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.2);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}

/* Progress indicator */
.progress-bar {
  height: 3px;
  background: var(--primary-light);
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-dark) 0%, var(--primary-mid) 100%);
  transition: width .3s;
}

/* Search */
.search-bar {
  padding: 8px 12px;
  background: linear-gradient(180deg, #dceef8 0%, #eef4f9 100%);
  border-bottom: 1px solid var(--border);
}
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-input {
  width: 100%;
  padding: 8px 36px 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fff;
}
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45,106,159,.12);
}
.search-clear {
  position: absolute;
  right: 6px;
  width: 26px;
  height: 26px;
  border: none;
  background: var(--border);
  color: var(--text-secondary);
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.search-clear.visible {
  display: flex;
}
.search-clear:active { background: var(--primary); color: #fff; }

/* ===== Sticky top nav wrapper ===== */
.sticky-top {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
}

/* ===== Q&A ALL view ===== */
.qa-all-view {
  padding: 0 12px 120px;
}
.qa-all-section-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 12px 4px 6px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 8px;
  margin-top: 16px;
}
.qa-all-section-header:first-child { margin-top: 4px; }
.qa-all-section-header.ch1 { border-color: var(--section-ch1); color: var(--section-ch1); }
.qa-all-section-header.ch2 { border-color: var(--section-ch2); color: var(--section-ch2); }
.qa-all-section-header.ch3 { border-color: var(--section-ch3); color: var(--section-ch3); }
.qa-all-section-header.ch4 { border-color: var(--section-ch4); color: var(--section-ch4); }
.qa-all-subsection-header {
  font-weight: 700;
  font-size: 15px;
  padding: 10px 16px 6px;
  border-bottom: 1px solid var(--border);
  background: rgba(45,106,159,0.06);
}
.qa-all-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}
.qa-all-item-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  padding: 10px 14px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--primary-light);
}
.qa-all-item-num {
  display: inline-block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 10px;
  text-align: center;
  line-height: 24px;
  margin-right: 6px;
  flex-shrink: 0;
}
.qa-all-item-body {
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--text);
  white-space: pre-wrap;
}
.qa-all-item .qa-text-content {
  padding: 10px 14px;
}
.qa-all-qa-block {
  border-top: 1px dashed var(--border);
  background: rgba(45,106,159,0.03);
}

/* Q&A ALL セクションジャンプ TOC */
.qa-all-toc {
  margin: 8px 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.qa-all-toc-toggle {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.qa-all-toc-toggle:hover { background: var(--hover); }
.qa-all-toc-count {
  font-weight: 400;
  font-size: 12px;
  color: var(--text-secondary);
}
.qa-all-toc-links {
  display: none;
  flex-direction: column;
  border-top: 1px solid var(--border);
  max-height: 40vh;
  overflow-y: auto;
}
.qa-all-toc.open .qa-all-toc-links {
  display: flex;
}
.qa-all-toc-link {
  padding: 7px 14px;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  line-height: 1.4;
  transition: background 0.1s;
  text-decoration: none;
}
.qa-all-toc-link:last-child { border-bottom: none; }
.qa-all-toc-link:hover { background: var(--hover); }
.qa-all-toc-link.ch1 { border-left: 3px solid var(--section-ch1); }
.qa-all-toc-link.ch2 { border-left: 3px solid var(--section-ch2); }
.qa-all-toc-link.ch3 { border-left: 3px solid var(--section-ch3); }
.qa-all-toc-link.ch4 { border-left: 3px solid var(--section-ch4); }

/* ページトップへ戻るボタン */
.scroll-top-btn {
  position: fixed;
  bottom: 72px;
  right: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scroll-top-btn.visible {
  opacity: 1;
  pointer-events: auto;
}
.scroll-top-btn:active { transform: scale(0.92); }
