:root {
  color-scheme: dark;
  --background: #000000;
  --surface: #03060a;
  --card: #05080d;
  --card-strong: #07101a;
  --ink: #ffd166;
  --muted: #b69cff;
  --placeholder: #76adff;
  --line: #1a2d46;
  --line-strong: #4f86c6;
  --quran-green: #19ff4b;
  --translation-red: #ff2929;
  --translation-red-soft: #300707;
  --reference-blue: #76adff;
  --reference-blue-soft: #07172a;
  --teal: #4cc9f0;
  --teal-soft: #061725;
  --rose: #ff4f5f;
  --rose-soft: #2b0508;
  --amber: #ffd166;
  --amber-soft: #271904;
  --violet: #b69cff;
  --violet-soft: #171025;
  --stone-soft: #071019;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.72);
  --font-arabic: "Geeza Pro", "Noto Naskh Arabic", "Scheherazade New", serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--background);
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #000000 0%, #02060b 52%, #000000 100%);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(118, 173, 255, 0.68);
  outline-offset: 2px;
}

::selection {
  background: rgba(255, 209, 102, 0.34);
  color: #000000;
}

* {
  scrollbar-color: #315b8e #050505;
  scrollbar-width: thin;
}

.app-shell {
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(118, 173, 255, 0.055), transparent 34%, rgba(182, 156, 255, 0.045)),
    var(--background);
}

.app-header {
  background:
    linear-gradient(180deg, rgba(118, 173, 255, 0.065), transparent),
    var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03);
}

.header-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 20px;
}

.product-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-bottom: 16px;
  border: 1px solid rgba(118, 173, 255, 0.55);
  border-radius: 6px;
  background: var(--reference-blue-soft);
  color: var(--reference-blue);
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.app-title {
  max-width: 780px;
  margin: 0;
  color: var(--ink);
  font-size: 40px;
  line-height: 1.14;
  font-weight: 760;
}

.app-subtitle {
  max-width: 760px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 16px;
  font-weight: 650;
  line-height: 1.7;
}

.panel,
.ayah-card,
.basmala-card,
.study-header {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(118, 173, 255, 0.032), transparent 42%),
    var(--card);
  box-shadow: var(--shadow);
}

.workbench {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 360px;
  gap: 20px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px;
}

.left-rail,
.right-rail {
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 20px;
  align-self: start;
}

.right-rail {
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding-right: 4px;
}

.reader-column,
.card-grid,
.study-set {
  display: grid;
  gap: 16px;
}

.panel {
  padding: 20px;
}

.panel-kicker {
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.panel-kicker.teal {
  color: var(--reference-blue);
}

.panel-kicker.rose {
  color: var(--translation-red);
}

.panel-kicker.amber {
  color: var(--amber);
}

.field-label {
  display: block;
  color: var(--reference-blue);
  font-size: 14px;
  font-weight: 760;
}

.field-label.spaced {
  margin-top: 16px;
}

.text-control {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #02060b;
  color: var(--ink);
  padding: 10px 12px;
  font-size: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.text-control:focus {
  border-color: var(--reference-blue);
}

.text-control::placeholder {
  color: var(--placeholder);
}

.load-status {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(118, 173, 255, 0.4);
  border-radius: 6px;
  background: var(--reference-blue-soft);
  color: var(--reference-blue);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.45;
}

.load-status strong {
  color: var(--reference-blue);
}

.load-status.loading {
  border-color: rgba(255, 209, 102, 0.45);
  background: rgba(65, 43, 19, 0.82);
  color: var(--amber);
}

.load-status.fallback {
  border-color: rgba(255, 41, 41, 0.45);
  background: rgba(48, 7, 7, 0.86);
  color: var(--rose);
}

.load-status span {
  color: inherit;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.button-row.compact {
  margin-top: 8px;
}

.button-row.inline {
  align-items: center;
  justify-content: flex-end;
  margin-top: 0;
}

.primary-button,
.secondary-button {
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 760;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease;
}

.primary-button:disabled,
.secondary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary-button {
  border: 1px solid var(--reference-blue);
  background: linear-gradient(180deg, #092b52, #07172a);
  color: var(--reference-blue);
  box-shadow: 0 8px 20px rgba(118, 173, 255, 0.18);
}

.primary-button:hover {
  background: linear-gradient(180deg, #0d3b6e, #092443);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--stone-soft);
  color: var(--reference-blue);
}

.secondary-button:hover,
.secondary-button.active {
  border-color: var(--reference-blue);
  background: var(--reference-blue-soft);
  color: var(--reference-blue);
}

.topic-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.topic-button,
.topic-pill,
.connection-button {
  border-radius: 6px;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.topic-button {
  border: 1px solid var(--line);
  background: var(--stone-soft);
  color: var(--reference-blue);
  padding: 10px 12px;
  text-align: left;
  font-size: 14px;
  font-weight: 700;
}

.topic-button:hover,
.topic-pill:hover {
  border-color: var(--violet);
  background: var(--violet-soft);
  color: var(--violet);
  transform: translateY(-1px);
}

.topic-button.active,
.topic-pill.active {
  border-color: var(--violet);
  background: linear-gradient(180deg, #261a45, #171025);
  color: var(--violet);
  box-shadow: 0 8px 18px rgba(182, 156, 255, 0.18);
}

.topic-pill {
  border: 1px solid var(--line);
  background: var(--stone-soft);
  color: var(--reference-blue);
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 760;
}

.topic-pill.soft {
  background: var(--stone-soft);
}

.topic-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.topic-row.padded {
  margin-top: 18px;
}

.topic-count,
.topic-more {
  color: var(--reference-blue);
  font-size: 12px;
  font-weight: 700;
}

.topic-count {
  margin-top: 8px;
}

.topic-more {
  display: inline-flex;
  align-items: center;
  padding: 6px 2px;
}

.surah-list {
  display: grid;
  gap: 16px;
  margin-top: 14px;
}

.surah-block {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.surah-block:first-child {
  border-top: 0;
  padding-top: 0;
}

.surah-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.surah-heading h3 {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
}

.surah-heading span {
  color: var(--reference-blue);
  font-size: 12px;
}

.reader-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.reader-summary h2,
.study-header h2 {
  margin: 0;
  color: var(--ink);
  font-size: 24px;
  line-height: 1.25;
}

.connection-button {
  border: 1px solid rgba(255, 41, 41, 0.52);
  background: var(--translation-red-soft);
  color: var(--translation-red);
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 760;
}

.connection-button:hover {
  border-color: var(--translation-red);
  background: rgba(255, 41, 41, 0.16);
}

.ayah-card {
  background:
    linear-gradient(180deg, rgba(118, 173, 255, 0.018), transparent),
    var(--card);
  padding: 20px;
}

.basmala-card {
  border-color: rgba(255, 209, 102, 0.36);
  background:
    linear-gradient(180deg, rgba(255, 209, 102, 0.075), transparent),
    var(--card-strong);
  padding: 18px 20px;
  text-align: center;
}

.basmala-arabic {
  margin: 0;
  color: var(--quran-green);
  font-family: var(--font-arabic);
  font-size: 34px;
  line-height: 1.9;
  direction: rtl;
  unicode-bidi: plaintext;
}

.basmala-translation {
  margin: 4px 0 0;
  color: var(--translation-red);
  font-size: 14px;
  line-height: 1.6;
}

.ayah-card.context {
  border-color: rgba(255, 209, 102, 0.42);
}

.ayah-card.selected-ayah {
  border-color: var(--amber);
  box-shadow:
    0 0 0 1px rgba(255, 209, 102, 0.34),
    0 18px 48px rgba(0, 0, 0, 0.46);
}

.ayah-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.ref-badge,
.nearby-badge,
.selected-badge,
.study-count,
.range-value,
.occurrence-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
}

.ref-badge {
  border: 0;
  background: var(--reference-blue-soft);
  color: var(--reference-blue);
  padding: 6px 8px;
}

.ref-button {
  cursor: pointer;
  font-family: inherit;
}

.ref-button:hover {
  background: rgba(118, 173, 255, 0.18);
}

.nearby-badge,
.selected-badge,
.study-count,
.range-value {
  background: var(--amber-soft);
  color: var(--amber);
  padding: 6px 8px;
}

.selected-badge {
  background: var(--amber-soft);
  color: var(--amber);
}

.arabic-line {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 12px 8px;
  margin: 0;
  color: var(--quran-green);
  font-family: var(--font-arabic);
  font-size: 32px;
  line-height: 2.1;
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
}

.arabic-token {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  padding: 4px 8px;
  font-family: var(--font-arabic);
}

.arabic-token:hover {
  border-color: rgba(255, 209, 102, 0.45);
  background: rgba(255, 209, 102, 0.08);
}

.arabic-token.known {
  border-color: rgba(118, 173, 255, 0.3);
  background: rgba(118, 173, 255, 0.08);
  color: var(--quran-green);
}

.arabic-token.known:hover {
  border-color: var(--amber);
  background: rgba(255, 209, 102, 0.12);
}

.arabic-token.selected,
.english-token.selected {
  background: rgba(255, 209, 102, 0.14);
  border-color: var(--amber);
}

.arabic-token.selected {
  color: var(--quran-green);
}

.english-token.selected {
  color: var(--translation-red);
}

.translation-block {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.english-line {
  margin: 0;
  color: var(--translation-red);
  font-size: 16px;
  line-height: 1.85;
}

.english-token {
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  padding: 2px 4px;
  text-align: left;
}

.english-token:hover {
  border-color: rgba(255, 41, 41, 0.32);
  background: rgba(255, 41, 41, 0.08);
}

.english-token.known {
  background: rgba(255, 41, 41, 0.08);
  color: var(--translation-red);
}

.english-token.known:hover {
  background: rgba(255, 41, 41, 0.14);
}

.ayah-card .topic-row {
  margin-top: 18px;
}

.ayah-note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.65;
}

.theme-row,
.similar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.theme-badge {
  border: 1px solid rgba(182, 156, 255, 0.42);
  border-radius: 6px;
  background: var(--violet-soft);
  color: var(--violet);
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 760;
  line-height: 1.4;
}

.similar-row > span {
  color: var(--reference-blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.inspector-panel {
  min-width: 0;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.inspector-title {
  margin: 0;
  color: var(--ink);
  font-size: 24px;
  line-height: 1.25;
}

.panel-kicker.rose + .inspector-title {
  color: var(--translation-red);
}

.inspector-title.arabic-title {
  color: var(--quran-green);
  font-family: var(--font-arabic);
  font-size: 32px;
  line-height: 1.7;
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
}

.panel-kicker.rose + .inspector-title.arabic-title {
  color: var(--quran-green);
}

.inspector-copy {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.7;
}

.inspector-stack {
  display: grid;
  gap: 20px;
  margin-top: 20px;
}

.entry-display {
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.definition-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.definition-item {
  border-left: 3px solid var(--reference-blue);
  padding-left: 12px;
}

.definition-item dt,
.section-heading {
  color: var(--reference-blue);
  font-size: 14px;
  font-weight: 800;
}

.definition-item dd {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.7;
}

.form-list {
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.7;
}

.analysis-token-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.analysis-token {
  border: 1px solid var(--reference-blue);
  border-radius: 6px;
  background: var(--reference-blue-soft);
  color: var(--reference-blue);
  padding: 5px 8px;
  font-size: 13px;
  font-weight: 800;
}

.analysis-token:hover {
  border-color: var(--amber);
  background: var(--amber-soft);
  color: var(--amber);
}

.analysis-token.arabic-analysis {
  color: var(--quran-green);
  font-family: var(--font-arabic);
  font-size: 16px;
  direction: rtl;
}

.analysis-transliteration {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.root-tree {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.root-node {
  justify-self: center;
  border: 1px solid var(--amber);
  border-radius: 8px;
  background: var(--amber-soft);
  color: var(--quran-green);
  padding: 10px 18px;
  font-family: var(--font-arabic);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.5;
}

.root-branches {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 8px;
}

.root-form-node {
  display: grid;
  gap: 4px;
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--stone-soft);
  padding: 10px 8px;
  text-align: center;
}

.root-form-node:hover {
  border-color: var(--amber);
  background: var(--amber-soft);
}

.root-form-arabic {
  color: var(--quran-green);
  font-family: var(--font-arabic);
  font-size: 22px;
  font-weight: 800;
  line-height: 1.5;
}

.root-form-count {
  color: var(--amber);
  font-size: 12px;
  font-weight: 900;
}

.root-form-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.root-form-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(182, 156, 255, 0.04), transparent 58%),
    var(--stone-soft);
  padding: 12px;
}

.root-form-heading {
  color: var(--quran-green);
  font-family: var(--font-arabic);
  font-size: 24px;
  font-weight: 800;
  line-height: 1.55;
}

.root-form-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
}

.root-back-button {
  justify-self: start;
}

.related-word-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.related-word-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--stone-soft);
  color: var(--reference-blue);
  padding: 6px 9px;
  font-size: 13px;
  font-weight: 800;
}

.related-word-button:hover {
  border-color: var(--reference-blue);
  background: var(--reference-blue-soft);
  color: var(--reference-blue);
}

.sense-list {
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.7;
}

.sense-pos {
  display: inline-block;
  margin-right: 6px;
  color: var(--reference-blue);
  font-weight: 800;
}

.topic-presence {
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.5;
}

.topic-presence.found {
  border: 1px solid rgba(118, 173, 255, 0.4);
  background: var(--reference-blue-soft);
  color: var(--reference-blue);
}

.topic-presence.missing {
  border: 1px solid rgba(255, 209, 102, 0.42);
  background: var(--amber-soft);
  color: var(--amber);
}

.text-reference-button {
  border: 0;
  border-radius: 4px;
  background: var(--reference-blue-soft);
  color: var(--reference-blue);
  padding: 1px 5px;
  font-size: inherit;
  font-weight: 800;
}

.text-reference-button:hover {
  background: rgba(118, 173, 255, 0.22);
  color: var(--placeholder);
}

.occurrence-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.occurrence-badge {
  border: 0;
  background: var(--reference-blue-soft);
  color: var(--reference-blue);
  padding: 6px 8px;
}

button.occurrence-badge:hover {
  background: rgba(118, 173, 255, 0.22);
  color: var(--placeholder);
}

.occurrence-badge.muted {
  background: var(--stone-soft);
  color: var(--reference-blue);
}

.empty-state,
.empty-search {
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.7;
}

.empty-state {
  margin-top: 20px;
  border-left: 3px solid var(--reference-blue);
  padding-left: 12px;
}

.empty-state.compact {
  margin-top: 8px;
}

.study-set {
  margin-top: 8px;
}

.study-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-color: rgba(182, 156, 255, 0.36);
  background:
    linear-gradient(180deg, rgba(182, 156, 255, 0.08), transparent),
    var(--card-strong);
  padding: 20px;
}

.study-header p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.65;
}

.range-control {
  margin-top: 14px;
}

.range-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--reference-blue);
  font-size: 14px;
  font-weight: 800;
}

.range-control input {
  width: 100%;
  margin-top: 12px;
  accent-color: var(--amber);
}

.range-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  color: var(--reference-blue);
  font-size: 12px;
  font-weight: 700;
}

@media (max-width: 1180px) {
  .workbench {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .right-rail {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    position: static;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .inspector-panel {
    max-height: none;
  }
}

@media (max-width: 860px) {
  .header-grid,
  .workbench,
  .right-rail {
    grid-template-columns: 1fr;
  }

  .header-grid,
  .workbench {
    padding: 16px;
  }

  .left-rail {
    position: static;
  }

  .app-title {
    font-size: 32px;
  }

  .reader-summary,
  .study-header {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .header-grid,
  .workbench {
    padding: 12px;
  }

  .panel,
  .ayah-card,
  .basmala-card,
  .study-header {
    padding: 14px;
  }

  .app-title {
    font-size: 30px;
  }

  .arabic-line,
  .basmala-arabic {
    font-size: 27px;
  }

  .inspector-title.arabic-title {
    font-size: 29px;
  }

  .arabic-token {
    min-height: 42px;
    padding: 3px 6px;
  }
}
