/* ============================================================
   Pour Yvonne — thème « ciel de nuit d'été, braise carmin »
   ============================================================ */

:root {
  --bg: oklch(0.12 0.015 17);
  --surface: oklch(0.17 0.02 17);
  --surface-2: oklch(0.22 0.025 20);
  --line: oklch(0.30 0.03 20);
  --ink: oklch(0.945 0.012 30);
  --muted: oklch(0.74 0.025 25);
  --primary: oklch(0.62 0.21 17);
  --primary-deep: oklch(0.45 0.16 15);
  --accent: oklch(0.86 0.11 85);
  --accent-dim: oklch(0.86 0.11 85 / 0.55);
  --paper: oklch(0.96 0.02 85);
  --paper-ink: oklch(0.28 0.03 40);
  --paper-muted: oklch(0.45 0.03 40);

  --font-display: 'Young Serif', ui-serif, Georgia, serif;
  --font-body: 'Alegreya Sans', system-ui, -apple-system, sans-serif;
  --font-script: 'Caveat', 'Segoe Script', cursive;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --z-toast: 40;
  --z-nav: 20;
  --z-gate: 50;
  --z-sim: 60;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.55;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* l'attribut hidden doit gagner contre tout display posé par une classe */
[hidden] { display: none !important; }

/* clavier : anneau or visible partout, sans doubler le focus souris */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* ---------- structure : colonne mobile, cadrée sur desktop ---------- */

.app { max-width: 27rem; margin: 0 auto; }

.view {
  padding: calc(1.25rem + var(--safe-t)) 1.375rem calc(6.5rem + var(--safe-b));
  min-height: 100dvh;
}

.view-head { margin: 1.5rem 0 1.75rem; }

.view-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.9rem, 7vw, 2.4rem);
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.view-sub { color: var(--muted); margin-top: 0.5rem; max-width: 34ch; }

/* ---------- ciel : étoiles, lune, lueur ---------- */

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

#stars { position: absolute; inset: 0; width: 100%; height: 100%; }

.moon {
  position: absolute;
  top: calc(3rem + var(--safe-t));
  right: 1.75rem;
  filter: drop-shadow(0 0 18px oklch(0.85 0.06 80 / 0.35));
}

.horizon-glow {
  position: absolute;
  left: 50%; bottom: -22vh;
  width: 130vw; height: 55vh;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at 50% 100%,
    oklch(0.34 0.11 20 / 0.55) 0%,
    oklch(0.22 0.06 18 / 0.28) 45%,
    transparent 72%);
  transition: background 1200ms var(--ease-out);
}

/* jour des retrouvailles : l'aube dorée remplace la braise — pic émotionnel */
.reunion .horizon-glow {
  background: radial-gradient(ellipse at 50% 100%,
    oklch(0.55 0.11 75 / 0.5) 0%,
    oklch(0.30 0.07 60 / 0.3) 45%,
    transparent 74%);
}

.reunion .count-num,
.reunion .count-cell:first-child .count-num { color: var(--accent); }

/* ---------- vue « ce soir » ---------- */

.hero { margin: 4.25rem 0 2.5rem; }

.hero-kicker {
  font-family: var(--font-script);
  font-weight: 500;
  font-size: 1.45rem;
  color: var(--accent);
  transform: rotate(-1.2deg);
  transform-origin: left;
}

.hero-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.4rem, 10vw, 3.1rem);
  line-height: 1.08;
  letter-spacing: -0.01em;
  margin-top: 0.5rem;
  text-wrap: balance;
}

.countdown { margin-top: 2.25rem; }

.count-grid {
  display: flex;
  align-items: baseline;
  gap: 1.1rem;
}

.count-cell { display: flex; flex-direction: column; align-items: center; min-width: 3.2rem; }

.count-num {
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 9vw, 2.9rem);
  line-height: 1;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.count-cell:first-child .count-num { color: oklch(0.68 0.21 17); font-size: clamp(2.6rem, 11vw, 3.6rem); }

.count-label {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.45rem;
}

.count-caption { color: var(--muted); margin-top: 0.9rem; }

.progress {
  margin-top: 1.9rem;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  min-width: 6px; /* une braise au départ : la jauge se lit comme une jauge même à 0 % */
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary-deep), var(--primary) 70%, var(--accent));
  transition: width 600ms var(--ease-out);
}

.progress-caption { color: var(--muted); font-size: 0.95rem; margin-top: 0.6rem; }

.tonight-card {
  margin-top: 2.4rem;
  padding: 1.4rem 1.5rem 1.5rem;
  background: oklch(0.17 0.02 17 / 0.82);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  backdrop-filter: blur(6px);
}

.tonight-label { color: var(--accent); font-weight: 500; margin-bottom: 0.9rem; }

.footer-note {
  margin-top: 3.5rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.footer-note .script {
  font-family: var(--font-script);
  font-size: 1.35rem;
  color: var(--accent);
  margin-left: 0.15rem;
}

/* ---------- boutons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.7rem 1.5rem;
  border-radius: 999px;
  font-weight: 700;
  transition: transform 180ms var(--ease-out), background-color 180ms var(--ease-out);
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary);
  color: oklch(0.98 0.005 17);
  box-shadow: 0 6px 24px oklch(0.62 0.21 17 / 0.32);
}

.btn-primary:hover { background: oklch(0.66 0.21 17); }

.btn-paper {
  background: var(--paper-ink);
  color: var(--paper);
}

/* ---------- vue « nos nuits » ---------- */

.prelude {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  padding: 1.05rem 1.2rem;
  margin-bottom: 1.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  transition: background-color 180ms var(--ease-out);
}

.prelude:hover { background: var(--surface-2); }

.prelude small { color: var(--muted); }

.prelude-seal {
  flex: none;
  width: 2.6rem; height: 2.6rem;
  display: grid; place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, oklch(0.68 0.21 17), var(--primary-deep));
  color: oklch(0.97 0.01 17);
  font-size: 1.1rem;
  box-shadow: 0 3px 10px oklch(0.45 0.16 15 / 0.5);
}

.nights {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.9rem;
}

.night {
  aspect-ratio: 1;
  width: 100%;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  border: 1px solid var(--line);
  color: var(--muted);
  background: transparent;
  transition: transform 200ms var(--ease-out), background-color 200ms var(--ease-out);
  position: relative;
}

.night .n { font-family: var(--font-display); font-size: 1.25rem; line-height: 1; }
.night .d { font-size: 0.62rem; letter-spacing: 0.02em; display: inline-flex; align-items: center; gap: 0.2em; }
.night .lk { width: 0.6rem; height: 0.6rem; opacity: 0.65; }

.night.is-open {
  background: oklch(0.86 0.11 85 / 0.12);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.night.is-today {
  background: var(--primary);
  border-color: transparent;
  color: oklch(0.98 0.005 17);
  animation: halo 2.6s ease-in-out infinite;
}

/* verrouillée : l'état est porté par la bordure éteinte + le cadenas,
   pas par une opacité qui rendrait le chiffre illisible le soir */

.night:not(.is-locked):hover { transform: scale(1.07); }

@keyframes halo {
  0%, 100% { box-shadow: 0 0 0 0 oklch(0.62 0.21 17 / 0.45); }
  50% { box-shadow: 0 0 0 11px oklch(0.62 0.21 17 / 0); }
}

/* ---------- vue « ouvre quand… » ---------- */

.envelopes {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.envelope {
  width: 100%;
  text-align: left;
  position: relative;
  padding: 1.15rem 1.25rem 1.15rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 1.05rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  overflow: hidden;
  transition: background-color 180ms var(--ease-out), transform 180ms var(--ease-out);
}

.envelope:hover { background: var(--surface-2); }
.envelope:active { transform: scale(0.985); }

.env-flap {
  flex: none;
  width: 3.4rem; height: 2.5rem;
  position: relative;
  border-radius: 0.45rem;
  background: linear-gradient(160deg, oklch(0.30 0.035 25), oklch(0.24 0.03 20));
  border: 1px solid var(--line);
}

.env-flap::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(0 0, 50% 62%, 100% 0);
  background: linear-gradient(180deg, oklch(0.36 0.04 25), oklch(0.28 0.03 20));
  border-radius: 0.45rem 0.45rem 0 0;
  transition: transform 420ms var(--ease-out);
  transform-origin: top;
}

.env-seal {
  position: absolute;
  left: 50%; top: 48%;
  transform: translate(-50%, -50%);
  width: 1.25rem; height: 1.25rem;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 0.62rem;
  background: radial-gradient(circle at 35% 30%, oklch(0.68 0.21 17), var(--primary-deep));
  color: oklch(0.97 0.01 17);
  box-shadow: 0 2px 6px oklch(0.45 0.16 15 / 0.55);
  transition: opacity 300ms var(--ease-out);
}

.envelope.is-opened .env-flap::before { transform: rotateX(158deg); }
.envelope.is-opened .env-seal { opacity: 0.25; }

.env-when { font-weight: 500; }
.env-state { display: block; color: var(--muted); font-size: 0.88rem; margin-top: 0.15rem; }

/* ---------- lettre ---------- */

.letter {
  border: 0;
  padding: 0;
  width: min(100vw, 30rem);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  background: transparent;
  margin: 0 auto;
}

.letter::backdrop { background: oklch(0.08 0.01 17 / 0.75); }

.letter-paper {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 85% -4%, oklch(0.93 0.045 75 / 0.9) 0%, transparent 34%),
    var(--paper);
  color: var(--paper-ink);
  padding: calc(2.2rem + var(--safe-t)) 1.75rem calc(2.2rem + var(--safe-b));
  display: flex;
  flex-direction: column;
  /* les lettres courtes se centrent au lieu de flotter en haut d'une page vide ;
     "safe" garantit que les longues restent scrollables depuis le haut */
  justify-content: safe center;
}

.letter-over {
  font-family: var(--font-script);
  font-weight: 500;
  font-size: 1.35rem;
  color: var(--primary-deep);
}

.letter-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.7rem, 6.5vw, 2.1rem);
  letter-spacing: -0.01em;
  margin: 0.4rem 0 1.4rem;
  text-wrap: balance;
}

.letter-body {
  font-size: 1.1rem;
  line-height: 1.65;
  max-width: 62ch;
  text-wrap: pretty;
  white-space: pre-line;
}

.letter-photo {
  margin-top: 1.5rem;
  width: 100%;
  border-radius: 0.9rem;
  box-shadow: 0 10px 30px oklch(0.28 0.03 40 / 0.25);
}

.letter-audio { margin-top: 1.5rem; width: 100%; }

.letter-video {
  margin-top: 1.5rem;
  width: 100%;
  border-radius: 0.9rem;
  box-shadow: 0 10px 30px oklch(0.28 0.03 40 / 0.25);
}

.letter-sign {
  font-family: var(--font-script);
  font-weight: 600;
  font-size: 1.7rem;
  color: var(--primary-deep);
  margin-top: 1.8rem;
  transform: rotate(-1.5deg);
}

.letter-close { margin-top: 2.5rem; align-self: flex-start; }

dialog.letter[open] .letter-paper { animation: letter-in 420ms var(--ease-out); }

@keyframes letter-in {
  from { opacity: 0; transform: translateY(26px); }
  to { opacity: 1; transform: none; }
}

/* ---------- gate ---------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: var(--z-gate);
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 50% 115%, oklch(0.30 0.10 20 / 0.5), transparent 60%),
    var(--bg);
  padding: 1.5rem;
}

.gate-inner { text-align: center; max-width: 20rem; }

.gate-heart {
  font-size: 2rem;
  color: var(--primary);
  animation: beat 1.8s ease-in-out infinite;
}

@keyframes beat {
  0%, 100% { transform: scale(1); }
  12% { transform: scale(1.18); }
  24% { transform: scale(1); }
}

.gate-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2.2rem;
  margin-top: 0.8rem;
}

.gate-sub { color: var(--muted); margin: 0.7rem 0 1.6rem; }

.prelock-count {
  font-family: var(--font-display);
  font-size: 2.1rem;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  margin: 0.2rem 0 1rem;
}

.gate-input {
  width: 100%;
  min-height: 52px;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.1rem;
  text-align: center;
  outline: none;
  transition: border-color 180ms var(--ease-out);
}

.gate-input::placeholder { color: var(--muted); }
.gate-input:focus { border-color: var(--primary); }

.gate-error { color: oklch(0.78 0.16 20); font-size: 0.95rem; margin-top: 0.7rem; }

.gate-btn { width: 100%; margin-top: 1rem; }

.gate.shake .gate-inner { animation: shake 380ms var(--ease-out); }

@keyframes shake {
  0%, 100% { transform: none; }
  25% { transform: translateX(-7px); }
  55% { transform: translateX(6px); }
  80% { transform: translateX(-3px); }
}

/* ---------- nav basse ---------- */

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 27rem;
  z-index: var(--z-nav);
  display: flex;
  padding: 0.4rem 0.6rem calc(0.5rem + var(--safe-b));
  background: oklch(0.14 0.018 17 / 0.88);
  backdrop-filter: blur(14px);
  border-top: 1px solid oklch(0.26 0.03 20 / 0.6);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.45rem 0;
  border-radius: 0.8rem;
  color: var(--muted);
  font-size: 0.78rem;
  transition: color 180ms var(--ease-out);
}

.tab svg { width: 22px; height: 22px; }

.tab.is-active { color: var(--accent); }

/* ---------- toast, bannières ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(6rem + var(--safe-b));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  font-size: 0.95rem;
  max-width: min(88vw, 24rem);
  text-align: center;
  animation: toast-in 260ms var(--ease-out);
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.sim-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: var(--z-sim);
  background: var(--accent);
  color: oklch(0.25 0.05 85);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  padding: 0.35rem 1rem calc(0.35rem);
}

/* notice discrète : elle ne doit jamais rivaliser avec le contenu émotionnel */
.install-hint {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(4.9rem + var(--safe-b));
  z-index: var(--z-toast);
  width: min(92vw, 25rem);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: oklch(0.14 0.018 17 / 0.85);
  border-radius: 0.6rem;
  padding: 0.35rem 0.2rem 0.35rem 0.9rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.install-hint p { flex: 1; }

.install-close {
  color: var(--muted);
  flex: none;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  margin: -0.6rem -0.7rem 0 0;
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- desktop : garder l'intimité d'une colonne ---------- */

@media (min-width: 48rem) {
  body { display: block; }
  .view { padding-top: 3rem; }
  .moon { right: calc(50vw - 13rem); }
}
