/* ==========================================================================
   Sutton & Barto RL 2. Baskı - Modern Mobil Öncelikli Okuyucu Tasarım Sistemi
   ========================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Merriweather', 'Charter', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
  
  /* Light Theme (Varsayılan) */
  --bg-primary: #fdfdfd;
  --bg-secondary: #f4f6f8;
  --bg-card: #ffffff;
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --border-color: #e2e8f0;
  --accent-color: #2b6cb0;
  --accent-hover: #2c5282;
  --accent-bg: #ebf8ff;
  --algo-bg: #f8fafc;
  --algo-border: #cbd5e1;
  --callout-info-bg: #eff6ff;
  --callout-info-border: #3b82f6;
  --callout-math-bg: #f0fdf4;
  --callout-math-border: #22c55e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.12);
  --sidebar-width: 320px;
  --header-height: 56px;
  --bottom-bar-height: 60px;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --accent-color: #38bdf8;
  --accent-hover: #7dd3fc;
  --accent-bg: #0369a122;
  --algo-bg: #111827;
  --algo-border: #374151;
  --callout-info-bg: #1e3a8a33;
  --callout-info-border: #60a5fa;
  --callout-math-bg: #064e3b33;
  --callout-math-border: #34d399;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
}

[data-theme="sepia"] {
  --bg-primary: #fbf0d9;
  --bg-secondary: #f2e3c6;
  --bg-card: #fff9e6;
  --text-primary: #433422;
  --text-secondary: #5f4b32;
  --text-muted: #8b7355;
  --border-color: #e4d1b5;
  --accent-color: #8c4a00;
  --accent-hover: #b86200;
  --accent-bg: #faebd7;
  --algo-bg: #f5e7ce;
  --algo-border: #ddcbb0;
  --callout-info-bg: #e8ded1;
  --callout-info-border: #9c6644;
}

[data-theme="amoled"] {
  --bg-primary: #000000;
  --bg-secondary: #0a0a0a;
  --bg-card: #111111;
  --text-primary: #ffffff;
  --text-secondary: #d1d5db;
  --text-muted: #888888;
  --border-color: #222222;
  --accent-color: #00e5ff;
  --accent-hover: #80f0ff;
  --algo-bg: #080808;
  --algo-border: #262626;
}

/* Temel Sıfırlamalar */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.75;
  transition: background-color 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
  padding-bottom: var(--bottom-bar-height);
}

/* Üst Başlık & İlerleme Çubuğu */
.reader-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 1000;
  backdrop-filter: blur(10px);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.book-title-header {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

@media (min-width: 640px) {
  .book-title-header {
    max-width: 450px;
    font-size: 1.05rem;
  }
}

.reading-progress-container {
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  z-index: 1001;
}

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

/* İkon Butonları */
.icon-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.2s ease;
}

.icon-btn:hover, .icon-btn:active {
  background: var(--bg-secondary);
  border-color: var(--accent-color);
  color: var(--accent-color);
}

/* Kenar Çekmecesi (TOC Drawer) */
.toc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.toc-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.toc-drawer {
  position: fixed;
  top: 0;
  left: -100%;
  width: 85%;
  max-width: 360px;
  height: 100%;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-lg);
}

.toc-drawer.active {
  left: 0;
}

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

.toc-search {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.toc-search input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.toc-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0;
}

.toc-part-title {
  padding: 0.75rem 1rem 0.25rem;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.toc-item {
  display: flex;
  align-items: center;
  padding: 0.65rem 1.25rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.92rem;
  line-height: 1.4;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
}

.toc-item:hover, .toc-item.active {
  background: var(--accent-bg);
  color: var(--accent-color);
  border-left-color: var(--accent-color);
  font-weight: 600;
}

/* Ana İçerik Konteyneri */
.reader-container {
  max-width: 780px;
  margin: calc(var(--header-height) + 1.25rem) auto 2rem;
  padding: 0 1.25rem;
}

@media (min-width: 1024px) {
  .reader-container {
    max-width: 860px;
  }
}

/* Tipografi & İçerik Stilleri */
.chapter-content {
  font-family: var(--font-sans);
  font-size: 1.06rem;
}

.chapter-content.font-serif {
  font-family: var(--font-serif);
}

.chapter-header-box {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border-color);
}

.chapter-part-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-color);
  font-weight: 700;
}

.chapter-title {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.3;
  margin-top: 0.25rem;
  color: var(--text-primary);
}

@media (min-width: 640px) {
  .chapter-title {
    font-size: 2.2rem;
  }
}

.chapter-content h2 {
  font-size: 1.45rem;
  font-weight: 750;
  margin-top: 2.25rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.4rem;
}

.chapter-content h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: 1.75rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.chapter-content h4 {
  font-size: 1.05rem;
  font-weight: 650;
  margin-top: 1.25rem;
  margin-bottom: 0.4rem;
}

.chapter-content p {
  margin-bottom: 1.15rem;
  text-align: justify;
  hyphens: auto;
}

.chapter-content ul, .chapter-content ol {
  margin-bottom: 1.25rem;
  padding-left: 1.5rem;
}

.chapter-content li {
  margin-bottom: 0.5rem;
}

/* Matematiksel Formüller (KaTeX Responsive Wrapper) */
.math-block {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.85rem 0.5rem;
  margin: 1.25rem 0;
  background: var(--bg-secondary);
  border-radius: 8px;
  border-left: 4px solid var(--accent-color);
  text-align: center;
}

.katex {
  font-size: 1.08em;
}

/* Algoritma Kutuları (Pseudocode) */
.algo-card {
  background: var(--algo-bg);
  border: 1px solid var(--algo-border);
  border-radius: 10px;
  margin: 1.75rem 0;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.algo-header {
  background: var(--bg-secondary);
  padding: 0.75rem 1rem;
  font-weight: 700;
  font-size: 0.98rem;
  border-bottom: 1px solid var(--algo-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.algo-title {
  color: var(--text-primary);
}

.algo-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--accent-color);
  color: #ffffff;
  font-weight: 600;
}

.algo-body {
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.7;
  overflow-x: auto;
}

.algo-line {
  display: block;
}

.algo-indent-1 { padding-left: 1.5rem; }
.algo-indent-2 { padding-left: 3rem; }
.algo-indent-3 { padding-left: 4.5rem; }

.algo-kw {
  font-weight: 700;
  color: var(--accent-color);
}

.algo-assign {
  font-weight: 700;
}

/* Şekiller ve Diyagramlar */
.figure-container {
  margin: 2rem 0;
  text-align: center;
}

.figure-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem;
  display: inline-block;
  max-width: 100%;
  box-shadow: var(--shadow-sm);
}

.figure-box img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  cursor: zoom-in;
  transition: transform 0.2s ease;
}

.figure-caption {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-top: 0.65rem;
  line-height: 1.45;
  text-align: left;
  padding: 0 0.5rem;
}

.figure-caption strong {
  color: var(--text-primary);
}

/* Tablolar */
.table-wrapper {
  overflow-x: auto;
  margin: 1.5rem 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  text-align: left;
}

th, td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

th {
  background: var(--bg-secondary);
  font-weight: 700;
  color: var(--text-primary);
}

tr:last-child td {
  border-bottom: none;
}

/* Kutular ve Notlar (Callouts) */
.callout {
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  border-radius: 8px;
  border-left: 4px solid var(--callout-info-border);
  background: var(--callout-info-bg);
  font-size: 0.95rem;
}

.callout-title {
  font-weight: 700;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Terim Vurguları & Sözlük Bağlantısı */
.rl-term {
  border-bottom: 1px dotted var(--accent-color);
  cursor: help;
  color: var(--text-primary);
  font-weight: 550;
}

.rl-term:hover {
  background: var(--accent-bg);
  color: var(--accent-color);
}

/* Mobil Alt Gezinme Çubuğu (Bottom Navigation Bar) */
.mobile-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-bar-height);
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 0.5rem;
  z-index: 1000;
  backdrop-filter: blur(10px);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.75rem;
  gap: 2px;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.bottom-nav-item i {
  font-size: 1.2rem;
}

.bottom-nav-item:hover, .bottom-nav-item:active {
  color: var(--accent-color);
}

/* Ayarlar & Sözlük Modalları */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-card);
  border-radius: 12px;
  max-width: 500px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

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

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.theme-options {
  display: flex;
  gap: 0.5rem;
}

.theme-btn {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
}

.theme-btn.active {
  border-color: var(--accent-color);
  background: var(--accent-bg);
  color: var(--accent-color);
  font-weight: 600;
}

/* Resim Büyüteç (Lightbox) */
.lightbox-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 1rem;
}

.lightbox-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.lightbox-modal img {
  max-width: 95%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 6px;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  border: none;
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
}

/* Bölüm Sonu İleri/Geri Navigasyon Kartları */
.chapter-nav-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

@media (min-width: 600px) {
  .chapter-nav-cards {
    grid-template-columns: 1fr 1fr;
  }
}

.nav-card {
  padding: 1rem 1.25rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  transition: all 0.2s ease;
}

.nav-card:hover {
  border-color: var(--accent-color);
  background: var(--accent-bg);
}

.nav-card-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
}

.nav-card-title {
  font-weight: 600;
  margin-top: 0.25rem;
  color: var(--text-primary);
}

/* ------------------------------------------------------------------
   Şekil Atıf Kutusu (figure-ref)
   Kitabın şekilleri telif nedeniyle gömülmez; okuyucu orijinal
   kaynağa yönlendirilir, açıklama Türkçe olarak burada verilir.
   ------------------------------------------------------------------ */
.figure-ref {
  margin: 1.75rem 0;
  padding: 0.9rem 1.1rem;
  border: 1px dashed var(--border-color);
  border-left: 4px solid var(--accent-color);
  border-radius: 8px;
  background: var(--bg-secondary);
}

.figure-ref-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.figure-ref-badge {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent-color);
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
}

.figure-ref-link {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-color);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

.figure-ref-link:hover {
  opacity: 0.8;
}

.figure-ref-caption {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text-secondary);
}

/* ------------------------------------------------------------------
   Düz Kod Blokları
   ------------------------------------------------------------------ */
.code-block {
  margin: 1.5rem 0;
  padding: 1rem 1.15rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--text-primary);
}

.code-block code {
  background: none;
  padding: 0;
  font: inherit;
  color: inherit;
  white-space: pre;
}

/* ------------------------------------------------------------------
   Uyarı Kutusu Etiketleri (> [!NOTE] vb.)
   ------------------------------------------------------------------ */
.callout-label {
  font-weight: 800;
  font-size: 0.74rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent-color);
  margin-bottom: 0.35rem;
}

.callout p {
  margin: 0;
}

.callout-warning {
  border-left-color: #f59e0b;
}

.callout-warning .callout-label {
  color: #b45309;
}

.callout-tip {
  border-left-color: #10b981;
}

.callout-tip .callout-label {
  color: #047857;
}

/* ------------------------------------------------------------------
   Bölüm Ayırıcı Çizgi
   ------------------------------------------------------------------ */
hr.section-rule {
  border: none;
  height: 1px;
  background: var(--border-color);
  margin: 2.25rem 0;
}

/* ------------------------------------------------------------------
   Altbilgi / Künye
   ------------------------------------------------------------------ */
.reader-footer {
  max-width: 780px;
  margin: 2rem auto 0;
  padding: 1.5rem 1.25rem calc(1.5rem + var(--bottom-bar-height));
  border-top: 1px solid var(--border-color);
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-muted);
  text-align: center;
}

.reader-footer a {
  color: var(--accent-color);
  text-decoration: none;
}

.reader-footer a:hover {
  text-decoration: underline;
}

.reader-footer .footer-author {
  font-weight: 700;
  color: var(--text-primary);
}

/* ------------------------------------------------------------------
   Uzun formüllerin mobilde taşmasını önle
   ------------------------------------------------------------------ */
.math-block,
.chapter-body .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.chapter-body .katex-display {
  padding-bottom: 0.35rem;
}

/* Satır içi formüller sözcük gibi sarmalansın */
.chapter-body .katex {
  white-space: normal;
}
