/* ============ Vakit — design system ============ */
:root {
  --brand: #0e6f5c;
  --brand-strong: #0a5748;
  --brand-soft: #e3f0ec;
  --gold: #c9a227;
  --bg: #eef3f1;
  --surface: #ffffff;
  --surface-2: #f6faf8;
  --ink: #16241f;
  --ink-2: #5b6f67;
  --line: #dde7e3;
  --ring-track: #e3ece8;
  --shadow: 0 1px 2px rgba(22, 36, 31, .05), 0 8px 24px rgba(22, 36, 31, .07);
  --radius: 20px;
  --tabbar-h: 64px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --brand: #2fbf9d;
  --brand-strong: #63d6bb;
  --brand-soft: #14312a;
  --gold: #d9b64a;
  --bg: #0b1411;
  --surface: #121e19;
  --surface-2: #182720;
  --ink: #e6efeb;
  --ink-2: #8ba59b;
  --line: #22352e;
  --ring-track: #1e2f28;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.ic { width: 22px; height: 22px; display: block; }

/* ============ top bar ============ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1160px; margin: 0 auto; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--brand); }
.brand-mark { width: 28px; height: 28px; }
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: .3px; color: var(--ink); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.city-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 999px; font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); max-width: 46vw;
}
.city-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.city-btn .ic { width: 17px; height: 17px; color: var(--brand); flex: none; }
.city-btn .chev { width: 14px; height: 14px; color: var(--ink-2); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 999px;
  display: grid; place-items: center; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface); color: var(--ink); }
:root[data-theme="dark"] .theme-sun { display: block; }
:root[data-theme="dark"] .theme-moon { display: none; }
.theme-sun { display: none; }
.theme-moon { display: block; }

.desktop-nav { display: none; }
.desktop-only { display: none; }

/* ============ layout ============ */
.layout { max-width: 1160px; margin: 0 auto; padding: 16px; }
.panel { display: none; }
body[data-view="today"] #view-today,
body[data-view="qibla"] #view-qibla,
body[data-view="calendar"] #view-calendar,
body[data-view="settings"] #view-settings { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-title { margin: 0 0 14px; font-size: 18px; font-weight: 800; }

/* ============ today ============ */
.today-card { padding: 24px 20px; }
.date-row { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.date-greg { font-weight: 700; font-size: 15px; }
.date-hijri { color: var(--brand); font-weight: 600; font-size: 14px; }

.countdown { position: relative; width: min(64vw, 250px); margin: 18px auto 22px; }
.ring { width: 100%; height: auto; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--ring-track); stroke-width: 10; }
.ring-bar {
  fill: none; stroke: var(--brand); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 615.75; stroke-dashoffset: 615.75;
  transition: stroke-dashoffset 1s linear;
}
.countdown-center {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 2px;
}
.cd-label { color: var(--ink-2); font-size: 14px; font-weight: 600; }
.cd-time { font-size: clamp(30px, 9vw, 42px); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.cd-at { color: var(--brand); font-weight: 700; font-size: 15px; }

.times-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.times-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px; border-radius: 14px;
  border: 1px solid transparent;
  font-size: 16px;
}
.times-list .t-name { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.times-list .t-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--line); flex: none; }
.times-list .t-time { font-variant-numeric: tabular-nums; font-weight: 700; }
.times-list li.past { color: var(--ink-2); }
.times-list li.past .t-name { font-weight: 500; }
.times-list li.current {
  background: linear-gradient(100deg, var(--brand) 0%, var(--brand-strong) 100%);
  color: #fff; border-color: transparent;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 35%, transparent);
}
:root[data-theme="dark"] .times-list li.current { color: #06231c; }
.times-list li.current .t-dot { background: var(--gold); }
.times-list li.next { border-color: var(--brand); }
.times-list li.next .t-dot { background: var(--brand); }
.src-note { margin: 14px 2px 0; font-size: 12.5px; color: var(--ink-2); }

/* ============ qibla ============ */
.compass-wrap { position: relative; width: min(78vw, 300px); margin: 6px auto 14px; }
#compass { width: 100%; height: auto; }
.dial-face { fill: var(--surface-2); stroke: var(--line); stroke-width: 1.5; }
.dial-n { fill: var(--brand); font-weight: 800; font-size: 20px; text-anchor: middle; }
.dial-c { fill: var(--ink-2); font-weight: 600; font-size: 15px; text-anchor: middle; }
#dialTicks line { stroke: var(--line); stroke-width: 1.5; }
#dialTicks line.major { stroke: var(--ink-2); stroke-width: 2; }
.qibla-arrow-head { fill: var(--gold); }
.kaaba-icon { fill: var(--ink); stroke: var(--gold); stroke-width: 2; }
.needle { fill: var(--brand); }
.needle-hub { fill: var(--brand-strong); }
#compassDial, #deviceNeedle { transform-origin: 130px 130px; transition: transform .25s ease-out; }
.qibla-status {
  position: absolute; left: 0; right: 0; bottom: -4px; text-align: center;
  font-size: 13px; font-weight: 700; color: var(--brand); min-height: 20px;
}
.qibla-status.aligned { color: var(--gold); }
.qibla-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.fact { background: var(--surface-2); border-radius: 14px; padding: 10px 12px; text-align: center; }
.fact-label { display: block; font-size: 12px; color: var(--ink-2); }
.fact-value { font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }
.qibla-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { font-size: 13px; color: var(--ink-2); margin: 12px 2px 0; }

/* ============ buttons ============ */
.btn {
  border-radius: 12px; padding: 10px 16px; font-weight: 700; font-size: 14.5px;
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1px solid var(--line); background: var(--surface);
}
.btn .ic { width: 18px; height: 18px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #06231c; }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-block { width: 100%; }

/* ============ calendar ============ */
.events-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.events-list li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  padding: 12px 14px; border-radius: 14px; background: var(--surface-2);
  border: 1px solid transparent;
}
.events-list li.soon { border-color: var(--gold); }
.ev-icon {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); font-size: 19px;
}
.ev-name { font-weight: 700; font-size: 15px; }
.ev-date { font-size: 13px; color: var(--ink-2); }
.ev-count { text-align: right; }
.ev-days { font-weight: 800; font-size: 17px; color: var(--brand); font-variant-numeric: tabular-nums; }
.ev-days-label { font-size: 11.5px; color: var(--ink-2); }

/* ============ settings ============ */
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 2px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.setting-label { font-weight: 600; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { padding: 7px 13px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.seg button[aria-checked="true"] { background: var(--brand); color: #fff; }
:root[data-theme="dark"] .seg button[aria-checked="true"] { color: #06231c; }
.about { padding-top: 16px; font-size: 14px; color: var(--ink-2); }

/* calculation method + preview */
.setting-col { flex-direction: column; align-items: stretch; }
.method-select {
  padding: 11px 12px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface-2); color: var(--ink); font: inherit; font-size: 15px;
  width: 100%;
}
.method-preview {
  margin-top: 14px; padding: 14px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.method-preview .mp-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  font-weight: 700; font-size: 14px; margin-bottom: 8px;
}
.method-preview .mp-date { font-weight: 500; font-size: 12.5px; color: var(--ink-2); }
.method-preview ul { list-style: none; margin: 0; padding: 0; }
.method-preview li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 2px; font-size: 14.5px;
  border-bottom: 1px dashed var(--line);
}
.method-preview li:last-child { border-bottom: 0; }
.method-preview .mp-name { color: var(--ink-2); font-weight: 600; }
.method-preview .mp-time { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }
.method-preview .mp-delta {
  font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-strong);
}
.method-preview .mp-delta.later { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); }
.method-preview li.changed { animation: mp-flash 900ms ease-out; }
@keyframes mp-flash {
  0% { background: color-mix(in srgb, var(--brand) 22%, transparent); }
  100% { background: transparent; }
}

/* ============ picker modal ============ */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 18, 15, .55);
  display: grid; place-items: end center;
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal-card {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 24px 24px 0 0; padding: 20px;
  max-height: 88dvh; overflow: auto;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.search-wrap { margin: 14px 0 10px; }
#citySearch {
  width: 100%; padding: 12px 16px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--surface-2); color: var(--ink);
  font: inherit; font-size: 16px; outline: none;
}
#citySearch:focus { border-color: var(--brand); }
.picker-list { list-style: none; margin: 0; padding: 0; }
.picker-list li button {
  width: 100%; text-align: left; padding: 11px 12px; border-radius: 12px;
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
.picker-list li button:hover { background: var(--surface-2); }
.picker-list .pc-name { font-weight: 600; }
.picker-list .pc-country { font-size: 12.5px; color: var(--ink-2); }
#browse { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
#browse summary { cursor: pointer; font-weight: 600; color: var(--ink-2); }
.browse-selects { display: grid; gap: 8px; margin-top: 10px; }
.browse-selects select {
  padding: 11px 12px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface-2); color: var(--ink); font: inherit; font-size: 15px;
}

/* ============ tab bar (mobile) ============ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 11px; font-weight: 600; color: var(--ink-2); max-width: 120px;
}
.tab .ic { width: 23px; height: 23px; }
.tab.active { color: var(--brand); }

/* ============ desktop ============ */
@media (min-width: 960px) {
  body { padding-bottom: 24px; }
  .tabbar { display: none; }
  .desktop-nav { display: flex; gap: 4px; margin-left: 18px; }
  .nav-link { padding: 8px 14px; border-radius: 10px; font-weight: 600; color: var(--ink-2); font-size: 14.5px; }
  .nav-link:hover { color: var(--ink); background: var(--surface); }
  .nav-link.active { color: var(--brand); background: var(--brand-soft); }
  .desktop-only { display: grid; }

  .layout {
    display: grid; gap: 20px; padding: 24px 20px;
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    align-items: start;
  }
  .panel { display: block !important; min-width: 0; }
  .panel-today { grid-column: 1; grid-row: 1 / span 2; }
  .panel-qibla { grid-column: 2; grid-row: 1; }
  .panel-calendar { grid-column: 2; grid-row: 2; }
  #view-settings {
    display: none !important;
    position: fixed; z-index: 40; top: 70px; right: 20px; width: 420px; max-height: 80vh; overflow: auto;
  }
  body.settings-open #view-settings { display: block !important; }
  #view-settings .card { box-shadow: 0 18px 50px rgba(0,0,0,.25); }

  .today-card { padding: 32px; }
  .countdown { width: 260px; }
  .times-list { grid-template-columns: 1fr 1fr; gap: 8px; }
  .times-list li { padding: 13px 18px; }
  .modal { place-items: center; }
  .modal-card { border-radius: 24px; }
}
@media (min-width: 1240px) {
  .times-list { grid-template-columns: repeat(3, 1fr); }
}

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