/* Registre des Naissances — royaume souterrain, encre d'os, lueur d'âme */

@font-face { font-family: "Cinzel"; src: url("/fonts/cinzel-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Cinzel"; src: url("/fonts/cinzel-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Cinzel"; src: url("/fonts/cinzel-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url("/fonts/alegreya-sans-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url("/fonts/alegreya-sans-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url("/fonts/alegreya-sans-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url("/fonts/alegreya-sans-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --abyss: #0a0e17;
  --abyss-2: #0e1321;      /* panneaux, barre d'onglets */
  --abyss-3: #141b2d;      /* champs */
  --stone: #1c2438;
  --ink: #e9edf3;          /* encre d'os */
  --ink-2: #a7b1c4;        /* texte secondaire */
  --ink-3: #7f8aa0;        /* texte tertiaire, >= 4.5:1 sur --abyss */
  --line: rgba(233, 237, 243, 0.1);
  --line-2: rgba(233, 237, 243, 0.2);
  --soul: #a9d2ff;         /* la seule lumière */
  --soul-deep: #5d8fc4;
  --danger: #e0806e;

  --fire: #e8946a;
  --earth: #a3bb83;
  --air: #c9cfdc;
  --water: #79b1e0;

  --display: "Cinzel", "Trajan Pro", Georgia, serif;
  --ui: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;

  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--abyss);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scrollbar-color: var(--stone) var(--abyss);
  scroll-padding-top: 150px;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-size: 1.0625rem;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

::selection { background: rgba(169, 210, 255, 0.28); color: #fff; }
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--abyss); }
::-webkit-scrollbar-thumb { background: var(--stone); border-radius: 10px; border: 2px solid var(--abyss); }

:focus-visible { outline: 2px solid var(--soul); outline-offset: 3px; border-radius: 6px; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Caverne ---------- */

.cavern { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.cavern::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(120% 60% at 20% 18%, rgba(93, 143, 196, 0.16), transparent 60%),
    radial-gradient(90% 50% at 85% 100%, rgba(93, 143, 196, 0.08), transparent 70%),
    var(--abyss);
}
.cavern svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.cavern-far path { fill: #111829; }
.cavern-near path { fill: #0c111d; }
.motes { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---------- Structure ---------- */

.app {
  position: relative; z-index: 1;
  max-width: 640px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) 20px calc(var(--tabbar-h) + var(--safe-b) + 32px);
}

.masthead { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.crest { width: 40px; height: 40px; flex: none; fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.masthead h1 {
  margin: 0; font-family: var(--display); font-weight: 600;
  font-size: 1.3125rem; letter-spacing: 0.04em; line-height: 1.15;
}
.masthead-sub { margin: 2px 0 0; color: var(--ink-3); font-size: 0.9375rem; }

#view:focus { outline: none; }

/* ---------- Lanterne ---------- */

.lantern {
  --heat: 0;
  position: relative;
  display: grid; grid-template-columns: 84px 1fr; gap: 16px; align-items: start;
  margin: 4px -20px 0; padding: 0 20px 22px;
  min-height: 176px;
}
.lantern::before {
  content: ""; position: absolute; left: -40px; top: -20px; width: 260px; height: 240px;
  background: radial-gradient(closest-side, rgba(169, 210, 255, calc(0.08 + var(--heat) * 0.22)), transparent);
  pointer-events: none;
}
.lantern-art { width: 84px; height: 160px; overflow: visible; }
.lantern-art .chain, .lantern-art .cage { fill: none; stroke: var(--ink-2); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.lantern-art .soul-glow { opacity: calc(0.25 + var(--heat) * 0.75); transform-origin: 45px 88px; }
.lantern-art .soul-core { fill: #f4f9ff; opacity: calc(0.35 + var(--heat) * 0.65); }
.lantern[data-state="empty"] .soul-glow { opacity: 0.08; }
.lantern[data-state="empty"] .soul-core { fill: var(--stone); opacity: 1; }
.lantern-swing { transform-origin: 45px 0; animation: swing 7s ease-in-out infinite alternate; }
.lantern-art .soul-glow { animation: breathe 3.6s ease-in-out infinite alternate; }

@keyframes swing { from { transform: rotate(-2.4deg); } to { transform: rotate(2.4deg); } }
@keyframes breathe { from { transform: scale(0.92); } to { transform: scale(1.06); } }

.lantern-text { position: relative; padding-top: 44px; min-width: 0; }
.lantern-name {
  margin: 0; font-family: var(--display); font-weight: 700;
  font-size: 1.875rem; line-height: 1.1; letter-spacing: 0.01em;
  text-wrap: balance; overflow-wrap: anywhere;
  text-shadow: 0 0 calc(var(--heat) * 24px) rgba(169, 210, 255, 0.45);
}
.lantern-when { margin: 8px 0 0; font-size: 1.125rem; color: var(--ink); }
.lantern-when strong { color: var(--soul); font-weight: 700; }
.lantern-meta { margin: 4px 0 0; color: var(--ink-2); font-size: 0.9375rem; }
.lantern-text .btn-primary { margin-top: 14px; width: auto; padding-inline: 18px; }

/* ---------- Contrôles ---------- */

.controls {
  position: sticky; top: 0; z-index: 5;
  margin: 0 -20px; padding: 12px 20px 10px;
  background: transparent;
  transition: background-color 200ms var(--ease-out), box-shadow 200ms var(--ease-out);
}
.controls[data-stuck] {
  background: var(--abyss);
  box-shadow: 0 10px 18px -12px rgba(0, 0, 0, 0.9), 0 1px 0 var(--line);
  display: grid; gap: 10px;
}

.segmented {
  display: grid; grid-template-columns: 1fr 1fr;
  padding: 3px; border-radius: 12px;
  background: var(--abyss-2); border: 1px solid var(--line);
}
.segmented button {
  min-height: 40px; border: 0; border-radius: 9px; background: transparent;
  color: var(--ink-2); font-weight: 500; font-size: 1rem;
  transition: background-color 180ms var(--ease-out), color 180ms var(--ease-out);
}
.segmented button[aria-checked="true"] { background: var(--stone); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.05); }
@media (hover: hover) { .segmented button[aria-checked="false"]:hover { color: var(--ink); } }

.search { position: relative; display: block; }
.search svg { position: absolute; left: 12px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); fill: none; stroke: var(--ink-3); stroke-width: 1.8; stroke-linecap: round; }
.search input {
  width: 100%; min-height: 44px; padding: 0 14px 0 40px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--abyss-2);
  font-size: 1rem; caret-color: var(--soul);
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { outline: none; border-color: var(--soul-deep); box-shadow: 0 0 0 3px rgba(169, 210, 255, 0.15); }
.search input::-webkit-search-cancel-button { filter: invert(0.7); }

.chips { margin-top: 2px; }
.chip-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.chips[data-mode="sign"] .chip-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.chip {
  display: grid; justify-items: center; align-content: center; gap: 1px;
  min-height: 50px; padding: 6px 2px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(14, 19, 33, 0.6); color: var(--ink-2);
  font-size: 0.875rem; line-height: 1.15; white-space: nowrap;
  transition: border-color 160ms var(--ease-out), color 160ms var(--ease-out), background-color 160ms var(--ease-out);
}
.chips[data-mode="sign"] .chip { min-height: 64px; }
.chip svg { width: 20px; height: 20px; margin-bottom: 2px; }
.chip-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.chip .chip-count { color: var(--ink-3); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.chip-reset {
  display: block; width: 100%; margin-top: 8px; min-height: 40px; padding: 0 12px;
  border-radius: 10px; border: 1px solid var(--line); background: transparent;
  color: var(--ink); font-weight: 500; font-size: 0.9375rem;
}
.chip-reset span { color: var(--ink-3); font-weight: 400; }
@media (hover: hover) { .chip-reset:hover { border-color: var(--line-2); } }
.chip[aria-pressed="true"] { border-color: var(--soul-deep); background: rgba(93, 143, 196, 0.16); color: var(--ink); }
.chip[aria-pressed="true"] .chip-count { color: var(--soul); }
.chip:disabled { opacity: 0.4; cursor: default; }
@media (hover: hover) { .chip:not(:disabled):hover { border-color: var(--line-2); color: var(--ink); } }

/* ---------- Registre ---------- */

.ledger { margin-top: 6px; }

.group { margin-top: 26px; }
.group:first-child { margin-top: 12px; }
.group-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
  margin: 0 0 6px;
}
.group-head h3 {
  margin: 0; display: flex; align-items: center; gap: 8px;
  font-family: var(--display); font-weight: 600; font-size: 1.0625rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink);
}
.group-head h3 svg { width: 20px; height: 20px; }
.group-head .flourish { height: 10px; width: 100%; fill: none; stroke: var(--line-2); stroke-width: 1.2; stroke-linecap: round; }
.group-head .flourish-r { transform: scaleX(-1); }
.group-current h3::after {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--soul);
}

.group-range { margin: -4px 0 4px; text-align: center; color: var(--ink-3); font-size: 0.875rem; }

.rows { list-style: none; margin: 0; padding: 0; }
.row { border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row a {
  --heat: 0;
  display: grid; grid-template-columns: 44px 1fr auto; gap: 14px; align-items: center;
  min-height: 68px; padding: 10px 6px; margin: 0 -6px; border-radius: 10px;
  color: inherit; text-decoration: none;
  transition: background-color 160ms var(--ease-out);
}
@media (hover: hover) { .row a:hover { background: rgba(233, 237, 243, 0.04); } }
.row a:active { background: rgba(233, 237, 243, 0.06); }

.row-name {
  margin: 0; font-family: var(--display); font-weight: 600; font-size: 1.0625rem;
  line-height: 1.2; letter-spacing: 0.01em; overflow-wrap: anywhere;
}
.row-meta { margin: 2px 0 0; color: var(--ink-2); font-size: 0.9375rem; }
.row-note { margin: 2px 0 0; color: var(--ink-3); font-size: 0.875rem; font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.row-text { min-width: 0; }
.row-when { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-days { display: block; font-weight: 700; font-size: 1rem; color: var(--ink-2); }
.row-age { display: block; font-size: 0.875rem; color: var(--ink-3); }
.row a[data-soon] .row-days { color: var(--soul); }
.row a[data-today] .row-days { color: #f4f9ff; text-shadow: 0 0 12px rgba(169, 210, 255, 0.8); }

/* Médaillon du signe */
.medallion {
  --tint: var(--air);
  position: relative; display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #1a2236, var(--abyss) 75%);
  border: 1px solid color-mix(in srgb, var(--tint) 45%, transparent);
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.5),
    0 0 calc(var(--heat, 0) * 22px) calc(var(--heat, 0) * 2px) rgba(169, 210, 255, calc(var(--heat, 0) * 0.55));
  flex: none;
}
.medallion svg { width: 24px; height: 24px; }
.glyph { fill: none; stroke: var(--tint); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.medallion.is-empty { border-style: dashed; border-color: var(--line-2); }
[data-el="fire"] { --tint: var(--fire); }
[data-el="earth"] { --tint: var(--earth); }
[data-el="air"] { --tint: var(--air); }
[data-el="water"] { --tint: var(--water); }

/* États vides et chargement */
.empty {
  margin: 36px 0 0; text-align: center; color: var(--ink-2);
  display: grid; justify-items: center; gap: 6px;
}
.empty svg { width: 56px; height: 56px; fill: none; stroke: var(--ink-3); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 6px; }
.empty p { margin: 0; max-width: 32ch; }
.empty .empty-title { font-family: var(--display); font-size: 1.125rem; color: var(--ink); }
.empty button { margin-top: 10px; }

.skeleton { display: grid; gap: 14px; margin-top: 22px; }
.skeleton span {
  display: block; height: 52px; border-radius: 10px;
  background: linear-gradient(90deg, var(--abyss-2), var(--abyss-3), var(--abyss-2));
  background-size: 200% 100%; animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Formulaire ---------- */

.view-form { padding-top: 18px; }
.form-title { margin: 0; font-family: var(--display); font-weight: 700; font-size: 1.75rem; line-height: 1.15; text-wrap: balance; }
.form-intro { margin: 6px 0 0; color: var(--ink-2); }

.preview {
  display: flex; align-items: center; gap: 14px;
  margin: 22px 0 8px; padding: 14px 16px;
  border-radius: 14px; background: var(--abyss-2); border: 1px solid var(--line);
}
.preview .medallion { width: 52px; height: 52px; }
.preview .medallion svg { width: 28px; height: 28px; }
.preview p { margin: 0; }
.preview-name { font-family: var(--display); font-weight: 600; font-size: 1.125rem; overflow-wrap: anywhere; }
.preview-name.is-placeholder { color: var(--ink-3); }
.preview-meta { color: var(--ink-2); font-size: 0.9375rem; }

.form { display: grid; gap: 16px; margin-top: 16px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 96px 1fr; gap: 12px; }
.field label { font-weight: 500; font-size: 0.9375rem; color: var(--ink-2); }
.optional { color: var(--ink-3); font-weight: 400; font-style: italic; margin-left: 4px; }

.field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border-radius: 12px; border: 1px solid var(--line-2); background: var(--abyss-3);
  font-size: 1rem; caret-color: var(--soul);
  transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}
.field select {
  appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a7b1c4' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 20px;
}
.field select option { background: var(--abyss-3); color: var(--ink); }
.field textarea { resize: vertical; min-height: 88px; line-height: 1.4; }
.field input::placeholder, .field textarea::placeholder { color: var(--ink-3); }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--soul-deep); box-shadow: 0 0 0 3px rgba(169, 210, 255, 0.15);
}
.field [aria-invalid="true"] { border-color: var(--danger); }

.form-error { margin: 0; color: var(--danger); font-weight: 500; }

.btn-primary {
  width: 100%; min-height: 50px; padding: 0 20px; border-radius: 12px;
  border: 1px solid rgba(244, 249, 255, 0.6);
  background: linear-gradient(#e9f2fd, #c6dcf3);
  color: #0b1424; font-weight: 700; font-size: 1.0625rem; letter-spacing: 0.01em;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.8), 0 2px 4px rgba(0, 0, 0, 0.4);
  transition: transform 120ms var(--ease-out), box-shadow 160ms var(--ease-out), opacity 160ms;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }
@media (hover: hover) { .btn-primary:not(:disabled):hover { background: linear-gradient(#f4f9ff, #d3e5f7); } }

.form-secondary { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.btn-ghost, .btn-danger {
  min-height: 44px; padding: 0 14px; border-radius: 10px;
  background: transparent; border: 1px solid var(--line); font-weight: 500;
}
.btn-ghost { color: var(--ink-2); }
.btn-danger { color: var(--danger); border-color: rgba(224, 128, 110, 0.35); }
.btn-danger[data-armed] { background: rgba(224, 128, 110, 0.14); border-color: var(--danger); }
@media (hover: hover) {
  .btn-ghost:hover { color: var(--ink); border-color: var(--line-2); }
  .btn-danger:hover { border-color: var(--danger); }
}

/* ---------- Barre d'onglets ---------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr 1fr;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--abyss-2); border-top: 1px solid var(--line);
}
.tabbar a {
  display: grid; place-content: center; justify-items: center; gap: 2px;
  color: var(--ink-3); text-decoration: none; font-size: 0.8125rem; font-weight: 500;
  -webkit-user-select: none; user-select: none;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--ink); }
.tabbar a[aria-current="page"] svg { stroke: var(--soul); }

/* ---------- Toast ---------- */

.toast {
  position: fixed; left: 50%; z-index: 20;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  max-width: min(92vw, 420px); padding: 12px 16px; border-radius: 12px;
  background: var(--stone); border: 1px solid var(--line-2); color: var(--ink);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.8);
  transform: translateX(-50%); animation: toast-in 220ms var(--ease-out);
}
.toast[data-tone="error"] { border-color: rgba(224, 128, 110, 0.6); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Transitions de vue ---------- */

::view-transition-old(root), ::view-transition-new(root) { animation-duration: 200ms; animation-timing-function: var(--ease-out); }

/* ---------- Grand écran ---------- */

@media (min-width: 720px) {
  .app { padding-top: 40px; }
  .masthead h1 { font-size: 1.625rem; }
  .lantern { grid-template-columns: 110px 1fr; min-height: 200px; }
  .lantern-art { width: 110px; height: 200px; }
  .lantern-name { font-size: 2.5rem; }
  .tabbar { left: 50%; right: auto; width: 360px; bottom: 16px; transform: translateX(-50%); border: 1px solid var(--line); border-radius: 16px; height: var(--tabbar-h); padding: 0; box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.8); }
  .toast { bottom: calc(var(--tabbar-h) + 30px); }
}

@media (prefers-reduced-motion: reduce) {
  .lantern-swing, .lantern-art .soul-glow, .skeleton span { animation: none; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  .toast { animation: none; }
}
