:root {
  --bg: #07110c;
  --bg-2: #0b1a12;
  --card: #102018;
  --card-2: #15281e;
  --line: rgba(212, 175, 90, 0.18);
  --gold: #d4af5a;
  --gold-2: #f0d48a;
  --cream: #f4ecda;
  --muted: #9aa894;
  --dim: #6d7a70;
  --now: #3faf74;
  --danger: #e0b36a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 22px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Cormorant Garamond", Georgia, serif;
  --arabic: "Noto Naskh Arabic", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { color-scheme: dark; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(212, 175, 90, 0.08), transparent 55%),
    var(--bg);
  color: var(--cream);
  min-height: 100dvh;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='72' height='72'><path d='M36 6 L40 32 L66 36 L40 40 L36 66 L32 40 L6 36 L32 32 Z' fill='none' stroke='%23d4af5a' stroke-width='1.2'/></svg>");
  background-size: 72px 72px;
}

.wrap {
  width: min(440px, 100%);
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top))
           calc(14px + env(safe-area-inset-right))
           calc(28px + env(safe-area-inset-bottom))
           calc(14px + env(safe-area-inset-left));
  position: relative;
  min-width: 0;
  overflow-x: clip;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.brand { min-width: 0; flex: 1; }
.kicker {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
}
h1 {
  font-family: var(--display);
  font-size: 28px;
  line-height: 1.05;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}
.where {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clock {
  text-align: right;
  flex: 0 1 42%;
  min-width: 0;
  max-width: 46%;
}
.clock time {
  display: block;
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.03em;
  white-space: nowrap;
}
.clock .date {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  white-space: nowrap;
}
.clock .hijri {
  color: var(--dim);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arabic {
  font-family: var(--arabic);
  text-align: center;
  font-size: 14px;
  color: var(--gold-2);
  margin: 4px 0 16px;
  line-height: 1.7;
  direction: rtl;
  padding: 0 2px;
}

.saying {
  margin: -6px 0 16px;
  padding: 14px 16px 12px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(212, 175, 90, 0.08), transparent 70%);
}
.saying-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 8px;
}
.saying-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-2);
  font-weight: 700;
}
.saying-meta {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.saying-body {
  margin: 0;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  color: var(--cream);
  min-height: 3.2em;
}
.saying-cursor {
  display: inline-block;
  width: 0.55ch;
  height: 1em;
  margin-left: 1px;
  background: var(--gold);
  vertical-align: -0.12em;
  animation: saying-blink 1s steps(1) infinite;
}
.saying-cursor.idle { opacity: 0.35; animation: none; }
@keyframes saying-blink {
  50% { opacity: 0; }
}
.saying-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
}
.saying-next {
  appearance: none;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--cream);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}
.saying-next:hover { background: rgba(255, 255, 255, 0.08); }
.saying-join {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--gold-2);
  border: 1px solid rgba(212, 175, 90, 0.4);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(212, 175, 90, 0.08);
}
.saying-join:hover { background: rgba(212, 175, 90, 0.16); }
@media (prefers-reduced-motion: reduce) {
  .saying-cursor { display: none; }
}

.hero {
  background:
    linear-gradient(180deg, rgba(212, 175, 90, 0.12), transparent 42%),
    linear-gradient(180deg, #163224, var(--card));
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 22px 20px 18px;
  box-shadow: var(--shadow);
  text-align: center;
  margin-bottom: 14px;
}

.hero .label {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
}
.hero .prayer-name {
  font-family: var(--display);
  font-size: clamp(48px, 15vw, 72px);
  line-height: 0.9;
  margin: 8px 0 2px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.hero .prayer-time {
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--gold-2);
}
.hero .countdown {
  margin-top: 10px;
  font-size: 15px;
  color: var(--cream);
}
.hero .countdown b {
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.04em;
}
.hero .status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.hero .combo {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(212, 175, 90, 0.12);
  color: var(--gold-2);
  font-size: 12px;
}

.progress {
  margin-top: 16px;
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 99px;
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--now), var(--gold));
  border-radius: inherit;
}

.banner {
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  line-height: 1.45;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--cream);
}
.banner.ramadan { background: #241c10; border-color: rgba(212,175,90,0.35); }
.banner.jumuah { background: #13261c; }
.banner b { color: var(--gold-2); }

.card {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: var(--radius);
  padding: 16px 14px 10px;
  margin-bottom: 14px;
  min-width: 0;
}

.card h2 {
  margin: 0 14px 10px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
}

.row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 11px 12px;
  border-radius: 14px;
  margin: 0 2px 4px;
}
.row.info {
  opacity: 0.62;
}
.row.passed { opacity: 0.45; }
.row.current {
  background: rgba(63, 175, 116, 0.12);
  outline: 1px solid rgba(63, 175, 116, 0.28);
}
.row.next {
  background: rgba(212, 175, 90, 0.1);
  outline: 1px solid rgba(212, 175, 90, 0.28);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dim);
  justify-self: center;
}
.row.current .dot {
  background: var(--now);
  box-shadow: 0 0 0 4px rgba(63, 175, 116, 0.18);
}
.row.next .dot {
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(212, 175, 90, 0.18);
}
.row .name {
  font-weight: 600;
  font-size: 16px;
}
.row .meta {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 1px;
}
.row .time {
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.03em;
  white-space: nowrap;
  min-width: 7.6ch;
  text-align: right;
}
.row .time small {
  display: block;
  text-align: right;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.week-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 6px 12px;
}
.week-head h2 { margin: 0; }
.range {
  color: var(--muted);
  font-size: 12px;
  margin: 2px 0 0;
}
.nav {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.nav button, .today-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--cream);
  border-radius: 999px;
  height: 34px;
  min-width: 34px;
  padding: 0 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.nav button:disabled { opacity: 0.35; cursor: default; }

.week-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  padding: 0 2px 8px;
}
.slot {
  background: var(--bg-2);
  border-radius: 14px;
  padding: 10px 2px 8px;
  text-align: center;
  min-width: 0;
}
.slot.changed { outline: 1px solid rgba(212, 175, 90, 0.45); }
.slot .n {
  display: block;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}
.slot .t {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.slot .sub {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  color: var(--gold);
  line-height: 1.2;
}

.sunrow {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 10px;
  color: var(--dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

details.year {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: var(--radius);
  padding: 4px 4px 8px;
  margin-bottom: 14px;
}
details.year > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
}
details.year > summary::-webkit-details-marker { display: none; }

.month { padding: 0 8px 12px; }
.month h3 {
  margin: 8px 6px 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.yrow {
  display: grid;
  grid-template-columns: 58px repeat(5, minmax(0, 1fr));
  gap: 2px;
  align-items: center;
  padding: 8px 4px;
  border-radius: 10px;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.yrow.this { background: rgba(212, 175, 90, 0.1); }
.yrow .d { color: var(--muted); font-weight: 600; }
.yrow span { text-align: center; min-width: 0; }
.yhead {
  color: var(--dim);
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.notes {
  color: var(--dim);
  font-size: 12px;
  line-height: 1.5;
  padding: 0 4px;
  overflow-wrap: anywhere;
}
.notes p { margin: 0 0 8px; }
.footer {
  margin-top: 18px;
  text-align: center;
  color: var(--dim);
  font-size: 12px;
  line-height: 1.55;
}
.footer a { color: var(--gold); text-decoration: none; }

.pills {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 0 0 16px;
}
.pills a {
  color: var(--cream);
  text-decoration: none;
  border: 1px solid var(--line);
  background: rgba(16, 32, 24, 0.7);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
}
.pills a:hover { border-color: var(--gold); color: var(--gold-2); }

#hero, #today, #qibla, #luna { scroll-margin-top: 12px; }

.qibla-stage {
  --head: 0;
  --qibla: 54.45;
  height: 300px;
  margin: 0 2px 12px;
  border-radius: 20px;
  overflow: hidden;
  position: relative;
  perspective: 520px;
  perspective-origin: 50% 40%;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, #123226 0%, #0b1c14 48%, #08140f 100%);
  touch-action: none;
  cursor: grab;
  user-select: none;
}
.qibla-stage:active { cursor: grabbing; }
.qibla-world {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateY(calc(var(--head) * 1deg));
}
.qibla-ground {
  position: absolute;
  left: 50%;
  top: 78%;
  width: 1600px;
  height: 1600px;
  margin-left: -800px;
  margin-top: -800px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(212, 175, 90, 0.28) 0 3px, transparent 4px),
    repeating-conic-gradient(from 0deg, rgba(212, 175, 90, 0.1) 0deg 0.6deg, transparent 0.6deg 22.5deg),
    radial-gradient(circle, #1a3d2b 0%, #0d2218 46%, #07110c 70%);
  transform: rotateX(88deg);
}
.qibla-labels { position: absolute; inset: 0; transform-style: preserve-3d; pointer-events: none; }
.ql {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 24px;
  margin-left: -12px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--gold);
  text-shadow: 0 2px 10px #000;
}
.ql-n { transform: rotateY(0deg) translateZ(-320px) translateY(-18px); }
.ql-e { transform: rotateY(-90deg) translateZ(-320px) translateY(-18px); }
.ql-s { display: none; }
.ql-w { transform: rotateY(90deg) translateZ(-320px) translateY(-18px); color: var(--dim); }

.kaaba-holder {
  position: absolute;
  left: 50%;
  top: 38%;
  width: 78px;
  height: 96px;
  margin-left: -39px;
  margin-top: -48px;
  transform-style: preserve-3d;
  transform: rotateY(calc(var(--qibla) * -1deg)) translateZ(-230px);
}
.kaaba {
  width: 78px;
  height: 96px;
  transform-style: preserve-3d;
  position: relative;
}
.k-face {
  position: absolute;
  left: 0;
  top: 0;
  width: 78px;
  height: 96px;
  background:
    linear-gradient(180deg, transparent 20%, rgba(212, 175, 90, 0.95) 22%, rgba(168, 128, 40, 0.95) 34%, transparent 36%),
    linear-gradient(180deg, #2a241c, #12100c);
  border: 1px solid rgba(212, 175, 90, 0.28);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.45);
}
.k-front { transform: translateZ(39px); }
.k-back { transform: rotateY(180deg) translateZ(39px); }
.k-left { transform: rotateY(-90deg) translateZ(39px); }
.k-right { transform: rotateY(90deg) translateZ(39px); }
.k-top {
  width: 78px;
  height: 78px;
  background: #3a3226;
  transform: rotateX(90deg) translateZ(48px);
}

.qibla-aim {
  position: absolute;
  left: 50%;
  top: 18%;
  bottom: 22%;
  width: 2px;
  margin-left: -1px;
  background: linear-gradient(180deg, transparent, rgba(212, 175, 90, 0.75), transparent);
  pointer-events: none;
}
.qibla-aim::before, .qibla-aim::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border: 2px solid rgba(212, 175, 90, 0.85);
  border-radius: 50%;
}
.qibla-aim::before { top: 36%; }
.qibla-aim::after { display: none; }

.qibla-stage.aligned {
  box-shadow: inset 0 0 40px rgba(212, 175, 90, 0.18);
}
.qibla-stage.aligned .kaaba {
  filter: drop-shadow(0 0 16px rgba(240, 212, 138, 0.65));
}
.qibla-stage.aligned .qibla-aim {
  background: linear-gradient(180deg, transparent, var(--gold-2), transparent);
}

.qibla-readout { text-align: center; padding: 4px 8px 10px; }
.qibla-deg {
  font-family: var(--display);
  font-size: 42px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.qibla-cardinal {
  color: var(--gold-2);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 12px;
  margin-top: 4px;
}
.qibla-dist, .qibla-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 8px 0 0;
}
.qibla-cta {
  display: block;
  width: calc(100% - 8px);
  margin: 4px 4px 10px;
  appearance: none;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #2a4a38, #1a3328);
  color: var(--cream);
  border-radius: 999px;
  padding: 12px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.qibla-cta:hover { border-color: var(--gold); color: var(--gold-2); }
.luna-actions {
  display: flex;
  gap: 8px;
  margin: 4px 4px 10px;
}
.luna-actions .qibla-cta { width: auto; flex: 1; margin: 0; }
.luna-paths-btn[aria-pressed="false"] { opacity: 0.65; }

.luna-stage {
  height: 320px;
  margin: 0 2px 10px;
  border-radius: 20px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--line);
  background: #070b16;
  touch-action: none;
  cursor: grab;
}
.luna-stage:active { cursor: grabbing; }
.luna-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.luna-stage.aligned {
  box-shadow: inset 0 0 40px rgba(212, 175, 90, 0.16);
}
.luna-hint {
  margin: 0 8px 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  min-height: 2.6em;
}
.luna-phase-row {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 14px;
  align-items: center;
  padding: 4px 8px 12px;
}
#luna-phase {
  width: 108px;
  height: 108px;
  display: block;
}
.luna-phase-name {
  font-family: var(--display);
  font-size: 26px;
  line-height: 1.1;
  font-weight: 600;
}
.luna-meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 400px) {
  .top { flex-wrap: wrap; }
  .clock { max-width: 100%; text-align: left; }
  .where { white-space: normal; }
}

@media (orientation: landscape) {
  .wrap { width: min(980px, 100%); }
}

@media (min-width: 720px), (orientation: landscape) and (min-width: 600px) {
  .wrap {
    width: min(980px, 100%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 14px;
    align-items: start;
  }
  .top, .arabic, .saying, .pills, .banner, .week-card, .year, .notes, .footer {
    grid-column: 1 / -1;
  }
  .clock { max-width: none; flex: 0 0 auto; }
  .slot .t { font-size: 14px; }
  body { background-color: #050c09; }
}

@media (min-width: 720px) and (min-height: 541px) {
  .wrap { padding-top: 28px; align-items: stretch; }
}

@media (orientation: landscape) and (max-height: 540px) {
  .wrap {
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .arabic { margin: 0 0 8px; font-size: 13px; }
  .pills { margin-bottom: 10px; }
  .hero { padding: 14px 16px 12px; }
  .hero .prayer-name { font-size: clamp(36px, 8vw, 56px); }
  h1 { font-size: 24px; }

  .qibla-card, .luna-card { grid-column: 1 / -1; }

  .qibla-card {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(200px, 0.85fr);
    column-gap: 12px;
    align-items: stretch;
  }
  .qibla-card .week-head { grid-column: 1 / -1; }
  .qibla-stage {
    grid-column: 1;
    grid-row: 2 / 4;
    height: min(68dvh, 380px);
    margin: 0 2px 10px;
  }
  .qibla-readout {
    grid-column: 2;
    grid-row: 2;
    text-align: left;
    padding: 0 8px 8px;
  }
  .qibla-card > .qibla-cta {
    grid-column: 2;
    grid-row: 3;
    width: auto;
    margin: 0 4px 10px;
  }

  .luna-card {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(200px, 0.85fr);
    column-gap: 12px;
    align-items: stretch;
  }
  .luna-card .week-head { grid-column: 1 / -1; }
  .luna-stage {
    grid-column: 1;
    grid-row: 2 / 5;
    height: min(68dvh, 380px);
    margin: 0 2px 10px;
  }
  .luna-hint {
    grid-column: 2;
    grid-row: 2;
    min-height: 0;
    margin: 0 8px 8px;
  }
  .luna-actions {
    grid-column: 2;
    grid-row: 3;
  }
  .luna-phase-row {
    grid-column: 2;
    grid-row: 4;
    grid-template-columns: 72px 1fr;
    gap: 10px;
    padding: 4px 8px 10px;
  }
  #luna-phase { width: 72px; height: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  .row.current .dot, .row.next .dot { box-shadow: none; }
  html { scroll-behavior: auto; }
}
