/* ===== Теми ===== */
:root {
  --font-size: 18px;
  --container-width: 700px;
}

html[data-theme='light'] {
  --bg: #ffffff;
  --bg-elevated: #f4f4f5;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --border: #e2e2e2;
  --accent: #3b6ea5;
  --shadow: rgba(0, 0, 0, 0.08);
}

html[data-theme='dark'] {
  --bg: #17181c;
  --bg-elevated: #23252b;
  --text: #d8d8d8;
  --text-muted: #8a8d94;
  --border: #33363d;
  --accent: #6ba3e0;
  --shadow: rgba(0, 0, 0, 0.4);
}

html[data-theme='sepia'] {
  --bg: #f4ecd8;
  --bg-elevated: #ebe0c8;
  --text: #4a3f2f;
  --text-muted: #8a7a5f;
  --border: #d9cbab;
  --accent: #9a6a3a;
  --shadow: rgba(90, 70, 40, 0.12);
}

/* ===== Базове ===== */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  transition: background 0.2s ease, color 0.2s ease;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.page {
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 24px 20px 80px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.topbar .back {
  font-size: 15px;
  color: var(--text-muted);
}

h1 {
  font-size: 1.6rem;
  margin: 0 0 4px;
}
h2 {
  font-size: 1.2rem;
  margin: 0;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 24px;
}

/* ===== Картки списків ===== */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  display: block;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  color: var(--text);
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}
.card:hover {
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--shadow);
}
.card .card-title {
  font-size: 1.05rem;
  font-weight: 600;
}
.card .card-meta {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Бейдж статусу */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.badge.review {
  background: #f9d97b33;
  color: #b8860b;
  border-color: #d9b34a66;
}
html[data-theme='dark'] .badge.review {
  color: #e0b84a;
}

/* ===== Текст розділу ===== */
.chapter-body {
  font-size: var(--font-size);
  line-height: 1.75;
  text-align: var(--text-align, left);
  text-align-last: left;
}
.chapter-body p {
  margin: 0 0 1.1em;
}

.notice {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid #d9b34a;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
}

/* ===== Кнопка-шестерня + панель ===== */
.gear {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 14px var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}
.settings-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 320px;
  max-width: 85vw;
  background: var(--bg);
  border-left: 1px solid var(--border);
  padding: 24px;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 40;
  overflow-y: auto;
}
.settings-panel.open {
  transform: translateX(0);
}
.settings-panel h3 {
  margin: 0 0 20px;
  font-size: 1.1rem;
}

.setting-group {
  margin-bottom: 24px;
}
.setting-group > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.theme-options {
  display: flex;
  gap: 10px;
}
.theme-btn {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 2px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  text-align: center;
}
.theme-btn.active {
  border-color: var(--accent);
}
.theme-btn[data-value='light'] { background: #ffffff; color: #1a1a1a; }
.theme-btn[data-value='dark'] { background: #17181c; color: #d8d8d8; }
.theme-btn[data-value='sepia'] { background: #f4ecd8; color: #4a3f2f; }

.stepper {
  display: flex;
  align-items: center;
  gap: 14px;
}
.stepper button {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}
.stepper .value {
  min-width: 60px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}
.range-presets {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.range-presets button {
  flex: 1;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.range-presets button.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== Мобільна адаптація ===== */
@media (max-width: 600px) {
  .page {
    max-width: 100% !important;
    padding: 16px 16px 80px;
  }

  /* Панель налаштувань → нижня шторка */
  .settings-panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 80vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }
  .settings-panel.open {
    transform: translateY(0);
  }
}
