/* Selection tools and the Theologians AI panel (tb-fathers-selection.js).

   Nothing here is painted until a reader deliberately selects something, and
   the dial is sized so it clears the line it belongs to at every width. */

/* ---- the sentence a voice is speaking ---------------------------------- */

/* ::highlight() paints a Range without touching the document, so a footnote
   marker or verse link inside the sentence keeps its own styling. Only colour
   and decoration properties apply to a custom highlight — a box-shadow or
   padding would simply be ignored. */
::highlight(tb-fa-sentence) {
  background-color: rgba(201, 162, 77, .3);
  color: #fff6dd;
}

::highlight(tb-theo-sentence) {
  background-color: rgba(201, 162, 77, .26);
  color: #fff6dd;
}

/* ---- the dial ----------------------------------------------------------- */

.tb-sel-dial {
  position: fixed;
  z-index: 4200;
  width: 168px;
  height: 168px;
  margin: -84px 0 0 -84px;
  pointer-events: none;
}

.tb-sel-dial[hidden] { display: none; }

.tb-sel-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  opacity: 0;
  transform: scale(.82);
  transition: opacity .16s ease, transform .16s cubic-bezier(.2, .9, .3, 1.2);
}

.tb-sel-open .tb-sel-ring {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.tb-sel-act,
.tb-sel-close {
  position: absolute;
  left: 50%;
  top: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .1rem;
  border-radius: 50%;
  cursor: pointer;
  background: rgba(10, 9, 6, .96);
  border: 1px solid rgba(201, 162, 77, .42);
  color: var(--gold, #C9A24D);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .55);
  backdrop-filter: blur(6px);
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
}

.tb-sel-act {
  width: 60px;
  height: 60px;
  /* Each button rides the ring at its own angle; the counter-rotation keeps
     its label upright. */
  transform:
    translate(-50%, -50%)
    rotate(var(--tb-sel-angle, 0deg))
    translateY(-54px)
    rotate(calc(-1 * var(--tb-sel-angle, 0deg)));
}

.tb-sel-act:hover,
.tb-sel-act:focus-visible {
  background: #17140c;
  border-color: rgba(201, 162, 77, .9);
  color: #ffe6a6;
  outline: none;
}

.tb-sel-glyph {
  font-size: .95rem;
  line-height: 1;
}

/* The emblem is a gold line drawing on transparency, so it needs no tinting —
   only the same lift the glyphs get when their button is focused. */
.tb-sel-mark {
  display: block;
  width: 19px;
  height: 19px;
  object-fit: contain;
  opacity: .88;
  transition: opacity .16s ease;
}

.tb-sel-act:hover .tb-sel-mark,
.tb-sel-act:focus-visible .tb-sel-mark { opacity: 1; }

.tb-sel-name {
  font-family: var(--cinzel, 'Cinzel', serif);
  font-size: .5rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-dim, #aaa18c);
}

.tb-sel-act:hover .tb-sel-name,
.tb-sel-act:focus-visible .tb-sel-name { color: #ffe6a6; }

.tb-sel-close {
  width: 30px;
  height: 30px;
  transform: translate(-50%, -50%);
  font-size: .72rem;
  color: var(--text-faint, #6e6657);
  border-color: rgba(201, 162, 77, .22);
  box-shadow: none;
}

.tb-sel-close:hover { color: #ffe6a6; border-color: rgba(201, 162, 77, .6); }

.tb-sel-toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 4300;
  transform: translate(-50%, 10px);
  padding: .55rem 1rem;
  background: #0f0e0a;
  border: 1px solid rgba(201, 162, 77, .42);
  border-radius: 999px;
  color: var(--text, #eee7d9);
  font-family: var(--cinzel, 'Cinzel', serif);
  font-size: .62rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.tb-sel-toast-on { opacity: 1; transform: translate(-50%, 0); }

/* ---- the panel ---------------------------------------------------------- */

.tb-theo-panel {
  position: fixed;
  z-index: 4100;
  top: 60px;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  display: flex;
  flex-direction: column;
  background: #070604;
  border-left: 1px solid var(--gold-border, rgba(201, 162, 77, .2));
  box-shadow: -18px 0 44px rgba(0, 0, 0, .55);
  animation: tb-theo-in .22s ease-out;
}

.tb-theo-panel[hidden] { display: none; }

@keyframes tb-theo-in {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: none; }
}

.tb-theo-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, .07));
}

.tb-theo-eyebrow {
  font-family: var(--cinzel, 'Cinzel', serif);
  font-size: .62rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--gold, #C9A24D);
}

.tb-theo-close {
  background: transparent;
  border: 0;
  color: var(--text-faint, #6e6657);
  font-size: 1.05rem;
  line-height: 1;
  padding: .25rem .4rem;
  cursor: pointer;
}

.tb-theo-close:hover { color: var(--gold, #C9A24D); }

.tb-theo-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
}

.tb-theo-passage {
  border-left: 2px solid rgba(201, 162, 77, .45);
  padding: .1rem 0 .1rem .8rem;
  margin-bottom: 1.1rem;
}

.tb-theo-passage-text {
  color: var(--text-dim, #aaa18c);
  font-style: italic;
  font-size: .92rem;
  line-height: 1.6;
  /* A long selection would push the answer off the panel; it is still all
     there, and the reader is looking at it on the page behind anyway. */
  max-height: 8.4em;
  overflow-y: auto;
}

.tb-theo-passage-ref {
  display: block;
  margin-top: .5rem;
  font-family: var(--cinzel, 'Cinzel', serif);
  font-size: .56rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gold-dim, #a07d35);
  font-style: normal;
}

.tb-theo-turn + .tb-theo-turn {
  margin-top: 1.4rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border, rgba(255, 255, 255, .07));
}

.tb-theo-question {
  color: var(--gold, #C9A24D);
  font-family: var(--cinzel, 'Cinzel', serif);
  font-size: .66rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  line-height: 1.5;
  margin-bottom: .7rem;
}

.tb-theo-status {
  color: var(--text-faint, #6e6657);
  font-size: .88rem;
  font-style: italic;
}

.tb-theo-error {
  color: #e2a0a0;
  font-size: .9rem;
  line-height: 1.6;
}

.tb-theo-answer { color: var(--text, #eee7d9); }

.tb-theo-h {
  font-family: var(--cinzel, 'Cinzel', serif);
  color: var(--gold, #C9A24D);
  font-size: .74rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  margin: 1rem 0 .45rem;
}

.tb-theo-p { margin-bottom: .8rem; line-height: 1.72; font-size: .97rem; }
.tb-theo-list { margin: 0 0 .8rem 1.1rem; }
.tb-theo-list li { margin-bottom: .35rem; line-height: 1.68; font-size: .95rem; }

.tb-theo-cite {
  color: var(--gold-dim, #a07d35);
  font-size: .62em;
  padding: 0 .1em;
}

.tb-theo-tools { margin: .9rem 0 .2rem; }

.tb-theo-listen {
  background: transparent;
  border: 1px solid rgba(201, 162, 77, .38);
  border-radius: 999px;
  color: var(--gold, #C9A24D);
  cursor: pointer;
  font-family: var(--cinzel, 'Cinzel', serif);
  font-size: .58rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: .42rem .9rem;
}

.tb-theo-listen:hover { border-color: rgba(201, 162, 77, .85); color: #ffe6a6; }

.tb-theo-sources { margin-top: 1rem; }

.tb-theo-sources-label {
  font-family: var(--cinzel, 'Cinzel', serif);
  font-size: .54rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--text-faint, #6e6657);
  margin-bottom: .45rem;
}

.tb-theo-source {
  display: flex;
  gap: .5rem;
  align-items: baseline;
  padding: .35rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, .045);
  color: var(--text-dim, #aaa18c);
  font-size: .82rem;
  text-decoration: none;
}

a.tb-theo-source:hover { color: var(--gold, #C9A24D); }

.tb-theo-source-n {
  flex: 0 0 auto;
  color: var(--gold-dim, #a07d35);
  font-size: .68rem;
}

.tb-theo-foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--border, rgba(255, 255, 255, .07));
  padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
  background: #050403;
}

.tb-theo-live {
  width: 100%;
  margin-bottom: .6rem;
  background: linear-gradient(160deg, rgba(224, 185, 95, .16), rgba(169, 126, 46, .1));
  border: 1px solid rgba(201, 162, 77, .5);
  border-radius: 999px;
  color: #f0d79a;
  cursor: pointer;
  font-family: var(--cinzel, 'Cinzel', serif);
  font-size: .6rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  padding: .6rem 1rem;
}

.tb-theo-live:hover { filter: brightness(1.15); }

.tb-theo-composer { display: flex; gap: .5rem; align-items: flex-end; }

.tb-theo-input {
  flex: 1 1 auto;
  min-height: 42px;
  max-height: 140px;
  resize: vertical;
  background: #0b0a07;
  border: 1px solid var(--gold-border, rgba(201, 162, 77, .2));
  color: var(--text, #eee7d9);
  font-family: var(--crimson, 'Crimson Text', serif);
  font-size: .95rem;
  line-height: 1.5;
  padding: .55rem .7rem;
  outline: none;
}

.tb-theo-input:focus { border-color: rgba(201, 162, 77, .6); }

.tb-theo-send {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid rgba(201, 162, 77, .45);
  color: var(--gold, #C9A24D);
  cursor: pointer;
  font-family: var(--cinzel, 'Cinzel', serif);
  font-size: .58rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  padding: .7rem .95rem;
}

.tb-theo-send:disabled { opacity: .45; cursor: default; }
.tb-theo-send:not(:disabled):hover { border-color: rgba(201, 162, 77, .9); color: #ffe6a6; }

/* ---- related passages (semantic lookup, not an AI thread) --------------- */

/* This mode has nothing to type into and no thread to hand off, so the
   composer and live-voice footer that belong to Simplify/Ask are hidden. */
.tb-theo-panel-related .tb-theo-foot { display: none; }

.tb-related-list {
  display: flex;
  flex-direction: column;
  gap: .9rem;
}

.tb-related-card {
  display: block;
  border: 1px solid var(--gold-border, rgba(201, 162, 77, .2));
  background: #0b0a07;
  padding: .9rem 1rem;
  color: var(--text, #eee7d9);
  text-decoration: none;
  transition: background .2s ease, border-color .2s ease, transform .2s ease;
}

.tb-related-card:hover {
  background: #111;
  border-color: rgba(201, 162, 77, .5);
  transform: translateY(-2px);
}

.tb-related-father {
  font-family: var(--cinzel, 'Cinzel', serif);
  color: var(--gold, #C9A24D);
  font-size: .82rem;
  letter-spacing: .04em;
  margin-bottom: .2rem;
}

.tb-related-work {
  font-family: var(--cinzel, 'Cinzel', serif);
  color: var(--text-faint, #6e6657);
  font-size: .56rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-bottom: .6rem;
}

.tb-related-card blockquote {
  margin: 0;
  color: var(--text-dim, #aaa18c);
  font-size: .9rem;
  line-height: 1.6;
  font-style: italic;
  border-left: 2px solid rgba(201, 162, 77, .3);
  padding-left: .75rem;
}

.tb-related-open {
  display: block;
  margin-top: .7rem;
  font-family: var(--cinzel, 'Cinzel', serif);
  font-size: .56rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--gold-dim, #a07d35);
}

.tb-related-card:hover .tb-related-open { color: var(--gold, #C9A24D); }

.tb-related-note {
  margin-top: 1.1rem;
  color: var(--text-faint, #6e6657);
  font-size: .8rem;
  font-style: italic;
}

/* On a wide screen the panel sits beside the book rather than over it, so a
   reader can keep following the passage the answer is about. */
@media (min-width: 1280px) {
  body.tb-theo-panel-open .layout { padding-right: 440px; }
}

@media (max-width: 720px) {
  /* A side panel on a phone is a bottom sheet; the book stays visible above
     it, which is the whole point of answering in place. */
  .tb-theo-panel {
    top: auto;
    left: 0;
    right: 0;
    height: min(76vh, 640px);
    width: auto;
    border-left: 0;
    border-top: 1px solid var(--gold-border, rgba(201, 162, 77, .2));
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -18px 44px rgba(0, 0, 0, .6);
    animation-name: tb-theo-up;
  }

  @keyframes tb-theo-up {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: none; }
  }

  .tb-sel-dial {
    width: 150px;
    height: 150px;
    margin: -75px 0 0 -75px;
  }

  .tb-sel-act {
    width: 54px;
    height: 54px;
    transform:
      translate(-50%, -50%)
      rotate(var(--tb-sel-angle, 0deg))
      translateY(-48px)
      rotate(calc(-1 * var(--tb-sel-angle, 0deg)));
  }

  /* The read-aloud bar and the sheet would otherwise stack on top of one
     another at the bottom of the screen. */
  body.tb-theo-panel-open .tb-fa-bar { display: none; }
}
