.tome {
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Nunito", ui-rounded, system-ui, sans-serif;
  --font-serif: "Iowan Old Style", "Georgia", "Times New Roman", serif;
  --ink: #1b2430;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 12px;
  font-family: var(--font-body);
}
.tome-text {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
  padding-bottom: 8px;
}
.tome-cap-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  max-width: min(440px, calc(100vw - 220px));
}
.tome-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  position: relative;
}

/* caption / speech bubble */
.tome-cap {
  position: relative;
  box-sizing: border-box;
  max-width: min(340px, calc(100vw - 32px));
  padding: 14px 18px;
  border-radius: 20px;
  background: #fcfdf9;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.5;
  font-weight: 400;
  border: 1px solid transparent;
  overflow: visible;
  word-break: normal;
  overflow-wrap: break-word;
  box-shadow: 0 10px 30px rgba(2, 8, 23, 0.28), 0 2px 6px rgba(2, 8, 23, 0.18);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  pointer-events: none;
  transition:
    opacity 0.22s ease,
    transform 0.22s ease,
    visibility 0.22s,
    background 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease;
}
.tome.show-cap .tome-cap {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
}
/* tail pointing toward the avatar/book on the right */
.tome-cap::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: 18px;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: #fcfdf9;
  transform: rotate(45deg);
  box-shadow: 2px 2px 6px rgba(2, 8, 23, 0.18);
}
/* speaking header + status dot */
.tome-cap .gh {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
}
.tome-cap .gh i {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #9aa5b1;
  flex: none;
}
.tome-cap.speaking .gh i {
  background: #e5484d;
  box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.5);
  animation: tome-pulse 1s infinite;
}
@keyframes tome-pulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.5);
  }
  70% {
    transform: scale(1.35);
    box-shadow: 0 0 0 6px rgba(229, 72, 77, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(229, 72, 77, 0);
  }
}
.tome-cap .w {
  opacity: 0;
  transition: opacity 0.35s ease;
  text-shadow: none;
}
.tome-cap .w.in {
  opacity: 1;
}
/* the light bubble is used in both dark and light sections */
.tome.on-light .tome-cap,
.tome.on-dark .tome-cap {
  background: #fcfdf9;
  color: var(--ink);
  border-color: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.tome.on-light .tome-cap .w,
.tome.on-dark .tome-cap .w {
  text-shadow: none;
}

/* level meter */
.tome-meter {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 18px;
  padding: 0 4px;
  opacity: 0;
  flex: none;
  transition: opacity 0.3s;
}
.tome.on-light .tome-meter {
  color: #0a254f;
}
.tome.on-dark .tome-meter {
  color: #7dd3fc;
}
.tome-meter.speaking {
  opacity: 1;
}
.tome-meter i {
  width: 3px;
  height: 16px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.35;
  transform: scaleY(0.25);
  transform-origin: bottom;
  transition: opacity 0.3s;
}

/* note */
.tome-note {
  max-width: min(340px, calc(100vw - 220px));
  font-family: var(--font-body);
  font-size: 11.5px;
  line-height: 1.4;
  color: #b45309;
  background: rgba(252, 211, 77, 0.15);
  border: 1px solid rgba(252, 211, 77, 0.35);
  padding: 6px 10px;
  border-radius: 10px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s;
}
.tome.on-dark .tome-note {
  color: #fde68a;
  background: rgba(250, 204, 21, 0.12);
  border-color: rgba(250, 204, 21, 0.3);
}
.tome.show-note .tome-note {
  opacity: 1;
  visibility: visible;
}

/* controls */
.tome-ctrls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.3s,
    visibility 0.3s;
}
.tome.active .tome-ctrls {
  opacity: 1;
  visibility: visible;
}
.tome-pill {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 99px;
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 700;
  transition:
    background 0.2s,
    color 0.2s,
    border-color 0.2s,
    transform 0.15s;
}
.tome.on-light .tome-pill {
  color: #0a254f;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(10, 37, 79, 0.14);
  box-shadow: 0 4px 12px -2px rgba(10, 37, 79, 0.08);
}
.tome.on-dark .tome-pill {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16);
}
.tome-pill:hover,
.tome-pill:focus-visible {
  transform: translateY(-1px);
}
.tome.on-light .tome-pill:hover {
  background: #fff;
  border-color: rgba(10, 37, 79, 0.3);
}
.tome.on-dark .tome-pill:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(125, 211, 252, 0.5);
}
.tome-pill[aria-expanded="true"] {
  border-color: #38bdf8 !important;
}
.tome-pill svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ask panel */
.tome-ask {
  max-width: min(340px, calc(100vw - 220px));
  padding: 12px 14px;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition:
    opacity 0.25s,
    transform 0.25s,
    visibility 0.25s;
  pointer-events: none;
}
.tome.ask-open .tome-ask {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
}
.tome.on-light .tome-ask {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(10, 37, 79, 0.15);
  color: #0a254f;
  box-shadow: 0 12px 30px -4px rgba(10, 37, 79, 0.12);
}
.tome.on-dark .tome-ask {
  background: rgba(4, 18, 43, 0.92);
  border: 1px solid rgba(125, 211, 252, 0.3);
  color: #e2e8f0;
  box-shadow: 0 16px 40px -8px rgba(0, 0, 0, 0.5);
}
.tome-ask small {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.65;
}
.tome-sugg {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tome-sugg button {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(27, 36, 48, 0.18);
  background: #fff;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}
.tome-sugg button:hover,
.tome-sugg button:focus-visible {
  background: #e6f1ff;
  border-color: #7db7ff;
  outline: none;
}
.tome-sugg button:focus-visible {
  box-shadow: 0 0 0 3px rgba(125, 183, 255, 0.5);
}
.tome-field {
  display: flex;
  gap: 8px;
}
.tome-field input {
  flex: 1 1 100%;
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(27, 36, 48, 0.18);
  outline: none;
  padding: 9px 12px;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
}
.tome-field input::placeholder {
  color: #9aa5b1;
}
.tome-field input:focus {
  border-color: #7db7ff;
  box-shadow: 0 0 0 3px rgba(125, 183, 255, 0.5);
}
.tome-field button {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 99px;
  display: grid;
  place-items: center;
  background: var(--g, linear-gradient(135deg, #38bdf8, #1d6fe8));
  color: #fff;
  flex: none;
}
.tome-field button svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* teaser */
.tome-teaser {
  position: relative;
  max-width: 230px;
  padding: 11px 14px;
  border-radius: 16px 16px 4px 16px;
  background: #fff;
  color: #0a254f;
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.35;
  box-shadow: 0 18px 40px -14px rgba(2, 8, 23, 0.55);
  animation: tome-pop 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  cursor: pointer;
}
.tome-teaser[hidden] {
  display: none;
}
.tome-teaser b {
  color: #0ea5e9;
}

/* ---------- LUMEN RESKIN: THE BOOK ---------- */
.lumen-book {
  position: relative;
  width: clamp(118px, 12vw, 170px);
  aspect-ratio: var(--book-aspect, 0.99756);
  user-select: none;
  -webkit-user-select: none;
  filter: drop-shadow(0 14px 22px rgba(2, 8, 23, 0.55))
    drop-shadow(0 0 16px rgba(56, 189, 248, 0.35));
  transition: transform 0.25s;
}
.lumen-book:hover {
  transform: scale(1.04);
}
.book-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  user-select: none;
}
.plate {
  transition: opacity 0.5s ease;
}
/* Phase-driven book cross-fade.
   The blank cover asset (#book-blank) is currently unavailable (HTTP 404),
   so painting it shows a broken-image grey square with silver corner
   brackets. Keep #book-blank at opacity 0 in EVERY phase so that broken
   placeholder never renders. The quill (#book-rest, which loads) is the
   resting book the orb wakes on: visible at idle and awakening, faded to 0
   for departing/attending/returning (no book frame, brackets or grey square
   behind the flying orb), and the book's drop-shadow is dropped in those
   phases so no shadow square remains either. The quill fades back in when
   the phase returns to idle (merge-flash). */
#book-blank {
  opacity: 0;
}
.tome[data-phase="idle"] #book-rest,
.tome[data-phase="awakening"] #book-rest {
  opacity: 1;
}
.tome[data-phase="departing"] #book-rest,
.tome[data-phase="attending"] #book-rest,
.tome[data-phase="returning"] #book-rest {
  opacity: 0;
  transition: opacity 0.35s ease;
}
.tome[data-phase="departing"] .lumen-book,
.tome[data-phase="attending"] .lumen-book,
.tome[data-phase="returning"] .lumen-book {
  filter: none;
}
#book-rest {
  z-index: 1;
}
#book-blank {
  z-index: 0;
}
.recess,
.home-orb,
.merge-flash {
  z-index: 2;
}
#book button.lumen-wake {
  z-index: 3;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: none;
  border: 0;
  padding: 0;
  border-radius: 10px;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
#book button.lumen-wake:focus-visible {
  box-shadow:
    0 0 0 3px #38bdf8,
    0 0 0 6px #070d18;
}

/* orb inside recess */
.orb-img {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  max-width: none;
  height: auto;
  pointer-events: none;
  user-select: none;
}
.recess,
.home-orb {
  position: absolute;
  border-radius: 9999px;
  left: calc(var(--rcx, 0.5482) * 100%);
  top: calc(var(--rcy, 0.4373) * 100%);
  width: calc(var(--os, 0.42) * 100%);
  aspect-ratio: 1;
  translate: -50% -50%;
}
.recess {
  pointer-events: none;
}
.home-orb {
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: homeFloat 7s ease-in-out infinite;
  will-change: transform, opacity;
}
.home-orb.off {
  opacity: 0;
  transition-duration: 0.16s;
}
@keyframes homeFloat {
  0%,
  100% {
    translate: -50% -50%;
  }
  50% {
    translate: -50% calc(-50% - 1.5px);
  }
}
.orb-aura {
  position: absolute;
  inset: -20%;
  border-radius: 9999px;
  background: radial-gradient(
    circle,
    rgba(96, 190, 255, 0.34) 0%,
    rgba(59, 130, 246, 0.12) 48%,
    transparent 72%
  );
  animation: breathe 5.2s cubic-bezier(0.4, 0, 0.3, 1) infinite;
}
@keyframes breathe {
  0%,
  100% {
    transform: scale(0.94);
    opacity: 0.55;
  }
  42% {
    transform: scale(1.1);
    opacity: 0.95;
  }
  70% {
    transform: scale(1.02);
    opacity: 0.75;
  }
}
.orb-ripple {
  position: absolute;
  inset: 4%;
  border-radius: 9999px;
  border: 1.5px solid rgba(125, 211, 252, 0.45);
  opacity: 0;
  animation: ripple 5.4s cubic-bezier(0.16, 0.8, 0.3, 1) infinite;
}
.orb-ripple.r2 {
  animation-delay: 2.7s;
}
@keyframes ripple {
  0% {
    transform: scale(0.62);
    opacity: 0;
  }
  10% {
    opacity: 0.55;
  }
  55% {
    opacity: 0.12;
  }
  100% {
    transform: scale(1.68);
    opacity: 0;
  }
}
.orb-burst {
  position: absolute;
  inset: 0;
  border-radius: 9999px;
  border: 2px solid rgba(186, 230, 253, 0.9);
  opacity: 0;
}
.home-orb.awake {
  animation: awakePulse 0.62s cubic-bezier(0.34, 1.4, 0.4, 1) 2;
}
.home-orb.awake .orb-aura {
  animation: breathe 1.05s cubic-bezier(0.4, 0, 0.3, 1) infinite;
  opacity: 1;
}
.home-orb.awake .orb-burst {
  animation: burst 0.78s cubic-bezier(0.16, 0.9, 0.3, 1) forwards;
}
.home-orb.awake .orb-ripple {
  animation-duration: 1.3s;
}
@keyframes awakePulse {
  0%,
  100% {
    translate: -50% -50%;
    scale: 1;
  }
  38% {
    translate: -50% -50%;
    scale: 1.07;
  }
}
@keyframes burst {
  0% {
    transform: scale(0.55);
    opacity: 0.95;
    border-width: 2.5px;
  }
  100% {
    transform: scale(2.3);
    opacity: 0;
    border-width: 0.5px;
  }
}

/* ember in recess */
.recess-ember {
  position: absolute;
  inset: 0;
  border-radius: 9999px;
  opacity: 0;
  transition: opacity 0.3s;
  background: radial-gradient(
    circle,
    rgba(56, 189, 248, 0.2) 0%,
    rgba(59, 130, 246, 0.07) 42%,
    transparent 68%
  );
}
.tome:not([data-phase="idle"]):not([data-phase="awakening"]) .recess-ember {
  opacity: 1;
  animation: emberWait 2.6s ease-in-out 0.25s infinite backwards;
}
@keyframes emberWait {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.82);
  }
  50% {
    opacity: 0.85;
    transform: scale(0.98);
  }
}
.merge-flash {
  position: absolute;
  border-radius: 9999px;
  pointer-events: none;
  left: calc(var(--rcx, 0.5482) * 100%);
  top: calc(var(--rcy, 0.4373) * 100%);
  width: calc(var(--os, 0.42) * 100%);
  aspect-ratio: 1;
  translate: -50% -50%;
  border: 2px solid rgba(186, 230, 253, 0.9);
  background: radial-gradient(
    circle,
    rgba(125, 211, 252, 0.4) 0%,
    transparent 62%
  );
  animation: mergeFlash 0.6s cubic-bezier(0.16, 0.9, 0.3, 1) forwards;
}
@keyframes mergeFlash {
  0% {
    opacity: 0.95;
    transform: scale(0.55);
    border-width: 3px;
  }
  100% {
    opacity: 0;
    transform: scale(1.75);
    border-width: 0.5px;
  }
}

/* travelling orb */
#float {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  opacity: 0;
  z-index: 65;
  pointer-events: none;
  will-change: transform, opacity;
  transition: opacity 0.2s ease;
}
#float .box {
  position: absolute;
  will-change: transform;
  transform-origin: 50% 50%;
}
.aura-fly {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  border-radius: 9999px;
  background: radial-gradient(
    circle,
    rgba(125, 211, 252, 0.3) 0%,
    rgba(79, 70, 229, 0.1) 46%,
    transparent 72%
  );
  animation: breathe 2.8s cubic-bezier(0.4, 0, 0.3, 1) infinite;
}
.arrive-ripple {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  border-radius: 9999px;
  border: 2px solid rgba(125, 211, 252, 0.8);
  opacity: 0;
  animation: arrive 0.8s cubic-bezier(0.16, 0.9, 0.3, 1) forwards;
}
@keyframes arrive {
  0% {
    opacity: 0.9;
    transform: scale(0.5);
    border-width: 3px;
  }
  100% {
    opacity: 0;
    transform: scale(1.5);
    border-width: 0.5px;
  }
}
.spark {
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 9999px;
  background: #bae6fd;
  box-shadow: 0 0 7px rgba(125, 211, 252, 0.95);
  opacity: 0;
  animation: orbitSpark var(--dur) cubic-bezier(0.3, 0, 0.5, 1) var(--delay) infinite;
}
@keyframes orbitSpark {
  0% {
    transform: rotate(var(--angle)) translateX(calc(var(--radius) * 0.35)) scale(0.4);
    opacity: 0;
  }
  25% {
    opacity: 0.9;
  }
  100% {
    transform: rotate(calc(var(--angle) + 140deg)) translateX(var(--radius)) scale(0.2);
    opacity: 0;
  }
}
#float-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#trail {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 62;
  pointer-events: none;
}

.tome-badge {
  position: absolute;
  right: -2px;
  top: -2px;
  width: 14px;
  height: 14px;
  border-radius: 9999px;
  background: #34d399;
  border: 2px solid #04122b;
  box-shadow: 0 0 10px #34d399;
  animation: tome-ping 2s infinite;
  z-index: 4;
}
.tome.active .tome-badge {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  .tome {
    right: 12px;
    bottom: 12px;
  }
  .lumen-book {
    width: 110px;
  }
  .tome-cap {
    max-width: min(340px, calc(100vw - 32px));
  }
  .tome-cap-row,
  .tome-note,
  .tome-ask {
    max-width: min(320px, calc(100vw - 140px));
  }
}
@media (prefers-reduced-motion: reduce) {
  .home-orb,
  .orb-aura,
  .orb-ripple,
  .aura-fly,
  .spark,
  .recess-ember {
    animation: none !important;
  }
  #trail {
    display: none;
  }
  .tome-meter {
    display: none;
  }
  .tome-cap .w {
    opacity: 1;
    transition: none;
  }
  .tome-cap {
    transform: none;
    transition: none;
  }
  .tome-cap.speaking .gh i {
    animation: none;
    background: #e5484d;
  }
  .tome-teaser {
    animation: none;
  }
}
@media print {
  .tome {
    display: none !important;
  }
}
