/* =========================================================
   Mobius | موبيوس — site assistant ("Ask Mobius"), see chat.js
   Uses the site's colours, so it follows light/dark and RTL.
   ========================================================= */

/* ---------- the launcher: a little ringed planet with a face ---------- */
.chat-launch {
  position: fixed;
  inset-inline-end: 12px;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 70;
  width: 78px;
  height: 78px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 6px 10px rgba(12, 9, 40, 0.28));
}
.chat-launch .mascot { width: 100%; height: 100%; }
.chat-launch:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.chat-launch.is-bounce .m-body { animation: m-squish 0.26s ease-out; }

/* the speech bubble next to it */
.chat-launch-label {
  position: absolute;
  inset-inline-end: calc(100% - 14px);
  bottom: 46px;
  padding: 7px 12px;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  border-end-end-radius: 4px;
  background: var(--panel);
  color: var(--star);
  font: 600 0.84rem/1.3 var(--sans);
  white-space: nowrap;
  box-shadow: 0 8px 24px -10px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(6px) scale(0.92);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
html[dir="rtl"] .chat-launch-label { transform-origin: bottom left; }
.chat-launch.is-greet .chat-launch-label { opacity: 1; transform: none; }
@media (hover: hover) {
  .chat-launch:hover .chat-launch-label { opacity: 1; transform: none; }
}

/* ---------- the mascot (also in the chat header) ---------- */
.mascot { display: block; overflow: visible; }
.m-shadow { fill: rgba(16, 13, 44, 0.2); transform-box: fill-box; transform-origin: center; animation: m-shadow 3.4s ease-in-out infinite; }
.m-body { transform-box: view-box; transform-origin: 32px 50px; animation: m-float 3.4s ease-in-out infinite; }
.m-eye ellipse { fill: #2b2152; }
.m-shine { fill: #fff; }
.m-eye { transform-box: fill-box; transform-origin: center; transition: transform 0.07s ease; }
.is-blink .m-eye { transform: scaleY(0.1); }
.m-look { transition: transform 0.18s ease-out; }
.m-cheek { fill: #ff7f9e; opacity: 0.5; transition: opacity 0.2s ease; }
.m-happy { stroke: #2b2152; opacity: 0; }
.m-smile { stroke: #2b2152; }
.m-grin { fill: #2b2152; opacity: 0; }
.m-open, .m-smile { transition: opacity 0.12s ease; }

.is-happy .m-open, .is-happy .m-smile { opacity: 0; }
.is-happy .m-happy, .is-happy .m-grin { opacity: 1; }
.is-happy .m-cheek { opacity: 0.85; }
.is-happy .m-body { animation: m-hop 0.9s ease-in-out infinite; }

.is-thinking .m-look { transform: translate(2px, -2.4px) !important; }
.is-thinking .m-body { animation: m-think 1.1s ease-in-out infinite; }

.m-spark path { transform-box: fill-box; transform-origin: center; animation: m-twinkle 2.6s ease-in-out infinite; }
.m-s1 { fill: #f7c35f; }
.m-s2 { fill: #b99cff; animation-delay: 0.9s !important; }
.m-s3 { fill: #7fd3ff; animation-delay: 1.7s !important; }

@keyframes m-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3.5px); } }
@keyframes m-shadow { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.8); opacity: 0.65; } }
@keyframes m-hop { 0%, 100% { transform: translateY(0) rotate(0); } 30% { transform: translateY(-5px) rotate(-4deg); } 60% { transform: translateY(0) rotate(3deg); } }
@keyframes m-think { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
@keyframes m-squish { 0% { transform: scale(1, 1); } 40% { transform: scale(1.12, 0.86); } 75% { transform: scale(0.94, 1.08); } 100% { transform: scale(1, 1); } }
@keyframes m-twinkle { 0%, 100% { transform: scale(0.4); opacity: 0.2; } 50% { transform: scale(1); opacity: 1; } }

html.chat-open .chat-launch { display: none; }

.chat-panel {
  position: fixed;
  inset-inline-end: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 75;
  display: flex;
  flex-direction: column;
  width: min(410px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 110px));
  height: min(640px, calc(100dvh - 110px));
  border: 1px solid var(--line-2);
  border-radius: 20px;
  background: var(--panel);
  color: var(--star);
  box-shadow: 0 28px 70px -24px rgba(0, 0, 0, 0.7);
  overflow: hidden;
  animation: chat-in 0.18s ease-out;
}
.chat-panel[hidden] { display: none; }
@keyframes chat-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px 12px 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--space-1) 55%, var(--panel));
}
html[dir="rtl"] .chat-head { padding: 12px 16px 12px 10px; }
.chat-orb { width: 42px; height: 42px; flex: none; margin: -4px 0; }
.chat-orb .mascot { width: 100%; height: 100%; }
.chat-titles { flex: 1; min-width: 0; }
.chat-title { margin: 0; font: 600 1.02rem/1.25 var(--sans); }
.chat-sub { margin: 2px 0 0; color: var(--dust); font-size: 0.8rem; line-height: 1.3; }
.chat-ai {
  display: inline-block;
  margin-inline-start: 7px;
  padding: 1px 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, #b99cff, #7fd3ff);
  color: #1d1640;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  vertical-align: 2px;
}
.chat-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--dust);
  cursor: pointer;
}
.chat-icon svg { width: 19px; height: 19px; }
.chat-icon:hover { background: color-mix(in srgb, var(--star) 8%, transparent); color: var(--star); }
.chat-icon:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  scroll-behavior: smooth;
}

.chat-msg { display: flex; margin: 0 0 12px; }
.chat-me { justify-content: flex-end; }
.chat-msg[dir="rtl"].chat-bot,
.chat-msg[dir="ltr"].chat-bot { justify-content: flex-start; }

.chat-bubble {
  max-width: 92%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 0.93rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.chat-me .chat-bubble {
  max-width: 82%;
  background: var(--brass);
  color: var(--space-0);
  border-end-end-radius: 5px;
}
.chat-bot .chat-bubble {
  width: 92%;
  background: color-mix(in srgb, var(--star) 6%, transparent);
  border: 1px solid var(--line);
  border-end-start-radius: 5px;
}
.chat-p { margin: 0 0 8px; }
.chat-p:last-child { margin-bottom: 0; }
.chat-p strong { font-weight: 600; }

/* book cards */
.chat-books { display: grid; gap: 7px; margin: 4px 0 10px; }
.chat-books:last-child { margin-bottom: 0; }
.chat-book {
  --lv: var(--brass);
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 11px;
  align-items: center;
  width: 100%;
  padding: 7px 10px 7px 7px;
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--lv);
  border-radius: 11px;
  background: var(--panel);
  color: var(--star);
  font: inherit;
  text-align: start;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
html[dir="rtl"] .chat-book { padding: 7px 7px 7px 10px; }
.chat-book:hover { background: var(--panel-2); border-color: var(--line-2); border-inline-start-color: var(--lv); }
.chat-book:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }
.chat-book.lv-beginner { --lv: var(--lv-beginner); }
.chat-book.lv-easy { --lv: var(--lv-easy); }
.chat-book.lv-medium { --lv: var(--lv-medium); }
.chat-book.lv-hard { --lv: var(--lv-hard); }
.chat-book.lv-extreme { --lv: var(--lv-extreme); }
.chat-book-cover {
  width: 40px;
  height: 56px;
  border-radius: 4px;
  overflow: hidden;
  background: color-mix(in srgb, var(--lv) 22%, var(--panel-2));
}
.chat-book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-book-cover.is-blank {
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--lv) 40%, transparent), transparent 70%),
    var(--panel-2);
}
.chat-book-text { display: grid; gap: 1px; min-width: 0; }
.chat-book-title {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
  text-align: start;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
html[dir="rtl"] .chat-book-title,
html[dir="rtl"] .chat-book-author { text-align: right; }
.chat-bot[dir="rtl"] .chat-book-title,
.chat-bot[dir="rtl"] .chat-book-author { text-align: right; }
.chat-bot[dir="ltr"] .chat-book-title,
.chat-bot[dir="ltr"] .chat-book-author { text-align: left; }
.chat-book-author { color: var(--dust); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-book-meta { color: var(--faint); font-size: 0.76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-book-level { color: var(--lv); font-weight: 600; }

/* subject links */
.chat-subjects { display: grid; gap: 5px; margin: 4px 0 6px; }
.chat-subject {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--star);
  text-decoration: none;
  font-size: 0.88rem;
}
.chat-subject:hover { background: var(--panel-2); border-color: var(--line-2); }
.chat-subject-count { color: var(--faint); font-size: 0.8rem; white-space: nowrap; }

.chat-link {
  display: inline-block;
  margin-top: 2px;
  color: var(--brass);
  font-weight: 600;
  font-size: 0.86rem;
  text-decoration: none;
}
.chat-link::after { content: " →"; }
.chat-bot[dir="rtl"] .chat-link::after { content: " ←"; }
.chat-link:hover { text-decoration: underline; }

/* quick replies */
.chat-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chat-chip {
  padding: 6px 11px;
  border: 1px solid color-mix(in srgb, var(--brass) 45%, var(--line-2));
  border-radius: 999px;
  background: transparent;
  color: var(--star);
  font: inherit;
  font-size: 0.82rem;
  line-height: 1.35;
  cursor: pointer;
}
.chat-chip:hover { background: color-mix(in srgb, var(--brass) 14%, transparent); }
.chat-chip:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }

/* typing dots */
.chat-typing .chat-bubble { width: auto; display: inline-flex; gap: 5px; padding: 13px 15px; }
.chat-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--dust);
  animation: chat-dot 1s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* input */
.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.chat-input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: color-mix(in srgb, var(--space-0) 40%, var(--panel));
  color: var(--star);
  font: inherit;
  font-size: 16px; /* stops phones from zooming in */
}
.chat-input::placeholder { color: var(--faint); }
.chat-input:focus { outline: 2px solid color-mix(in srgb, var(--brass) 70%, transparent); outline-offset: 0; border-color: transparent; }
.chat-send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 12px;
  background: var(--brass);
  color: var(--space-0);
  cursor: pointer;
}
.chat-send svg { width: 20px; height: 20px; }
html[dir="rtl"] .chat-send svg { transform: scaleX(-1); }
.chat-send:disabled { opacity: 0.55; cursor: default; }
.chat-send:focus-visible { outline: 2px solid var(--star); outline-offset: 2px; }

/* phones: a sheet from the bottom, round button without the label */
@media (max-width: 700px) {
  .chat-launch { width: 70px; height: 70px; inset-inline-end: 8px; }
  .chat-launch-label { bottom: 42px; font-size: 0.8rem; }
  .chat-panel {
    inset: auto 0 0 0;
    width: 100%;
    height: 88vh;
    height: 88dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
  }
  html.chat-open { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel, .chat-typing span { animation: none; }
  .m-body, .m-shadow, .m-spark path, .is-happy .m-body, .is-thinking .m-body, .chat-launch.is-bounce .m-body { animation: none; }
  .chat-launch-label { transition: none; }
  .chat-log { scroll-behavior: auto; }
}

@media print {
  .chat-launch, .chat-panel { display: none !important; }
}
