/* Istighfar — estilos. Móvil primero, sin frameworks. */

:root {
  --bg: #0B0B0B;
  --card: #111111;
  --border: #333333;
  --text: #FFFFFF;
  --text-2: #B3B3B3;
  --text-3: #8C8C8C;
  --green: #159570;
  --green-soft: #4CC79C;
  --track: #262626;
  --ghost: #171717;
  --ghost-hover: #1C1C1C;
  --ghost-active: #232323;
  --field: #0E0E0E;
  --warn: #E0A24B;
  --error: #E07B64;
  --radius-card: 24px;
  --radius-btn: 16px;
  --radius-ghost: 14px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* Android trae Noto Naskh Arabic; iPhone y Mac traen Geeza Pro. Ninguna requiere descarga. */
  --font-arabic: "Noto Naskh Arabic", "Noto Naskh Arabic UI", "Amiri", "Scheherazade New", "Geeza Pro", "Al Nile", "Damascus", "Arabic Typesetting", "Traditional Arabic", serif;
}

/* Si algún día quieres una fuente árabe propia, deja el archivo en fonts/ y descomenta:
@font-face {
  font-family: "Noto Naskh Arabic";
  src: url("./fonts/NotoNaskhArabic-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
*/

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

/* El atributo hidden gana siempre, aunque la clase defina display */
[hidden] { display: none !important; }

html {
  height: 100%;
  background: var(--bg);
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding:
    calc(16px + env(safe-area-inset-top, 0px))
    calc(16px + env(safe-area-inset-right, 0px))
    calc(16px + env(safe-area-inset-bottom, 0px))
    calc(16px + env(safe-area-inset-left, 0px));
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior-y: none;
}

.app {
  width: 100%;
  flex: 1 1 auto;        /* ocupa toda la altura libre: el botón de contar crece hacia abajo */
  display: flex;
  justify-content: center;
  min-height: 0;
}

/* ---------- Tarjeta principal ---------- */

.card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 30px 22px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: color .15s var(--ease), background-color .15s var(--ease);
}
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, .05); }
.icon-btn:active { color: var(--text); background: rgba(255, 255, 255, .09); }

.settings-btn { position: absolute; top: 10px; right: 10px; }
@media (max-width: 480px) {
  .settings-btn {
    position: fixed;
    top: calc(8px + env(safe-area-inset-top, 0px));
    right: calc(8px + env(safe-area-inset-right, 0px));
    z-index: 5;
  }
}

.eyebrow {
  display: flex;
  justify-content: center;
  width: 100%;
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-3);
}
.eyebrow-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  margin: -6px 0;
  padding: 6px 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  transition: color .15s var(--ease), background-color .15s var(--ease);
}
.eyebrow-btn:hover { color: #C9C9C9; background: rgba(255, 255, 255, .05); }
.eyebrow-btn:active { color: var(--text); }
.eyebrow-btn .chev { flex: none; opacity: .85; }
@media (max-width: 359px) {
  .eyebrow { font-size: 11px; letter-spacing: .12em; }
}

.arabic {
  margin: 16px 0 2px;
  font-family: var(--font-arabic);
  font-size: clamp(34px, 10.5vw, 44px);
  font-weight: 400;
  line-height: 1.8;
  color: #F4F4F4;
  direction: rtl;
  unicode-bidi: isolate;
}

.counter {
  margin: 0;
  font-size: clamp(40px, 12.5vw, 52px);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  transform-origin: 50% 60%;
}
.counter .sep { color: #BDBDBD; font-weight: 500; }

.progress {
  width: 100%;
  height: 8px;
  margin-top: 18px;
  background: var(--track);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: inherit;
  transition: width .25s var(--ease);
}

.status {
  margin: 12px 0 0;
  min-height: 20px;
  font-size: 14px;
  color: var(--text-2);
}
.status.done { color: var(--green-soft); }

.count-btn {
  margin-top: 16px;
  width: 100%;
  flex: 1 1 auto;        /* todo el espacio que quede hasta abajo */
  min-height: 240px;     /* al menos 4 veces el botón original (60px) */
  border: 0;
  border-radius: 22px;
  background: #FFFFFF;
  color: var(--bg);
  font: inherit;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: .01em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 70ms ease-out, background-color 70ms ease-out;
}
.count-btn:hover { background: #F4F4F4; }
.count-btn:active,
.count-btn.is-pressed { transform: scale(.975); background: #E6E6E6; }

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  margin-top: 18px;
}

.ghost-btn {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-ghost);
  background: var(--ghost);
  color: #DADADA;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  touch-action: manipulation;
  transition: background-color 90ms ease-out, transform 70ms ease-out, border-color .15s;
}
.ghost-btn:hover { background: var(--ghost-hover); border-color: #404040; }
.ghost-btn:active { background: var(--ghost-active); transform: scale(.985); }
.ghost-btn.wide { width: 100%; }
.glyph { font-size: 1.1em; line-height: 1; color: #BDBDBD; }

.note {
  margin: 12px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-3);
}
.note.warn { color: var(--warn); }
.note-desktop { display: none; margin-top: 6px; }
@media (hover: hover) and (pointer: fine) and (min-width: 480px) {
  .note-desktop { display: block; }
}

/* Foco visible solo al navegar con teclado */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

/* ---------- Diálogos ---------- */

.dialog {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 0;
  margin: auto;
  width: calc(100% - 32px);
  max-width: 420px;
  border-radius: 20px;
}
.dialog::backdrop { background: rgba(0, 0, 0, .62); }
.dialog:not([open]) { display: none; }
.dialog-inner { padding: 18px 20px calc(20px + env(safe-area-inset-bottom, 0px)); }

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -8px 4px 0;
}
.sheet-header h2 { margin: 0; font-size: 18px; font-weight: 600; }

.group { padding: 16px 0; border-top: 1px solid #222222; }
.group-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.hint { margin: 10px 0 0; font-size: 13px; line-height: 1.45; color: var(--text-3); }
.hint.error { color: var(--error); }
.footnote { margin-top: 14px; font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--ghost);
  color: #DADADA;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color .12s, color .12s, border-color .12s;
}
.inline.single { grid-template-columns: 1fr; }
.hint.intro { margin: 2px 0 14px; color: var(--text-2); }
.done-btn { margin-top: 18px; min-height: 54px; font-size: 16px; }

/* Fila «Objetivo» dentro de ajustes */
.row-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 8px 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.row-value {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: none;
  color: var(--text-2);
  font-size: 16px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  transition: color .15s var(--ease);
}
.row-btn:hover .row-value { color: var(--text); }
.chip:hover { border-color: #474747; }
.chip[aria-pressed="true"] { background: #FFFFFF; color: var(--bg); border-color: #FFFFFF; }

.inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

input[type="number"] {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px evita el zoom automático de iOS al enfocar */
  -webkit-user-select: text;
  user-select: text;
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"]:focus { border-color: #5C5C5C; }
input[aria-invalid="true"] { border-color: #B5553F; }

.small-btn {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: #FFFFFF;
  color: var(--bg);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 70ms ease-out, background-color 70ms ease-out;
}
.small-btn:hover { background: #F4F4F4; }
.small-btn:active { transform: scale(.975); background: #E6E6E6; }

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--green-soft);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.link-btn:hover { color: #7FDDB8; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
}
.switch-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; text-align: left; }
.switch-label { font-size: 16px; font-weight: 500; }
.switch-text .hint { margin: 0; }

.switch {
  position: relative;
  flex: none;
  width: 50px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #303030;
  cursor: pointer;
  transition: background-color .15s var(--ease);
}
.switch .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #FFFFFF;
  transition: transform .15s var(--ease);
}
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"] .knob { transform: translateX(20px); }

.confirm-title { margin: 0 0 6px; font-size: 18px; font-weight: 600; line-height: 1.3; }
.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

/* En teléfonos los ajustes salen como hoja desde abajo */
@media (max-width: 559px) {
  .sheet {
    margin: auto 0 0;
    width: 100%;
    max-width: none;
    max-height: 92vh;
    max-height: 92dvh;
    overflow: auto;
    border-radius: 24px 24px 0 0;
    border-bottom: 0;
  }
}

@keyframes dlg-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
@keyframes sheet-in {
  from { opacity: .5; transform: translateY(40px); }
  to   { opacity: 1; transform: none; }
}
@keyframes backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.dialog[open] { animation: dlg-in .18s var(--ease); }
.dialog[open]::backdrop { animation: backdrop-in .18s ease-out; }
@media (max-width: 559px) {
  .sheet[open] { animation: sheet-in .24s var(--ease); }
}

/* ---------- Celebración sutil al llegar al objetivo ---------- */

@keyframes counter-pulse {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}
@keyframes bar-glow {
  0%   { box-shadow: 0 0 0 0 rgba(21, 149, 112, 0); }
  30%  { box-shadow: 0 0 0 6px rgba(21, 149, 112, .22), 0 0 28px rgba(21, 149, 112, .55); }
  100% { box-shadow: 0 0 0 0 rgba(21, 149, 112, 0); }
}
.card.celebrate .counter { animation: counter-pulse .7s var(--ease); }
.card.celebrate .progress { animation: bar-glow 1.1s ease-out; overflow: visible; }
.card.celebrate .progress-fill { border-radius: 999px; }

/* ---------- Utilidades ---------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.haptic {
  position: fixed;
  top: 0;
  left: -9999px;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

/* ---------- Tamaños de pantalla ---------- */

/* Pantallas bajas (iPhone SE, apaisado): todo un poco más compacto */
@media (max-height: 640px) {
  .card { padding: 24px 18px 16px; }
  .arabic { margin-top: 10px; font-size: clamp(30px, 9vw, 38px); line-height: 1.6; }
  .counter { font-size: clamp(36px, 11vw, 44px); }
  .progress { margin-top: 14px; }
  .status { margin-top: 10px; }
  .count-btn { margin-top: 12px; min-height: 160px; }
  .row { margin-top: 12px; }
  .note { margin-top: 10px; }
}

/* Tablet y ordenador: la tarjeta no se estira a toda la ventana; el botón se queda en 240px mínimo */
@media (min-width: 600px) {
  .app { flex: 0 0 auto; }
  .card { padding: 34px 28px 24px; }
}

/* Menos movimiento si el sistema lo pide */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
