/* ========================================================
   ÉCRAN DE LECTURE
   ======================================================== */

#screen-reader {
  --page-bg: #ffffff;
  --page-fg: #1f1f1f;
  --page-muted: #8a8a8a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --footer-h: 30px;

  --panel-bg: #161a22;
  --panel-raised: #222835;
  --panel-border: #2c3342;
  --panel-text: #eef1f6;
  --panel-muted: #8f98aa;
  --panel-accent: #5b8cff;

  background: var(--page-bg);
  color: var(--page-fg);
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  transition: background-color 0.2s;
}

/* Zone de texte du livre (les marges latérales sont appliquées en JS) */
#reader-content {
  position: absolute;
  top: calc(var(--safe-top) + 22px);
  bottom: calc(var(--safe-bottom) + var(--footer-h));
  left: 0;
  right: 0;
  box-sizing: border-box;
  overflow: hidden;
}

/* Pied de page */
#reader-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--safe-bottom);
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--page-muted);
  pointer-events: none;
}

#reader-footer-chapter {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}

#reader-footer-page {
  flex-shrink: 0;
}

/* Calque de gestes : au-dessus du texte, invisible */
#reader-gesture-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: default;
}

#brightness-overlay {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 40;
}

/* ---------------------------------------------------------------- contrôles */
#reader-controls {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}

#reader-controls.visible {
  pointer-events: auto;
}

#reader-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  opacity: 0;
  transition: opacity 0.2s;
}

#reader-controls.visible #reader-scrim {
  opacity: 1;
}

#reader-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(var(--safe-top) + 8px) 8px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-bg);
  color: var(--panel-text);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  transform: translateY(-100%);
  transition: transform 0.22s ease;
}

#reader-controls.visible #reader-topbar {
  transform: translateY(0);
}

.rc-title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rc-icon-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--panel-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.rc-icon-btn:active {
  background: var(--panel-raised);
}

.rc-icon-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rc-icon-btn.small {
  width: 40px;
  height: 40px;
}

.rc-icon-btn.small svg {
  width: 20px;
  height: 20px;
}

#btn-reader-bookmark.active svg {
  fill: #ff5a5a;
  stroke: #ff5a5a;
}

/* Panneau du bas */
#reader-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 78%;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  color: var(--panel-text);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.35);
  padding-bottom: var(--safe-bottom);
  transform: translateY(105%);
  transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
}

#reader-controls.visible #reader-panel {
  transform: translateY(0);
}

@media (min-width: 640px) {
  #reader-panel {
    left: 50%;
    right: auto;
    width: 560px;
    margin-left: -280px;
  }
}

.rc-progress {
  padding: 14px 12px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.rc-progress-chapter {
  font-size: 13px;
  color: var(--panel-muted);
  max-width: 90%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rc-progress-row {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
}

.rc-progress-label {
  font-size: 12px;
  color: var(--panel-muted);
  font-variant-numeric: tabular-nums;
}

/* Curseurs natifs, stylés */
#rc-progress-range,
.rc-range {
  flex: 1;
  min-width: 0;
  height: 32px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  touch-action: pan-x;
  cursor: pointer;
}

#rc-progress-range:disabled {
  opacity: 0.4;
}

#rc-progress-range::-webkit-slider-runnable-track,
.rc-range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--panel-border);
}

#rc-progress-range::-webkit-slider-thumb,
.rc-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--panel-accent);
  border: 3px solid var(--panel-bg);
  box-shadow: 0 0 0 1px var(--panel-accent);
}

#rc-progress-range::-moz-range-track,
.rc-range::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--panel-border);
}

#rc-progress-range::-moz-range-thumb,
.rc-range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--panel-accent);
  border: 3px solid var(--panel-bg);
}

/* Onglets */
.rc-tabs {
  display: flex;
  margin: 6px 16px 0;
  border-bottom: 1px solid var(--panel-border);
}

.rc-tab {
  flex: 1;
  padding: 12px 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--panel-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.rc-tab.active {
  color: var(--panel-text);
  border-bottom-color: var(--panel-accent);
}

.rc-view {
  display: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 16px;
}

.rc-view.active {
  display: block;
}

#rc-view-toc,
#rc-view-bookmarks {
  padding: 4px 0 8px;
  min-height: 200px;
}

/* Thèmes */
.rc-themes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.rc-theme {
  height: 48px;
  border-radius: 12px;
  font-size: 18px;
  font-family: Georgia, serif;
  cursor: pointer;
  border: 2px solid transparent;
}

.rc-theme[data-theme="white"] { background: #ffffff; color: #1f1f1f; }
.rc-theme[data-theme="sepia"] { background: #f4ecd8; color: #3b2f22; }
.rc-theme[data-theme="dark"]  { background: #24272e; color: #d8dbe2; border-color: #353a45; }
.rc-theme[data-theme="black"] { background: #000000; color: #c9c9c9; border-color: #2a2a2a; }

.rc-theme.active {
  border-color: var(--panel-accent);
  box-shadow: 0 0 0 2px var(--panel-accent);
}

/* Lignes de réglage */
.rc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
}

.rc-row + .rc-row {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.rc-label {
  font-size: 14px;
  color: var(--panel-muted);
  flex-shrink: 0;
}

.rc-row .rc-range {
  max-width: 220px;
}

.rc-segmented {
  display: flex;
  background: var(--panel-raised);
  border-radius: 10px;
  padding: 3px;
  min-width: 0;
}

.rc-segmented button {
  border: none;
  background: none;
  color: var(--panel-muted);
  padding: 8px 9px;
  font-size: 13px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.rc-segmented button.active {
  background: var(--panel-accent);
  color: #fff;
}

.rc-stepper {
  display: flex;
  align-items: center;
  background: var(--panel-raised);
  border-radius: 10px;
}

.rc-stepper button {
  width: 52px;
  height: 40px;
  border: none;
  background: none;
  color: var(--panel-text);
  font-size: 20px;
  cursor: pointer;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rc-stepper button:active {
  background: var(--panel-border);
}

.rc-stepper button:disabled {
  opacity: 0.3;
}

.rc-stepper output {
  min-width: 44px;
  text-align: center;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.rc-switch {
  width: 50px;
  height: 30px;
  border-radius: 15px;
  border: none;
  background: var(--panel-border);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.rc-switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.rc-switch[aria-checked="true"] {
  background: var(--panel-accent);
}

.rc-switch[aria-checked="true"] span {
  transform: translateX(20px);
}

/* Listes (sommaire, signets) */
.rc-list {
  list-style: none;
}

.rc-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  min-height: 48px;
  font-size: 14px;
  color: #cfd5e0;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.rc-list li:active {
  background: var(--panel-raised);
}

.rc-list li.current {
  color: var(--panel-accent);
  font-weight: 600;
}

.rc-list li .rc-item-text {
  flex: 1;
  min-width: 0;
  padding: 12px 0;
  line-height: 1.35;
}

.rc-list li .rc-item-sub {
  display: block;
  font-size: 12px;
  color: var(--panel-muted);
  font-weight: 400;
  margin-top: 2px;
}

.rc-list li.rc-empty {
  color: var(--panel-muted);
  justify-content: center;
  cursor: default;
  border: none;
  padding-top: 24px;
}

.rc-list .rc-delete {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--panel-muted);
  font-size: 18px;
  cursor: pointer;
  border-radius: 50%;
}

/* ========================================================
   TRADUCTION (EN -> FR)
   ======================================================== */

#translate-scrim {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#translate-scrim.visible {
  opacity: 1;
  pointer-events: auto;
}

#translate-modal {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: #161a22;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  z-index: 9999;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  color: #ffffff;
  transform: translateY(105%);
  transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@media (min-width: 640px) {
  #translate-modal {
    left: 50%;
    width: 560px;
    margin-left: -280px;
  }
}

#translate-modal.visible {
  transform: translateY(0);
}

.trans-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.trans-word-en {
  font-size: 22px;
  font-weight: 700;
  word-break: break-word;
}

.trans-word-fr {
  font-size: 19px;
  font-weight: 600;
  color: #7aa7ff;
  margin-top: 4px;
}

.trans-close {
  background: #222835;
  border: none;
  color: #8f98aa;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
}

.trans-details {
  margin: 12px 0 18px;
  font-size: 14px;
  color: #a5adbd;
  line-height: 1.5;
  max-height: 32vh;
  overflow-y: auto;
  user-select: text;
}

.trans-pos-group {
  margin-bottom: 8px;
}

.trans-pos-title {
  color: #dbe1ea;
  font-weight: 600;
  text-transform: capitalize;
}

.btn-save-vocab {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  background: #2563eb;
  color: #ffffff;
  border: none;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}
