/* ------------------------------------------------------------------------
   Al-Kindi — midnight mushaf theme.
   Classical tazhib palette (gold leaf / lapis-black / mushaf cream) over a
   faint girih star lattice. All motion is transform/opacity only; the audio
   hot path never touches layout.
   ------------------------------------------------------------------------ */

/* --- fonts (self-hosted, OFL 1.1; arabic + latin subsets) --- */
@font-face {
  font-family: "Amiri Quran";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/amiri-quran-arabic.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF,
    U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: "Amiri Quran";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/amiri-quran-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+2000-206F, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Reem Kufi";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/reem-kufi-arabic.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: "Reem Kufi";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/reem-kufi-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+2000-206F, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Noto Naskh Arabic";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/noto-naskh-arabic-arabic.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFC;
}

:root {
  --ground: #10141d;      /* lapis-black */
  --panel: #1a2130;
  --panel-2: #141a27;
  --cream: #f8ebd5;       /* mushaf paper */
  --cream-2: #fff7ea;
  --ink: #2b2417;
  --ink-soft: #6b5d41;
  --gold: #f0cd8c;        /* gold-leaf ramp */
  --gold-2: #d4b478;
  --gold-3: #8d774e;
  --gold-line: rgba(240, 205, 140, 0.28);
  --gold-faint: rgba(240, 205, 140, 0.12);
  --emerald: #2e7d5b;
  --emerald-2: #1f5c42;
  --emerald-soft: #415d49;
  --danger: #c65454;
  --danger-2: #a03e3e;
  --fg: #efe2cd;          /* cream text on midnight */
  --muted: #9a8f79;

  --kufi: "Reem Kufi", "Noto Naskh Arabic", sans-serif;
  --quran: "Amiri Quran", "Noto Naskh Arabic", serif;
  --naskh: "Noto Naskh Arabic", "Amiri Quran", serif;
  --body: Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 0;
  color: var(--fg);
  font: 16px/1.55 var(--body);
  background-color: var(--ground);
  /* girih star lattice, whisper-quiet, over a deep radial dusk */
  background-image:
    radial-gradient(1100px 700px at 50% -12%, rgba(240, 205, 140, 0.07), transparent 62%),
    radial-gradient(900px 900px at 50% 115%, rgba(46, 125, 91, 0.06), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='88' height='88' viewBox='0 0 88 88'%3E%3Cg fill='none' stroke='rgba(240,205,140,0.055)' stroke-width='1'%3E%3Cpolygon points='44,14 74,44 44,74 14,44'/%3E%3Cpolygon points='23,23 65,23 65,65 23,65'/%3E%3Ccircle cx='44' cy='44' r='7.5'/%3E%3Cpolygon points='44,-11 55,0 44,11 33,0'/%3E%3Cpolygon points='44,77 55,88 44,99 33,88'/%3E%3Cpolygon points='-11,44 0,55 -11,66'/%3E%3Cpolygon points='0,33 11,44 0,55'/%3E%3Cpolygon points='88,33 99,44 88,55'/%3E%3Cpolygon points='77,44 88,55 77,66'/%3E%3C/g%3E%3C/svg%3E");
}

/* ---------------------------------------------------------------- card --- */

.card {
  position: relative;
  width: min(460px, 92vw);
  padding: 44px 30px 30px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(240, 205, 140, 0.05), rgba(240, 205, 140, 0) 30%),
    var(--panel);
  border: 1px solid var(--gold-line);
  border-radius: 26px;
  box-shadow:
    0 0 0 5px var(--panel-2),
    0 0 0 6px var(--gold-faint),
    0 34px 90px rgba(0, 0, 0, 0.55);
}
/* illuminated-frame corner strokes */
.card::before,
.card::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  border: 1px solid var(--gold-2);
  opacity: 0.65;
  pointer-events: none;
}
.card::before { top: 9px; left: 9px; border-width: 1px 0 0 1px; border-top-left-radius: 14px; }
.card::after { bottom: 9px; right: 9px; border-width: 0 1px 1px 0; border-bottom-right-radius: 14px; }

/* --- headings: Kufic gold foil --- */
h1, .title {
  margin: 12px 0 0;
  font-family: var(--kufi);
  font-weight: 600;
  font-size: 30px;
  letter-spacing: 0.06em;
  background: linear-gradient(175deg, var(--gold) 20%, var(--gold-2) 55%, var(--gold-3) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.title-ar {
  margin: 2px 0 0;
  font-family: var(--quran);
  font-size: 17px;
  line-height: 2;
  color: var(--gold-2);
  opacity: 0.85;
}

.status {
  margin: 6px 0 20px;
  min-height: 1.5em;
  color: var(--muted);
  font-style: italic;
  letter-spacing: 0.02em;
}

/* ---------------------------------------------------------------- star --- */

.star-wrap { display: grid; place-items: center; margin: 0 auto 4px; }
.star {
  width: 148px;
  height: 148px;
  overflow: visible;
  filter: drop-shadow(0 0 10px rgba(240, 205, 140, 0.14));
  transition: filter 0.5s ease, opacity 0.5s ease;
}
.star * { transform-box: view-box; transform-origin: 50% 50%; }
.star-frame { stroke: var(--gold-2); stroke-width: 1.4; fill: none; opacity: 0.9; }
.star-lace  { stroke: var(--gold-3); stroke-width: 1;   fill: none; opacity: 0.55; }
.star-rose {
  stroke: var(--gold);
  stroke-width: 1.2;
  fill: rgba(240, 205, 140, 0.06);
  will-change: transform;
}
.star-glow {
  stroke: var(--gold);
  stroke-width: 5;
  fill: none;
  opacity: 0;                 /* JS drives with agent-voice amplitude */
  filter: blur(6px);
  will-change: opacity;
}
.star-core {
  fill: var(--gold-2);
  will-change: transform;
  transition: fill 0.4s ease;
}

/* state choreography (data-state lives on .card) */
.star-spin { animation: none; }
[data-state="in-call"] .star-spin { animation: spin 90s linear infinite; }
[data-state="in-call"] .star-core { fill: var(--emerald); }
[data-state="in-call"] .star { filter: drop-shadow(0 0 14px rgba(240, 205, 140, 0.22)); }
[data-state="connecting"] .star { animation: star-pulse 1.15s ease-in-out infinite; }
[data-state="ended"] .star,
[data-state="error"] .star { filter: grayscale(0.75); opacity: 0.45; }
.card.reciting .star { filter: drop-shadow(0 0 20px rgba(240, 205, 140, 0.38)); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes star-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* small static star on chooser cards */
.star.star-sm { width: 72px; height: 72px; filter: none; }

/* -------------------------------------------------------------- button --- */

.btn {
  appearance: none;
  border: 1px solid rgba(240, 205, 140, 0.35);
  cursor: pointer;
  padding: 14px 42px;
  border-radius: 999px;
  font-family: var(--kufi);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--cream-2);
  background: linear-gradient(180deg, var(--emerald), var(--emerald-2));
  box-shadow: 0 10px 26px rgba(46, 125, 91, 0.28);
  transition: transform 0.08s ease, filter 0.2s ease, box-shadow 0.3s ease;
}
.btn:hover { filter: brightness(1.12); box-shadow: 0 12px 30px rgba(46, 125, 91, 0.4); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }
[data-state="in-call"] .btn {
  background: linear-gradient(180deg, var(--danger), var(--danger-2));
  box-shadow: 0 10px 26px rgba(198, 84, 84, 0.25);
}

/* --------------------------------------------------------- now playing --- */

.nowplaying {
  margin: 22px 0 0;
  padding: 20px 20px 14px;
  position: relative;
  text-align: center;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--cream-2), var(--cream) 55%);
  border: 1px solid var(--gold-3);
  border-radius: 16px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 247, 234, 0.8),
    inset 0 0 0 4px rgba(141, 119, 78, 0.14),
    0 16px 40px rgba(0, 0, 0, 0.35);
  /* enter/exit animation */
  opacity: 0;
  transform: translateY(14px) scale(0.985);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.05);
}
.nowplaying.active { opacity: 1; transform: translateY(0) scale(1); }
.nowplaying[hidden] { display: none; }

.np-ornament {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 12px;
  background: var(--cream-2);
  border: 1px solid var(--gold-3);
  border-radius: 999px;
  font-family: var(--quran);
  font-size: 15px;
  line-height: 1.7;
  color: var(--gold-3);
}

.np-surah {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 4px 0 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(141, 119, 78, 0.3);
}
.np-surah-ar {
  font-family: var(--quran);
  font-size: 21px;
  line-height: 1.9;
  color: var(--ink);
}
.np-surah-en {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* verse-to-verse cross-fade wrapper */
.np-body { transition: opacity 0.16s ease; }
.np-body.swap { opacity: 0; }

.np-ayah {
  margin: 6px 0;
  font-family: var(--quran);
  font-size: 26px;
  line-height: 2.15;   /* headroom for stacked harakat — do not tighten */
  color: var(--ink);
  overflow: visible;
}
.np-translation {
  margin: 8px auto 2px;
  max-width: 42ch;
  font-size: 14px;
  font-style: italic;
  line-height: 1.6;
  color: var(--ink-soft);
}

.np-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
}
.np-meta .chip {
  padding: 2px 10px;
  border: 1px solid rgba(141, 119, 78, 0.35);
  border-radius: 999px;
  font-family: var(--kufi);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--gold-3);
  background: rgba(141, 119, 78, 0.07);
}

/* control-word bar under the panel: say stop / again / next / previous */
.hint {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
  padding: 6px 14px;
  border: 1px solid var(--gold-faint);
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: rgba(240, 205, 140, 0.05);
}
.hint[hidden] { display: none; }
.hint .hint-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold-2);
  animation: hint-pulse 2.2s ease-in-out infinite;
}
.hint-label { font-style: italic; }
.hint .kw {
  padding: 1px 9px;
  border: 1px solid rgba(240, 205, 140, 0.22);
  border-radius: 999px;
  font-family: var(--kufi);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--gold-2);
  background: rgba(240, 205, 140, 0.06);
  transition: color 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}
/* the spotted word flashes gold: instant "heard you" feedback */
.hint .kw.hit {
  animation: kw-hit 0.9s ease;
}
@keyframes kw-hit {
  0% { color: var(--ink); background: var(--gold); border-color: var(--gold); transform: scale(1.12); }
  100% { color: var(--gold-2); background: rgba(240, 205, 140, 0.06); border-color: rgba(240, 205, 140, 0.22); transform: scale(1); }
}
@keyframes hint-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

/* ---------------------------------------------------------- transcript --- */

.transcript {
  margin-top: 22px;
  text-align: left;
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-3) transparent;
}
.line {
  padding: 9px 14px;
  border-radius: 14px;
  max-width: 86%;
  font-size: 14px;
  line-height: 1.6;
}
.line.user {
  align-self: flex-end;
  color: var(--fg);
  background: rgba(46, 125, 91, 0.16);
  border: 1px solid rgba(46, 125, 91, 0.3);
  border-bottom-right-radius: 4px;
}
.line.agent {
  align-self: flex-start;
  color: var(--ink);
  background: linear-gradient(180deg, var(--cream-2), var(--cream));
  border: 1px solid rgba(141, 119, 78, 0.45);
  border-bottom-left-radius: 4px;
}
.line.partial { opacity: 0.6; }
.line[lang="ar"] {
  font-family: var(--quran);
  font-size: 17px;
  line-height: 2.1;   /* harakat headroom */
}

.tool {
  margin-top: 12px;
  min-height: 1.3em;
  font-family: var(--kufi);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  color: var(--gold-2);
}

/* ------------------------------------------------- badge + back (calls) --- */

.badge {
  position: absolute;
  top: 15px;
  right: 17px;
  font-family: var(--kufi);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 4px 11px;
  border-radius: 999px;
  color: var(--gold);
  background: rgba(240, 205, 140, 0.08);
  border: 1px solid var(--gold-line);
}
.badge.alt { color: var(--emerald); border-color: rgba(46, 125, 91, 0.45); background: rgba(46, 125, 91, 0.1); }
.back {
  position: absolute;
  top: 16px;
  left: 18px;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s ease;
}
.back:hover { color: var(--gold); }

/* ------------------------------------------------------------- chooser --- */

.chooser { width: min(740px, 94vw); text-align: center; }
.basmala {
  font-family: var(--quran);
  font-size: 30px;
  line-height: 2.4;
  margin-bottom: -4px;
  background: linear-gradient(175deg, var(--gold) 20%, var(--gold-2) 60%, var(--gold-3) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.chooser h1 { font-size: 38px; margin: 0; }
.chooser .title-ar { font-size: 19px; }
.chooser .sub { color: var(--muted); font-style: italic; margin: 10px 0 30px; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 580px) { .cards { grid-template-columns: 1fr; } }
.choice {
  position: relative;
  display: block;
  text-decoration: none;
  color: var(--fg);
  padding: 30px 22px 26px;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(240, 205, 140, 0.05), rgba(240, 205, 140, 0) 35%),
    var(--panel);
  border: 1px solid var(--gold-faint);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.choice:hover {
  transform: translateY(-4px);
  border-color: var(--gold-line);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.5), 0 0 24px rgba(240, 205, 140, 0.07);
}
.choice h2 {
  margin: 14px 0 6px;
  font-family: var(--kufi);
  font-weight: 500;
  font-size: 19px;
  letter-spacing: 0.05em;
  color: var(--gold);
}
.choice p { color: var(--muted); font-size: 13.5px; margin: 0; }

/* ------------------------------------------------------------- HUD ------ */

#hud {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 50;
  min-width: 132px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(13, 16, 24, 0.85);
  border: 1px solid var(--gold-faint);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  font: 12px/1.3 var(--mono);
  color: var(--fg);
}
#hud .hud-t { color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; font-size: 10px; }
#hud .hud-v { font-size: 22px; font-weight: 700; margin: 2px 0; }
#hud .hud-v.good { color: #4fbf8f; }
#hud .hud-v.ok { color: var(--gold-2); }
#hud .hud-v.bad { color: var(--danger); }
#hud .hud-s { color: var(--muted); }

/* ---------------------------------------------------------- motion off --- */

@media (prefers-reduced-motion: reduce) {
  .star-spin,
  [data-state="connecting"] .star,
  .hint .kw.hit,
  .hint .hint-dot { animation: none !important; }
  .nowplaying { transition: opacity 0.2s ease; transform: none; }
  .np-body { transition: none; }
}
