:root {
  --ink: #2a2622;
  --ink-soft: #6b625a;
  --gold: #b8862b;
  --gold-deep: #8f6417;
  --glass: rgba(255, 255, 255, 0.62);
  --glass-edge: rgba(255, 255, 255, 0.85);
  --sky: #e9e7e3;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  font-family: 'Cormorant Garamond', 'Amiri', Georgia, serif;
  color: var(--ink);
  background: var(--sky);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

/* The phone-width stage. On desktop it stays a centred column. */
.stage {
  position: relative;
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  overflow: hidden;
  background: #f1efec url('/bg.jpg') center bottom / cover no-repeat;
  display: flex;
  flex-direction: column;
  padding: max(20px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom));
}

/* Soft fade so text stays readable at the top of the sky */
.stage::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(255,255,255,0.55), rgba(255,255,255,0) 55%);
  pointer-events: none;
}

.stage > * { position: relative; }

.bismillah {
  text-align: center;
  font-family: 'Amiri', serif;
  font-size: 1.5rem;
  color: var(--gold-deep);
  margin: 6px 0 0;
  letter-spacing: 0.02em;
}

.card {
  margin-top: 14px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--glass-edge);
  border-radius: 26px;
  padding: 26px 22px 24px;
  box-shadow: 0 18px 50px rgba(60, 45, 20, 0.16), inset 0 1px 0 rgba(255,255,255,0.9);
}

h1 {
  margin: 0 0 6px;
  font-weight: 600;
  font-size: 2.15rem;
  line-height: 1.05;
  text-align: center;
}

.sub {
  margin: 0 0 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 1.15rem;
  line-height: 1.25;
}

label {
  display: block;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-deep);
  margin: 0 0 7px 4px;
}

input[type=text], textarea {
  width: 100%;
  font: inherit;
  font-size: 1.25rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(184, 134, 43, 0.28);
  border-radius: 16px;
  padding: 13px 15px;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}

textarea { min-height: 128px; resize: none; line-height: 1.35; }

input:focus, textarea:focus {
  border-color: var(--gold);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(184, 134, 43, 0.16);
}

.field { margin-bottom: 16px; }

.hp { position: absolute; left: -9999px; opacity: 0; height: 0; width: 0; }

.btn {
  display: block;
  width: 100%;
  font: inherit;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  color: #fff;
  background: linear-gradient(180deg, #c99a3d, var(--gold-deep));
  border: 0;
  border-radius: 999px;
  padding: 17px 20px;
  box-shadow: 0 10px 24px rgba(143, 100, 23, 0.34), inset 0 1px 0 rgba(255,255,255,0.35);
  cursor: pointer;
  transition: transform .12s, opacity .2s;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.55; }

.btn.ghost {
  color: var(--gold-deep);
  background: rgba(255,255,255,0.7);
  box-shadow: none;
  border: 1px solid rgba(184,134,43,0.35);
}

.msg { min-height: 1.3em; margin: 12px 0 0; text-align: center; font-family: 'Inter', sans-serif; font-size: 0.85rem; color: #a3402b; }

.thanks { text-align: center; padding: 6px 0 2px; }
.thanks .ar { font-family: 'Amiri', serif; font-size: 1.7rem; color: var(--gold-deep); margin: 0 0 8px; }
.thanks p { margin: 0 0 20px; font-size: 1.3rem; color: var(--ink-soft); line-height: 1.3; }

.hidden { display: none !important; }

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

.counter {
  text-align: center;
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  color: var(--ink-soft);
  margin: 10px 0 0;
}

.prayer-card {
  margin-top: 12px;
  max-height: 52dvh;
  display: flex;
  flex-direction: column;
  padding: 24px 22px 22px;
  animation: rise .45s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.from {
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-deep);
  margin: 0 0 4px;
}
.who { font-size: 2.1rem; font-weight: 600; margin: 0 0 14px; line-height: 1.05; overflow-wrap: anywhere; }
.rule { height: 1px; background: linear-gradient(90deg, var(--gold), transparent); opacity: .5; margin-bottom: 14px; }
.what { overflow-y: auto; font-size: 1.5rem; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.what[dir=rtl], .who[dir=rtl] { font-family: 'Amiri', serif; }

.nav { display: flex; gap: 10px; margin-top: 14px; }
.nav .btn.ghost { width: 34%; }
.nav .btn.next { width: 66%; }

.fade-out { animation: out .18s ease both; }
@keyframes out { to { opacity: 0; transform: translateY(-8px); } }

@media (prefers-reduced-motion: reduce) {
  .prayer-card, .fade-out { animation: none; }
}

/* ---------- Language toggle + RTL ---------- */
.lang {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  inset-inline-end: 16px;
  z-index: 5;
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-edge);
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(60, 45, 20, 0.12);
}
.lang button {
  font: inherit;
  font-family: 'Inter', 'Amiri', system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.lang button[lang=ar] { font-family: 'Amiri', serif; font-size: 1rem; padding: 4px 14px 6px; }
.lang button.on { color: #fff; background: linear-gradient(180deg, #c99a3d, var(--gold-deep)); }

.bismillah { margin-top: 44px; }

/* Arabic UI: Inter has no Arabic glyphs, and letter-spacing breaks Arabic joining */
html[dir=rtl] label,
html[dir=rtl] .btn,
html[dir=rtl] .from,
html[dir=rtl] .counter,
html[dir=rtl] .msg {
  font-family: 'Amiri', serif;
  letter-spacing: 0;
  text-transform: none;
}
html[dir=rtl] label { font-size: 0.95rem; }
html[dir=rtl] .btn { font-size: 1.1rem; }
html[dir=rtl] .from { font-size: 0.95rem; }
html[dir=rtl] .sub, html[dir=rtl] .thanks p { line-height: 1.55; }
html[dir=rtl] h1 { font-family: 'Amiri', serif; line-height: 1.3; }
.who { text-align: start; }
