/* Layout: app de uma tela. Celular = cabeçalho, terço, oração, botões (empilhados).
   Computador = terço numa coluna à esquerda, oração e botões à direita. */
:root {
  --bg: #EEF1F6;          /* azul-pedra bem claro */
  --surface: #FAFBFD;
  --ink: #1B2440;         /* azul-marinho, o "manto" */
  --muted: #5A6380;
  --line: #CBD2E1;
  --gold: #8F6614;        /* ouro escuro, legível como texto */
  --bead: #C2952F;        /* conta já rezada */
  --halo: rgba(194, 149, 47, .30);
  --blue: #2B4485;
  --on-blue: #F5F7FC;

  --f-display: "Cormorant Garamond", "Cormorant", Garamond, Georgia, serif;
  --f-text: "Literata", Georgia, "Times New Roman", serif;

  --scale: 1;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1424; --surface: #151C30; --ink: #E7EAF3; --muted: #9AA3BE; --line: #2A3352;
    --gold: #E2BC68; --bead: #D8AE52; --halo: rgba(216, 174, 82, .28);
    --blue: #8EA7EA; --on-blue: #0E1424;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1424; --surface: #151C30; --ink: #E7EAF3; --muted: #9AA3BE; --line: #2A3352;
  --gold: #E2BC68; --bead: #D8AE52; --halo: rgba(216, 174, 82, .28);
  --blue: #8EA7EA; --on-blue: #0E1424;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-text);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "rosary" "card" "controls";
  max-width: 1120px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 12px max(12px, env(safe-area-inset-bottom, 0px));
  gap: 10px;
}

/* Cabeçalho */
.top {
  grid-area: top;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 12px;
  align-items: center;
}
.brand { min-width: 0; }
.brand h1 {
  margin: 0;
  white-space: nowrap;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.75rem;
  line-height: 1;
  letter-spacing: .01em;
}
.hoje {
  margin: 4px 0 0;
  font-size: .78rem;
  color: var(--muted);
  font-variant: small-caps;
  letter-spacing: .06em;
}
.tools { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tool {
  font: 500 .8rem/1 var(--f-text);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 11px;
  cursor: pointer;
}
.tool:hover { border-color: var(--muted); }
.tool-install { border-color: var(--gold); color: var(--gold); }

.sets {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.sets::-webkit-scrollbar { display: none; }
.set {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font: 500 .88rem/1 var(--f-text);
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 9px 11px;
  cursor: pointer;
}
.set:hover { color: var(--ink); }
.set[aria-pressed="true"] {
  color: var(--on-blue);
  background: var(--blue);
}
.set .hoje-tag {
  font-size: .68rem;
  font-variant: small-caps;
  letter-spacing: .08em;
  color: var(--gold);
}
.set[aria-pressed="true"] .hoje-tag { color: inherit; opacity: .8; }

.progress {
  grid-column: 1 / -1;
  height: 2px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--bead);
  transition: width .3s ease;
}

/* Terço desenhado */
.rosary {
  grid-area: rosary;
  display: flex;
  justify-content: center;
  height: clamp(150px, 27vh, 250px);
}
.rosary svg { height: 100%; width: auto; max-width: 100%; overflow: visible; }
.chain { fill: none; stroke: var(--line); stroke-width: 1.2; }
.bead { fill: var(--surface); stroke: var(--muted); stroke-width: 1.1; cursor: pointer; transition: fill .2s, r .2s; }
.bead.big { stroke-width: 1.4; }
.bead.done { fill: var(--bead); stroke: var(--bead); }
.bead.now { fill: var(--bead); stroke: var(--gold); stroke-width: 2; }
.halo { fill: var(--halo); opacity: 0; transition: opacity .2s; pointer-events: none; }
.halo.on { opacity: 1; }
.cross { fill: var(--surface); stroke: var(--muted); stroke-width: 1.4; cursor: pointer; }
.cross.done, .cross.now { fill: var(--bead); stroke: var(--gold); }
.medal { fill: var(--surface); stroke: var(--muted); stroke-width: 1.3; cursor: pointer; }
.medal.done, .medal.now { fill: var(--bead); stroke: var(--gold); }
.medal-m { fill: var(--muted); font: 600 9px var(--f-display); pointer-events: none; }
.medal.done + .medal-m, .medal.now + .medal-m { fill: var(--surface); }

/* Cartão da oração */
.card {
  grid-area: card;
  min-height: 0;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 20px 24px;
  cursor: pointer;
  user-select: none;
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.card-inner { max-width: 36em; margin: 0 auto; display: grid; gap: 10px; }
.card.fade .card-inner { animation: fade .28s ease; }
@keyframes fade { from { opacity: .35; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.eyebrow {
  margin: 0;
  font-size: .78rem;
  font-variant: small-caps;
  letter-spacing: .09em;
  color: var(--gold);
}
.mystery-line {
  margin: 0;
  font-family: var(--f-display);
  font-style: italic;
  font-size: 1.08rem;
  color: var(--muted);
  line-height: 1.25;
}
.prayer-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.prayer-name {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 2rem;
  line-height: 1.05;
  text-wrap: balance;
}
.count {
  flex: 0 0 auto;
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 1.6rem;
  color: var(--gold);
  font-variant-numeric: lining-nums tabular-nums;
}
.count small { font-size: .9rem; color: var(--muted); font-weight: 500; }
.note {
  margin: 0;
  font-size: .9rem;
  color: var(--muted);
}
.prayer-text {
  margin: 4px 0 0;
  font-size: calc(1.08rem * var(--scale));
  line-height: 1.65;
}
.prayer-text p { margin: 0 0 .7em; }
.prayer-text p:last-child { margin-bottom: 0; }

.announce-title {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 600;
  font-size: calc(2.1rem * var(--scale));
  line-height: 1.08;
  text-wrap: balance;
}
.cite { margin: 0; color: var(--muted); font-size: .9rem; font-variant-numeric: lining-nums; }
.fruit {
  margin: 8px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: calc(1rem * var(--scale));
  line-height: 1.55;
}
.fruit b { font-weight: 600; color: var(--gold); }
.hint { margin: 6px 0 0; font-size: .82rem; color: var(--muted); }

.end-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* Orações opcionais */
.eyebrow-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.badge {
  font-size: .72rem;
  font-variant: small-caps;
  letter-spacing: .08em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
}
.card.escolha { border-style: dashed; border-color: var(--muted); cursor: default; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; max-width: 26em; }
.lembrar { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); cursor: pointer; }
.lembrar input { width: 18px; height: 18px; accent-color: var(--blue); }
.opt-list { display: grid; gap: 0; margin-top: 6px; border-top: 1px solid var(--line); }
.opt-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.opt-row label { font-family: var(--f-display); font-weight: 600; font-size: 1.2rem; }
.opt-row select {
  font: 500 .9rem var(--f-text); color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px;
}

/* Botões */
.controls {
  grid-area: controls;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}
.btn {
  font: 600 1rem/1 var(--f-text);
  border-radius: 12px;
  padding: 15px 18px;
  cursor: pointer;
  border: 1px solid var(--line);
  min-height: 50px;
}
.btn.primary { background: var(--blue); color: var(--on-blue); border-color: var(--blue); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn:disabled { opacity: .4; cursor: default; }
.pos {
  font-size: .8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
  min-width: 4.5em;
}

button:focus-visible, .card:focus-visible, .bead:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Computador */
@media (min-width: 860px) {
  .app {
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top top" "rosary card" "rosary controls";
    gap: 16px 28px;
    padding-block: 24px;
  }
  .top { grid-template-columns: auto minmax(0, 1fr) auto; }
  .brand h1 { font-size: 2.1rem; }
  .brand { grid-column: 1; grid-row: 1; }
  .sets { grid-column: 2; grid-row: 1; justify-content: center; }
  .tools { grid-column: 3; grid-row: 1; }
  .progress { grid-row: 2; }
  .rosary { height: auto; align-items: center; }
  .rosary svg { height: auto; width: 100%; max-height: 100%; }
  .card { padding: 36px 40px; }
  .prayer-name { font-size: 2.5rem; }
  .announce-title { font-size: calc(2.7rem * var(--scale)); }
  .prayer-text { font-size: calc(1.2rem * var(--scale)); }
}

@media (prefers-reduced-motion: reduce) {
  .card.fade .card-inner { animation: none; }
  .progress span, .bead, .halo { transition: none; }
}
