:root {
  --bg: #0e0c0a;
  --surface: #181310;
  --surface-2: #211a14;
  --text: #f3ede2;
  --text-muted: #a2968a;
  --accent: #e2a95d;
  --accent-deep: #c9822e;
  --border: rgba(255, 225, 180, 0.10);
  --glass-bg: rgba(24, 19, 15, 0.55);
  --radius: 16px;
  --app-w: 480px;
  --tier-0: #1a1511;
  --tier-1: #38291a;
  --tier-2: #6b4620;
  --tier-3: #a86e2a;
  --tier-4: #e2a95d;
}

* { box-sizing: border-box; }

/* Garantit que [hidden] gagne toujours, quelle que soit la spécificité d'une règle display: ailleurs */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

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

input, select, textarea {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
textarea { resize: none; }

.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  backdrop-filter: blur(20px) saturate(1.2);
  border: 1px solid var(--border);
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(20px + env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
  position: relative;
  background: var(--bg);
  max-width: var(--app-w);
  margin-left: auto;
  margin-right: auto;
}

.fullbleed-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}
.fullbleed-scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(180deg, rgba(14,12,10,0.30) 0%, rgba(14,12,10,0.55) 60%, rgba(14,12,10,0.85) 100%);
}

.error { color: #d08770; font-size: 14px; margin: 0; }

/* ---- Login ---- */
#screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
}
#login-form {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  border-radius: 24px;
  padding: 28px 22px;
}
#login-form h1 {
  font-weight: 400;
  font-size: 26px;
  letter-spacing: 0.12em;
  margin: 0 0 6px;
  color: var(--text);
}
#login-form input { background: rgba(14,12,10,0.5); }

/* ---- Boutons ---- */
.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, #ecb96e 0%, #c9822e 100%);
  color: #231507;
  font-weight: 600;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 15px;
  box-shadow: 0 8px 28px rgba(226, 169, 93, 0.22);
  transition: opacity 200ms, transform 150ms;
}
.primary-btn:active { opacity: 0.85; transform: scale(0.99); }
.primary-btn:disabled { opacity: 0.5; }

.link-btn {
  color: var(--accent);
  font-size: 14px;
  padding: 10px 8px;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  position: relative;
  z-index: 2;
}
.topbar h1 {
  font-size: 19px;
  font-weight: 400;
  letter-spacing: 0.1em;
  margin: 0;
  color: var(--text);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.icon-btn {
  font-size: 17px;
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.streak-badge {
  font-size: 14px;
  font-weight: 600;
  padding: 6px 13px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ecb96e, #c9822e);
  color: #231507;
  transition: background 200ms, color 200ms;
}
.streak-badge.at-stake {
  background: rgba(24, 19, 15, 0.5);
  color: var(--accent);
  border: 1px solid var(--border);
}

/* ---- Accueil ---- */
#screen-home { overflow: hidden; }
.home-glow {
  position: absolute;
  top: -180px;
  left: 50%;
  transform: translateX(-50%);
  width: 560px;
  height: 420px;
  background: radial-gradient(ellipse at center, rgba(226, 169, 93, 0.13) 0%, transparent 65%);
  pointer-events: none;
  z-index: 0;
}
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  position: relative;
  z-index: 1;
}
.month-nav button {
  font-size: 20px;
  color: var(--text-muted);
  padding: 6px 14px;
  transition: color 200ms;
}
.month-nav button:active { color: var(--accent); }
#month-label {
  font-size: 15px;
  color: var(--text);
  text-transform: capitalize;
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 6px;
  position: relative;
  z-index: 1;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  position: relative;
  z-index: 1;
}
.day-cell {
  aspect-ratio: 1;
  border-radius: 12px;
  background: var(--tier-0);
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 150ms;
}
.day-cell:active { transform: scale(0.92); }
.day-cell.empty { background: transparent; }
.day-cell.tier-1 { background: var(--tier-1); color: var(--text); }
.day-cell.tier-2 { background: var(--tier-2); color: var(--text); }
.day-cell.tier-3 { background: var(--tier-3); color: #1c120a; font-weight: 600; }
.day-cell.tier-4 { background: var(--tier-4); color: #231507; font-weight: 600; box-shadow: 0 0 18px rgba(226,169,93,0.25); }
.day-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.day-cell.tier-4.today { box-shadow: inset 0 0 0 2px #fff3e0, 0 0 18px rgba(226,169,93,0.25); }

.fab {
  position: fixed;
  right: max(20px, calc((100vw - var(--app-w)) / 2 + 20px));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ecb96e, #c9822e);
  color: #231507;
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 32px rgba(226, 169, 93, 0.35);
  transition: transform 150ms;
  z-index: 5;
}
.fab:active { transform: scale(0.92); }

/* ---- Sheets ---- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 6, 4, 0.55);
  z-index: 10;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: var(--app-w);
  margin-left: auto;
  margin-right: auto;
  z-index: 11;
  border-radius: 22px 22px 0 0;
  border-bottom: none;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
  max-height: 82vh;
  overflow-y: auto;
  animation: sheet-in 220ms ease-out;
}
@keyframes sheet-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 6px auto 14px;
}
.sheet h2 {
  font-size: 17px;
  font-weight: 500;
  text-transform: capitalize;
  margin: 0 0 14px;
}

.session-row {
  display: grid;
  grid-template-columns: 44px auto 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 13px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.session-row:last-child { border-bottom: none; }
.session-time { color: var(--text-muted); font-size: 13px; }
.session-type { color: var(--accent); font-size: 13px; }
.session-title { font-size: 14px; }
.session-duration { color: var(--text-muted); font-size: 13px; }

.add-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

/* ---- Détail séance ---- */
.detail-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
}
.detail-why {
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  margin: 0 0 18px;
}
.detail-step { margin-bottom: 18px; }
.detail-step h3 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 6px;
}
.detail-step p {
  font-size: 14px;
  line-height: 1.65;
  margin: 0;
  white-space: pre-line;
}
#detail-note {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 14px;
  white-space: pre-line;
}

/* ---- Nouvelle méditation ---- */
#screen-new h1 {
  font-size: 21px;
  font-weight: 400;
  margin: 4px 0 18px;
}
.mode-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-radius: var(--radius);
  padding: 4px;
}
.mode-btn {
  flex: 1;
  padding: 10px;
  border-radius: calc(var(--radius) - 5px);
  color: var(--text-muted);
  font-size: 14px;
  transition: background 200ms, color 200ms;
}
.mode-btn.active {
  background: linear-gradient(135deg, #ecb96e, #c9822e);
  color: #231507;
  font-weight: 600;
}

#guide-feeling {
  width: 100%;
  margin-bottom: 20px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

/* Cartes de types — artwork + nom + description concrète */
.type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.type-card {
  position: relative;
  aspect-ratio: 4 / 5;
  border-radius: 18px;
  overflow: hidden;
  text-align: left;
  border: 1px solid var(--border);
  padding: 0;
  transition: transform 150ms, border-color 200ms, box-shadow 200ms;
  background: var(--surface-2);
}
.type-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 300ms;
}
.type-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(14,12,10,0) 30%, rgba(14,12,10,0.55) 65%, rgba(14,12,10,0.92) 100%);
}
.type-card .type-card-text {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 11px;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.type-card .type-card-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.type-card .type-card-desc {
  font-size: 11.5px;
  line-height: 1.35;
  color: rgba(243, 237, 226, 0.75);
}
.type-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 8px 30px rgba(226,169,93,0.25);
  transform: scale(0.985);
}
.type-card.active .type-card-label { color: var(--accent); }

#direct-subject {
  width: 100%;
  margin: 4px 0 20px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.duration-row {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}
.duration-row button {
  flex: 1;
  padding: 11px 0;
  border-radius: 14px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-muted);
  transition: background 200ms, color 200ms;
}
.duration-row button.active {
  background: linear-gradient(135deg, #ecb96e, #c9822e);
  border-color: transparent;
  color: #231507;
  font-weight: 600;
}

/* Carte préset Universal One */
.preset-card {
  position: relative;
  display: flex;
  align-items: flex-end;
  width: 100%;
  height: 92px;
  margin-top: 22px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
  padding: 0;
  text-align: left;
  background: var(--surface-2);
  transition: transform 150ms;
}
.preset-card:active { transform: scale(0.985); }
.preset-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.preset-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(14,12,10,0.85) 0%, rgba(14,12,10,0.35) 60%, rgba(14,12,10,0.15) 100%);
}
.preset-card-text {
  position: relative;
  z-index: 1;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.preset-card-title { font-size: 15px; font-weight: 600; }
.preset-card-desc { font-size: 12px; color: rgba(243, 237, 226, 0.75); }

/* ---- Génération ---- */
#screen-generating {
  display: flex;
  align-items: center;
  justify-content: center;
}
.breathing-orb {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  animation: breathe 4.5s ease-in-out infinite;
  box-shadow: 0 0 70px rgba(226, 169, 93, 0.35);
}
@keyframes breathe {
  0%, 100% { transform: scale(0.86); box-shadow: 0 0 40px rgba(226,169,93,0.20); }
  50% { transform: scale(1.12); box-shadow: 0 0 90px rgba(226,169,93,0.45); }
}

/* ---- Aperçu ---- */
.has-hero { padding-top: 0; }
.hero {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 44vh;
  z-index: 0;
  overflow: hidden;
}
.hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.hero-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(14,12,10,0.25) 0%, rgba(14,12,10,0.35) 55%, var(--bg) 100%);
}
.over-hero { padding-top: calc(20px + env(safe-area-inset-top)); }
.hero-spacer { height: calc(30vh - 60px); }
#preview-title {
  position: relative;
  z-index: 1;
  font-size: 26px;
  font-weight: 400;
  margin: 4px 0 10px;
}
.outline-card {
  position: relative;
  z-index: 1;
  border-radius: 18px;
  padding: 4px 16px;
  margin-bottom: 24px;
}
.outline-row {
  display: flex;
  justify-content: space-between;
  padding: 13px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.outline-row:last-child { border-bottom: none; }
.outline-minutes { color: var(--text-muted); }
#preview-why { position: relative; z-index: 1; }
.preview-eyebrow {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.preview-type {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--accent);
}
.preview-eyebrow .fallback-badge { margin-bottom: 0; }
.fallback-badge {
  position: relative;
  z-index: 1;
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
  margin-bottom: 8px;
  background: var(--glass-bg);
}
#preview-start { position: relative; z-index: 1; }

/* ---- Player ---- */
#screen-player {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.player-scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(180deg, rgba(14,12,10,0.15) 0%, rgba(14,12,10,0.35) 45%, rgba(14,12,10,0.88) 78%, var(--bg) 100%);
}
.player-close {
  position: absolute;
  top: calc(18px + env(safe-area-inset-top));
  left: 16px;
  font-size: 22px;
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
}
#player-body {
  position: relative;
  z-index: 2;
  padding-bottom: 8px;
}
#player-step-label {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 14px;
}
#player-step-text {
  font-size: 20px;
  line-height: 1.75;
  font-weight: 300;
  white-space: pre-line;
  margin: 0 0 28px;
  max-height: 46vh;
  overflow-y: auto;
  -webkit-mask-image: linear-gradient(180deg, #000 88%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 88%, transparent 100%);
}
.player-controls { padding-bottom: 4px; }
.step-progress {
  height: 3px;
  background: rgba(255, 225, 180, 0.14);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 14px;
}
.step-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ecb96e, #c9822e);
}
#player-pause {
  display: block;
  margin: 0 auto;
}
#player-finished {
  position: relative;
  z-index: 2;
  text-align: center;
  padding-bottom: 8px;
}
#player-closing-text {
  font-size: 19px;
  font-weight: 300;
  line-height: 1.65;
  margin-bottom: 24px;
}
#player-ideas {
  width: 100%;
  margin-bottom: 16px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

/* ---- Réglages ---- */
#screen-settings h1 {
  font-size: 21px;
  font-weight: 400;
  margin: 4px 0 20px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row label { font-size: 14px; }
.settings-row input[type="time"] {
  width: auto;
  padding: 8px 10px;
}
.settings-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}
.settings-btn { margin-top: 22px; }
.settings-status {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin: 10px 0 0;
  min-height: 1em;
}
.logout-btn {
  color: var(--text-muted);
  margin-top: 40px;
}

/* ===========================================================
   Desktop / large screens — l'app reste une colonne format
   téléphone, centrée dans un champ ambiant chaud.
   =========================================================== */
@media (min-width: 540px) {
  html, body {
    background:
      radial-gradient(90% 60% at 50% -5%, rgba(226, 169, 93, 0.10) 0%, transparent 55%),
      radial-gradient(120% 90% at 50% 115%, rgba(201, 130, 46, 0.10) 0%, transparent 55%),
      #080706;
  }
  .screen {
    border-left: 1px solid rgba(255, 225, 180, 0.06);
    border-right: 1px solid rgba(255, 225, 180, 0.06);
    box-shadow: 0 0 100px rgba(0, 0, 0, 0.6);
  }
  /* Le player et le login sont en image plein cadre : on garde le cadre net,
     et on arrondit joliment les coins de la colonne sur les écrans internes. */
  #screen-home, #screen-new, #screen-settings, #screen-preview {
    border-radius: 0;
  }
  /* Curseur pointer sur tout ce qui est cliquable (confort desktop). */
  .type-card, .preset-card, .day-cell, .session-row, .mode-btn,
  .duration-row button, .month-nav button, .icon-btn { cursor: pointer; }
}
