:root {
  --bg: #0f172a;
  --card: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #8b5cf6;
  --accent-strong: #7c3aed;
  --border: #1f2937;
  --reader-bg: #0b1020;
  --reader-text: #e5e7eb;
  --reader-safe-inline: clamp(12px, 4vw, 36px);
  --reader-safe-block: clamp(12px, 5vh, 48px);
}

[data-theme="light"] {
  --bg: #f6f8fa;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #4b5563;
  --accent: #6366f1;
  --accent-strong: #4f46e5;
  --border: #e5e7eb;
  --reader-bg: #ffffff;
  --reader-text: #111827;
}

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

body {
  font-family: "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

/* ========================================
   全画面リーダー
======================================== */

.fullscreen-reader {
  position: fixed;
  inset: 0;
  background: var(--reader-bg);
  color: var(--reader-text);
}

#fullscreenReader {
  z-index: 10;
}

#fullscreenReader iframe {
  pointer-events: auto;
}

.viewer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* EPUBスクロールモード（縦書き�E横書きともに縦スクロール�E�E*/
.fullscreen-reader.epub-scroll .viewer {
  overflow-y: auto;
  overflow-x: hidden;
}


/* クリチE��検知用オーバ�Eレイ */
.click-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: all;
  background: transparent;
  display: none;
}

.viewer.visible~.click-overlay {
  display: block;
}

.fullscreen-reader.epub-scroll .click-overlay {
  display: none;
  pointer-events: none;
}

/* ========================================
   フローチEI
======================================== */

#floatOverlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: none;
  pointer-events: none;
}

#floatOverlay.visible {
  display: block;
  pointer-events: auto;
}

iframe[src*="accounts.google.com"],
div[id^="g_id_"] {
  z-index: 2147483647 !important;
  position: fixed !important;
}

body.google-auth-active * {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  filter: none !important;
}

body.google-auth-active #floatOverlay,
body.google-auth-active .float-backdrop,
body.google-auth-active .float-buttons,
body.google-auth-active .modal-backdrop {
  display: none !important;
  pointer-events: none !important;
}

.float-backdrop {
  position: absolute;
  inset: 0;
  backdrop-filter: blur(4px);
  background: rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  z-index: 1;
}

.float-title {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
  z-index: 2;
}

.float-title img {
  width: min(240px, 60vw);
  height: auto;
}

[data-theme="light"] #floatOverlay .float-backdrop {
  background: rgba(255, 255, 255, 0.85);
}

[data-theme="light"] #floatOverlay button {
  background: #f0f0f0;
  color: #111;
  border: 1px solid #ccc;
}

[data-theme="light"] #floatOverlay button:hover {
  background: #e6e6e6;
}

[data-theme="light"] #floatOverlay .float-title img {
  filter: none;
}

.float-buttons {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.float-main-menu {
  position: absolute;
  top: 50%;
  left: 20px;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}

.float-settings {
  position: absolute;
  top: 20px;
  left: 20px;
}

.float-buttons button {
  pointer-events: auto;
  min-width: 52px;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.85);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.float-buttons button:hover {
  background: rgba(17, 24, 39, 0.95);
}

.float-top-right {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.float-top-right button {
  pointer-events: auto;
}

.font-buttons {
  position: absolute;
  right: 24px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}

#toggleTheme {
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  pointer-events: auto;
}

#toggleZoom {
  position: absolute;
  right: 24px;
  top: calc(50% + 50px);
  transform: translateY(-50%);
  font-size: 1.2rem;
  pointer-events: auto;
}

#toggleLanguage {
  position: absolute;
  left: 24px;
  bottom: 24px;
  padding: 8px 10px;
  pointer-events: auto;
}

#toggleLanguage img {
  width: 28px;
  height: auto;
  display: block;
}

#floatProgress {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, 60%);
  pointer-events: auto;
  z-index: 3;
}

#floatProgressPercent {
  text-align: center;
  margin-bottom: 8px;
  font-weight: 600;
}

#floatProgressTrack {
  position: relative;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

[data-theme="light"] #floatProgressTrack {
  background: rgba(0, 0, 0, 0.15);
}

#floatProgressMarks {
  position: absolute;
  inset: 0;
}

#floatProgressFill {
  position: absolute;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  border-radius: 3px;
}

#floatProgressThumb {
  position: absolute;
  top: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(17, 24, 39, 0.8);
}

/* RTL（右開き）時の進捗バー反転 */
#floatProgress.rtl-progress #floatProgressTrack {
  transform: scaleX(-1);
}

#floatProgress.rtl-progress #floatProgressFill {
  transform: scaleX(-1);
}

#floatProgress.rtl-progress #floatProgressThumb {
  right: auto;
}

/* スクロール時�Eメニューボタン */
.floating-menu-button {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 12;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: none;
  background: rgba(15, 23, 42, 0.65);
  color: #fff;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.floating-menu-button:hover {
  background: rgba(15, 23, 42, 0.8);
}

.reader-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 95;
}

.control-btn {
  min-width: 56px;
  min-height: 44px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.75);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.control-btn:hover {
  background: rgba(17, 24, 39, 0.9);
}

.control-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* メニューが開ぁE��ぁE��時�Eオーバ�Eレイを非表示 */
.left-menu.visible~.fullscreen-reader .click-overlay,
.progress-bar-panel.visible~.fullscreen-reader .click-overlay,
.bookmark-menu.visible~.fullscreen-reader .click-overlay {
  pointer-events: none;
}

.image-viewer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--reader-bg);
  padding: var(--reader-safe-block) var(--reader-safe-inline);
}

.image-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: zoom-in;
}

/* 見開きコンテナ */
.image-viewer .spread-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  height: 100%;
}

.image-viewer .spread-page {
  max-width: 50%;
  max-height: 100%;
  object-fit: contain;
  cursor: zoom-in;
}

.image-viewer .spread-left {
  /* 左ページ */
}

.image-viewer .spread-right {
  /* 右ページ */
}

/* ズーム状態 */
.image-viewer.zoomed {
  overflow: auto;
  cursor: grab;
}

.image-viewer.zoomed:active {
  cursor: grabbing;
}

.image-viewer.zoomed img,
.image-viewer.zoomed .spread-container {
  transform: scale(2);
  transform-origin: center center;
  cursor: zoom-out;
}

/* RTL モード時の見開き表示順序 */
.image-viewer.rtl-mode .spread-container {
  flex-direction: row-reverse;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem;
}

.empty-icon {
  font-size: 5rem;
  margin-bottom: 1.5rem;
  opacity: 0.5;
}

.empty-book-icon {
  width: 140px;
  opacity: 0.85;
  margin-bottom: 1.5rem;
}

.empty-state h2 {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.empty-state p {
  color: var(--muted);
  font-size: 1rem;
}

.cloud-empty {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.cloud-empty-title {
  font-weight: 600;
  color: var(--text);
}

.cloud-empty-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

/* ========================================
   左サイドメニュー
======================================== */

.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.menu-backdrop.visible {
  display: block;
  opacity: 1;
}

/* 左メニュー用バックドロチE�E�E�左メニューの下！E*/
#leftMenuBackdrop {
  z-index: 99;
}

/* 進捗バー用バックドロチE�E�E�進捗バーの下！E*/
#progressBarBackdrop {
  z-index: 85;
}

.left-menu {
  position: fixed;
  left: -320px;
  top: 0;
  bottom: 0;
  width: 300px;
  background: var(--card);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
}

.left-menu.visible {
  left: 0;
}

.menu-header {
  padding: 2rem 1.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: center;
}

.menu-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.3);
}

.menu-header h2 {
  font-size: 1.25rem;
  background: linear-gradient(135deg, #a78bfa, #c4b5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.menu-title-image {
  width: 100%;
  max-width: 260px;
  height: auto;
}

.menu-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease;
  text-align: left;
}

.menu-item:hover {
  background: rgba(139, 92, 246, 0.1);
}

.menu-item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.menu-item:disabled:hover {
  background: transparent;
}

.menu-icon {
  font-size: 1.25rem;
  width: 1.5rem;
  text-align: center;
}

.menu-language {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1.5rem 1rem;
}

.lang-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 1.25rem;
  padding: 0.35rem 0.6rem;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.lang-btn:hover {
  border-color: var(--accent);
}

.lang-btn.active {
  background: rgba(139, 92, 246, 0.2);
  border-color: var(--accent);
}

.menu-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.user-info {
  font-size: 0.875rem;
  color: var(--muted);
  word-break: break-all;
}

.btn-icon {
  margin-right: 0.5rem;
}

/* ========================================
   進捗バーパネル
======================================== */

.progress-bar-panel {
  position: fixed;
  bottom: -100px;
  left: 0;
  right: 0;
  height: 80px;
  background: rgba(17, 24, 39, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 2rem;
  transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 90;
}

[data-theme="light"] .progress-bar-panel {
  background: rgba(255, 255, 255, 0.95);
  border-top-color: var(--border);
}

.progress-bar-panel.visible {
  bottom: 0;
}

.progress-container {
  width: 100%;
  max-width: 1000px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.progress-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.progress-arrow {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
  transition: all 0.2s ease;
}

.progress-arrow:hover {
  background: rgba(139, 92, 246, 0.2);
  border-color: var(--accent);
}

.progress-track {
  flex: 1;
  position: relative;
  height: 12px;
  /* 濁E��グレーで白背景でも確実に視認可能 */
  background: #374151;
  border: 2px solid #1f2937;
  border-radius: 999px;
  cursor: pointer;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.4),
    0 2px 4px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .progress-track {
  background: #e2e8f0;
  /* slate-200 */
  border-color: #cbd5e1;
  /* slate-300 */
}

[data-theme="light"] .current-page-input {
  background: #ffffff;
  border-color: #d1d5db;
  color: #0f172a;
}

.progress-fill {
  position: absolute;
  left: 2px;
  top: 2px;
  bottom: 2px;
  /* 鮮めE��なグラチE�Eションで視認性向丁E*/
  background: linear-gradient(90deg, #8b5cf6, #a855f7);
  border-radius: 999px;
  transition: width 0.2s ease;
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.5);
}



.progress-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  /* 白背景でも黒背景でも見えるツマミ */
  background: linear-gradient(135deg, #f8fafc, #e2e8f0);
  border: 3px solid #1f2937;
  border-radius: 50%;
  cursor: grab;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.3),
    inset 0 1px 2px rgba(255, 255, 255, 0.8);
  transition: transform 0.2s ease;
}

.progress-thumb:hover {
  transform: translate(-50%, -50%) scale(1.2);
}

.progress-thumb.dragging {
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.3);
}

.progress-info {
  display: flex;
  justify-content: center;
  align-items: center;
}

.page-numbers {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  color: var(--text);
}

.current-page-input {
  width: 60px;
  padding: 0.25rem 0.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  text-align: center;
  font-size: 1rem;
}

.current-page-input:focus {
  outline: none;
  border-color: var(--accent);
}

.total-pages {
  color: var(--muted);
}

/* しおり�Eーカー�E�進捗バー上！E*/
.bookmark-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  background: #fbbf24;
  border: 2px solid white;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  appearance: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.bookmark-marker:hover {
  transform: translate(-50%, -50%) scale(1.3);
}

/* ========================================
   しおりメニュー�E�モーダル�E�E
======================================== */

.bookmark-menu {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 110;
}

.bookmark-menu.visible {
  display: flex;
}

.bookmark-menu .modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}

.bookmark-menu .modal-header {
  margin-bottom: 1rem;
}

.bookmark-menu .modal-header h3 {
  font-size: 1.25rem;
}

.toc-section {
  margin-bottom: 1rem;
  padding: 0 1.5rem 0.5rem;
}

.toc-title {
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
  max-height: 240px;
  overflow-y: auto;
}

.toc-item {
  width: 100%;
}

.toc-link {
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: inherit;
  cursor: pointer;
  transition: background 0.2s ease;
}

.toc-link:hover {
  background: rgba(148, 163, 184, 0.2);
}

.bookmark-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
  max-height: 400px;
  overflow-y: auto;
}

.bookmark-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(139, 92, 246, 0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.bookmark-item:hover {
  background: rgba(139, 92, 246, 0.1);
}

.bookmark-info {
  flex: 1;
}

.bookmark-label {
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.bookmark-meta {
  font-size: 0.875rem;
  color: var(--muted);
}

.bookmark-delete {
  padding: 0.5rem;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.25rem;
  transition: color 0.2s ease;
}

.bookmark-delete:hover {
  color: #ef4444;
}

.add-bookmark-btn {
  width: 100%;
  padding: 0.75rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border: none;
  border-radius: 10px;
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.add-bookmark-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.4);
}

/* ========================================
   モーダル共送E
======================================== */

#modalOverlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  /* > #floatOverlay(900). 追加ブラー層が増えてもモーダルを最前面に */
  display: none;
}

#modalOverlay.visible {
  display: block;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 120;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
}

.modal .modal-content {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
  z-index: 1;
}

.modal-large {
  width: min(800px, 90vw);
}

.modal-medium {
  width: min(600px, 90vw);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1.5rem;
}

.close-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.25rem;
  display: grid;
  place-items: center;
  transition: background 0.2s ease;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sync-message {
  color: var(--text);
  line-height: 1.6;
}

.sync-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sync-action-btn {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.75);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.sync-action-btn:hover {
  background: rgba(15, 23, 42, 0.9);
}

.sync-action-btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border: none;
}

.sync-action-btn.primary:hover {
  transform: translateY(-1px);
}

/* ========================================
   ファイル選択�Eライブラリ
======================================== */

.file-input-hidden {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.file-input-label {
  display: block;
  padding: 2rem;
  border: 2px dashed var(--border);
  border-radius: 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.file-input-label:hover {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.05);
}

.file-input-label span {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.file-input-label input {
  display: none;
}

.library-section h4 {
  font-size: 1.125rem;
}

.library-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.library-view-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.library-view-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.library-view-btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.library-view-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
}

.library-grid[data-view="list"] {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.library-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.library-grid[data-view="list"] .library-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
}

.library-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.library-cover {
  width: 100%;
  aspect-ratio: 3/4;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(139, 92, 246, 0.05));
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.library-grid[data-view="list"] .library-cover {
  width: 48px;
  aspect-ratio: 1 / 1;
  margin-bottom: 0;
  font-size: 1.25rem;
}

.library-title {
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-grid[data-view="list"] .library-title {
  flex: 1;
  margin-bottom: 0;
  white-space: normal;
}

.library-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.library-grid[data-view="list"] .library-meta {
  margin-left: auto;
}

.library-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
  align-items: center;
}

.library-grid[data-view="list"] .library-actions {
  margin-top: 0;
  margin-left: auto;
}

.library-badge {
  font-size: 0.65rem;
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(139, 92, 246, 0.1);
}

.library-type-badge {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--accent);
  margin-right: 0.5rem;
}

.library-attach {
  font-size: 0.7rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  cursor: pointer;
}

.library-attach:hover {
  border-color: var(--accent);
}

/* ========================================
   履歴リスチE
======================================== */

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: background 0.2s ease;
}

.history-item:hover {
  background: rgba(139, 92, 246, 0.1);
}

.history-info {
  flex: 1;
}

.history-delete {
  margin-left: auto;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.history-title {
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.history-meta {
  font-size: 0.875rem;
  color: var(--muted);
}

/* ========================================
   チE��スト検索
======================================== */

.search-input-container {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.search-input {
  flex: 1;
  padding: 0.75rem 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.search-btn {
  padding: 0.75rem 1.5rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border: none;
  border-radius: 8px;
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
  white-space: nowrap;
}

.search-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.4);
}

.search-btn:active {
  transform: translateY(0);
}

.search-results {
  max-height: 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.search-result-item {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.search-result-item:hover {
  background: rgba(139, 92, 246, 0.1);
  transform: translateY(-2px);
}

.search-result-excerpt {
  font-size: 0.875rem;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 0.5rem;
}

.search-result-excerpt mark {
  background: rgba(139, 92, 246, 0.3);
  color: var(--text);
  padding: 0.125rem 0.25rem;
  border-radius: 3px;
}

.search-result-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.search-no-results {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

.search-loading {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

/* ========================================
   設宁E
======================================== */

.settings-section {
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.settings-section h4 {
  font-size: 1.125rem;
  margin-bottom: 1rem;
}

.setting-item {
  margin-bottom: 1rem;
}

.setting-item:last-child {
  margin-bottom: 0;
}

.setting-item label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.setting-item select,
.setting-item input[type="text"],
.setting-item input[type="number"] {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.875rem;
}

.setting-item select:focus,
.setting-item input:focus {
  outline: none;
  border-color: var(--accent);
}

.setting-hint {
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

.setting-warning {
  color: #f0ad4e;
}

.setting-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.secondary-btn {
  padding: 0.625rem 1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease;
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ========================================
   レスポンシチE
======================================== */

@media (max-width: 768px) {
  .left-menu {
    width: 280px;
    left: -300px;
  }

  .progress-bar-panel {
    padding: 0 1rem;
  }

  .library-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}

@media (max-width: 480px) {
  .empty-icon {
    font-size: 3rem;
  }

  .empty-state h2 {
    font-size: 1.25rem;
  }

  .left-menu {
    width: min(320px, 85vw);
    left: calc(-1 * min(320px, 85vw));
  }

  .left-menu.visible {
    left: 0;
  }
}

/* 候補リスチE*/
.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0;
  max-height: 300px;
  overflow-y: auto;
}

.candidate-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.candidate-item:hover {
  background: rgba(139, 92, 246, 0.1);
  border-color: var(--accent);
}

.candidate-title {
  font-weight: 600;
  color: var(--text);
}

.candidate-author {
  font-size: 0.875rem;
  color: var(--muted);
}

.candidate-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* ========================================
   ローディングオーバーレイ
======================================== */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-overlay.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.book-loader {
  position: relative;
  width: 60px;
  height: 45px;
  margin-bottom: 20px;
  perspective: 1000px;
}

.book-loader div {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transform-origin: 0 50%;
  animation: flip 1.2s infinite ease-in-out;
  border: 2px solid var(--border);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.book-loader div:nth-child(1) {
  animation-delay: 0s;
  background: var(--card);
}

.book-loader div:nth-child(2) {
  animation-delay: -0.4s;
  background: var(--card);
}

.book-loader div:nth-child(3) {
  animation-delay: -0.8s;
  background: var(--accent);
}

@keyframes flip {
  0% {
    transform: rotateY(0deg);
  }

  50% {
    transform: rotateY(-180deg);
  }

  100% {
    transform: rotateY(-180deg);
  }
}

.loading-text {
  font-size: 1.1rem;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.05em;
  animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 0.6;
  }

  50% {
    opacity: 1;
  }
}

/* ========================================
   言語選択メニュー（フロートUI用・地球儀ボタン横）
======================================== */

.float-lang-menu {
  position: absolute;
  left: 76px;
  bottom: 24px;
  background: rgba(17, 24, 39, 0.85);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: row;
  gap: 6px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  z-index: 910;
  pointer-events: auto;
}

.float-lang-menu.hidden {
  display: none;
}

.lang-option-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s ease;
}

.lang-option-btn:hover {
  background: rgba(139, 92, 246, 0.2);
}

.lang-option-btn img {
  width: 28px;
  height: 28px;
  border-radius: 2px;
}

/* ズームボタン配置 (テーマ切替ボタンの下) */
#toggleZoom {
  position: absolute;
  right: 24px;
  top: calc(50% + 60px);
  /* toggleThemeの約60px下 */
  transform: translateY(-50%);
  font-size: 1.2rem;
  pointer-events: auto;
  transition: opacity 0.2s ease;
}

/* ズーム時のUI制御 */
body.is-zoomed #floatOverlay .float-backdrop {
  backdrop-filter: none !important;
  background: transparent !important;
}

/* ズーム時はズームボタン以外を非表示 */
body.is-zoomed #floatOverlay .float-buttons>*:not(#toggleZoom) {
  opacity: 0;
  pointer-events: none;
}

/* 明示的な指定（念のため） */
body.is-zoomed #floatOverlay .float-buttons .font-buttons,
body.is-zoomed #floatOverlay .float-buttons .float-top-right,
body.is-zoomed #floatOverlay .float-main-menu,
body.is-zoomed #floatOverlay .top-bar-title,
/* 追加: ソフトタイトルがあれば */
body.is-zoomed #toggleLanguage,
body.is-zoomed #toggleTheme {
  opacity: 0;
  pointer-events: none;
}

/* ズーム時はスクロールを有効化（パン操作） */
#imageViewer.zoomed {
  overflow: auto;
  /* タッチデバイスでの慣性スクロール */
  -webkit-overflow-scrolling: touch;
}

.float-buttons {
  z-index: 1600;
  /* GridOverlayより上にする */
}

/* クリックエリア可視化グリッド */
.area-grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* デフォルトは操作不可 */
  z-index: 1400;
  /* floatOverlay(1500?)より手前にするが、ボタン系は1600以上にする必要あり */
  /* 実装確認: floatOverlayは z-index指定なし(static)だが、.float-buttons等は絶対配置 */
  /* ここでは、ボタンより下、背景より上にする。 */
  /* 一旦 z-index: 100 に下げて様子を見るか、あるいはボタンを上げる。 */
  /* ユーザー要望: "ボタンが効かない" -> gridが上にあるから。 */
  /* Gridはあくまでガイドなので、ボタンクリックを邪魔してはいけないが、
     "色なしエリアをクリックしたらリーダー状態に戻る" 機能のためには click を受け取る必要がある。 */
  /* 解決策: Gridの z-index を 1500 (floatOverlayと同等) にしつつ、ボタンの z-index を 1600 に上げる。 */
  display: grid;
  grid-template-columns: 20% 60% 20%;
  grid-template-rows: 20% 60% 20%;
  opacity: 0;
  transition: opacity 0.2s;
}

.area-grid-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.area-cell {
  border: 1px solid rgba(255, 255, 255, 0.3);
  /* 線を濃くする */
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

.area-cell.has-function {
  background-color: rgba(64, 150, 255, 0.1);
  cursor: pointer;
}

.area-cell.active-function {
  background-color: rgba(64, 150, 255, 0.3);
}

.area-label {
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.area-cell.show-label .area-label {
  opacity: 1;
}