/* =========================================================================
   reader.css — the RSVP word display.

   How the fixed pivot works:
   - .rsvp is the box. --anchor says where the pivot letter must sit
     (38% from the left, a little left of centre, like Spritz).
   - The two .rsvp__guide marks are drawn at --anchor.
   - word-view.js measures the pivot letter and shifts .rsvp__line so the
     letter's centre lands exactly on the guides' position.
   So --anchor is the single place to change the pivot position.
   ========================================================================= */

.rsvp {
  --anchor: 38%;

  position: relative;
  height: clamp(140px, 28vh, 220px);
  overflow: hidden;            /* nothing may spill outside the box */
  border-block: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  user-select: none;
  cursor: pointer;             /* click / tap to play or pause */
}

/* Small tick marks above and below the pivot letter */
.rsvp__guide {
  position: absolute;
  left: var(--anchor);
  width: 2px;
  height: 18px;
  transform: translateX(-50%);
  background: var(--muted);
  opacity: 0.6;
}

.rsvp__guide--top {
  top: 0;
}

.rsvp__guide--bottom {
  bottom: 0;
}

/* The word itself. JS sets transform: translate(Xpx, -50%) */
.rsvp__line {
  position: absolute;
  top: 50%;
  left: 0;
  white-space: pre;            /* keep spaces (needed for 2–3 word chunks) */
  font-family: var(--font-reading);
  /* --word-scale is set by the Text size switch (settings.js) */
  font-size: calc(var(--word-size) * var(--word-scale, 1));
  font-weight: 500;
  line-height: 1;
  transform: translateY(-50%);
}

.rsvp__pivot {
  color: var(--accent);
}

/* Narration with 2–3 words: dim the group, highlight the word being spoken */
.rsvp__line--speaking > span {
  opacity: 0.35;
}

/* The spoken word, and always the pivot letter: it's where your eye rests */
.rsvp__line--speaking > .rsvp__spoken,
.rsvp__line--speaking > .rsvp__pivot {
  opacity: 1;
}

/* ---------- Controls under the display ---------- */

/* ---------- Progress bar ---------- */

.progress {
  margin-top: 12px;
}

.progress__bar {
  width: 100%;
  margin: 0;
  accent-color: var(--primary);   /* Chrome/Firefox also colour the part already read */
  cursor: pointer;
}

.progress__labels {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;  /* digits don't jiggle as they change */
}

/* ---------- Playback buttons ---------- */

.reader-controls {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

.transport {
  display: flex;
  gap: 8px;
}

/* Phones: playback buttons fill the width, Play gets the most room */
@media (max-width: 480px) {
  .transport {
    width: 100%;
  }

  .transport .button {
    min-height: 48px;          /* comfortable touch target */
  }

  .transport #play-button {
    flex: 1;
  }
}

/* Touch screens: no keyboard, so no shortcut hints */
@media (hover: none) and (pointer: coarse) {
  .shortcuts {
    display: none;
  }
}

/* Square-ish buttons that hold a single symbol */
.button--icon {
  min-width: 44px;
  padding-inline: 12px;
}

/* ---------- Shortcut hint ---------- */

.shortcuts {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
  text-align: center;
}

/* ---------- Context view (shown while paused) ---------- */

.context {
  position: relative;          /* so word.offsetTop is measured from this box */
  max-height: 40vh;
  overflow-y: auto;
  margin-top: 16px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.context__text {
  margin: 0;
  font-family: var(--font-reading);
  font-size: 1.05rem;
  line-height: 1.7;
}

.context__word {
  border-radius: 4px;
  cursor: pointer;
}

.context__word:hover {
  background: color-mix(in srgb, var(--primary) 15%, transparent);
}

.context__word--current {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* ---------- Settings under the controls ---------- */

.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px 24px;
  margin-top: 20px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.control--grow {
  flex: 1 1 240px;
}

.control__label {
  padding: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.control__label output {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.slider {
  width: 100%;
  accent-color: var(--primary);   /* colours the native slider */
}

/* ---------- Narration row ---------- */

.settings-row--narration {
  align-items: center;
  margin-top: 8px;
}

.select {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.narration-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* On/off switch: a real checkbox (keyboard + screen reader friendly),
   hidden, with a drawn track and knob */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch__track {
  position: relative;
  width: 40px;
  height: 22px;
  flex: none;
  border-radius: 999px;
  background: var(--border);
  transition: background-color 0.15s;
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  transition: transform 0.15s;
}

.switch input:checked + .switch__track {
  background: var(--primary);
}

.switch input:checked + .switch__track::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch__track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.switch input:disabled ~ * {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Segmented switch: real radio buttons (keyboard + screen reader friendly),
   visually hidden, with their <span> styled as the buttons. */
.segmented__options {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  min-width: 44px;
  padding: 6px 12px;
  text-align: center;
  cursor: pointer;
}

.segmented label + label span {
  border-left: 1px solid var(--border);
}

.segmented input:checked + span {
  background: var(--primary);
  color: var(--primary-text);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

/* ---------- Extracted-text preview ---------- */

.preview {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.preview summary {
  padding: 12px 16px;
  color: var(--muted);
  cursor: pointer;
}

.preview__stats {
  margin: 0;
  padding: 0 16px 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.preview__body {
  max-height: 50vh;
  overflow-y: auto;
  padding: 0 16px 16px;
}

.preview__paragraph {
  margin: 0;
  padding: 8px;
  border-radius: 8px;
  font-family: var(--font-reading);
  line-height: 1.6;
  cursor: pointer;
}

.preview__paragraph:hover {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
}

/* ---------- Debug mode (add ?debug to the URL) ----------
   Draws a full-height line through the anchor so you can check that the
   pivot letter never moves. */
.debug .rsvp::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--anchor);
  width: 1px;
  transform: translateX(-50%);
  background: var(--accent);
  opacity: 0.5;
  pointer-events: none;
}

.debug-panel {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.8rem;
}
