@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg:        #121212;
  --surface:   #1e1e1e;
  --surface2:  #2a2a2a;
  --border:    #333333;
  --accent:    #ffdb4d;
  --text:      #ffffff;
  --text-muted:#9e9e9e;
  --danger:    #ff5252;
  --radius:    12px;
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.telegram-login {
  max-width: 600px;
  margin: 0 auto;
  padding: max(32px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom));
  text-align: center;
}

.telegram-login h1 { margin-bottom: 16px; }
.telegram-login p { margin-bottom: 20px; }
.telegram-login__retry[hidden] { display: none; }

/* ── FLASH ────────────────────────────────────────────────────────────────── */

.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}

.flash--notice {
  background: rgba(255, 219, 77, 0.15);
  border: 1px solid rgba(255, 219, 77, 0.3);
  color: var(--accent);
}

.flash--alert {
  background: rgba(255, 82, 82, 0.15);
  border: 1px solid rgba(255, 82, 82, 0.3);
  color: var(--danger);
}

/* ── LIBRARY PAGE ─────────────────────────────────────────────────────────── */

.library {
  max-width: 600px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}

.library-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.library-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

/* Upload section */
.upload-section {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  transition: border-color 0.2s;
}

.upload-section:hover {
  border-color: var(--accent);
}

.upload-section h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.upload-help {
  margin: -4px 0 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.upload-field {
  margin-bottom: 12px;
}

.upload-field input[type="file"] {
  font-size: 14px;
  color: var(--text-muted);
  width: 100%;
}

.upload-field input[type="file"]::file-selector-button {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  min-height: 44px;
  padding: 10px 16px;
  font-size: 13px;
  cursor: pointer;
  margin-right: 12px;
  transition: background 0.15s;
}

.upload-field input[type="file"]::file-selector-button:hover {
  background: var(--border);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn--primary {
  background: var(--accent);
  color: #000;
}

.btn--primary:hover {
  background: #ffe566;
  transform: translateY(-1px);
}

.btn--secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--secondary:hover {
  background: var(--border);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn--ghost:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn--danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
}

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

input[type="submit"] {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: #000;
  transition: all 0.15s;
}

input[type="submit"]:hover {
  background: #ffe566;
}

input[type="submit"]:disabled {
  opacity: 0.65;
  cursor: wait;
}

.upload-progress {
  margin: 8px 0 14px;
  min-height: 52px;
}

.upload-progress__label {
  min-height: 20px;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}

.upload-progress__bar {
  height: 8px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface2);
}

.upload-progress__fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.12s linear;
}

.upload-progress__details {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 5px;
  color: var(--text-muted);
  font-size: 12px;
}

.upload-progress__details span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-progress__details span:last-child {
  flex-shrink: 0;
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Books list */
.books-list { display: flex; flex-direction: column; gap: 10px; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-size: 15px;
}

.book-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color 0.15s, background 0.15s;
}

.book-card:hover {
  border-color: var(--accent);
  background: var(--surface2);
}

.book-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.book-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.btn-read {
  flex-shrink: 0;
  margin-left: 12px;
  background: var(--accent);
  color: #000;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
  transition: background 0.15s;
}

.btn-read:hover { background: #ffe566; }

/* ── READER PAGE ──────────────────────────────────────────────────────────── */

.reader-page {
  max-width: 600px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100vh;
}

.reader-background {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.reader-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-link {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s;
}

.back-link:hover { color: var(--text); }

.book-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.book-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

/* Word display */
.word-display {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 12px;
  text-align: center;
  min-height: 180px;
  display: flex;
  align-items: safe center;
  justify-content: center;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: min(45dvh, 360px);
}

.word-display::before,
.word-display::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 12px;
  background: var(--accent);
  opacity: 0.55;
  pointer-events: none;
}

.word-display::before { top: 12px; }
.word-display::after { bottom: 12px; }

.word-output {
  width: 100%;
  min-width: 0;
  font-size: clamp(28px, 9vw, 42px);
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.word-output--single {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
}

.word-output__left,
.word-output__right { min-width: 0; }
.word-output__left { text-align: right; }
.word-output__right { text-align: left; }
.word-output__orp { color: var(--accent); }
.word-output--phrase { text-align: center; }

.reader-status {
  min-height: 20px;
  margin-top: -12px;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

.reader-status[hidden] { display: none; }

@keyframes flash-in {
  0%   { opacity: 0.3; }
  100% { opacity: 1; }
}

.flash { animation: flash-in 0.08s ease-out forwards; }

/* Progress */
.progress-bar {
  height: 3px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-top: 6px;
}

/* Controls */
.controls-panel {
  display: flex;
  gap: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 120px;
}

.control-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  min-width: 40px;
}

.control-unit {
  font-size: 12px;
  color: var(--text-muted);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 44px;
  background: transparent;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  width: 100%;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: var(--border);
}

input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: var(--border);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -10px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s;
}

input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
}

input[type="range"]:focus-visible,
.control-label--toggle input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.control-group--focus { min-width: 150px; }
.control-label--toggle {
  display: flex;
  align-items: center;
  min-height: 44px;
  gap: 10px;
  cursor: pointer;
}

.control-label--toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.3);
}

/* Playback controls */
.playback-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.playback-controls .btn {
  min-width: 80px;
  min-height: 44px;
}

.playback-controls .btn--icon {
  min-width: 44px;
  width: 44px;
  padding-right: 8px;
  padding-left: 8px;
}

/* Keyboard hint */
.kbd-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

kbd {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-family: inherit;
}

.book-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: 12px;
}

.btn-delete {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 44px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
}

.btn-delete:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(255, 82, 82, 0.1);
}

.book-progress {
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
  width: 100%;
}

.book-progress__fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

.book-progress__text {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── MODAL ────────────────────────────────────────────────────────────────── */

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

.modal--visible {
  display: flex;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal__box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: calc(100% - 48px);
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal__message {
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
}

.modal__actions {
  display: flex;
  gap: 10px;
}

.modal__actions .btn {
  flex: 1;
  min-height: 44px;
}

.btn--danger-solid {
  background: var(--danger);
  color: #fff;
  border: none;
}

.btn--danger-solid:hover {
  background: #ff6b6b;
}

.progress-bar {
  position: relative;
  overflow: visible;
}

input[type="range"].progress-seek {
  position: absolute;
  inset: -20px 0;
  width: 100%;
  height: calc(100% + 40px);
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"].progress-seek::-webkit-slider-runnable-track {
  height: 4px;
  background: transparent;
}

input[type="range"].progress-seek::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -7px;
  appearance: none;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

input[type="range"].progress-seek::-moz-range-track {
  height: 4px;
  background: transparent;
}

input[type="range"].progress-seek::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

input[type="range"].progress-seek:disabled {
  cursor: default;
}

input[type="range"].progress-seek:disabled::-webkit-slider-thumb,
input[type="range"].progress-seek:disabled::-moz-range-thumb {
  opacity: 0.45;
}

.progress-bar:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

/* ── NAVIGATION PREVIEW ──────────────────────────────────────────────────── */

.navigation-preview {
  width: min(calc(100% - 24px), 560px);
  max-height: calc(100dvh - max(32px, env(safe-area-inset-top)) - max(32px, env(safe-area-inset-bottom)));
  margin: auto;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.navigation-preview::backdrop {
  background: rgba(0, 0, 0, 0.75);
}

.navigation-preview__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.navigation-preview__eyebrow {
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.navigation-preview__header h2 {
  margin-top: 3px;
  font-size: 18px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.navigation-preview__close {
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
}

.navigation-preview__meta {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.navigation-preview__text {
  max-height: min(45dvh, 420px);
  margin: 16px 0;
  padding: 14px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  font-size: 15px;
  line-height: 1.8;
  overflow-wrap: anywhere;
  overscroll-behavior: contain;
}

.navigation-preview__actions {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 10px;
}

.navigation-preview__actions .btn {
  min-height: 44px;
}

/* ── CHAPTER NAVIGATION ───────────────────────────────────────────────────── */

.chapter-quick {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reader-page {
  padding-bottom: max(84px, calc(64px + env(safe-area-inset-bottom)));
}

.chapter-quick__title {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-quick__controls,
.context-chapter-controls {
  display: grid;
  grid-template-columns: 1fr 1.45fr 1fr;
  gap: 8px;
}

.chapter-quick__controls .btn,
.context-chapter-controls .btn {
  min-width: 0;
  min-height: 44px;
  padding: 9px 8px;
}

.btn:disabled {
  cursor: default;
  opacity: 0.4;
  transform: none;
}

/* ── CONTEXT SHEET ────────────────────────────────────────────────────────── */

.bottom-sheet__backdrop {
  position: fixed;
  inset: 0;
  z-index: 49;
  display: block;
  padding: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.62);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.bottom-sheet__backdrop--visible {
  opacity: 1;
  pointer-events: auto;
}

.bottom-sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  display: flex;
  height: min(72dvh, 680px);
  max-height: calc(100dvh - max(16px, env(safe-area-inset-top)));
  flex-direction: column;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  background: var(--surface);
  box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.35);
  transform: translateY(calc(100% - 56px - env(safe-area-inset-bottom)));
  transition: transform 0.25s ease;
}

.bottom-sheet--open {
  transform: translateY(0);
}

.bottom-sheet__handle {
  display: flex;
  min-height: 56px;
  flex-shrink: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.bottom-sheet__handle:active { cursor: grabbing; }

.bottom-sheet__handle:focus-visible,
.chapter-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.bottom-sheet__handle-bar {
  width: 42px;
  height: 4px;
  border-radius: 2px;
  background: var(--text-muted);
}

.bottom-sheet__handle-label {
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.bottom-sheet__content {
  flex: 1;
  overflow-y: auto;
  padding: 0 18px max(24px, env(safe-area-inset-bottom));
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.context-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0 14px;
}

.context-header__eyebrow {
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.context-header__title {
  margin-top: 3px;
  font-size: 18px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.context-close {
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
}

.context-chapters-toggle {
  width: 100%;
  min-height: 44px;
  margin: 10px 0 14px;
}

.context-chapters[hidden] { display: none; }

.context-chapters h3 {
  padding: 6px 0 10px;
  font-size: 14px;
}

.chapters-list {
  max-height: 34vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}

.chapter-item {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.chapter-item:last-child { border-bottom: 0; }
.chapter-item:hover {
  background: var(--surface2);
}

.chapter-item--current {
  background: rgba(255, 219, 77, 0.08);
}

.chapter-item--current .chapter-item__title {
  color: var(--accent);
}

.chapter-item__title {
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.chapter-item__meta {
  font-size: 11px;
  color: var(--text-muted);
}

.bottom-sheet__text {
  margin-top: 16px;
  padding-bottom: 12px;
  color: var(--text);
  font-size: 16px;
  line-height: 1.8;
}

.context-word--read { color: var(--text-muted); }

.context-boundary {
  border-radius: 4px;
  background: rgba(255, 219, 77, 0.28);
  color: var(--accent);
  padding: 1px 3px;
}

.context-terminal {
  display: inline-block;
  margin-left: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

/* Native modal keeps keyboard focus inside the structured-content card. */
.structured-dialog {
  width: min(calc(100% - 24px), 560px);
  max-height: calc(100dvh - max(32px, env(safe-area-inset-top)) - max(32px, env(safe-area-inset-bottom)));
  margin: auto;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.structured-dialog::backdrop { background: rgba(0, 0, 0, 0.75); }
.structured-dialog__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.structured-dialog__header h2 { font-size: 18px; }
.structured-dialog__close { min-width: 44px; min-height: 44px; padding: 8px; }
.structured-dialog__body { max-height: min(55dvh, 520px); overflow-y: auto; margin: 16px 0; }
.structured-dialog__body pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.6;
}
.structured-dialog__destination { margin-top: 12px; color: var(--text-muted); overflow-wrap: anywhere; }
.structured-dialog__destination[hidden] { display: none; }
.structured-dialog__media[hidden] { display: none; }
.structured-dialog__figure { margin: 0 0 16px; text-align: center; }
.structured-dialog__figure:last-child { margin-bottom: 0; }
.structured-dialog__figure img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: min(55dvh, 560px);
  margin: 0 auto;
  object-fit: contain;
}
.structured-dialog__figure figcaption { margin-top: 8px; color: var(--text-muted); }
.structured-dialog__continue { width: 100%; min-height: 44px; }

@media (max-width: 360px) {
  .reader-page { padding-right: 12px; padding-left: 12px; }
  .chapter-quick__controls,
  .context-chapter-controls { gap: 5px; }
  .chapter-quick__controls .btn,
  .context-chapter-controls .btn { font-size: 12px; }
  .bottom-sheet__content { padding-right: 14px; padding-left: 14px; }
}


/* ── MARKETING / WEB ENTRY ───────────────────────────────────────────────── */

.marketing {
  min-height: 100dvh;
  padding: max(48px, env(safe-area-inset-top)) 20px max(48px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at top left, rgba(139, 92, 246, 0.16), transparent 34rem),
    var(--bg);
}

.marketing__hero,
.marketing__features {
  width: min(100%, 1040px);
  margin-inline: auto;
}

.marketing__hero {
  padding: clamp(40px, 8vw, 96px) 0 56px;
}

.marketing__eyebrow,
.admin-eyebrow {
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.marketing__hero h1 {
  max-width: 760px;
  font-size: clamp(42px, 8vw, 86px);
  line-height: 0.98;
  letter-spacing: -0.04em;
}

.marketing__lead {
  max-width: 680px;
  margin-top: 24px;
  color: var(--text-muted);
  font-size: clamp(17px, 2.3vw, 22px);
  line-height: 1.6;
}

.marketing__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 30px;
}

.marketing__telegram-status {
  margin-top: 16px;
  color: var(--text-muted);
  font-size: 13px;
}

.marketing__features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.marketing__features article {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.marketing__features h2 {
  margin-bottom: 10px;
  font-size: 18px;
}

.marketing__features p {
  color: var(--text-muted);
  line-height: 1.55;
}

/* ── ADMIN ────────────────────────────────────────────────────────────────── */

.admin-body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
}

.admin-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
}

.admin-nav > div {
  display: grid;
  gap: 3px;
}

.admin-nav > div span {
  color: var(--text-muted);
  font-size: 12px;
}

.admin-nav nav {
  display: flex;
  align-items: center;
  gap: 14px;
}

.admin-nav a,
.admin-nav__logout {
  color: var(--text-muted);
  font: inherit;
  text-decoration: none;
}

.admin-nav__logout {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.admin-nav a:hover,
.admin-nav__logout:hover {
  color: var(--text);
}

.admin-main {
  width: min(100% - 32px, 1240px);
  margin-inline: auto;
  padding: 36px 0 64px;
}

.admin-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 24px;
}

.admin-heading h1 {
  font-size: clamp(30px, 5vw, 52px);
  letter-spacing: -0.03em;
}

.admin-heading p:last-child {
  margin-top: 8px;
  color: var(--text-muted);
}

.admin-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.admin-metric,
.admin-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.admin-metric {
  display: grid;
  gap: 10px;
  min-height: 116px;
  padding: 18px;
}

.admin-metric span {
  color: var(--text-muted);
  font-size: 12px;
}

.admin-metric strong {
  align-self: end;
  font-size: 28px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.admin-card {
  margin-bottom: 18px;
  padding: 20px;
}

.admin-card h2 {
  margin-bottom: 16px;
  font-size: 18px;
}

.admin-list {
  display: grid;
  gap: 12px;
}

.admin-list > div {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.admin-list > div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.admin-list dt {
  color: var(--text-muted);
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th,
.admin-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.admin-table tbody tr:last-child td {
  border-bottom: 0;
}

.admin-table a {
  color: var(--accent);
}

.admin-table code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-muted);
  font-size: 11px;
}

@media (max-width: 800px) {
  .marketing__features,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-nav {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-nav nav {
    flex-wrap: wrap;
  }
}

@media (max-width: 520px) {
  .admin-metrics {
    grid-template-columns: 1fr;
  }

  .marketing__actions .btn {
    width: 100%;
  }
}

/* ── SOUNDSCAPES ──────────────────────────────────────────────────────────── */
.control-group--soundscape {
  min-width: min(100%, 220px);
}

.soundscape-select,
.admin-field input[type="text"],
.admin-field input[type="number"] {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font: inherit;
}

.soundscape-select:focus-visible,
.admin-field input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.soundscape-toggle {
  width: 100%;
  min-height: 44px;
}

.soundscape-status {
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
}

.soundscape-status[hidden] { display: none; }

.admin-card--form { max-width: 680px; }
.admin-form { display: grid; gap: 18px; }
.admin-field { display: grid; gap: 7px; color: var(--text-muted); font-size: 13px; }
.admin-field > span { color: var(--text); font-weight: 600; }
.admin-field small { line-height: 1.4; }
.admin-field--checkbox { grid-template-columns: auto 1fr; align-items: center; }
.admin-field--checkbox input { width: 20px; height: 20px; accent-color: var(--accent); }
.admin-form__actions, .admin-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.admin-audio, .admin-audio-preview audio { width: min(320px, 100%); }
.admin-audio-preview { display: grid; gap: 6px; }
.admin-audio-preview small, .admin-table small { color: var(--text-muted); }
