/* Amadeus page: uses the site's own stylesheet (app.css, loaded first). These rules add the avatar, the microphone
   and the answer card, using the site's tokens so both themes match the rest of the site. */

body.page-amadeus .amadeus-wrap { padding-block: var(--s-4) var(--s-5); }

body.page-amadeus .welcome { margin: 0; }
body.page-amadeus .welcome .greet { margin-top: 0; }
body.page-amadeus .welcome .hint { margin-bottom: 0; }
/* Starter questions under the hint. They go once a conversation starts, so the chat is the main item. */
body.page-amadeus .starters { margin: var(--s-4) 0 0; }
body.page-amadeus.has-exchange .starters { display: none; }
body.page-amadeus .stage { display: grid; justify-items: center; gap: var(--s-2); margin: var(--s-2) 0 0; text-align: center; }
body.page-amadeus .face {
  position: relative; width: min(260px, 64vw); aspect-ratio: 1 / 1; border-radius: 50%; overflow: hidden;
  background: radial-gradient(circle at 50% 40%, var(--bg-raised), var(--bg-page) 72%);
  box-shadow: var(--e-2);
}
body.page-amadeus .face img { display: block; width: 100%; height: 100%; object-fit: cover; }
body.page-amadeus .face .mouth { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
/* The status line sits in the composer, just above the text box and the microphone, so a message about the microphone
   ("Listening…", "The microphone is blocked…") is on screen next to the button that caused it, even on a phone. Empty,
   it takes no room, but stays in the page so screen readers still announce it. */
body.page-amadeus .status { max-width: 680px; margin: 0 auto var(--s-2); text-align: center; color: var(--text-soft); font-size: var(--t-micro); }
body.page-amadeus .status:empty { margin-bottom: 0; }
body.page-amadeus .status.error { color: var(--color-antique-gold); }

/* The stage shows the Amadeus mark and it pulses while Amadeus speaks (the script sets its size and glow). The face stays in the code. */
/* The logo is as large as fits above the composer, up to 300px, so the whole mark shows on load. */
body.page-amadeus .mark { display: none; width: min(300px, 70vw, max(180px, calc(100vh - 690px))); margin: 0 auto; }
body.page-amadeus .mark img { display: block; width: 100%; height: auto; transform-origin: 50% 50%; }
body.page-amadeus.view-mark .mark { display: block; }
body.page-amadeus.view-mark .face { display: none; }
/* Once there is an answer, the chat is the main item: the logo shrinks so the reply has room. It still pulses. */
body.page-amadeus.has-exchange .mark { width: min(150px, 40vw); }

/* Waiting for an answer: an open blue book sits in the conversation where the reply will appear, and its pages turn over
   the spine. It is the site's Library book, drawn in CSS so the page's Content-Security-Policy is not changed. */
/* The Three.js scene (book-scene.js) sits in the same place; this box holds its canvas. */
body.page-amadeus .reply .book-scene {
  position: relative; width: 92%; height: 240px; margin: var(--s-2) auto var(--s-1);
}
body.page-amadeus .reply .book-scene canvas { display: block; }
/* Without WebGL, the CSS book below stands in. */
body.page-amadeus .reply .book {
  position: relative; display: block; width: 92%; height: 120px; margin: var(--s-2) auto var(--s-1);
  perspective: 900px; transform-style: preserve-3d;
}
body.page-amadeus .reply .book-cover {
  position: absolute; inset: 0; border-radius: 6px; background: #1f3d93;
  box-shadow: inset 0 0 0 1px rgba(217, 184, 103, 0.75), 0 10px 24px rgba(0, 0, 0, 0.35);
}
body.page-amadeus .reply .book-stack {
  position: absolute; top: 6px; bottom: 6px; width: calc(50% - 8px); background: #f1ead8;
}
body.page-amadeus .reply .book-stack.left { left: 6px; border-radius: 3px 0 0 3px; }
body.page-amadeus .reply .book-stack.right { right: 6px; border-radius: 0 3px 3px 0; }
body.page-amadeus .reply .book::after {
  content: ''; position: absolute; top: 6px; bottom: 6px; left: 50%; width: 2px; transform: translateX(-1px);
  background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0));
}
body.page-amadeus .reply .book-page {
  position: absolute; top: 6px; bottom: 6px; left: 50%; width: calc(50% - 8px); background: #f6f1e4;
  transform-origin: left center; animation: book-turn 2s ease-in-out infinite;
}
body.page-amadeus .reply .book-page.delay-1 { animation-delay: .66s; }
body.page-amadeus .reply .book-page.delay-2 { animation-delay: 1.33s; }
@keyframes book-turn {
  0% { transform: rotateY(0deg); opacity: 1; }
  50% { transform: rotateY(-180deg); opacity: 1; }
  50.1%, 100% { transform: rotateY(-180deg); opacity: 0; }
}
body.page-amadeus.thinking .mark img { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }


/* The conversation: every turn of the visit, oldest first. The student's words sit on the right in a frosted bubble;
   Amadeus answers on the left, under its mark, on the papyrus sheet the Ask page uses for replies. */
body.page-amadeus .exchange {
  width: 100%; box-sizing: border-box; max-width: 680px; min-width: 0; margin: var(--s-5) auto 0;
  display: grid; gap: var(--s-6);
}
body.page-amadeus .exchange[hidden] { display: none; }
body.page-amadeus .turn { display: grid; gap: var(--s-4); min-width: 0; animation: turn-in var(--d-slow) var(--ease-out) both; }
@keyframes turn-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

body.page-amadeus .exchange .label {
  display: flex; align-items: center; gap: var(--s-2); margin: 0 0 var(--s-2);
  font-family: var(--font-sans); font-weight: 600; font-size: var(--t-label); letter-spacing: .06em;
  font-variant-caps: all-small-caps; color: var(--text-soft);
}

/* The student's words. */
body.page-amadeus .said { justify-self: end; display: grid; justify-items: end; max-width: min(85%, 34rem); min-width: 0; }
body.page-amadeus .said .label { padding-right: var(--s-2); }
body.page-amadeus .heard {
  margin: 0; padding: var(--s-3) var(--s-4); min-height: 1.5em; box-sizing: border-box; max-width: 100%;
  font-family: var(--font-sans); font-size: var(--t-body); line-height: 1.5; color: var(--text-primary);
  white-space: pre-wrap; overflow-wrap: anywhere;
  background: color-mix(in srgb, var(--bg-raised) 62%, transparent);
  border: 1px solid var(--border-subtle); border-radius: 18px 18px 4px 18px;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}

/* Amadeus's answer. Until there is one, the answer block stays hidden. */
body.page-amadeus .answer { min-width: 0; }
body.page-amadeus .turn:has(.reply:empty) .answer { display: none; }
body.page-amadeus .answer .label .amadeus-mark { width: 24px; height: 24px; }
body.page-amadeus .reply {
  margin: 0; padding: var(--s-5) var(--s-5) var(--s-6); min-width: 0;
  font-family: var(--font-serif); font-size: var(--t-body-serif); line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere;
  /* A reply is a reading surface in both themes: parchment ground, midnight ink. */
  color-scheme: light; color: var(--color-midnight);
  background:
    radial-gradient(ellipse at 18% 10%, color-mix(in srgb, var(--color-moonlight) 55%, transparent), transparent 55%),
    var(--grad-ethereal-light);
  border-radius: 3px 12px 5px 10px / 10px 4px 12px 5px;
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--color-antique-gold) 45%, transparent),
    0 1px 2px rgba(11, 16, 32, .3),
    0 10px 26px -12px rgba(11, 16, 32, .7);
  animation: turn-in var(--d-slow) var(--ease-out) both;
}
body.page-amadeus .reply::before {
  content: ""; display: block; width: 32px; height: 1px; margin-bottom: var(--s-4); background: var(--accent-line);
}
/* While Amadeus thinks, the book turns its pages where the answer will appear, on the scene rather than on the sheet,
   and the mark beside the name breathes. */
body.page-amadeus .reply:has(.book-scene, .book) { padding: 0; background: none; box-shadow: none; animation: none; }
body.page-amadeus .reply:has(.book-scene, .book)::before { display: none; }
body.page-amadeus .answer:has(.book-scene, .book) .amadeus-mark { animation: amadeus-breathe 3s ease-in-out infinite; }

@media (max-width: 480px) {
  body.page-amadeus .exchange { gap: var(--s-5); }
  body.page-amadeus .said { max-width: 92%; }
  body.page-amadeus .reply { font-size: 1.0625rem; padding: var(--s-4) var(--s-4) var(--s-5); }
}

/* The microphone sits inside the composer, to the left of the send button. */
body.page-amadeus form#ask textarea { padding-right: 112px; }
body.page-amadeus .mic {
  position: absolute; right: 56px; bottom: 6px; width: 44px; height: 44px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--border-strong); background: color-mix(in srgb, var(--bg-page) 60%, transparent); color: var(--text-primary);
  transition: background var(--d-base) var(--ease-out), color var(--d-base) var(--ease-out);
}
body.page-amadeus .mic:hover { border-color: var(--text-primary); }
body.page-amadeus .mic[aria-pressed="true"] { background: #a4553f; border-color: #a4553f; color: #fff; }
body.page-amadeus .mic:disabled { opacity: .45; cursor: default; }
body.page-amadeus .mic:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
body.page-amadeus #send:disabled { opacity: .45; }

/* While Amadeus speaks, a stop button takes the send button's place. */
body.page-amadeus #stop {
  display: none; position: absolute; right: 6px; bottom: 6px; width: 44px; height: 44px; padding: 0;
  place-items: center; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--bg-inverse); color: var(--text-inverse);
}
body.page-amadeus #stop:hover { background: var(--primary-hover); }
body.page-amadeus #stop:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
body.page-amadeus.speaking #send { display: none; }
body.page-amadeus.speaking #stop { display: grid; }

/* The disclaimer under the composer is one short line; "Details" opens the rest (affiliation, voice, privacy). */
body.page-amadeus details.note > summary { cursor: pointer; list-style: none; text-align: center; }
body.page-amadeus details.note > summary::-webkit-details-marker { display: none; }
body.page-amadeus details.note .note-more { color: var(--text-primary); text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
body.page-amadeus details.note[open] .note-more { display: none; }
body.page-amadeus details.note > p { margin: var(--s-1) 0 0; }
body.page-amadeus details.note > summary:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: 4px; }

/* On a phone, the focused field opens up (amadeus.js adds .expanded): the text takes the full width, and the microphone
   and send buttons sit in a row under it, inside the same rounded box. The field grows with the text. */
@media (max-width: 640px) {
  body.page-amadeus form#ask.expanded textarea {
    padding: 14px var(--s-5) 62px; min-height: 112px; max-height: 200px; border-radius: 24px; overflow-y: auto;
  }
  body.page-amadeus form#ask.expanded textarea::placeholder { white-space: normal; }
}

body.page-amadeus #captcha-box { max-width: 680px; margin: 0 auto var(--s-3); display: grid; gap: var(--s-2); justify-items: center; text-align: center; font-size: var(--t-micro); color: var(--text-soft); }
body.page-amadeus #captcha-box[hidden] { display: none; }

/* Recording: while the microphone is on, the strip replaces the text field. Send keeps the recording; delete drops it. */
body.page-amadeus .rec {
  display: none; flex: 1; align-items: center; gap: var(--s-3); min-width: 0; min-height: 56px; box-sizing: border-box;
  padding: 6px 6px 6px var(--s-3); border: 1px solid var(--text-primary); border-radius: 28px;
  background: color-mix(in srgb, var(--bg-page) 72%, transparent); box-shadow: var(--e-2);
  -webkit-backdrop-filter: blur(16px) saturate(1.1); backdrop-filter: blur(16px) saturate(1.1);
}
body.page-amadeus form#ask.recording textarea,
body.page-amadeus form#ask.recording #talk,
body.page-amadeus form#ask.recording #send { display: none; }
body.page-amadeus form#ask.recording .rec { display: flex; }

body.page-amadeus .rec-btn {
  width: 44px; height: 44px; flex: none; padding: 0; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 50%; background: transparent; color: var(--text-primary);
  transition: background var(--d-base) var(--ease-out), border-color var(--d-base) var(--ease-out);
}
body.page-amadeus .rec-btn:hover { border-color: var(--text-primary); }
body.page-amadeus .rec-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
body.page-amadeus .rec-send { background: var(--bg-inverse); color: var(--text-inverse); border-color: transparent; }
body.page-amadeus .rec-send:hover { background: var(--primary-hover); }

body.page-amadeus .rec-wave { flex: 1; min-width: 0; height: 40px; }
body.page-amadeus .rec-wave canvas { display: block; width: 100%; height: 100%; color: var(--color-antique-gold); }

body.page-amadeus .rec-time {
  flex: none; display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-micro); color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
body.page-amadeus .rec-time::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: #a4553f;
  animation: rec-blink 1.2s ease-in-out infinite;
}
@keyframes rec-blink { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

@media (prefers-reduced-motion: reduce) { body.page-amadeus * { transition: none !important; animation: none !important; } }
