/* ==========================================================================
   Novel Reader - Editorial Typography Design System
   ========================================================================== */

:root {
  /* Accent Color: Single Color Only (#0284c7 - Deep Cerulean) */
  --accent-color: #0284c7;
  --accent-subtle: rgba(2, 132, 199, 0.12);
  --accent-border: rgba(2, 132, 199, 0.3);

  /* Surface & Tone Hierarchy (No Glassmorphism, Pure Tone Depth) */
  --bg-dark-base: #0a0b0e;
  --surface-dark-1: #111318;
  --surface-dark-2: #181b22;
  --border-dark: #222630;
  --border-subtle: rgba(255, 255, 255, 0.07);

  /* Typography */
  --font-heading: 'Shippori Mincho B1', 'Shippori Mincho', serif;
  --font-body: 'Shippori Mincho', 'Noto Serif JP', serif;
  --font-ui: 'Noto Sans JP', sans-serif;
  --font-code: 'Cinzel', serif;

  --font-size: 18px;
  --line-height: 1.85;
  --letter-spacing: 0.04em;
  --content-width: 780px;

  --text-primary: #ededed;
  --text-secondary: #8c93a0;
  --text-dim: #545b68;

  /* Reader State Properties */
  --bg-opacity: 0.75;
  --bg-blur: 3px;
  --bg-dim: 0.45;
  --bg-mask-color: rgba(10, 11, 14, var(--bg-dim));
  --card-blur: 0px;

  /* Card Background & Shadows (Restrained, Flat & Editorial) */
  --card-bg: rgba(17, 19, 24, 0.88);
  --card-border: 1px solid var(--border-dark);
  --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);

  --transition-speed: 0.2s ease;
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

html, body {
  width: 100%;
  min-height: 100%;
  font-family: var(--font-body);
  background: transparent;
  color: var(--text-primary);
  overflow-x: hidden;
  line-height: var(--line-height);
}

/* ==========================================================================
   Background System (Restrained & Elegant)
   ========================================================================== */

#bg-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

#bg-base-color {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #0a0b0e;
  transition: background var(--transition-speed);
}

#bg-image-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  opacity: var(--bg-opacity);
  filter: blur(var(--bg-blur));
  transition: opacity var(--transition-speed), filter var(--transition-speed);
}

#bg-illust {
  position: absolute;
  display: block;
  user-select: none;
  pointer-events: none;
  transition: all var(--transition-speed);
}

/* Background Position Modes */
body.bg-pos-right #bg-illust {
  right: 0;
  bottom: 0;
  height: 95vh;
  max-width: 55vw;
  object-fit: contain;
  object-position: right bottom;
}

body.bg-pos-center #bg-illust {
  left: 0;
  right: 0;
  margin: 0 auto;
  bottom: 0;
  height: 95vh;
  max-width: 85vw;
  object-fit: contain;
  object-position: center bottom;
}

body.bg-pos-cover #bg-illust {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

#bg-overlay-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: var(--bg-mask-color);
  transition: background var(--transition-speed);
}

/* ==========================================================================
   Theme Presets (No Gimmicks, Crisp Literary Tone)
   ========================================================================== */

/* 1. Illust Mode (Default) */
body.theme-illust {
  --text-primary: #ededed;
  --text-secondary: #949ca8;
}
body.theme-illust #bg-illust {
  display: block;
}

/* 2. Dark Mode (Ink Slate / Strict Monochrome) */
body.theme-dark {
  --card-bg: #111318;
  --card-border: 1px solid #1c1f26;
  --text-primary: #e4e7eb;
  --text-secondary: #767e8c;
  --text-shadow: none;
}
body.theme-dark #bg-base-color {
  background: #090a0d;
}
body.theme-dark #bg-image-layer,
body.theme-dark #bg-illust {
  display: none !important;
}
body.theme-dark #bg-overlay-layer {
  background: transparent;
}

/* 3. White Mode (Book Paper / Off-White) */
body.theme-white {
  --card-bg: #ffffff;
  --card-border: 1px solid #e5e5e5;
  --card-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
  --text-primary: #171717;
  --text-secondary: #737373;
  --text-dim: #a3a3a3;
  --text-shadow: none;
  --accent-color: #0284c7;
  --border-subtle: rgba(0, 0, 0, 0.06);
}
body.theme-white #bg-base-color {
  background: #f7f7f6;
}
body.theme-white #bg-image-layer,
body.theme-white #bg-illust {
  display: none !important;
}
body.theme-white #bg-overlay-layer {
  background: transparent;
}

/* 4. Sepia Mode (Archive Paper) */
body.theme-sepia {
  --card-bg: #fdfbf7;
  --card-border: 1px solid #eae3d2;
  --card-shadow: 0 4px 15px rgba(60, 40, 20, 0.04);
  --text-primary: #382c1e;
  --text-secondary: #78644e;
  --text-dim: #9e8972;
  --text-shadow: none;
  --accent-color: #8c5b24;
  --border-subtle: rgba(60, 40, 20, 0.08);
}
body.theme-sepia #bg-base-color {
  background: #f3edd9;
}
body.theme-sepia #bg-image-layer,
body.theme-sepia #bg-illust {
  display: none !important;
}
body.theme-sepia #bg-overlay-layer {
  background: transparent;
}

/* ==========================================================================
   Minimal Flat Toolbar (No Glassmorphism, Strict Hierarchy)
   ========================================================================== */

#progress-bar-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: transparent;
  z-index: 1001;
}

#progress-bar {
  width: 0%;
  height: 100%;
  background: var(--accent-color);
  transition: width 0.1s linear;
}

#top-toolbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--surface-dark-1);
  border-bottom: 1px solid var(--border-dark);
  z-index: 1000;
  transition: background var(--transition-speed);
}
body.theme-white #top-toolbar {
  background: #ffffff;
  border-bottom-color: #e5e5e5;
}
body.theme-sepia #top-toolbar {
  background: #fdfbf7;
  border-bottom-color: #eae3d2;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

#novel-header-title {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.badge {
  font-family: var(--font-code);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 2px;
  background: var(--surface-dark-2);
  color: var(--text-secondary);
  border: 1px solid var(--border-dark);
}
body.theme-white .badge {
  background: #f5f5f4;
  border-color: #e5e5e5;
  color: #737373;
}
body.theme-sepia .badge {
  background: #f4edd9;
  border-color: #eae3d2;
  color: #78644e;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Version Toggle Button */
.version-switch-group {
  display: flex;
  align-items: center;
  background: var(--surface-dark-2);
  padding: 2px;
  border-radius: 2px;
  border: 1px solid var(--border-dark);
}
body.theme-white .version-switch-group {
  background: #f5f5f4;
  border-color: #e5e5e5;
}
body.theme-sepia .version-switch-group {
  background: #f4edd9;
  border-color: #eae3d2;
}

.btn-toggle {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 2px;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.btn-toggle.active {
  background: var(--accent-color);
  color: #ffffff;
}

/* Locked Version Button (Paid Only) */
.locked-toggle-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.btn-toggle.locked {
  cursor: not-allowed;
  opacity: 0.72;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  user-select: none;
}
.btn-toggle.locked:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.lock-icon {
  font-size: 9px;
  opacity: 0.8;
  vertical-align: middle;
}

/* Paid Mini Tooltip on Hover */
.paid-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-3px);
  background: var(--surface-dark-1);
  color: var(--accent-color);
  border: 1px solid var(--accent-border);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 2px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  z-index: 1005;
}
.paid-tooltip::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 4px solid var(--accent-border);
}

.locked-toggle-wrapper:hover .paid-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

body.theme-white .paid-tooltip {
  background: #ffffff;
  border-color: #cbd5e1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
body.theme-white .paid-tooltip::before {
  border-bottom-color: #cbd5e1;
}

body.theme-sepia .paid-tooltip {
  background: #fdfbf7;
  border-color: #dec8b0;
  box-shadow: 0 4px 12px rgba(60, 40, 20, 0.08);
}
body.theme-sepia .paid-tooltip::before {
  border-bottom-color: #dec8b0;
}

/* Shake animation on click attempt */
.btn-toggle.shake {
  animation: lock-shake 0.35s ease-in-out;
}
@keyframes lock-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-3px); }
  40%, 80% { transform: translateX(3px); }
}

/* Toast Message Notification */
.toast-message {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: var(--surface-dark-1);
  border: 1px solid var(--border-dark);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
  padding: 8px 18px;
  border-radius: 2px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  z-index: 10000;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease;
}
.toast-message.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
body.theme-white .toast-message {
  background: #ffffff;
  border-color: #e5e5e5;
  color: #171717;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}
body.theme-sepia .toast-message {
  background: #fdfbf7;
  border-color: #eae3d2;
  color: #382c1e;
  box-shadow: 0 6px 16px rgba(60, 40, 20, 0.08);
}

.quick-theme-group {
  display: flex;
  gap: 3px;
}

.btn-icon {
  background: var(--surface-dark-2);
  border: 1px solid var(--border-dark);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition-speed);
}
body.theme-white .btn-icon {
  background: #f5f5f4;
  border-color: #e5e5e5;
  color: #525252;
}
body.theme-sepia .btn-icon {
  background: #f4edd9;
  border-color: #eae3d2;
  color: #634b35;
}

.btn-icon:hover {
  color: var(--text-primary);
  border-color: var(--accent-color);
}

.btn-icon.active {
  border-color: var(--accent-color);
  color: var(--accent-color);
  background: var(--accent-subtle);
}

.btn-icon.primary {
  width: auto;
  padding: 0 12px;
  gap: 6px;
  background: var(--surface-dark-2);
  border: 1px solid var(--border-dark);
  color: var(--text-primary);
}
.btn-icon.primary:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}
.btn-icon.primary .btn-label {
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-ui);
}

/* ==========================================================================
   Main Novel Container & Reading Paper (Editorial Layout)
   ========================================================================== */

#novel-container {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding: 84px 24px 80px 24px;
  min-height: 100vh;
  width: 100%;
}

@media (min-width: 1300px) {
  body.bg-pos-right:not(.layout-vertical) #novel-container {
    justify-content: flex-start;
    padding-left: max(48px, calc((100vw - var(--content-width) - 480px) / 2));
  }
}

#reading-card {
  width: 100%;
  max-width: var(--content-width);
  border-radius: 2px;
  padding: 64px 56px;
  position: relative;
  transition: background var(--transition-speed), border-color var(--transition-speed);
}

/* Card Styles: Clean Paper Tones, No Gimmick Blur */
#reading-card.card-glass,
#reading-card.card-semi-dark {
  background: var(--card-bg);
  border: var(--card-border);
  box-shadow: var(--card-shadow);
}

#reading-card.card-semi-light {
  background: rgba(248, 248, 246, 0.94);
  border: 1px solid #d4d4d8;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  color: #18181b;
}

#reading-card.card-none {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding-left: 12px;
  padding-right: 12px;
}

#reading-card.card-solid {
  background: var(--surface-dark-1);
  border: 1px solid var(--border-dark);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
body.theme-white #reading-card.card-solid {
  background: #ffffff;
  border-color: #e5e5e5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}
body.theme-sepia #reading-card.card-solid {
  background: #fdfbf7;
  border-color: #eae3d2;
  box-shadow: 0 4px 16px rgba(60, 40, 20, 0.04);
}

/* ==========================================================================
   Novel Header & Metadata (Editorial Typography)
   ========================================================================== */

#novel-meta-header {
  margin-bottom: 40px;
  text-align: center;
}

.novel-title-badge {
  display: inline-block;
  font-family: var(--font-code);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 3px 12px;
  border-radius: 2px;
  background: var(--surface-dark-2);
  border: 1px solid var(--border-dark);
  color: var(--text-secondary);
  margin-bottom: 18px;
}
body.theme-white .novel-title-badge {
  background: #f5f5f4;
  border-color: #e5e5e5;
  color: #737373;
}
body.theme-sepia .novel-title-badge {
  background: #f4edd9;
  border-color: #eae3d2;
  color: #78644e;
}

#novel-main-title {
  font-family: var(--font-heading);
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.4;
  margin-bottom: 24px;
  color: var(--text-primary);
  text-shadow: var(--text-shadow);
}

/* Tags Accordion (Restrained Editorial Stamp) */
.tags-details {
  background: var(--surface-dark-2);
  border: 1px solid var(--border-dark);
  border-radius: 2px;
  padding: 12px 18px;
  margin: 20px auto;
  max-width: 620px;
  text-align: left;
}
body.theme-white .tags-details {
  background: #fafaf9;
  border-color: #e5e5e5;
}
body.theme-sepia .tags-details {
  background: #f7f1e1;
  border-color: #eae3d2;
}

.tags-summary {
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  color: var(--text-secondary);
}
.tags-summary:hover {
  color: var(--text-primary);
}

.tag-counter {
  font-family: var(--font-code);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 2px;
  background: var(--surface-dark-1);
  border: 1px solid var(--border-dark);
}
body.theme-white .tag-counter {
  background: #ffffff;
  border-color: #e5e5e5;
}

.tags-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.play-tag {
  font-family: var(--font-ui);
  font-size: 11.5px;
  background: var(--surface-dark-1);
  color: var(--text-secondary);
  border: 1px solid var(--border-dark);
  padding: 2px 8px;
  border-radius: 2px;
  line-height: 1.5;
  letter-spacing: 0.02em;
}
.play-tag:hover {
  color: var(--text-primary);
  border-color: var(--accent-color);
}
body.theme-white .play-tag {
  background: #ffffff;
  border-color: #e5e5e5;
  color: #525252;
}
body.theme-sepia .play-tag {
  background: #ffffff;
  border-color: #eae3d2;
  color: #634b35;
}

.play-tag.enlarged {
  border-color: var(--accent-border);
  color: var(--accent-color);
  background: var(--accent-subtle);
}

.divider {
  width: 100%;
  height: 1px;
  background: var(--border-subtle);
  margin: 36px 0 44px 0;
}

/* ==========================================================================
   Novel Text Content Rendering
   ========================================================================== */

#novel-body {
  font-size: var(--font-size);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
  text-shadow: var(--text-shadow);
  word-break: break-all;
}

/* Paragraphs & Natural Rhythm */
#novel-body p {
  margin-bottom: 0.25em;
  text-align: justify;
}

#novel-body p.paragraph-break {
  margin-top: 1.35em;
}

#novel-body p.dialogue {
  text-indent: 0;
  margin-left: 0.5em;
}

#novel-body p.thought {
  color: rgba(240, 243, 248, 0.92);
  font-style: normal;
  letter-spacing: 0.03em;
}
body.theme-dark #novel-body p.thought {
  color: #d1d5db;
}
body.theme-white #novel-body p.thought {
  color: #334155;
}
body.theme-sepia #novel-body p.thought {
  color: #4a3b2c;
}

#novel-body p.scene-break {
  text-align: center;
  margin: 2.8em 0;
  letter-spacing: 0.6em;
  color: var(--text-dim);
  font-family: var(--font-code);
}

/* Text Shadow Options */
body.shadow-soft #novel-body {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}
body.shadow-sharp #novel-body {
  text-shadow: 0 0 1px #000, 0 1px 2px #000;
}
body.shadow-none #novel-body {
  text-shadow: none !important;
}

/* End Mark */
#novel-footer {
  margin-top: 64px;
  text-align: center;
  padding-top: 36px;
  border-top: 1px solid var(--border-subtle);
}

.end-mark {
  font-family: var(--font-code);
  font-size: 13px;
  letter-spacing: 0.35em;
  color: var(--text-dim);
  margin-bottom: 24px;
}

.btn-pill {
  font-family: var(--font-ui);
  background: var(--surface-dark-2);
  border: 1px solid var(--border-dark);
  color: var(--text-secondary);
  padding: 8px 22px;
  border-radius: 2px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: all var(--transition-speed);
}
.btn-pill:hover {
  background: var(--surface-dark-1);
  color: var(--text-primary);
  border-color: var(--accent-color);
}
body.theme-white .btn-pill {
  background: #f5f5f4;
  border-color: #e5e5e5;
  color: #525252;
}
body.theme-sepia .btn-pill {
  background: #f4edd9;
  border-color: #eae3d2;
  color: #634b35;
}

.btn-pill.secondary {
  width: 100%;
  background: var(--accent-subtle);
  color: var(--accent-color);
  border-color: var(--accent-border);
}
.btn-pill.secondary:hover {
  background: var(--accent-color);
  color: #ffffff;
}

/* ==========================================================================
   Vertical Writing Mode (縦書きレイアウト)
   ========================================================================== */

body.layout-vertical {
  overflow-y: hidden;
  overflow-x: auto;
}

body.layout-vertical #novel-container {
  padding: 68px 36px 36px 36px;
  height: 100vh;
  min-height: auto;
  display: block;
}

body.layout-vertical #reading-card {
  height: calc(100vh - 104px);
  max-width: none;
  width: max-content;
  writing-mode: vertical-rl;
  -webkit-writing-mode: vertical-rl;
  padding: 40px 48px;
  overflow-x: visible;
  display: flex;
  flex-direction: column;
}

body.layout-vertical #novel-meta-header {
  margin-bottom: 0;
  margin-left: 40px;
  text-align: left;
}

body.layout-vertical .divider {
  width: 1px;
  height: 100%;
  margin: 0 36px;
  background: var(--border-subtle);
}

body.layout-vertical #novel-body {
  height: 100%;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
}

body.layout-vertical #novel-body p {
  margin-bottom: 0;
  margin-left: 0.35em;
}

body.layout-vertical #novel-body p.paragraph-break {
  margin-left: 1.4em;
}

body.layout-vertical #novel-footer {
  margin-top: 0;
  margin-left: 48px;
  border-top: none;
  border-left: 1px solid var(--border-subtle);
  padding-top: 0;
  padding-left: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   Autoscroll Control (Editorial Floating Widget)
   ========================================================================== */

#autoscroll-bar {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 980;
}

.btn-icon.circle {
  width: 38px;
  height: 38px;
  border-radius: 2px;
  background: var(--surface-dark-1);
  border: 1px solid var(--border-dark);
  color: var(--text-secondary);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  font-size: 14px;
}
body.theme-white .btn-icon.circle {
  background: #ffffff;
  border-color: #e5e5e5;
  color: #525252;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
body.theme-sepia .btn-icon.circle {
  background: #fdfbf7;
  border-color: #eae3d2;
  color: #634b35;
}

.btn-icon.circle.playing {
  background: var(--accent-color);
  color: #ffffff;
  border-color: var(--accent-color);
}

.speed-popup {
  display: none;
  background: var(--surface-dark-1);
  border: 1px solid var(--border-dark);
  padding: 6px 12px;
  border-radius: 2px;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
body.theme-white .speed-popup {
  background: #ffffff;
  border-color: #e5e5e5;
}
body.theme-sepia .speed-popup {
  background: #fdfbf7;
  border-color: #eae3d2;
}

#autoscroll-bar:hover .speed-popup {
  display: flex;
}

.speed-label {
  font-family: var(--font-code);
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
}

/* ==========================================================================
   Settings Drawer (Editorial Bento / Strict Hierarchy)
   ========================================================================== */

#settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.65);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--transition-speed), visibility var(--transition-speed);
}
#settings-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  max-width: 100vw;
  height: 100vh;
  background: var(--surface-dark-1);
  border-left: 1px solid var(--border-dark);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  visibility: hidden;
  transition: transform 0.28s ease, visibility 0.28s ease;
}
body.theme-white #settings-drawer {
  background: #ffffff;
  border-left-color: #e5e5e5;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
}
body.theme-sepia #settings-drawer {
  background: #fdfbf7;
  border-left-color: #eae3d2;
  box-shadow: -8px 0 24px rgba(60, 40, 20, 0.08);
}

#settings-drawer.open {
  transform: translateX(0);
  visibility: visible;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-dark);
  background: var(--surface-dark-1);
  gap: 10px;
}
body.theme-white .drawer-header {
  background: #ffffff;
  border-bottom-color: #e5e5e5;
}
body.theme-sepia .drawer-header {
  background: #fdfbf7;
  border-bottom-color: #eae3d2;
}

.drawer-header h3 {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-primary);
  white-space: nowrap;
}

.btn-pill-close {
  background: var(--surface-dark-2);
  border: 1px solid var(--border-dark);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: 2px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-speed);
}
.btn-pill-close:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
  background: var(--accent-subtle);
}
body.theme-white .btn-pill-close {
  background: #f5f5f4;
  border-color: #e5e5e5;
  color: #525252;
}
body.theme-sepia .btn-pill-close {
  background: #f4edd9;
  border-color: #eae3d2;
  color: #634b35;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
  transition: color var(--transition-speed);
}
.btn-close:hover {
  color: var(--text-primary);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.setting-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 18px;
}
.setting-section.footer-section {
  border-bottom: none;
  padding-bottom: 0;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-color);
  font-family: var(--font-code);
}

/* Theme Bento Grid */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.theme-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-dark-2);
  border: 1px solid var(--border-dark);
  padding: 8px 12px;
  border-radius: 2px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-speed);
}
body.theme-white .theme-card {
  background: #f5f5f4;
  border-color: #e5e5e5;
  color: #525252;
}
body.theme-sepia .theme-card {
  background: #f4edd9;
  border-color: #eae3d2;
  color: #634b35;
}

.theme-card:hover {
  border-color: var(--accent-color);
  color: var(--text-primary);
}
.theme-card.active {
  border-color: var(--accent-color);
  background: var(--accent-subtle);
  color: var(--accent-color);
}
.theme-icon {
  font-size: 14px;
}
.theme-name {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
}

/* Controls */
.control-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.control-label-group {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-ui);
}
.control-val {
  font-family: var(--font-code);
  font-weight: 600;
  color: var(--text-primary);
}

/* Range Inputs: Minimal Editorial Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--surface-dark-2);
  border: 1px solid var(--border-dark);
  border-radius: 1px;
  outline: none;
}
body.theme-white input[type="range"] {
  background: #e5e5e5;
  border-color: #d4d4d8;
}
body.theme-sepia input[type="range"] {
  background: #eae3d2;
  border-color: #dec8b0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  background: var(--accent-color);
  cursor: pointer;
  border: 1px solid #ffffff;
  transition: transform var(--transition-speed);
}
input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* Option Button Groups */
.option-button-group {
  display: flex;
  gap: 4px;
  background: var(--surface-dark-2);
  padding: 2px;
  border-radius: 2px;
  border: 1px solid var(--border-dark);
}
body.theme-white .option-button-group {
  background: #f5f5f4;
  border-color: #e5e5e5;
}
body.theme-sepia .option-button-group {
  background: #f4edd9;
  border-color: #eae3d2;
}

.btn-option {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 11px;
  padding: 5px 6px;
  border-radius: 2px;
  cursor: pointer;
  transition: all var(--transition-speed);
  white-space: nowrap;
}
.btn-option:hover {
  color: var(--text-primary);
}
.btn-option.active {
  background: var(--accent-color);
  color: #ffffff;
  font-weight: 500;
}

/* Color Chips */
.color-options {
  display: flex;
  gap: 8px;
}
.color-chip {
  width: 24px;
  height: 24px;
  border-radius: 2px;
  border: 1px solid var(--border-dark);
  cursor: pointer;
  transition: transform var(--transition-speed);
}
.color-chip:hover {
  transform: scale(1.1);
}
.color-chip.active {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 1px var(--accent-color);
}

/* Select Box */
.select-styled {
  background: var(--surface-dark-2);
  border: 1px solid var(--border-dark);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 2px;
  font-size: 12px;
  font-family: var(--font-ui);
  outline: none;
}
body.theme-white .select-styled {
  background: #ffffff;
  border-color: #e5e5e5;
  color: #171717;
}
body.theme-sepia .select-styled {
  background: #ffffff;
  border-color: #eae3d2;
  color: #382c1e;
}
.select-styled option {
  background: var(--surface-dark-1);
  color: var(--text-primary);
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 768px) {
  #top-toolbar {
    height: 48px;
    padding: 0 12px;
  }
  #novel-header-title {
    max-width: 110px;
    font-size: 12px;
  }
  .badge {
    font-size: 10px;
    padding: 2px 6px;
  }
  .quick-theme-group {
    display: none;
  }
  #btn-fullscreen {
    display: none;
  }
  .btn-icon {
    width: 30px;
    height: 30px;
    font-size: 12px;
  }
  .btn-icon.primary {
    padding: 0 8px;
  }
  .btn-icon.primary .btn-label {
    font-size: 11px;
  }
  .btn-toggle {
    padding: 3px 6px;
    font-size: 11px;
  }
  #novel-container {
    padding: 68px 12px 60px 12px;
  }
  #reading-card {
    padding: 24px 16px;
    border-radius: 2px;
  }
  #novel-main-title {
    font-size: 20px;
    line-height: 1.45;
    margin-bottom: 18px;
    word-break: break-word;
  }
  #novel-body {
    font-size: 16.5px;
  }
  #novel-body p {
    margin-bottom: 0.3em;
  }
  #novel-body p.paragraph-break {
    margin-top: 1.2em;
  }
  #bg-illust {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    object-fit: cover !important;
    object-position: center 20% !important;
    margin: 0 !important;
  }
  #settings-drawer {
    width: 100vw;
    right: 0;
  }
  body.layout-vertical #reading-card {
    padding: 20px 14px;
    height: calc(100vh - 85px);
  }
}

/* ==========================================================================
   Novel In-body Illustration (挿絵)
   ========================================================================== */
.novel-illustration {
  margin: 48px auto;
  text-align: center;
  max-width: 100%;
  position: relative;
  user-select: none;
}

.illustration-wrapper {
  display: inline-block;
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border-dark);
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.5);
  background: var(--surface-dark-1);
  max-width: 100%;
}

body.theme-white .illustration-wrapper {
  border-color: #e5e5e5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

body.theme-sepia .illustration-wrapper {
  border-color: #eae3d2;
  box-shadow: 0 8px 24px rgba(60, 40, 20, 0.1);
}

.illustration-img {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  width: auto;
  height: auto;
  margin: 0 auto;
  object-fit: contain;
  cursor: zoom-in;
  transition: transform 0.25s ease;
}

.illustration-img:hover {
  transform: scale(1.01);
}

.illustration-caption {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 10px;
  letter-spacing: 0.08em;
}

/* 縦書きモード時の挿絵 */
body.layout-vertical .novel-illustration {
  margin: 0 36px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: calc(100vh - 180px);
  max-height: 720px;
}

body.layout-vertical .illustration-wrapper {
  height: 100%;
  max-width: none;
}

body.layout-vertical .illustration-img {
  height: 100%;
  max-height: 100%;
  width: auto;
  max-width: none;
}

/* 挿絵モーダル（クリックでフルスクリーン拡大） */
#illust-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(8px);
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

#illust-modal.show {
  opacity: 1;
  visibility: visible;
}

#illust-modal img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 2px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}
