/* =========================================================
   Mobius | موبيوس — header tools, light theme, RTL
   Loaded after style.css on every page.
   ========================================================= */
/* Arabic/Kurdish fonts are loaded by the page only when those languages are used (see ui.js). */

/* while a saved Arabic/Kurdish page is being translated */
html.i18n-wait body > header,
html.i18n-wait body > main,
html.i18n-wait body > footer {
  visibility: hidden;
}

/* ---------- Light theme ----------
   Set on <body>, so the moving figures (which read their colours
   from <html>) keep their night-sky palette inside dark panels. */
html[data-theme="light"] body {
  color-scheme: light;
  --space-0: #f7f5ef;
  --space-1: #e8e4f6;
  --panel: #ffffff;
  --panel-2: #f2effa;
  --line: rgba(38, 30, 104, 0.12);
  --line-2: rgba(38, 30, 104, 0.22);
  --star: #17133a;
  --dust: #4c4770;
  --faint: #66618a;
  --brass: #9a5b06;
  --rose: #c23a57;
  --ice: #1f6fae;
  --lv-beginner: #11845a;
  --lv-easy: #1f6fbf;
  --lv-medium: #a2620a;
  --lv-hard: #c4402f;
  --lv-extreme: #7448c9;
  --header-bg: rgba(247, 245, 239, 0.86);
}

html[data-theme="light"] {
  background: #f7f5ef;
}

/* the night-sky pieces stay dark in light mode */
html[data-theme="light"] .hero,
html[data-theme="light"] .page-home .site-header:not(.is-solid) {
  --space-0: #070618;
  --space-1: #100d2c;
  --panel: #131034;
  --panel-2: #1a1642;
  --line: rgba(196, 186, 255, 0.12);
  --line-2: rgba(196, 186, 255, 0.22);
  --star: #f4efe4;
  --dust: #a49fc4;
  --faint: #7d78a0;
  --brass: #f0b44a;
  color: var(--star);
}

html[data-theme="light"] .hero {
  background: linear-gradient(180deg, #100d2c, #0b0a22);
}

html[data-theme="light"] .hero::after {
  background:
    radial-gradient(ellipse 55% 50% at 20% 52%, rgba(7, 6, 24, 0.7), transparent 72%),
    linear-gradient(180deg, transparent 78%, #f7f5ef);
}

html[data-theme="light"] .tile canvas,
html[data-theme="light"] .door canvas,
html[data-theme="light"] .banner canvas {
  background: radial-gradient(ellipse at 50% 40%, #1a1642, #100d2c 75%);
}

html[data-theme="light"] .site-header,
html[data-theme="light"] .page-home .site-header.is-solid {
  background: var(--header-bg);
}

html[data-theme="light"] .tile,
html[data-theme="light"] .door {
  box-shadow: 0 1px 2px rgba(38, 30, 104, 0.06), 0 10px 24px -18px rgba(38, 30, 104, 0.35);
}

html[data-theme="light"] .cover {
  box-shadow: 0 0 0 1px rgba(38, 30, 104, 0.1), 0 14px 26px -16px rgba(38, 30, 104, 0.55);
}

html[data-theme="light"] ::selection {
  color: #fff;
}

@media (min-width: 561px) {
  html[data-theme="light"] .banner-text {
    --star: #f4efe4;
    --dust: #a49fc4;
    --faint: #7d78a0;
    --brass: #f0b44a;
    color: var(--star);
  }
}

/* ---------- Header tools ---------- */
.header-inner {
  gap: 10px 18px;
}

.nav {
  margin-inline-start: auto;
}

.tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  min-width: 38px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: color-mix(in srgb, var(--panel) 55%, transparent);
  color: var(--star);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.tool:hover {
  border-color: color-mix(in srgb, var(--brass) 60%, transparent);
  color: var(--brass);
}

.tool svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.tool-search {
  min-width: 170px;
  justify-content: flex-start;
  color: var(--dust);
}

.tool-label {
  flex: 1;
  text-align: start;
}

.tool-kbd {
  padding: 1px 7px;
  border-radius: 5px;
  border: 1px solid var(--line-2);
  font: 500 0.75rem/1.4 var(--sans);
  color: var(--faint);
}

.tool-theme .i-moon,
html[data-theme="light"] .tool-theme .i-sun {
  display: none;
}

html[data-theme="light"] .tool-theme .i-moon {
  display: block;
}

.tool-code {
  min-width: 1.2em;
  font-size: 0.85rem;
}

.lang {
  position: relative;
}

.lang-menu {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  z-index: 50;
  min-width: 200px;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.6);
}

.lang-menu button {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--star);
  font: inherit;
  font-size: 0.95rem;
  text-align: start;
  cursor: pointer;
}

.lang-menu button:hover,
.lang-menu button:focus-visible {
  background: var(--panel-2);
  outline: none;
}

.lang-short {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  color: var(--dust);
  font-size: 0.78rem;
  font-weight: 600;
}

.lang-menu [aria-checked="true"] .lang-short {
  border-color: var(--brass);
  background: var(--brass);
  color: var(--space-0);
}

.lang-menu [aria-checked="true"] .lang-name {
  font-weight: 600;
}

.lang-menu [lang="ar"],
.lang-menu [lang="ku"] {
  font-family: "Noto Sans Arabic", var(--sans);
}

@media (max-width: 860px) {
  .tool-search {
    min-width: 38px;
    padding: 0;
  }
  .tool-label,
  .tool-kbd {
    display: none;
  }
}

/* phones: brand and tools on one row, the two sections on a second row */
@media (max-width: 640px) {
  .header-inner {
    flex-wrap: wrap;
    min-height: 0;
    padding-top: 10px;
  }
  .tools {
    margin-inline-start: auto;
  }
  .nav {
    order: 3;
    width: 100%;
    margin: 0;
    gap: 22px;
    border-top: 1px solid var(--line);
  }
  .nav a {
    padding: 9px 0 10px;
  }
  .nav a[aria-current="page"]::after {
    bottom: 0;
  }
  .page-home .site-header:not(.is-solid) .nav {
    border-top-color: transparent;
  }
}

/* ---------- Search dialog ---------- */
html.search-open {
  overflow: hidden;
}

.search {
  width: min(640px, calc(100% - 32px));
  max-height: min(640px, calc(100% - 96px));
  margin: 72px auto auto;
  padding: 0;
  border-radius: 16px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--star);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

.search[open] {
  display: flex;
  flex-direction: column;
}

.search::backdrop {
  background: rgba(7, 6, 24, 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 16px;
  padding-inline: 16px 8px;
  border-bottom: 1px solid var(--line);
}

.search-box > svg {
  width: 20px;
  height: 20px;
  flex: none;
  color: var(--brass);
}

.search-box input {
  flex: 1;
  min-width: 0;
  height: 48px;
  border: 0;
  background: transparent;
  color: var(--star);
  font: inherit;
  font-size: 1.08rem;
  outline: none;
}

.search-box input::placeholder {
  color: var(--faint);
}

.search-box input::-webkit-search-cancel-button {
  display: none;
}

.search-close {
  appearance: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--dust);
  cursor: pointer;
}

.search-close:hover {
  background: var(--panel-2);
  color: var(--star);
}

.search-close svg {
  width: 18px;
  height: 18px;
}

.search-results {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 8px 12px;
}

.search-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 10px 6px;
  font: 500 0.8rem/1.2 var(--sans);
  color: var(--faint);
}

.search-count {
  padding: 0 7px;
  border-radius: 99px;
  border: 1px solid var(--line-2);
  font-variant-numeric: tabular-nums;
}

.result {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--star);
}

.result:hover,
.result[aria-selected="true"] {
  background: var(--panel-2);
}

.result[aria-selected="true"] {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brass) 45%, transparent);
}

.result-orb {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 8%, var(--brass) 45%, color-mix(in srgb, var(--brass) 45%, #000) 100%);
  opacity: 0.85;
}

.result-cover {
  flex: none;
  width: 36px;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 2px;
  border-top: 2px solid var(--lv, var(--brass));
  background: var(--panel-2);
}

.result-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.result-text {
  display: grid;
  min-width: 0;
}

.result-title {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
  unicode-bidi: plaintext;
  text-align: start;
}

.result-author {
  color: var(--dust);
  font-size: 0.85rem;
  unicode-bidi: plaintext;
  text-align: start;
}

.result-meta {
  margin-top: 2px;
  color: var(--faint);
  font-size: 0.8rem;
}

.result-level {
  color: var(--lv, var(--brass));
  font-weight: 600;
}

.result-title,
.result-author,
.result-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-hint,
.search-empty {
  margin: 14px 10px 6px;
  color: var(--dust);
}

.search-empty strong {
  color: var(--star);
}

.search-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 10px 4px;
}

.search-chip {
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--line-2);
  color: var(--star);
  font-size: 0.88rem;
  text-decoration: none;
}

.search-chip:hover {
  border-color: var(--brass);
  color: var(--brass);
}

@media (max-width: 560px) {
  .search {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0px);
  }
}

/* a book found through search glows for a moment */
.book.is-found .cover {
  animation: found 2.4s ease-out;
}

@keyframes found {
  0%, 40% {
    box-shadow: 0 0 0 3px var(--lv, var(--brass)), 0 0 34px 4px color-mix(in srgb, var(--lv, var(--brass)) 55%, transparent);
  }
  100% {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 14px 26px -16px rgba(0, 0, 0, 0.9);
  }
}

/* ---------- Arabic & Kurdish (right to left) ---------- */
html[dir="rtl"] {
  --serif: "Newsreader", "Noto Naskh Arabic", Georgia, serif;
  --sans: "Onest", "Noto Sans Arabic", system-ui, sans-serif;
  --arabic: "Noto Sans Arabic", "Readex Pro", system-ui, sans-serif;
}

html[dir="rtl"] body {
  line-height: 1.75;
}

html[dir="rtl"] .page-title,
html[dir="rtl"] .section-title,
html[dir="rtl"] .banner h1,
html[dir="rtl"] .door h2,
html[dir="rtl"] .field-title {
  line-height: 1.35;
}

html[dir="rtl"] .field-title small {
  margin-left: 0;
  margin-inline-start: auto;
}

html[dir="rtl"] .level-list span:last-child {
  text-align: left;
}

html[dir="rtl"] .pill {
  padding: 7px 11px 7px 13px;
}

/* book titles, authors and equations stay left-to-right */
html[dir="rtl"] .book-title,
html[dir="rtl"] .book-author,
html[dir="rtl"] .cover-blank {
  unicode-bidi: plaintext;
  text-align: start;
}

html[dir="rtl"] .figure-cap {
  unicode-bidi: isolate;
}

html[dir="rtl"] .wordmark,
html[dir="rtl"] .brand-name {
  direction: ltr;
}

html[dir="rtl"] .credits div {
  grid-template-columns: 7.5rem 1fr;
}

@media (max-width: 440px) {
  html[dir="rtl"] .nav {
    gap: 18px;
  }
}

/* ---------- small fixes ---------- */
html[data-theme="light"] .page-home .site-header:not(.is-solid) {
  background: transparent;
}

html[data-theme="light"] .brand svg ellipse {
  stroke: var(--star);
}

.result-text {
  flex: 1;
}

html[dir="rtl"] .result-title,
html[dir="rtl"] .result-author {
  text-align: right;
}

html[dir="rtl"] .wordmark {
  text-align: right;
}

@media (max-width: 860px) {
  .tool-search {
    justify-content: center;
  }
}

/* ---------- note shown when a book's link isn't added yet ---------- */
.soon-toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 80;
  width: max-content;
  max-width: calc(100vw - 32px);
  margin: 0 auto;
  text-align: center;
  padding: 11px 18px 11px 16px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: var(--panel);
  color: var(--star);
  font-size: 0.92rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.soon-toast::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-inline-end: 9px;
  border-radius: 50%;
  background: var(--brass);
  vertical-align: 1px;
}
.soon-toast.is-on {
  opacity: 1;
  transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
  .soon-toast { transition: none; }
}

/* ---------- Book panel (book-panel.js) ---------- */
html.book-open {
  overflow: hidden;
}
.book-panel {
  --lv: var(--brass);
  width: min(720px, calc(100% - 32px));
  max-height: min(860px, calc(100% - 64px));
  margin: auto;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 18px;
  background: var(--panel);
  color: var(--star);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}
.book-panel.lv-beginner { --lv: var(--lv-beginner); }
.book-panel.lv-easy { --lv: var(--lv-easy); }
.book-panel.lv-medium { --lv: var(--lv-medium); }
.book-panel.lv-hard { --lv: var(--lv-hard); }
.book-panel.lv-extreme { --lv: var(--lv-extreme); }
.book-panel[open] {
  display: flex;
  flex-direction: column;
  animation: bp-in 0.22s ease-out;
}
@keyframes bp-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.book-panel::backdrop {
  background: rgba(7, 6, 24, 0.66);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}
.bp-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 32px 32px 36px;
  border-top: 3px solid var(--lv);
}
.bp-close {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-2);
  border-radius: 50%;
  background: var(--panel);
  color: var(--star);
  cursor: pointer;
}
.bp-close:hover { border-color: var(--lv); }
.bp-close svg { width: 18px; height: 18px; }

.bp-head {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 26px;
  align-items: end;
  padding-inline-end: 34px;
}
.bp-cover {
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 4px;
  background: var(--panel-2);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 22px 34px -18px rgba(0, 0, 0, 0.95);
}
.bp-cover img { width: 100%; height: 100%; object-fit: cover; }
.bp-cover .cover-blank { border-top-color: var(--lv); font-size: 1rem; }

.bp-level {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--dust);
}
.bp-level .planet {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--lv);
  box-shadow: 0 0 10px var(--lv);
}
.bp-level-name { color: var(--lv); font-weight: 600; }
.bp-subject { flex-basis: 100%; color: var(--faint); }
.bp-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.6rem, 3.4vw, 2.2rem);
  line-height: 1.12;
}
.bp-author { margin: 8px 0 0; color: var(--dust); font-size: 1rem; }
.bp-note {
  display: inline-block;
  margin: 10px 0 0;
  padding: 1px 8px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  color: var(--dust);
  font-size: 0.78rem;
}
.bp-note[hidden] { display: none; }

.bp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 26px 0 6px;
}
.bp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--star);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.bp-btn svg { width: 19px; height: 19px; flex: none; }
.bp-btn:hover { border-color: var(--lv); }
.bp-read {
  background: var(--brass);
  border-color: var(--brass);
  color: #17133a;
}
.bp-read:hover { background: #f6c66c; border-color: #f6c66c; }
html[data-theme="light"] .bp-read { color: #fff; }
html[data-theme="light"] .bp-read:hover { background: #b06c0d; border-color: #b06c0d; }
.bp-btn[hidden] { display: none; }

.bp-body section {
  padding: 20px 0 0;
  margin-top: 20px;
  border-top: 1px solid var(--line);
}
.bp-body h3 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lv);
}
html[dir="rtl"] .bp-body h3 { letter-spacing: 0; text-transform: none; font-size: 0.95rem; }
.bp-body p {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.7;
  color: var(--star);
  opacity: 0.92;
}
.bp-empty { margin-top: 24px !important; color: var(--dust) !important; }

/* the "coming soon" note when it sits inside the panel */
.book-panel .soon-toast { z-index: 5; }

@media (max-width: 560px) {
  .book-panel {
    width: 100%;
    max-width: 100%;
    height: calc(100% - 24px);
    max-height: none;
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
  }
  .bp-scroll { padding: 26px 18px calc(30px + env(safe-area-inset-bottom, 0px)); }
  .bp-head { grid-template-columns: 104px 1fr; gap: 16px; padding-inline-end: 30px; }
  .bp-title { font-size: 1.45rem; }
  .bp-actions .bp-btn { flex: 1 1 0; padding: 0 12px; white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  .book-panel[open] { animation: none; }
}

/* ---------- speed: on phones the panel and search fill the screen, so the
   costly blur behind them is almost invisible; a slightly deeper tint replaces it ---------- */
@media (max-width: 560px) {
  .book-panel::backdrop,
  .search::backdrop {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: rgba(7, 6, 24, 0.74);
  }
}
