/* ==========================================================================
   Base CSS — Reset, Design Tokens (BEM), Shell, Auth & Toast
   ========================================================================== */

:root {
  --font-display: 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  /* Palette Pain d'épice & Sucre d'orge */
  --color-sky-top: #091326;
  --color-sky-mid: #132544;
  --color-sky-bottom: #1d355b;
  --color-ginger-dark: #572a12;
  --color-ginger-mid: #854621;
  --color-ginger-light: #b66c3c;
  --color-ginger-crust: #3f1c0b;
  --color-icing: #fffaf2;
  --color-icing-soft: #f6ead7;
  --color-candy-red: #c82333;
  --color-candy-red-dark: #971724;
  --color-pine: #164431;
  --color-pine-light: #22664a;
  --color-gold: #f5c249;
  --color-gold-bright: #ffe28a;
  --color-text: #341b0c;
  --color-text-light: #fdf7ed;
  --color-muted: #7a5843;

  /* Rayons & Ombres */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-soft: 0 12px 30px rgba(4, 10, 24, 0.42);
  --shadow-card: 0 20px 50px rgba(3, 8, 20, 0.65);

  /* Couches Z-index */
  --z-backdrop: 1;
  --z-tree: 10;
  --z-header: 30;
  --z-snow: 50;
  --z-toast: 70;
  --z-sandbox: 90;
  --z-modal: 100;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--color-text-light);
  background: linear-gradient(180deg, var(--color-sky-top) 0%, var(--color-sky-mid) 55%, var(--color-sky-bottom) 100%);
  overflow-x: clip;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.has-sandbox-bar {
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

img {
  display: block;
  max-width: 100%;
}

[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;
}

:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 2px;
}

/* Canvas Neige plein écran */
.snow-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: var(--z-snow);
}

/* Shell Principal */
.app-shell {
  position: relative;
  z-index: var(--z-tree);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

.app-header {
  position: relative;
  z-index: var(--z-header);
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-header__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-header__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 3.4vw, 1.75rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--color-icing);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
}

.app-header__subtitle {
  margin: 0;
  font-size: 0.82rem;
  color: var(--color-gold-bright);
  opacity: 0.92;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.12);
  border: 1px solid rgba(255, 250, 242, 0.24);
  font-size: 0.82rem;
  color: var(--color-icing);
  backdrop-filter: blur(6px);
}

/* Compte à rebours synchronisé */
.countdown {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin: 0 auto;
  padding: 8px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(87, 42, 18, 0.92), rgba(133, 70, 33, 0.92));
  border: 2px solid rgba(255, 250, 242, 0.72);
  box-shadow: 0 8px 22px rgba(4, 9, 20, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  text-align: center;
  max-width: 100%;
}

.countdown__label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-icing-soft);
}

.countdown__timer {
  font-family: var(--font-display);
  font-size: clamp(0.95rem, 2.8vw, 1.15rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--color-gold-bright);
  letter-spacing: 0.03em;
}

.countdown--complete {
  background: linear-gradient(135deg, var(--color-pine), #1f6346);
  border-color: var(--color-gold);
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 12px 18px;
}

/* Écran de connexion */
.auth-screen {
  position: relative;
  z-index: var(--z-tree);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-card__inner {
  padding: 28px 24px 24px;
}

.auth-card__badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--color-pine);
  color: var(--color-icing);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.auth-card__title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.65rem;
  color: var(--color-text);
  line-height: 1.2;
}

.auth-card__desc {
  margin: 0 0 20px;
  font-size: 0.93rem;
  color: var(--color-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form__field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.auth-form__label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text);
}

.auth-form__input {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 2px solid #d7bfa6;
  background: #ffffff;
  color: var(--color-text);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.auth-form__input:focus {
  outline: none;
  border-color: var(--color-candy-red);
  box-shadow: 0 0 0 3px rgba(200, 35, 51, 0.18);
}

.auth-form__checkbox {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.88rem;
  color: var(--color-text);
  cursor: pointer;
  min-height: 36px;
}

.auth-form__checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--color-candy-red);
}

.auth-form__error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #fde8ea;
  border: 1px solid #f5b4bb;
  color: #8f1421;
  font-size: 0.88rem;
  font-weight: 600;
}

/* Toasts */
.toast-region {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  width: min(92vw, 430px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 600;
  text-align: center;
  color: var(--color-icing);
  background: rgba(52, 27, 12, 0.95);
  border: 2px solid var(--color-gold);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  animation: toast-in 0.24s ease-out both;
}

.toast--warning {
  background: linear-gradient(135deg, #971724, #c82333);
  border-color: var(--color-icing);
}

.toast--success {
  background: linear-gradient(135deg, #123c2b, #1d5d43);
  border-color: var(--color-gold);
}

.toast--leaving {
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 640px) {
  .app-header {
    padding: 8px 12px 6px;
    gap: 6px;
  }

  .app-header__subtitle {
    display: none;
  }

  .countdown {
    padding: 7px 13px;
    border-radius: 16px;
  }

  body.has-sandbox-bar {
    padding-bottom: calc(105px + env(safe-area-inset-bottom));
  }
}

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