:root {
  /* Couleurs système iOS (variantes lisibles sur fond clair). */
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #ececf0;
  --text: #000000;
  --muted: #6c6c70;
  --line: #c6c6c8;
  --accent: #0066dd;
  --accent-text: #ffffff;
  --ok: #248a3d;
  --warn: #b25000;
  --danger: #d70015;
  --stage: radial-gradient(circle at 50% 45%, #e5e5ea 0%, #f2f2f7 70%);
  --material: rgba(249, 249, 249, 0.78);
  --radius: 12px;
  --spring: cubic-bezier(0.32, 0.72, 0, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #ffffff;
    --muted: #98989f;
    --line: #38383a;
    --accent: #0a84ff;
    --accent-text: #ffffff;
    --ok: #30d158;
    --warn: #ff9f0a;
    --danger: #ff453a;
    --stage: radial-gradient(circle at 50% 45%, #1c1c1e 0%, #000000 70%);
    --material: rgba(22, 22, 24, 0.78);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0.6em 0 0.4em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.02rem; }
h4 { font-size: 0.92rem; color: var(--muted); }
p { margin: 0.4em 0; }
blockquote { margin: 0.6em 0; padding: 0.6em 0.9em; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 10px 10px 0; white-space: pre-wrap; }
pre { white-space: pre-wrap; word-break: break-word; font-size: 0.8rem; }
.pre { white-space: pre-wrap; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; word-break: break-all; }
.small { font-size: 0.85rem; }
.big { font-size: 1.15rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.private { color: var(--warn); font-style: italic; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.mode { font-size: 0.72rem; letter-spacing: 0.08em; padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.mode.reel { color: var(--ok); border-color: var(--ok); }
.stop {
  font-weight: 800; letter-spacing: 0.08em; font-size: 0.85rem;
  background: var(--danger); color: #fff; border: 0; border-radius: 99px;
  padding: 9px 18px; min-height: 40px; cursor: pointer;
}
.stop.stopped { background: var(--surface-2); color: var(--danger); border: 1px solid var(--danger); }

.main { max-width: 720px; margin: 0 auto; padding: 0 16px 24px; }
.screen { display: flex; flex-direction: column; gap: 14px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { text-align: center; padding: 14px 2px; font-size: 0.8rem; color: var(--muted); text-decoration: none; }
.tabbar a.active { color: var(--accent); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card.inner { background: var(--surface-2); border: 0; margin: 10px 0; }
.card > h2:first-child { margin-top: 0; }

.stage { background: var(--stage); border-radius: 22px; padding: 8px 0 16px; text-align: center; }
.creature-host { width: min(78vw, 360px); aspect-ratio: 1; margin: 0 auto; }
.creature-host.big { width: min(86vw, 70vh, 520px); }
.creature { width: 100%; height: 100%; overflow: visible; }
.stage-name { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.stage-name h1 { width: 100%; margin: 0 0 4px; }

.badge { display: inline-block; font-size: 0.75rem; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.mood-eveil { color: var(--accent); border-color: var(--accent); }
.mood-reflexion { color: var(--accent); }
.mood-fragilite, .mood-arret { color: var(--danger); border-color: var(--danger); }
.st-valide { color: var(--ok); border-color: var(--ok); }
.st-a_confirmer { color: var(--warn); border-color: var(--warn); }

.gauges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 480px) { .gauges { grid-template-columns: repeat(2, 1fr); } }
.gauge { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.gauge-label { font-size: 0.8rem; color: var(--muted); }
.gauge-value { font-weight: 600; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 6px 0 2px; }
.bar span { display: block; height: 100%; background: var(--accent); }

.notices { display: flex; flex-direction: column; gap: 8px; }
.notice { padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 0.92rem; }
.notice .btn, .notice .row { margin-top: 8px; }
.notice.warn { border-color: var(--warn); }
.notice.danger { border-color: var(--danger); }
.notice.ok { border-color: var(--ok); }
.notice.soft { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 0.95rem; text-decoration: none; cursor: pointer;
}
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; }
.btn.big { min-height: 56px; padding: 14px 28px; font-size: 1.1rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.busy::after { content: ''; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; margin: 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

.input {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 6px 0;
}
.row .input { flex: 1 1 140px; width: auto; }
.input.small { width: auto; font-size: 0.85rem; padding: 6px 10px; }
.letter { font-family: Georgia, "Times New Roman", serif; line-height: 1.6; }
.field { display: block; font-size: 0.85rem; color: var(--muted); margin: 8px 0; }

.list { padding-left: 1.2em; margin: 0.4em 0; }
.list li { margin: 0.3em 0; }
.list li.rejected, .rejected { opacity: 0.6; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { font: inherit; font-size: 0.85rem; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; text-align: left; }
.fold summary { cursor: pointer; color: var(--muted); margin: 8px 0; }
.tabs { display: flex; gap: 6px; }
.tabs a { padding: 8px 14px; border-radius: 99px; text-decoration: none; color: var(--muted); border: 1px solid var(--line); }
.tabs a.active { color: var(--accent); border-color: var(--accent); }

.phases { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
.phases li { font-size: 0.75rem; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.phases li span { font-weight: 700; }
.phases li.done { color: var(--ok); border-color: var(--ok); }
.phases li.current { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }

.missions, .clauses, .journal { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.missions a { display: block; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); color: var(--text); text-decoration: none; }
.clause { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.clause.rejetee { opacity: 0.65; }
.memories { display: flex; flex-direction: column; gap: 10px; }
.memory { padding: 12px; border-radius: 12px; background: var(--surface-2); }
.memory.archive { opacity: 0.6; }
.entry { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border-left: 3px solid var(--line); }
.entry.actor-melo { border-left-color: var(--accent); }
.entry.actor-entite { border-left-color: var(--ok); }
.entry.actor-miroir { border-left-color: var(--warn); }
.entry.focus { outline: 2px solid var(--accent); }
.entry.broken { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface-2)); }
.seq { font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; color: var(--muted); }
.result { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.constitution { font-size: 0.88rem; max-height: 60vh; overflow: auto; background: var(--surface-2); padding: 12px; border-radius: 12px; }

.spaces { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.space { padding: 10px; border-radius: 12px; border: 1px solid var(--line); }
.space.open { border-color: var(--accent); }
.space.locked { opacity: 0.55; }
.space-name { font-weight: 600; font-size: 0.9rem; }

.reveal-wait { text-align: center; padding: 10px 0; }
.reveal {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px;
  transition: opacity 1.2s;
}
.reveal.fade { opacity: 0; }
.reveal-name, .reveal-words { opacity: 0; transition: opacity 2.5s; text-align: center; max-width: 560px; }
.reveal-name { font-size: 2.2rem; letter-spacing: 0.04em; }
.reveal-words { font-size: 1.15rem; }
.reveal-words.soft { color: var(--muted); }
.reveal .show { opacity: 1; }
body.revealing .topbar, body.revealing .tabbar { visibility: hidden; }

.modal { position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, 0.45); display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
@media (min-width: 600px) { .modal { align-items: center; } }
.modal-card { background: var(--surface); border-radius: 18px; padding: 18px; width: 100%; max-width: 480px; max-height: 85vh; overflow: auto; }
.modal-card h3 { margin-top: 0; }
.modal[hidden] { display: none; }
.sheet { align-items: flex-end; padding: 0; }
.sheet .modal-card { max-width: 720px; border-radius: 18px 18px 0 0; max-height: 82dvh; padding-bottom: calc(18px + env(safe-area-inset-bottom)); animation: rise 0.2s ease-out; }
.sheet .modal-card h3 { margin: 0; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

/* Foyer : tout tient sur un écran, le détail s'ouvre en fenêtre. */
.home { gap: 10px; }
.home .stage { padding: 4px 0 10px; }
.home .creature-host { width: min(62vw, 34dvh, 300px); }
.home .stage-name h1 { font-size: 1.35rem; }
.home .gauges { grid-template-columns: repeat(4, 1fr); gap: 6px; }
.home .gauge { padding: 6px 8px; }
.home .gauge-label { font-size: 0.72rem; }
.home .gauge .small { font-size: 0.72rem; }
.next { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.next p { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

/* Écrans à liste : la page ne défile pas, seule la liste défile dans sa carte. */
.fit { gap: 10px; height: 100%; }
.fit > .card:last-of-type { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.fit .scroll { flex: 1; min-height: 0; overflow-y: auto; }
.fit .card > h2:first-child { margin: 0 0 6px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tile { min-height: 64px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 0.95rem; text-align: left; cursor: pointer; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 300;
  max-width: 560px; margin: 0 auto; padding: 12px 14px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 0.92rem;
  opacity: 0; transform: translateY(10px); transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ——— Toucher et matières façon iOS ——— */
html { -webkit-tap-highlight-color: transparent; }
body { font-family: -apple-system, "SF Pro Text", system-ui, sans-serif; font-size: 17px; letter-spacing: -0.01em; overscroll-behavior-y: none; }
h1 { font-weight: 700; letter-spacing: -0.02em; }
button, a, .tile, .chip, summary { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.btn, .tile, .chip, .tabbar a, .stop, .close { transition: transform 0.15s var(--spring), opacity 0.15s; }
.btn:active, .tile:active, .chip:active, .stop:active, .close:active { transform: scale(0.96); opacity: 0.7; }
.btn.primary { font-weight: 600; }
.card { border: 0; }
.gauge, .notice, .space, .tile { border-color: transparent; background: var(--surface); }
.scroll, .modal-card { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

.topbar, .tabbar { background: var(--material); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); }
.topbar { border-bottom: 0.5px solid var(--line); }
.tabbar { border-top: 0.5px solid var(--line); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 2px 5px; font-size: 0.62rem; font-weight: 500; }
.tabbar svg { width: 26px; height: 26px; }
.tabbar a:active { opacity: 0.6; }

/* Fenêtres : poignée, ressort d'iOS, fermeture en glissant. */
.sheet { background: rgba(0, 0, 0, 0.35); animation: fade 0.28s ease-out; }
.sheet .modal-card { animation: slide-up 0.38s var(--spring); transition: transform 0.28s var(--spring); padding-top: 8px; }
.sheet.closing { animation: fade 0.28s ease-in reverse forwards; }
.sheet.closing .modal-card { transform: translateY(105%) !important; }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.close { width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--muted); font-size: 0.8rem; font-weight: 700; cursor: pointer; }
@keyframes slide-up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* Passage d'un onglet à l'autre en fondu (Safari 18+). */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 0.2s; }

/* Foyer adaptatif : la créature prend la place qui reste, du petit iPhone à l'iPad. */
.home { height: 100%; }
.home .stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.home .creature-host { flex: 1 1 0; min-height: 64px; max-height: 320px; width: auto; max-width: 100%; aspect-ratio: 1; }
.home > :not(.stage) { flex-shrink: 0; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (orientation: landscape) and (max-height: 500px) {
  .home .stage-name h1 { font-size: 1.1rem; }
}

/* Plus de barre d'onglets : les espaces sont en orbite autour de la créature. */
.home .stage { position: relative; }
.orbit { position: absolute; inset: 10px; pointer-events: none; z-index: 1; }
.moon {
  position: absolute; pointer-events: auto; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text); text-decoration: none; font-size: 0.7rem; font-weight: 500;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
  transition: transform 0.15s var(--spring), opacity 0.15s;
  animation: float 6s ease-in-out infinite;
}
.moon svg { width: 46px; height: 46px; padding: 11px; border-radius: 50%; background: var(--material); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08); color: var(--accent); }
.moon:active { transform: scale(0.92); opacity: 0.7; }
.moon:nth-child(1) { top: 0; left: 0; }
.moon:nth-child(2) { top: 0; right: 0; }
.moon:nth-child(3) { bottom: 0; left: 0; }
.moon:nth-child(4) { bottom: 0; right: 0; }
@keyframes float { 50% { translate: 0 -4px; } }
.back { font-size: 1.05rem; color: var(--accent); text-decoration: none; padding: 8px 4px; }
.back[hidden] { display: none; }
.topbar .mode { margin-right: auto; margin-left: 10px; }

/* L'app épouse l'écran : barre du haut, puis la zone principale prend tout le reste.
   Pas de hauteur calculée à la main, donc juste sur chaque iPhone et iPad. */
html, body { height: 100%; }
body { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
.topbar { flex: none; }
.main { flex: 1; min-height: 0; width: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.screen { min-height: 100%; }
.moon { width: 72px; }
