/* ===================== Design tokens ===================== */
:root {
  --bg: #131315;
  --surface: #1b1b1e;
  --surface-2: #212124;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text-0: #eeeeec;
  --text-1: #9d9d98;
  --text-2: #686863;
  --accent: #c99a5b;
  --accent-soft: rgba(201, 154, 91, 0.12);
  --done: #7fa87a;
  --danger: #b8695a;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 24px -18px rgba(0, 0, 0, 0.7);
  --shadow-lift: 0 4px 10px rgba(0, 0, 0, 0.35), 0 16px 32px -16px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* old Edge/IE */
}
html::-webkit-scrollbar, body::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

body {
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  background: radial-gradient(ellipse 900px 500px at 50% -10%, #1c1c20, var(--bg) 60%);
  background-color: var(--bg);
  color: var(--text-0);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* ===================== Layout ===================== */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(32px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) calc(60px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-pill {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-1);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  white-space: nowrap;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.icon-btn svg { width: 17px; height: 17px; fill: currentColor; }
.icon-btn:active { background: var(--surface-2); color: var(--text-0); transform: scale(0.93); }
.icon-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #171512;
}

/* ===================== Timeline ===================== */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.prayer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.prayer-card.active {
  border-color: rgba(201, 154, 91, 0.45);
  background: linear-gradient(160deg, var(--accent-soft), transparent 55%), var(--surface);
  box-shadow: var(--shadow-lift), 0 0 0 1px rgba(201, 154, 91, 0.2) inset;
}

.prayer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.prayer-id {
  display: flex;
  align-items: center;
  gap: 12px;
}

.prayer-emoji {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.prayer-name-ar {
  font-family: 'Amiri', serif;
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--text-2);
  margin-left: 7px;
}

.prayer-name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.005em;
  color: var(--text-0);
}

.prayer-sub {
  margin: 2px 0 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.after-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 12px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-2);
  font-weight: 700;
}
.after-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--border), transparent);
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 8px;
  border-radius: var(--radius-md);
  transition: background 0.15s ease;
}
.task-list.drag-over {
  background: var(--accent-soft);
  outline: 1.5px dashed var(--accent);
  outline-offset: 4px;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  transition: border-color 0.2s ease, opacity 0.15s ease, transform 0.15s ease, box-shadow 0.2s ease;
}
.task-item.dragging {
  opacity: 0.4;
}

.task-drag-handle {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.task-drag-handle svg { width: 14px; height: 14px; }
.task-item.dragging .task-drag-handle { cursor: grabbing; }

/* Editing controls (drag, delete, add) only show in edit mode */
body:not(.edit-mode) .task-drag-handle,
body:not(.edit-mode) .task-del,
body:not(.edit-mode) .add-task-btn {
  display: none !important;
}

.task-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
  color: transparent;
}
.task-check:active { transform: scale(0.88); }
.task-check svg { width: 12px; height: 12px; }
.task-item.done .task-check {
  background: var(--done);
  border-color: var(--done);
  color: #12160f;
  transform: scale(1.05);
}

.task-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-0);
}
.task-item.done .task-name {
  color: var(--text-2);
  text-decoration: line-through;
  text-decoration-color: var(--text-2);
}

.task-del {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.task-del:active { background: rgba(184, 105, 90, 0.18); color: var(--danger); transform: scale(0.9); }
.task-del svg { width: 14px; height: 14px; }

.add-task-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  width: 100%;
  padding: 9px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease, transform 0.1s ease;
  margin-top: 2px;
}
.add-task-btn:active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  transform: scale(0.98);
}

.empty-hint {
  font-size: 0.82rem;
  color: var(--text-2);
  padding: 4px 2px 2px;
}

/* ===================== Footer ===================== */
.app-footer {
  margin-top: 26px;
  text-align: center;
}

.ghost-btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-1);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 9px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease, transform 0.1s ease;
}
.ghost-btn:active {
  border-color: var(--border-strong);
  color: var(--text-0);
  background: var(--surface-2);
  transform: scale(0.97);
}

.primary-btn {
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  color: #171512;
  background: var(--accent);
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 6px 16px -6px rgba(201, 154, 91, 0.45);
  transition: opacity 0.12s ease, transform 0.1s ease;
}
.primary-btn:active { opacity: 0.85; transform: scale(0.97); }

/* ===================== Modal ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lift);
  animation: pop-in 0.15s ease;
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

.modal h3 { margin: 0 0 16px; font-size: 1.05rem; font-weight: 800; }

.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.field span { font-size: 0.76rem; font-weight: 700; color: var(--text-1); }
.field input[type="text"] {
  font-family: inherit;
  font-size: 0.92rem;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-0);
}
.field input[type="text"]:focus { outline: none; border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ===================== Celebration overlay ===================== */
.celebration-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(8, 8, 9, 0.92);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.celebration-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.celebration-badge {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--done);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(0.6);
  opacity: 0;
}
.celebration-overlay.show .celebration-badge {
  animation: celebration-pop 0.35s ease forwards;
}

.celebration-check {
  width: 46px;
  height: 46px;
  fill: none;
  stroke: #12160f;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 40;
  stroke-dashoffset: 40;
}
.celebration-overlay.show .celebration-check {
  animation: celebration-draw 0.35s ease 0.2s forwards;
}

.celebration-text {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-0);
  opacity: 0;
}
.celebration-overlay.show .celebration-text {
  animation: celebration-text-in 0.3s ease 0.3s forwards;
}

@keyframes celebration-pop {
  to { transform: scale(1); opacity: 1; }
}
@keyframes celebration-draw {
  to { stroke-dashoffset: 0; }
}
@keyframes celebration-text-in {
  to { opacity: 1; }
}

/* ===================== Hover (mouse/trackpad only) ===================== */
/* Scoped so touch devices (iPhone/Android) never get a "stuck" hover state
   after a tap — they rely on the :active rules above instead. */
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { background: var(--surface-2); color: var(--text-0); transform: translateY(-1px); }
  .task-item:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px -6px rgba(0, 0, 0, 0.5);
  }
  .task-drag-handle:hover { color: var(--text-1); }
  .task-check:hover { border-color: var(--accent); }
  .task-item:hover .task-del { color: var(--text-1); }
  .task-del:hover { background: rgba(184, 105, 90, 0.14); color: var(--danger); }
  .add-task-btn:hover { border-color: var(--accent); color: var(--accent); }
  .ghost-btn:hover { border-color: var(--border-strong); color: var(--text-0); }
  .primary-btn:hover { opacity: 0.9; transform: translateY(-1px); }
}

/* ===================== Responsive ===================== */
@media (max-width: 480px) {
  .app {
    padding: calc(22px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(50px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  }
  .date-pill { font-size: 0.72rem; padding: 7px 12px; }
}

/* ===================== Portrait lock (phones only) ===================== */
/* iOS has no orientation-lock API for web apps, so this rotates the whole
   page back to upright whenever a touch phone is turned sideways — the
   layout visually stays put instead of flipping to landscape. Scoped to
   coarse-pointer/no-hover touch devices under 950px so desktop and tablet
   browser windows (which are normally landscape-shaped) are never affected. */
@media screen and (orientation: landscape) and (hover: none) and (pointer: coarse) and (max-width: 950px) {
  html {
    transform: rotate(-90deg);
    transform-origin: left top;
    width: 100vh;
    height: 100vw;
    overflow-x: hidden;
    position: absolute;
    top: 100%;
    left: 0;
  }
}
