/* ==========================================================================
   SAKINA — Zikr Counter
   Soft-glassmorphism iOS styling. Every animated property is transform or
   opacity only (GPU-composited), so nothing here triggers layout/paint work
   on tap → buttery 60fps even on older iPhones.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. DESIGN TOKENS
   Everything themable lives in CSS variables. The six pastel space themes
   below override --accent* on a per-card / per-screen basis via [data-theme].
   -------------------------------------------------------------------------- */
:root {
  /* Base surface + ink */
  --bg:            #EEF0FA;
  --ink:           #2A2B3D;
  --ink-soft:      #6E7191;
  --ink-faint:     #9DA0BC;

  /* Glass recipe (kept lightweight: low blur radius, no nested filters) */
  --glass:         rgba(255, 255, 255, 0.58);
  --glass-strong:  rgba(255, 255, 255, 0.78);
  --glass-border:  rgba(255, 255, 255, 0.75);
  --glass-shadow:  0 10px 30px rgba(66, 71, 118, 0.13);
  --blur:          14px;

  /* Default accent (overridden by themes) */
  --accent:        #A7C4F5;
  --accent-deep:   #5D82C4;
  --accent-soft:   rgba(167, 196, 245, 0.35);

  --radius-lg:     26px;
  --radius-md:     18px;

  /* iOS safe areas (notch / home indicator) */
  --safe-top:      env(safe-area-inset-top, 0px);
  --safe-bottom:   env(safe-area-inset-bottom, 0px);

  --spring: cubic-bezier(0.32, 1.4, 0.42, 1); /* playful overshoot */
  --ease:   cubic-bezier(0.25, 0.8, 0.3, 1);
}

/* The 6 pastel space themes. Applied as data-theme="sky" etc. on cards,
   swatches, and the counting screen. */
[data-theme="sky"]   { --accent:#A7C4F5; --accent-deep:#5D82C4; --accent-soft:rgba(167,196,245,.38); }
[data-theme="mint"]  { --accent:#A9DDC3; --accent-deep:#4F9C77; --accent-soft:rgba(169,221,195,.38); }
[data-theme="blush"] { --accent:#F5B8C4; --accent-deep:#C4637C; --accent-soft:rgba(245,184,196,.38); }
[data-theme="lilac"] { --accent:#C9B8F0; --accent-deep:#7E63BE; --accent-soft:rgba(201,184,240,.38); }
[data-theme="peach"] { --accent:#F7CBA8; --accent-deep:#C77E43; --accent-soft:rgba(247,203,168,.38); }
[data-theme="sand"]  { --accent:#E4D6B0; --accent-deep:#9C8A52; --accent-soft:rgba(228,214,176,.38); }

/* --------------------------------------------------------------------------
   2. RESET + iOS BEHAVIOUR KILLS
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  /* Kills the 300ms tap delay AND double-tap-to-zoom on every element. */
  touch-action: manipulation;
  /* Stops the page (and pull-to-refresh) from rubber-banding. */
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  /* position:fixed + inset:0 is the bullet-proof iOS way to prevent the
     Safari body "bounce": the body itself can never scroll, only the inner
     .scroll containers can. */
  position: fixed;
  inset: 0;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  /* No grey tap flash, no text-selection while tapping the counter. */
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none; /* no long-press callout menu */
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

input {
  font: inherit;
  color: var(--ink);
  -webkit-user-select: text;
  user-select: text;
}

/* --------------------------------------------------------------------------
   3. AMBIENT BACKGROUND
   Three big blurred pastel blobs. They are static (no animation) so they
   cost one composite each and zero ongoing GPU work.
   -------------------------------------------------------------------------- */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.bg-blob {
  position: absolute;
  width: 65vmax; height: 65vmax;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.5;
}
.bg-blob-a { background: #C9D8FB; top: -25vmax; left: -20vmax; }
.bg-blob-b { background: #F6D6DE; bottom: -30vmax; right: -22vmax; }
.bg-blob-c { background: #D9F0E3; bottom: -12vmax; left: 8vmax; opacity: 0.4; }

/* --------------------------------------------------------------------------
   4. LOCK SCREEN
   -------------------------------------------------------------------------- */
.lock {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-top) + 16px) 20px calc(var(--safe-bottom) + 16px);
  z-index: 50;
}
.lock-inner { width: min(340px, 100%); text-align: center; }

.lock-glyph {
  width: 74px; height: 74px;
  margin: 0 auto 18px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 24px;
  color: var(--accent-deep);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
}

.lock-title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.lock-sub   { margin-top: 6px; font-size: 14px; color: var(--ink-soft); }

.pin-dots { display: flex; gap: 16px; justify-content: center; margin: 26px 0 30px; }
.pin-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.6px solid var(--ink-faint);
  transition: transform 0.18s var(--spring), background 0.15s, border-color 0.15s;
}
.pin-dot.filled {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  transform: scale(1.15);
}

/* Wrong PIN → shake the dots row. translateX only = composited. */
.pin-dots.shake { animation: shake 0.45s var(--ease); }
@keyframes shake {
  20% { transform: translateX(-10px); }
  40% { transform: translateX(9px);  }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px);  }
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  justify-items: center;
}
.pin-key {
  width: 76px; height: 76px;
  border-radius: 50%;
  font-size: 28px; font-weight: 500;
  display: flex; align-items: center; justify-content: center;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: 0 4px 14px rgba(66, 71, 118, 0.10);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  transition: transform 0.12s var(--ease), background 0.12s;
}
.pin-key:active { transform: scale(0.9); background: var(--glass-strong); }
.pin-key-blank  { visibility: hidden; }
.pin-key-del    { color: var(--ink-soft); }

/* Unlock: lock screen floats up and fades away (transform+opacity only). */
.lock.unlocking {
  animation: lockAway 0.45s var(--ease) forwards;
  pointer-events: none;
}
@keyframes lockAway {
  to { opacity: 0; transform: translateY(-40px) scale(0.96); }
}

/* --------------------------------------------------------------------------
   5. APP SHELL (injected after unlock)
   -------------------------------------------------------------------------- */
.app { position: fixed; inset: 0; }

.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  padding-top: calc(var(--safe-top) + 14px);
}
.screen[hidden] { display: none; }

/* Screens fade/slide in on navigation. */
.screen.enter { animation: screenIn 0.32s var(--ease); }
@keyframes screenIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* Only inner containers scroll — never the body (rubber-band defense). */
.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 4px 20px calc(var(--safe-bottom) + 110px); /* room for nav bar */
}

.screen-head {
  padding: 6px 22px 14px;
  display: flex; align-items: baseline; justify-content: space-between;
}
.screen-title { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
.screen-date  { font-size: 13px; color: var(--ink-faint); font-weight: 600; }

/* ---- Zikr space cards ------------------------------------------------- */
.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.space-card {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 18px 16px 16px;
  min-height: 148px;
  display: flex; flex-direction: column; justify-content: space-between;
  text-align: left;
  background:
    linear-gradient(160deg, var(--accent-soft), rgba(255,255,255,0.14)),
    var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  transition: transform 0.15s var(--ease);
  overflow: hidden;
}
.space-card:active { transform: scale(0.96); }

.space-card-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent-deep);
  margin-bottom: 8px;
}
.space-card-name {
  font-size: 15px; font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.space-card-count {
  font-size: 34px; font-weight: 800; letter-spacing: -0.03em;
  color: var(--accent-deep);
  font-variant-numeric: tabular-nums;
}
.space-card-target { font-size: 12px; font-weight: 600; color: var(--ink-faint); }

.space-card-edit {
  position: absolute; top: 8px; right: 8px;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--ink-soft);
}
.space-card-edit:active { transform: scale(0.85); }

/* Empty state */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 56px 24px;
  color: var(--ink-soft);
}
.empty svg { color: var(--ink-faint); margin-bottom: 14px; }
.empty p   { font-size: 15px; line-height: 1.5; }

/* ---- Bottom navigation ------------------------------------------------- */
.nav {
  position: absolute;
  left: 16px; right: 16px;
  bottom: calc(var(--safe-bottom) + 14px);
  height: 66px;
  display: flex; align-items: center; justify-content: space-around;
  border-radius: 33px;
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  z-index: 10;
}
.nav-btn {
  width: 62px; height: 62px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--ink-faint);
  font-size: 10px; font-weight: 700;
  transition: color 0.15s;
}
.nav-btn.active { color: var(--accent-deep); }
.nav-btn:active { transform: scale(0.9); }

/* Central floating "+" action button, raised out of the bar. */
.nav-fab {
  width: 60px; height: 60px;
  margin-top: -34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  background: linear-gradient(150deg, var(--accent), var(--accent-deep));
  box-shadow: 0 10px 22px var(--accent-soft), 0 4px 10px rgba(66,71,118,0.18);
  transition: transform 0.15s var(--spring);
}
.nav-fab:active { transform: scale(0.88); }

/* --------------------------------------------------------------------------
   6. COUNTING SCREEN
   -------------------------------------------------------------------------- */
.count-screen {
  /* touch-action:none — on THIS screen no gesture should scroll or zoom;
     every touch is a count. */
  touch-action: none;
  background: linear-gradient(180deg, var(--accent-soft), transparent 55%);
}

.count-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
}
.icon-btn {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--ink-soft);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
}
.icon-btn:active { transform: scale(0.88); }

.count-name {
  font-size: 16px; font-weight: 700;
  max-width: 55%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* The tap surface fills everything under the header. */
.count-stage {
  flex: 1;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}

/* The big central circle. Pulse animation is applied by JS via
   element.animate() (transform+opacity only). */
.count-circle {
  position: relative;
  width: min(72vw, 320px);
  height: min(72vw, 320px);
  border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 32% 28%, rgba(255,255,255,0.95), rgba(255,255,255,0.35) 60%),
    var(--accent-soft);
  border: 1px solid var(--glass-border);
  box-shadow:
    0 24px 60px var(--accent-soft),
    inset 0 2px 6px rgba(255,255,255,0.8);
  /* Promote to its own GPU layer up front so the first tap doesn't jank. */
  will-change: transform;
}

.count-value {
  font-size: clamp(56px, 19vw, 88px);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--accent-deep);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.count-target-label {
  margin-top: 6px;
  font-size: 14px; font-weight: 600;
  color: var(--ink-soft);
}

/* Progress ring (SVG) hugging the circle. Only stroke-dashoffset changes. */
.count-ring {
  position: absolute;
  inset: -12px;
  transform: rotate(-90deg);
  pointer-events: none;
}
.count-ring circle { fill: none; stroke-width: 5; stroke-linecap: round; }
.count-ring .ring-track { stroke: rgba(255,255,255,0.6); }
.count-ring .ring-fill  {
  stroke: var(--accent-deep);
  transition: stroke-dashoffset 0.25s var(--ease);
}

/* Tap ripples: spawned at the touch point, expand + fade, then removed.
   scale/opacity only → composited. */
.ripple {
  position: absolute;
  width: 20px; height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  border: 2px solid var(--accent-deep);
  opacity: 0.55;
  pointer-events: none;
  animation: rippleOut 0.55s var(--ease) forwards;
}
@keyframes rippleOut {
  to { transform: scale(9); opacity: 0; }
}

/* Milestone flourish: a glowing ring bursting from the circle. */
.milestone-burst {
  position: absolute;
  left: 50%; top: 50%;
  width: min(72vw, 320px); height: min(72vw, 320px);
  border-radius: 50%;
  border: 3px solid var(--accent-deep);
  box-shadow: 0 0 40px var(--accent-soft);
  opacity: 0.8;
  pointer-events: none;
  /* translate(-50%,-50%) centers it; keyframes must repeat the translate
     because `transform` is a single property — otherwise the scale would
     overwrite the centering and the ring would jump to the corner. */
  transform: translate(-50%, -50%);
  animation: burst 0.9s var(--ease) forwards;
}
@keyframes burst {
  from { transform: translate(-50%, -50%) scale(1);   opacity: 0.8; }
  to   { transform: translate(-50%, -50%) scale(1.9); opacity: 0; }
}

.count-hint {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 28px);
  left: 0; right: 0;
  text-align: center;
  font-size: 13px; font-weight: 600;
  color: var(--ink-faint);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   7. SETTINGS SCREEN
   -------------------------------------------------------------------------- */
.settings-group {
  border-radius: var(--radius-lg);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  overflow: hidden;
  margin-bottom: 18px;
}
.settings-row {
  width: 100%;
  display: flex; align-items: center; gap: 14px;
  padding: 15px 18px;
  text-align: left;
  font-size: 15px; font-weight: 600;
}
.settings-row + .settings-row { border-top: 1px solid rgba(120,124,160,0.14); }
.settings-row-icon { color: var(--accent-deep); display: flex; }
.settings-row-label { flex: 1; }
.settings-row-sub { display:block; font-size: 12px; font-weight: 500; color: var(--ink-faint); margin-top: 2px; }
.settings-row.danger .settings-row-icon,
.settings-row.danger .settings-row-label { color: #C0564F; }

/* iOS-style toggle switch */
.switch {
  position: relative;
  width: 50px; height: 30px; flex-shrink: 0;
  border-radius: 15px;
  background: rgba(120,124,160,0.28);
  transition: background 0.2s;
}
.switch::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  transition: transform 0.2s var(--spring);
}
.switch.on { background: var(--accent-deep); }
.switch.on::after { transform: translateX(20px); }

.settings-footer { text-align: center; font-size: 12px; color: var(--ink-faint); padding: 8px; }

/* --------------------------------------------------------------------------
   8. BOTTOM SHEET (create / edit space)
   -------------------------------------------------------------------------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(40, 42, 66, 0.35);
  z-index: 20;
  animation: fadeIn 0.25s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 21;
  border-radius: 28px 28px 0 0;
  padding: 14px 22px calc(var(--safe-bottom) + 22px);
  background: var(--glass-strong);
  border-top: 1px solid var(--glass-border);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  box-shadow: 0 -12px 40px rgba(66,71,118,0.22);
  animation: sheetUp 0.34s var(--spring);
  max-height: 86%;
  overflow-y: auto;
  overscroll-behavior: contain;
}
@keyframes sheetUp { from { transform: translateY(100%); } }
.sheet.closing          { animation: sheetDown 0.25s var(--ease) forwards; }
.sheet-backdrop.closing { animation: fadeOut  0.25s var(--ease) forwards; }
@keyframes sheetDown { to { transform: translateY(100%); } }
@keyframes fadeOut   { to { opacity: 0; } }

.sheet-grip {
  width: 40px; height: 5px;
  margin: 0 auto 16px;
  border-radius: 3px;
  background: rgba(120,124,160,0.35);
}
.sheet-title { font-size: 20px; font-weight: 800; margin-bottom: 18px; }

.field { margin-bottom: 20px; }
.field-label {
  display: block;
  font-size: 12px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 9px;
}
.field-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px; /* ≥16px stops iOS auto-zooming the page on focus */
  border-radius: var(--radius-md);
  border: 1.5px solid rgba(120,124,160,0.22);
  background: rgba(255,255,255,0.7);
  outline: none;
}
.field-input:focus { border-color: var(--accent-deep); }

/* Colour palette swatches */
.swatch-row { display: flex; gap: 12px; }
.swatch {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid transparent;
  transition: transform 0.15s var(--spring), border-color 0.15s;
}
.swatch.selected {
  border-color: var(--accent-deep);
  transform: scale(1.12);
}

/* Milestone interval chips */
.chip-row { display: flex; gap: 10px; flex-wrap: wrap; }
.chip {
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px; font-weight: 700;
  color: var(--ink-soft);
  background: rgba(255,255,255,0.7);
  border: 1.5px solid rgba(120,124,160,0.22);
  transition: transform 0.12s var(--ease);
}
.chip:active { transform: scale(0.92); }
.chip.selected {
  color: #fff;
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

.sheet-actions { display: flex; gap: 12px; margin-top: 6px; }
.btn {
  flex: 1;
  padding: 16px;
  border-radius: var(--radius-md);
  font-size: 16px; font-weight: 700;
  transition: transform 0.12s var(--ease);
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  color: #fff;
  background: linear-gradient(150deg, var(--accent), var(--accent-deep));
  box-shadow: 0 8px 18px var(--accent-soft);
}
.btn-danger { color: #C0564F; background: rgba(192, 86, 79, 0.12); flex: 0 0 auto; padding: 16px 18px; }

/* Toast (small confirmations) */
.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--safe-bottom) + 100px);
  transform: translateX(-50%);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px; font-weight: 700;
  color: var(--ink);
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  z-index: 30;
  pointer-events: none;
  animation: toastIn 2s var(--ease) forwards;
}
@keyframes toastIn {
  0%   { opacity: 0; transform: translate(-50%, 14px); }
  12%  { opacity: 1; transform: translate(-50%, 0); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -8px); }
}

/* --------------------------------------------------------------------------
   9. ACCESSIBILITY: honour reduced-motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
