/* ── Freeze state ──────────────────────────────────────────────────────── */

body.analysis-frozen {
  overflow: hidden;
}

body.analysis-frozen .page-reader,
body.analysis-frozen #ann-toolbar,
body.analysis-frozen .rsp-header,
body.analysis-frozen #sl-body {
  pointer-events: none;
  user-select: none;
}

/* Hide “Show panels” while sentence analysis is active (sidebar restore is outside the dimmed reader). */
body.analysis-frozen .sidebar-restore-btn {
  display: none !important;
}

body.analysis-frozen #ann-toolbar,
body.analysis-frozen .rsp-header {
  opacity: 0.22;
  transition: opacity 0.9s ease;
}

/* Dim all text sections and block headers into the background */
body.analysis-frozen .text-section,
body.analysis-frozen .text-block-header {
  transition: color 0.9s ease, opacity 0.9s ease;
  color: var(--text-freeze-dim);
  opacity: 0.34;
}

/* Annotations: strip visual decorations but keep text visible */
body.analysis-frozen .ann-span {
  background: transparent !important;
  border-bottom: none !important;
  text-decoration: none !important;
  outline: none !important;
  cursor: default;
  transition: none;
}
body.analysis-frozen .ann-span::after {
  display: none;
}

/* Analysed section — restores opacity so the sentence can be seen, but uses
   --text-freeze-dim (= text-faint blended to 40% on the theme bg) for all
   non-sentence text so it reads as "infinite unfocus" just like other sections.
   Child .ao-sentence then overrides to the brighter "unfocus" color. */
body.analysis-frozen .ao-target {
  color: var(--text-freeze-dim);
  opacity: 1;
  transition: color 0.9s ease;
}

/* Sentence within the analysed section: "unfocus" — visibly brighter than
   surrounding non-sentence text (infinite unfocus). Token spans lit further by
   JS-applied classes on top of this. */
body.analysis-frozen .ao-target .ao-sentence {
  color: var(--text-faint);
  transition: color 0.9s ease;
}

/* ── Token spans ───────────────────────────────────────────────────────── */

/* Sentence wrapper — gives gap text (spaces, punctuation) uniform faint color */
.ao-sentence {
  color: var(--text-faint);
}

.ao-token {
  display: inline-block;
  transition: color 0.18s linear, text-decoration 0.25s ease-out;
}

.ao-char {
  display: inline;
  transition: color 0.12s linear;
}

/* Auto-play states */
.ao-future { color: var(--text-faint); font-weight: 500; }

.ao-active {
  color: #c0483a;
  font-weight: 500;
}

/* Individual post-focus tokens: de-bold, keep full color. No underline here —
   the wrapper span handles that so the line is continuous across gap text. */
.ao-post-focus {
  color: var(--text);
  font-weight: 500;
}

/* Continuous underline across a run of consecutive post-focus tokens.
   CSS text-decoration on a parent draws under all inline content including
   text nodes (spaces), so the line is unbroken between adjacent words. */
.ao-post-focus-run {
  text-decoration: none;
  background-image: linear-gradient(var(--text-dim), var(--text-dim));
  background-repeat: no-repeat;
  background-position: left calc(100% - 1px);
  background-size: 0% 1.5px;
  animation: ao-ink-underline 0.45s ease-out forwards;
}

/* Manual states */
.ao-manual-past   { color: var(--text); font-weight: 500; text-decoration: none; }
.ao-manual-active {
  color: #c0483a;
  font-weight: 500;
  text-decoration: none;
}
.ao-manual-future { color: var(--text-faint); font-weight: 500; }

/* Ink sweep: starts at --text-dim, transitions to --text */
.ao-sweep-init { color: var(--text-dim); }

/* ── Fixed controls container ──────────────────────────────────────────── */

#ao-controls {
  position: fixed;
  z-index: 180;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.28));
  opacity: 0;
  transform: translateY(-6px) scale(0.94);
  animation: ao-controls-pop-in var(--ao-toolbar-enter-ms, 500ms) ease-in forwards;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

#ao-controls.ao-controls-exit {
  opacity: 0;
  transform: translateY(-4px);
}

body.analysis-frozen.analysis-exiting #ann-toolbar,
body.analysis-frozen.analysis-exiting .rsp-header {
  opacity: 1;
}

body.analysis-frozen.analysis-exiting .text-section,
body.analysis-frozen.analysis-exiting .text-block-header,
body.analysis-frozen.analysis-exiting .ao-target,
body.analysis-frozen.analysis-exiting .ao-target .ao-sentence {
  color: var(--text);
  opacity: 1;
}

/* dep/clause toggle */
#ao-toggle {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--bg-hover);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
  font-family: system-ui, sans-serif;
  font-size: 12px;
  cursor: pointer;
}

#ao-toggle .ao-tab {
  border-radius: 16px;
  padding: 4px 12px;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

#ao-toggle .ao-tab.active {
  background: var(--accent);
  color: #12100e;
  font-weight: 600;
}

/* Layer selector row */
#ao-selector {
  position: relative;    /* anchor for .ao-layer-progress */
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--bg-hover);
  border-radius: 20px;
  padding: 5px 12px;
  font-family: system-ui, sans-serif;
  font-size: 12px;
  white-space: nowrap;
  transform-origin: center;
  overflow: visible;
}

#ao-selector.ao-toolbar-advance-cue {
  animation: ao-selector-advance-cue var(--ao-selector-advance-ms, 420ms) ease-out forwards;
}

.ao-arrow {
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 2px;
  font-size: 16px;
  line-height: 1;
  user-select: none;
  transition: color 0.15s;
}
.ao-arrow:hover { color: var(--text); }

#ao-labels {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 22px;
}

.ao-labels-track {
  position: relative;
  display: inline-flex;
  align-items: center;
  z-index: 1;
}

.ao-layer-highlight {
  position: absolute;
  left: 0;
  top: 50%;
  height: 22px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--bg-hover) 78%, transparent);
  border: 1px solid color-mix(in srgb, var(--text-faint) 18%, transparent);
  box-shadow: 0 0 0 rgba(192, 72, 58, 0), 0 6px 14px rgba(0,0,0,0.16);
  opacity: 0;
  pointer-events: none;
  transform: translate(0, -50%);
  transition:
    transform 220ms cubic-bezier(0.22, 1, 0.36, 1),
    width 220ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 150ms ease,
    box-shadow 180ms ease,
    background 180ms ease;
}

.ao-layer-highlight.ao-instant {
  transition: none;
}

.ao-layer-highlight.is-preview {
  background: color-mix(in srgb, var(--accent) 18%, var(--bg-hover));
  box-shadow: 0 0 0 rgba(192, 72, 58, 0), 0 4px 10px rgba(0,0,0,0.12);
}

.ao-layer-label {
  color: var(--text-faint);
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 4px;
  position: relative;
  z-index: 1;
  transition: color 0.15s;
  user-select: none;
}
.ao-layer-label.active       { color: #c0483a; font-weight: 700; }
.ao-layer-label.ao-manual-active { color: #c0483a; font-weight: 700; }
.ao-layer-label.past         { color: var(--text-dim); }

.ao-sep { color: var(--text-faint); opacity: 0.4; }

#ao-play-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--bg-hover);
  background: transparent;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 9px;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
#ao-play-btn:hover { color: var(--text); border-color: var(--text-dim); }

#ao-exit-btn {
  font-family: system-ui, sans-serif;
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg-card);
  border: 1px solid var(--bg-hover);
  border-radius: 6px;
  padding: 3px 9px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
#ao-exit-btn:hover { color: var(--text-dim); border-color: var(--text-dim); }

/* Speed selector (0.75× 1× 1.5×) */
.ao-speed-selector {
  display: flex;
  gap: 0;
  margin-left: 4px;
}

.ao-speed-opt {
  font-family: system-ui, sans-serif;
  font-size: 10px;
  color: var(--text-faint);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  user-select: none;
  transition: color 0.15s;
}
.ao-speed-opt:hover  { color: var(--text-dim); }
.ao-speed-opt.active { color: var(--text); font-weight: 600; }

.ao-confidence {
  --ao-confidence-color: #7c8796;
  --ao-confidence-bg: color-mix(in srgb, var(--bg-card) 88%, var(--ao-confidence-color));
  --ao-confidence-border: color-mix(in srgb, var(--ao-confidence-color) 36%, var(--bg-hover));
  --ao-confidence-pulse-scale: 1.12;
  --ao-confidence-offset-top: 3px;
  --ao-confidence-offset-right: 8px;
  position: absolute;
  top: var(--ao-confidence-offset-top);
  right: var(--ao-confidence-offset-right);
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.ao-confidence--high {
  --ao-confidence-color: #2fbf71;
}

.ao-confidence--medium {
  --ao-confidence-color: #22b8b0;
}

.ao-confidence--low {
  --ao-confidence-color: #d4a72c;
}

.ao-confidence--uncertain {
  --ao-confidence-color: #d97706;
}

.ao-confidence--unusable {
  --ao-confidence-color: #d64545;
}

.ao-confidence-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 18px;
  height: 18px;
  max-width: 18px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  transition:
    width 180ms ease,
    max-width 180ms ease,
    padding 180ms ease,
    border-radius 180ms ease,
    background 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.ao-confidence.is-expanded .ao-confidence-chip,
.ao-confidence:focus-visible .ao-confidence-chip {
  width: auto;
  max-width: 72px;
  padding: 0 8px 0 6px;
  border-radius: 8px;
  border-color: var(--ao-confidence-border);
  background: color-mix(in srgb, var(--bg-card) 78%, var(--ao-confidence-color) 12%);
  -webkit-backdrop-filter: blur(10px) saturate(1.08);
  backdrop-filter: blur(10px) saturate(1.08);
  box-shadow: 0 6px 16px rgba(0,0,0,0.18);
}

.ao-confidence-dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ao-confidence-color);
  flex-shrink: 0;
  box-shadow: 0 0 0 1px color-mix(in srgb, white 28%, transparent);
  animation: ao-confidence-breathe 2.4s ease-in-out infinite;
  transform-origin: center;
}

.ao-confidence-dot::before,
.ao-confidence-dot::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.ao-confidence-dot::before {
  width: 14px;
  height: 14px;
  background: color-mix(in srgb, var(--ao-confidence-color) 26%, transparent);
  filter: blur(5px);
  opacity: 0.72;
}

.ao-confidence-dot::after {
  width: 18px;
  height: 18px;
  background: color-mix(in srgb, var(--ao-confidence-color) 12%, transparent);
  filter: blur(10px);
  opacity: 0.48;
}

.ao-confidence-label {
  margin-left: 0;
  max-width: 0;
  overflow: hidden;
  color: var(--ao-confidence-color);
  font-family: system-ui, sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-2px);
  transition:
    max-width 180ms ease,
    opacity 120ms ease 70ms,
    transform 180ms ease,
    margin-left 180ms ease;
}

.ao-confidence.is-expanded .ao-confidence-label,
.ao-confidence:focus-visible .ao-confidence-label {
  margin-left: 6px;
  max-width: 40px;
  opacity: 1;
  transform: translateX(0);
}

/* Report a problem — bottom-right on #ao-selector (symmetric to .ao-confidence top-right). */
.ao-report-error {
  --ao-report-error-accent: #9a7a6a;
  --ao-report-error-bg: color-mix(in srgb, var(--bg-card) 88%, var(--ao-report-error-accent));
  --ao-report-error-border: color-mix(in srgb, var(--ao-report-error-accent) 34%, var(--bg-hover));
  --ao-report-error-offset-bottom: -6px;
  --ao-report-error-offset-right: -4px;
  position: absolute;
  bottom: var(--ao-report-error-offset-bottom);
  right: var(--ao-report-error-offset-right);
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  cursor: pointer;
  outline: none;
}

.ao-report-error:focus-visible {
  filter: drop-shadow(0 0 0 2px color-mix(in srgb, var(--ao-report-error-accent) 55%, transparent));
}

.ao-report-error-chip {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  width: auto;
  min-width: 24px;
  height: 18px;
  max-width: 24px;
  padding: 0;
  border: 1px solid var(--ao-report-error-border);
  border-radius: 6px;
  background: color-mix(in srgb, var(--ao-report-error-bg) 92%, transparent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  transition:
    max-width 180ms ease,
    padding 180ms ease,
    border-color 180ms ease,
    background 180ms ease,
    box-shadow 180ms ease;
}

.ao-report-error.is-expanded .ao-report-error-chip,
.ao-report-error:focus-visible .ao-report-error-chip {
  max-width: 200px;
  padding: 0 8px;
  justify-content: flex-start;
  border-color: var(--ao-report-error-border);
  background: color-mix(in srgb, var(--bg-card) 78%, var(--ao-report-error-accent) 10%);
  -webkit-backdrop-filter: blur(10px) saturate(1.08);
  backdrop-filter: blur(10px) saturate(1.08);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.ao-report-error-mark {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 100%;
  font-family: system-ui, sans-serif;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: color-mix(in srgb, var(--ao-report-error-accent) 55%, var(--text-dim));
  user-select: none;
  opacity: 1;
  transition: opacity 120ms ease, min-width 180ms ease, width 180ms ease, margin 180ms ease;
}

.ao-report-error.is-expanded .ao-report-error-mark,
.ao-report-error:focus-visible .ao-report-error-mark {
  opacity: 0;
  min-width: 0;
  width: 0;
  max-width: 0;
  margin: 0;
  overflow: hidden;
  pointer-events: none;
}

.ao-report-error-label {
  max-width: 0;
  margin-right: 0;
  overflow: hidden;
  color: var(--text-dim);
  font-family: system-ui, sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(4px);
  transition:
    max-width 180ms ease,
    opacity 120ms ease 70ms,
    transform 180ms ease,
    margin-right 180ms ease;
}

.ao-report-error.is-expanded .ao-report-error-label,
.ao-report-error:focus-visible .ao-report-error-label {
  margin-right: 0;
  max-width: 120px;
  opacity: 1;
  transform: translateX(0);
}

/* Auto-play layer progress bar — sits flush at the bottom edge of #ao-selector */
.ao-layer-progress {
  position: absolute;
  bottom: -3px;
  left: 12px;       /* inset to match selector padding */
  right: 12px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  transform-origin: left;
  animation: ao-layer-shrink linear forwards;
}

@keyframes ao-layer-shrink {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

@keyframes ao-controls-pop-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes ao-selector-advance-cue {
  0% {
    transform: scale(1);
    box-shadow: none;
  }
  50% {
    transform: scale(var(--ao-selector-advance-scale, 1.1));
    box-shadow:
      0 0 0 1px color-mix(in srgb, var(--accent) calc(var(--ao-selector-glow-ring-alpha, 0.22) * 100%), transparent),
      0 0 var(--ao-selector-glow-blur, 12px) color-mix(in srgb, var(--accent) calc(var(--ao-selector-glow-ring-alpha, 0.22) * 100%), transparent),
      0 8px 14px rgba(0,0,0,var(--ao-selector-glow-shadow-alpha, 0.16));
  }
  100% {
    transform: scale(1);
    box-shadow: none;
  }
}

@keyframes ao-confidence-breathe {
  0%, 100% {
    transform: scale(1);
    opacity: 0.94;
  }
  50% {
    transform: scale(var(--ao-confidence-pulse-scale, 1.12));
    opacity: 1;
  }
}

@keyframes ao-ink-underline {
  from { background-size: 0% 1.5px; }
  to   { background-size: 100% 1.5px; }
}

/* Top indeterminate progress bar */
#ao-progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  background: var(--accent);
  z-index: 200;
  width: 30%;
  animation: ao-progress-slide 1.4s ease-in-out infinite;
}

@keyframes ao-progress-slide {
  0%   { left: -30%; width: 30%; }
  60%  { left: 100%; width: 30%; }
  100% { left: 100%; width: 30%; }
}

/* Toggle bounce hint */
@keyframes ao-bounce {
  0%, 100% { transform: scale(1); }
  30%       { transform: scale(1.15); }
  60%       { transform: scale(0.95); }
}

.ao-bounce {
  animation: ao-bounce 0.4s ease-in-out 2;
}

@media (prefers-reduced-motion: reduce) {
  .ao-confidence-dot {
    animation: none;
  }

  .ao-confidence-chip,
  .ao-confidence-label {
    transition: none;
  }

  .ao-report-error-chip,
  .ao-report-error-label,
  .ao-report-error-mark {
    transition: none;
  }
}

/* Reader chrome: statusbar is on body; splitter is in #app. Re-assert after all sheets (see layout.css). */
html body > .reader-statusbar {
  transition-property: background-color, color, border-top-color, border-right-color;
  transition-duration: var(--theme-xfade-duration);
  transition-timing-function: var(--theme-xfade-ease);
}
html body > .reader-statusbar:hover {
  transition-duration: var(--theme-tap-duration);
}
#app .reader-splitter::before {
  transition-property: background-color, opacity;
  transition-duration: var(--theme-xfade-duration);
  transition-timing-function: var(--theme-xfade-ease);
}
