/*
 * Minimal: one system typeface, no rules or boxes around content, one accent,
 * and a large thin countdown as the single focal point. Light and dark follow
 * prefers-color-scheme. Every token and its reason lives in DESIGN.md; change
 * both together.
 */

:root {
  color-scheme: light dark;

  --bg: #fbfaf7;
  --surface: #ffffff;
  --ink: #171613;
  --ink-soft: #5f5a50;
  --ink-faint: #726d62; /* 4.93:1 on --bg, 5.15:1 on --surface (WCAG AA) */
  --line: #e6e1d6;
  /* Input boundaries need 3:1 (WCAG 1.4.11): 3.39:1 on --surface, 3.25:1 on --bg. */
  --line-input: #908b80;
  --accent: #0f5c39;
  --accent-wash: #edf5f0; /* --accent on it: 7.0:1 */
  --accent-wash-strong: #dcebe2;
  --danger: #8a2f22;
  /* The countdown's unlit segments: barely there, decorative. */
  --clock-unlit: #e6e1d6;
  /* The current prayer's row: one step darker than the page, same warm hue. */
  --now-tint: #efebe2;
  --backdrop: rgb(0 0 0 / 0.4);

  /* Radius scale: controls, floating surfaces, and the pill for .btn-primary only. */
  --radius-control: 8px;
  --radius: 12px;
  --measure: 33rem;
  /* First screen: the header is fixed at this height, and this much of the
     schedule heading shows below the hero. */
  --top-h: calc(44px + 0.75rem);
  --peek: 3rem;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', sans-serif;
  /* The countdown only. Fixed-width segments, so it never shifts as it ticks. */
  --font-clock: 'DSEG7 Classic', var(--font-sans);
}

/*
 * DSEG7 Classic by keshikan, SIL OFL 1.1 (public/fonts/DSEG-LICENSE.txt).
 * The page's one web font: 5 KB, preloaded in index.astro. `block` keeps the
 * fallback digits from flashing in before the segments; the preload makes the
 * wait a few milliseconds.
 */
@font-face {
  font-family: 'DSEG7 Classic';
  src: url('/fonts/dseg7-classic-bold-italic.woff2') format('woff2');
  font-weight: 700;
  font-style: italic;
  font-display: block;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --surface: #1a1917;
    --ink: #f4f1e9;
    --ink-soft: #b3ac9e;
    --ink-faint: #8b8477;
    --line: #2c2a26;
    --line-input: #716c62;
    --accent: #86d3a7;
    --accent-wash: #1b2a22;
    --accent-wash-strong: #22382c;
    --danger: #eb9b8b;
    --clock-unlit: #2c2a26;
    --now-tint: #24211d;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

/* Components set `display`, which would otherwise beat the attribute. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  /* Every time on the page lines up digit for digit. */
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1rem 1.25rem 4rem;
}

/* Phosphor, light weight. Sized to the text it sits beside. */
.icon {
  flex-shrink: 0;
  width: 1.15em;
  height: 1.15em;
}

.icon-caret {
  width: 0.8em;
  height: 0.8em;
  opacity: 0.7;
}

/*
 * First screen: header plus hero fill the viewport, less --peek, so only the
 * "Jadwal hari ini" heading shows below. The hero's focus group must fit a
 * 360×640 viewport; see DESIGN.md before adding to it.
 */

/* ---------- header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--top-h);
  padding-bottom: 0.75rem;
}

.wordmark {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

/* Plain text with a pin: the city reads as a label you can change, not a form field. */
.city-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 60%;
  min-height: 44px;
  margin-right: -0.5rem;
  padding: 0 0.5rem;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.city-trigger:hover {
  color: var(--ink);
}

/* The way back from the qibla page: quiet like the city button. */
.top-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-inline-end: -0.5rem;
  padding-inline: 0.5rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
  text-decoration: none;
}

.top-link:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.city-trigger .name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ---------- hero ---------- */

.hero {
  display: flex;
  flex-direction: column;
  /* vh first for old browsers; svh ignores the collapsing mobile URL bar. */
  min-height: calc(100vh - 1rem - var(--top-h) - var(--peek));
  min-height: calc(100svh - 1rem - var(--top-h) - var(--peek));
  padding: 1.5rem 0 1rem;
  text-align: center;
}

/* Auto margins center the group in whatever height the date line leaves. */
.hero-focus {
  margin: auto 0;
}

.eyebrow {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-faint);
}

.prayer {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.prayer-lead {
  font-weight: 400;
  color: var(--ink-soft);
}

/*
 * A seven-segment readout, like a digital clock: bold, leaning forward as
 * many LCD clocks do. The unlit segments ("88:88:88")
 * sit faintly behind the digits, as on a real LCD. DSEG gives digits and the
 * colon fixed widths, so the two layers stay aligned whatever the value.
 */
.countdown {
  position: relative;
  isolation: isolate;
  width: fit-content;
  margin: 0.75rem auto 0;
  font-family: var(--font-clock);
  font-size: clamp(2.6rem, 14.5vw, 5.5rem);
  font-weight: 700;
  font-style: italic;
  line-height: 1;
}

.countdown::before {
  content: '88:88:88';
  position: absolute;
  inset: 0;
  z-index: -1;
  color: var(--clock-unlit);
}

.countdown.is-soon {
  color: var(--accent);
}

.hero-at {
  margin: 0.9rem 0 0;
  font-size: 0.92rem;
  color: var(--ink-faint);
}

.hero-subuh {
  margin: 0.25rem 0 0;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.hero-subuh-time {
  font-weight: 600;
  color: var(--ink);
}

.hero-meta {
  margin: 1.5rem 0 0;
  font-size: 0.82rem;
  color: var(--ink-faint);
}

.hero-meta .dot {
  padding: 0 0.4rem;
}

/* A device in another zone gets its own line instead of a mid-phrase wrap. */
.clock-away {
  display: block;
}

/* The way to the qibla page: quieter than "Ingatkan saya", like the city button. */
.hero-kiblat {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  margin-top: 1rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
  text-decoration: none;
}

.hero-kiblat:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- reminder ---------- */

.remind {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 2rem;
}

.remind-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
}

/* The only floating surface on the page: it overlaps the schedule, so it
   carries the one shadow to read as above it. */
.remind-menu {
  position: absolute;
  top: calc(44px + 0.25rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  text-align: left;
  width: min(17rem, 100%);
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.12);
}

.remind-menu-label {
  margin: 0;
  padding: 0.4rem 0.75rem 0.2rem;
  font-size: 0.78rem;
  color: var(--ink-faint);
}

.remind-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  min-height: 44px;
  padding: 0 0.75rem;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
}

.remind-option:hover:not(:disabled) {
  background: var(--accent-wash);
}

.remind-option[aria-pressed='true'] {
  color: var(--accent);
  font-weight: 500;
}

/* Each timing carries a check; only the chosen one shows it. */
.remind-option .icon-check {
  visibility: hidden;
}

.remind-option[aria-pressed='true'] .icon-check {
  visibility: visible;
}

.remind-off {
  justify-content: flex-start;
  margin-top: 0.35rem;
  color: var(--danger);
}

.remind-off:hover:not(:disabled) {
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.remind-status {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.remind-status[data-tone='error'] {
  color: var(--danger);
}

/* ---------- schedule ---------- */

/* The heading is the scroll cue: it peeks in at the bottom of the first screen. */
.day-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.day-title a {
  display: block;
  min-height: 44px;
  line-height: 44px;
  text-decoration: none;
}

.day-title a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* No rules: spacing alone separates the rows, and the times share one right edge. */
.schedule {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Every row is faint except now and next (below), so the eye lands on those two. */
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 1rem;
  padding: 0.65rem 0;
  color: var(--ink-faint);
}

.row-name,
.row-time {
  font-size: 1rem;
}

.row-note {
  margin-left: 0.5rem;
  font-size: 0.75rem;
  color: var(--ink-faint);
}

/*
 * Now and next are both full ink and bold; the current row also sits on a
 * neutral tint so the two read apart at a glance. Not green: green is kept
 * for things you can tap.
 */
.row[data-state='current'],
.row[data-state='next'] {
  color: var(--ink);
  font-weight: 600;
}

/* The tint bleeds into the gutter so the text stays on the column edges. */
.row[data-state='current'] {
  margin: 0 -0.9rem;
  padding-left: 0.9rem;
  padding-right: 0.9rem;
  border-radius: var(--radius-control);
  background: var(--now-tint);
}

.row-tag {
  margin-left: 0.5rem;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--ink-soft);
}

.row-tag:empty {
  display: none;
}

.row[data-state='current'] {
  position: relative;
}

/* Centered in the tint's left padding: 0.275rem either side. */
.row[data-state='current']::before {
  content: '';
  position: absolute;
  left: 0.275rem;
  top: calc(50% - 0.175rem);
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background: var(--ink);
}

.muted {
  margin: 0.35rem 0 0;
  color: var(--ink-faint);
  font-size: 0.8rem;
}

/* ---------- qibla (kiblat.shol.at) ---------- */

/*
 * Four groups, top to bottom in order of importance: what to do (status), the
 * instrument (Kaaba and arrow), the reading (degrees and place), the action.
 * Space alone separates them: 0.75rem inside the instrument, 1.5rem or more
 * between groups. The Kaaba stays still as the target; only the arrow turns.
 * Lined up, the instrument takes the accent (the page's one "you're there"
 * signal, like the countdown's last 15 minutes).
 */
.qibla {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* Leaves --peek for the "Tentang arah kiblat" heading below, as on the schedule. */
  min-height: calc(100vh - 1rem - var(--top-h) - var(--peek));
  min-height: calc(100svh - 1rem - var(--top-h) - var(--peek));
  padding-block: 1rem;
  text-align: center;
}

/* Room for two lines, set from the bottom: a status that wraps on a narrow
   screen or a wide font never pushes the instrument down. */
.qibla-status {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: calc(2 * 1.55em);
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.qibla-instrument {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-block-start: 1.5rem;
}

/* Faint until the compass is live: before that, the top of the screen is north, not the qibla. */
.qibla-instrument .qibla-kaaba {
  width: 2.5rem;
  height: 2.5rem;
  color: var(--ink-faint);
}

.qibla[data-mode='live'] .qibla-kaaba {
  color: var(--ink);
}

/*
 * Shrinks on short screens so the reading and Mulai stay in the first view.
 * The neutral disc holds the arrow as one shape under the Kaaba; it turns to the
 * accent wash when aligned, so the state change is a color, not a new shape.
 */
.qibla-stage {
  position: relative;
  /* vh first: without svh support the line below is dropped, and a stage with
     only absolute children would collapse to nothing. */
  width: min(64vw, 16rem, 36vh);
  width: min(64vw, 16rem, 36svh);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--now-tint);
}

.qibla-dial {
  position: absolute;
  inset: 0;
  color: var(--ink);
  transform: rotate(var(--turn, 0deg));
}

/* From the pivot to just inside the edge, so the tip sweeps close to the Kaaba. */
.qibla-arrow {
  position: absolute;
  top: 8%;
  left: 45%;
  width: 10%;
  height: 42%;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.qibla-pivot {
  position: absolute;
  top: calc(50% - 0.3rem);
  left: calc(50% - 0.3rem);
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--ink);
}

.qibla[data-aligned='true'] .qibla-status,
.qibla[data-aligned='true'] .qibla-kaaba,
.qibla[data-aligned='true'] .qibla-dial {
  color: var(--accent);
}

.qibla[data-aligned='true'] .qibla-stage {
  background: var(--accent-wash);
}

.qibla[data-aligned='true'] .qibla-pivot {
  background: var(--accent);
}

/* The measurement leads; where it was measured from trails, quieter. */
.qibla-meta {
  margin: 1.5rem 0 0;
  font-size: 0.92rem;
  color: var(--ink-faint);
}

.qibla-degrees {
  font-weight: 600;
  color: var(--ink);
}

.qibla-meta .dot {
  padding-inline: 0.4rem;
}

/* The heading peeks in at the bottom edge as the cue that tips sit below. */
.foot.qibla-foot {
  margin-top: 0;
}

.foot.qibla-foot h2 {
  line-height: var(--peek);
  margin: 0;
}

/* Mulai, then the hint if one is needed, in the same slot: nothing below the arrow moves. */
.qibla-action {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 3rem;
  margin-block-start: 1.5rem;
}

.qibla-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.qibla-hint a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.6rem 1.2rem;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

/* The one pill on the page: a soft tint of the accent, quiet but unmistakable. */
.btn-primary {
  border-radius: 999px;
  background: var(--accent-wash);
  color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-wash-strong);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Working, not unavailable: the label already says what is happening. */
.btn[aria-busy='true']:disabled {
  cursor: progress;
  opacity: 1;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* ---------- dialog ---------- */

dialog {
  width: min(26rem, calc(100% - 2rem));
  margin: 10vh auto auto;
  /* Keeps the bottom edge on screen under the top margin; the body scrolls instead. */
  max-height: calc(100% - 10vh - 1rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

dialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}

/* 44×44 hit area; the negative margins keep the header at its visual height. */
.dialog-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: -0.75rem -0.75rem -0.75rem 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.15rem;
  cursor: pointer;
}

.dialog-close:hover {
  color: var(--ink);
}

.dialog-body {
  padding: 1rem;
}

.search {
  position: relative;
}

.search .icon {
  position: absolute;
  top: 50%;
  left: 0.75rem;
  transform: translateY(-50%);
  color: var(--ink-faint);
  pointer-events: none;
}

.search input[type='search'] {
  width: 100%;
  padding: 0.6rem 0.75rem 0.6rem 2.35rem;
  border: 1px solid var(--line-input);
  border-radius: var(--radius-control);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
}

/* Browsers default to a grey that misses 4.5:1 here (4.41 light, 4.09 dark). */
.search input[type='search']::placeholder {
  color: var(--ink-faint);
  opacity: 1;
}

.search input[type='search']:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.city-list {
  max-height: 45vh;
  margin: 0.5rem 0 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.city-list button {
  display: block;
  width: 100%;
  padding: 0.55rem 0.25rem;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
}

.city-list button:hover,
.city-list button[aria-current='true'] {
  color: var(--accent);
  font-weight: 600;
}

.city-list .province {
  display: block;
  color: var(--ink-faint);
  font-size: 0.75rem;
  font-weight: 400;
}

.geo {
  padding-top: 0.25rem;
}

.geo-button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
}

.geo-button:hover:not(:disabled) {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.geo-button:disabled {
  cursor: progress;
  color: var(--ink-soft);
}

.geo-status {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--danger);
}

.geo-status:empty {
  margin: 0;
}

.empty {
  padding: 0.75rem 0.25rem;
  color: var(--ink-faint);
  font-size: 0.85rem;
}

/* ---------- footer ---------- */

.foot {
  margin-top: 3.5rem;
  color: var(--ink-faint);
  font-size: 0.78rem;
}

.foot h2 {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.foot p {
  margin: 0 0 0.5rem;
}

/* ---------- utilities ---------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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