/*
 * Material 3 tokens lifted verbatim from the Android app's ui/Theme.kt, so the web build is the
 * same colour scheme rather than an approximation of it. Light is the bare :root block; dark is
 * applied for the system preference and for an explicit data-theme, so neither can strand a
 * colour that was only ever defined inside a media query.
 */
:root {
  --primary: #1F6F5C;
  --on-primary: #FFFFFF;
  --primary-container: #CDEDE1;
  --on-primary-container: #07281F;
  --secondary: #8C6D3F;
  --on-secondary: #FFFFFF;
  --secondary-container: #F3E5CE;
  --on-secondary-container: #2C2009;
  --background: #FCFAF6;
  --on-background: #1A1C1B;
  --surface: #FCFAF6;
  --on-surface: #1A1C1B;
  --surface-variant: #E6E5DF;
  --on-surface-variant: #484A47;
  --outline: #797A76;
  /* primary at 12%, the alpha Compose uses for the ayah marker's ring. */
  --primary-tint: rgba(31, 111, 92, 0.12);

  /* Dialogs sit on a raised surface; M3 derives it from primary at low opacity over surface. */
  --surface-dialog: #F5F3EE;
  --scrim: rgba(0, 0, 0, 0.32);

  --shape-small: 8px;
  --shape-medium: 12px;
  --shape-x-large: 28px;

  --font-ui: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue",
    Arial, sans-serif;
  /*
   * Compose asked for FontFamily.Serif, which Android resolves to Noto Naskh Arabic -- the face
   * that renders the Uthmani marks properly. This stack names the equivalent on each platform
   * before falling back to generic serif, so nothing is fetched at runtime.
   */
  --font-arabic: "SF Arabic", "Geeza Pro", "Noto Naskh Arabic", "Noto Naskh Arabic UI", "Amiri",
    "Scheherazade New", "Traditional Arabic", "Al Bayan", "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #87D2BA;
    --on-primary: #003829;
    --primary-container: #11543F;
    --on-primary-container: #A3EFD5;
    --secondary: #D9BE8F;
    --on-secondary: #3B2A0C;
    --secondary-container: #53401F;
    --on-secondary-container: #F6DBAB;
    --background: #11140F;
    --on-background: #E2E3DD;
    --surface: #11140F;
    --on-surface: #E2E3DD;
    --surface-variant: #43483F;
    --on-surface-variant: #C3C8BC;
    --outline: #8D9287;
    --primary-tint: rgba(135, 210, 186, 0.12);
    --surface-dialog: #1D211A;
    --scrim: rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --primary: #87D2BA;
  --on-primary: #003829;
  --primary-container: #11543F;
  --on-primary-container: #A3EFD5;
  --secondary: #D9BE8F;
  --on-secondary: #3B2A0C;
  --secondary-container: #53401F;
  --on-secondary-container: #F6DBAB;
  --background: #11140F;
  --on-background: #E2E3DD;
  --surface: #11140F;
  --on-surface: #E2E3DD;
  --surface-variant: #43483F;
  --on-surface-variant: #C3C8BC;
  --outline: #8D9287;
  --primary-tint: rgba(135, 210, 186, 0.12);
  --surface-dialog: #1D211A;
  --scrim: rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--background);
  color: var(--on-background);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

/* The app was drawn for a phone; on a wide window it stays a phone-width column rather than
   stretching the cards into letterboxes. */
#app {
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Material 3 type scale ---- */
.headline-medium { font-size: 28px; line-height: 36px; font-weight: 400; }
.headline-small  { font-size: 24px; line-height: 32px; font-weight: 400; }
.title-medium    { font-size: 16px; line-height: 24px; font-weight: 500; letter-spacing: 0.15px; }
.body-large      { font-size: 16px; line-height: 24px; letter-spacing: 0.5px; }
.body-medium     { font-size: 14px; line-height: 20px; letter-spacing: 0.25px; }
.body-small      { font-size: 12px; line-height: 16px; letter-spacing: 0.4px; }
.label-large     { font-size: 14px; line-height: 20px; font-weight: 500; letter-spacing: 0.1px; }
.semibold        { font-weight: 600; }

.on-surface-variant { color: var(--on-surface-variant); }

/* ---- Arabic ---- */
.arabic {
  font-family: var(--font-arabic);
  direction: rtl;
  text-align: right;
  /* Compose used lineHeight = fontSize * 1.9 so the Uthmani marks above and below never collide. */
  line-height: 1.9;
}

/* ---- Buttons ---- */
button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
}

.btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 24px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1px;
  transition: background-color 120ms linear;
}

/* The state layer M3 paints over a button on hover/press, as its own element so it tints the
   container colour instead of replacing it. */
.btn::after,
.icon-btn::after,
.card-clickable::after {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity 120ms linear;
  pointer-events: none;
}

@media (hover: hover) {
  .btn:hover::after,
  .icon-btn:hover::after,
  .card-clickable:hover::after { opacity: 0.08; }
}

.btn:active::after,
.icon-btn:active::after,
.card-clickable:active::after { opacity: 0.12; }

.btn:focus-visible,
.icon-btn:focus-visible,
.card-clickable:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.btn-tonal {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

.btn-outlined {
  border: 1px solid var(--outline);
  color: var(--primary);
  background: transparent;
}

.btn-text {
  color: var(--primary);
  background: transparent;
  padding: 0 12px;
}

.btn-block { width: 100%; }

.icon-btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: var(--on-surface-variant);
}

.icon-btn svg { width: 24px; height: 24px; }
.btn svg { width: 18px; height: 18px; }
svg { fill: currentColor; display: block; }

/* ---- Cards ---- */
.card {
  position: relative;
  overflow: hidden;
  border-radius: var(--shape-medium);
  width: 100%;
  display: block;
  text-align: left;
}

.card-primary {
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.card-variant {
  background: var(--surface-variant);
  color: var(--on-surface-variant);
}

/* ---- Choice screen ---- */
.screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.choice {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100%;
  padding: 24px max(24px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
}

.choice h1 { margin: 0; }
.choice .lede { margin: 8px 0 0; }
.choice .cards { margin-top: 32px; display: flex; flex-direction: column; gap: 16px; }

.group-card-inner { padding: 20px; }

.group-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.group-arabic {
  font-family: var(--font-arabic);
  font-size: 20px;
  direction: rtl;
}

.group-card-blurb { margin-top: 6px; }

/* ---- Pair screen ---- */
.pair {
  padding: 0 max(20px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-top: max(4px, env(safe-area-inset-top));
}

.topbar .title { flex: 1; min-width: 0; }

.pair-cards { margin-top: 4px; display: flex; flex-direction: column; gap: 16px; }

.surah-card-inner { padding: 20px; }

.rakah-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rakah-label {
  color: var(--primary);
  font-weight: 600;
}

.surah-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.number-badge {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: var(--shape-small);
  background: var(--primary);
  color: var(--on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.15px;
}

.surah-names { min-width: 0; flex: 1; }

.surah-arabic-name {
  font-family: var(--font-arabic);
  font-size: 30px;
  line-height: 1.35;
  color: var(--on-surface);
  text-align: left;
}

.divider {
  height: 1px;
  border: 0;
  margin: 14px 0;
  background: var(--outline);
  opacity: 0.3;
}

.preview {
  font-size: 22px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

.card-actions .btn { flex: 1 1 0; min-width: 0; padding: 0 12px; }

.pick-again { margin-top: 20px; }

/* ---- Reader ---- */
.reader {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.reader-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: max(4px, env(safe-area-inset-top)) 8px 4px;
  flex: 0 0 auto;
}

.reader-bar .titles { flex: 1; min-width: 0; }

.reader-title {
  font-family: var(--font-arabic);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
}

.reader-bar .divider { margin: 0; }

.reader-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px max(20px, env(safe-area-inset-left))
    calc(48px + env(safe-area-inset-bottom));
}

.basmala {
  font-size: 24px;
  text-align: center;
  color: var(--primary);
  margin-bottom: 20px;
}

.ayah {
  font-size: 26px;
  padding-bottom: 14px;
}

/* The mushaf-style end-of-verse ring: the number in Arabic-Indic digits inside a tinted circle,
   flowing straight after the last word instead of sitting on its own line. */
.ayah-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7em;
  height: 1.7em;
  border-radius: 50%;
  background: var(--primary-tint);
  color: var(--primary);
  vertical-align: middle;
  margin-inline-start: 0.25em;
}

.ayah-marker span { font-size: 0.46em; line-height: 1; }

/* ---- About dialog ---- */
dialog.about {
  border: none;
  padding: 24px;
  width: min(calc(100% - 48px), 360px);
  border-radius: var(--shape-x-large);
  background: var(--surface-dialog);
  color: var(--on-surface);
}

dialog.about::backdrop { background: var(--scrim); }

dialog.about h2 { margin: 0 0 16px; font-size: 24px; line-height: 32px; font-weight: 400; }
dialog.about p { margin: 0; }
dialog.about .notice { margin-top: 12px; }
dialog.about .verbatim { margin-top: 4px; color: var(--on-surface-variant); }

.dialog-actions {
  margin-top: 24px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---- Snackbar (the Toast the Android build shows when the Quran app is missing) ---- */
.snackbar {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 8px);
  max-width: min(calc(100vw - 32px), 480px);
  padding: 14px 16px;
  border-radius: var(--shape-small);
  background: var(--on-surface);
  color: var(--surface);
  font-size: 14px;
  line-height: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms linear, transform 150ms ease-out;
  z-index: 10;
}

.snackbar.visible { opacity: 1; transform: translate(-50%, 0); }

.spinner {
  margin: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid var(--primary-tint);
  border-top-color: var(--primary);
  animation: spin 900ms linear infinite;
}

.loading { flex: 1; display: flex; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
