/* ============================================================
   Pereski — Rituel des cartes
   ============================================================ */

:root {
  --font-serif: "Cormorant Garamond", "Times New Roman", serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --gold: #c9a961;
  --gold-soft: #8a7645;
  --gold-faint: rgba(201, 169, 97, 0.18);

  --card-paper: #f5ede0;
  --card-paper-edge: #e8dcc6;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Dark theme (default) */
[data-theme="dark"] {
  /* Fond beige constant : seules les cartes basculent entre les variantes light/dark */
  --bg: #f6f1e7;
  --bg-elev: #fbf7ee;
  --fg: #e9e1cf;
  --fg-dim: #9b9283;
  --fg-faint: #5a5245;
  --border: rgba(201, 169, 97, 0.22);
  --border-soft: rgba(201, 169, 97, 0.10);
  --shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.8),
            0 8px 24px -8px rgba(0, 0, 0, 0.5);

  /* cards flip to inked-paper black */
  --card-paper: #0f0c0a;
  --card-paper-edge: #1a1613;
  --card-ink: #f3ead7;
  --card-ink-soft: #c9a961;
  --card-corner: rgba(201, 169, 97, 0.55);
}

/* Light theme defaults for card ink (complements :root paper vars) */
:root {
  --card-ink: #2a2520;
  --card-ink-soft: #8a7645;
  --card-corner: var(--card-corner);
}

/* Light theme */
[data-theme="light"] {
  --bg: #f6f1e7;
  --bg-elev: #fbf7ee;
  --fg: #2a2520;
  --fg-dim: #6a6253;
  --fg-faint: #a8a091;
  --gold: #8a7645;
  --gold-soft: #6d5c34;
  --gold-faint: rgba(138, 118, 69, 0.16);
  --border: rgba(138, 118, 69, 0.28);
  --border-soft: rgba(138, 118, 69, 0.12);
  --card-paper: #ffffff;
  --card-paper-edge: #efe7d4;
  --shadow: 0 24px 60px -20px rgba(90, 70, 30, 0.22),
            0 8px 24px -8px rgba(90, 70, 30, 0.10);
}

/* ============================================================
   Base
   ============================================================ */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
}

html {
  height: 100vh;
  height: 100dvh;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-weight: 300;
  letter-spacing: 0.01em;
  transition: background 0.6s var(--ease), color 0.6s var(--ease);
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  /* Keep the bottom edge clear of the system UI:
     - iOS: env(safe-area-inset-bottom) reports the home-indicator height
     - Android (3-button nav / gesture bar): env() often returns 0 in
       Chrome, so we enforce a generous floor with max() */
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
}

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

a { color: inherit; text-decoration: none; }

/* ============================================================
   Top bar
   ============================================================ */
.top-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 15px 32px;
  gap: 16px;
  z-index: 10;
}

.brand        { justify-self: start;  }
.toggle--collection { justify-self: center; }
.toggle--theme      { justify-self: end;    }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--gold);
}

.brand-logo {
  display: block;
  height: 70px;
  width: auto;
  user-select: none;
  -webkit-user-drag: none;
}

/* ----- Generic modern toggle (pill with sliding gold indicator) ----- */
.toggle {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  padding: 4px;
  background: var(--card-paper);
  border-radius: 100px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--card-ink) 12%, transparent);
  overflow: hidden;
  isolation: isolate;
  transition: background 0.6s var(--ease), box-shadow 0.6s var(--ease);
}

.toggle::after {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc(50% - 4px);
  border-radius: 100px;
  background: var(--gold);
  transition: transform 0.45s var(--ease);
  z-index: 0;
}

/* Collection toggle */
.toggle--collection {
  grid-template-columns: 1fr 1fr;
  min-width: 240px;
}

.toggle-option {
  position: relative;
  z-index: 1;
  padding: 10px 24px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--card-ink);
  opacity: 0.55;
  border-radius: 100px;
  transition: opacity 0.3s var(--ease), color 0.3s var(--ease);
  text-align: center;
  white-space: nowrap;
}
.toggle-option:hover { opacity: 0.85; }
.toggle-option.is-active {
  opacity: 1;
  color: #0a0806;
}

body[data-collection="cocons"] .toggle--collection::after {
  transform: translateX(100%);
}

/* Theme toggle (card white / card black) */
.toggle--theme {
  grid-template-columns: 1fr 1fr;
  width: 74px;
  height: 38px;
  cursor: pointer;
}

.theme-option {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  color: var(--card-ink);
  opacity: 0.45;
  transition: opacity 0.3s var(--ease), color 0.3s var(--ease);
}
.theme-option svg { width: 14px; height: 18px; display: block; }

body[data-theme="light"] .theme-option--light,
body[data-theme="dark"]  .theme-option--dark {
  opacity: 1;
  color: #0a0806;
}

body[data-theme="dark"] .toggle--theme::after {
  transform: translateX(100%);
}

/* ============================================================
   Stage + Deck
   ============================================================ */
.stage {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto auto;
  align-items: center;
  justify-items: center;
  padding: 20px 20px 30px;
  overflow: hidden;
  min-height: 0;
}

.deck {
  position: relative;
  width: min(300px, 80vw);
  aspect-ratio: 5 / 7;
  perspective: 1400px;
  align-self: center;
  justify-self: center;
  touch-action: pan-y;
  transition: width 0.45s var(--ease);
}

/* Card */
.card {
  position: absolute;
  inset: 0;
  background: var(--card-paper);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: grab;
  will-change: transform, opacity;
  transform-origin: center 110%;
  color: var(--card-ink);
  transition: background 0.6s var(--ease), color 0.6s var(--ease);
}

.card.is-dragging { cursor: grabbing; transition: none !important; }

.card-img {
  position: absolute;
  /* negative inset crops the registration marks + thin border from the source PDFs */
  top: -8%;
  left: -8%;
  width: 116%;
  height: 116%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* When the active card is landscape, the whole deck rotates to a 7:5 frame
   so the illustration fills the card exactly like the portrait variants do. */
.deck.is-landscape { aspect-ratio: 7 / 5; }

/* Landscape sources are full-bleed artwork (no registration marks),
   so skip the -8% safety crop used for portrait scans. */
.card-img.is-landscape {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Hint */
.hint {
  font-size: 9.5px;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin: 26px 0 18px;
  position: relative;
  padding: 0 26px;
  transition: opacity 0.4s var(--ease);
}

.hint::before,
.hint::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 18px;
  height: 1px;
  background: var(--border);
}
.hint::before { left: 0; }
.hint::after  { right: 0; }

/* Dots */
.dots {
  display: flex;
  gap: 10px;
  padding: 4px 0 10px;
}

.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--fg-faint);
  opacity: 0.5;
  transition: background 0.3s var(--ease), opacity 0.3s var(--ease), transform 0.3s var(--ease);
  cursor: pointer;
  border: none;
  padding: 0;
}
.dot:hover { opacity: 0.9; }
.dot.is-active {
  background: var(--gold);
  opacity: 1;
  transform: scale(1.3);
}

/* ============================================================
   Player — pill layout with spinning disc
   ============================================================ */
.player {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 18px;
  padding: 14px 22px 14px 14px;
  background: var(--card-paper);
  border-radius: 72px;
  box-shadow:
    0 14px 36px -14px rgba(0, 0, 0, 0.35),
    0 4px 12px -4px rgba(0, 0, 0, 0.14);
  margin: 0 18px 18px;
  transition: background 0.6s var(--ease), color 0.6s var(--ease);
}

/* Disc */
.disc {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--card-paper-edge);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.disc-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  animation: discSpin 14s linear infinite;
  animation-play-state: paused;
}

.player.is-playing .disc-art { animation-play-state: running; }

.disc-spindle {
  position: absolute;
  top: 50%; left: 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--card-paper);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
  pointer-events: none;
}

@keyframes discSpin {
  to { transform: rotate(360deg); }
}

/* Main column (title + progress + controls) */
.player-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  min-width: 0;
}

.player-title {
  font-family: var(--font-serif);
  font-size: 20px;
  color: var(--card-ink);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

/* Progress bar */
.progress {
  position: relative;
  height: 2px;
  background: color-mix(in srgb, var(--card-ink) 12%, transparent);
  border-radius: 2px;
  cursor: pointer;
  outline: none;
}
.progress:focus-visible { box-shadow: 0 0 0 2px var(--gold-faint); }

.progress-bar {
  position: absolute;
  inset: 0;
  width: 0%;
  background: var(--gold);
  border-radius: 2px;
  transition: width 0.1s linear;
}

.progress-handle {
  position: absolute;
  top: 50%;
  left: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  transform: translate(-50%, -50%);
  transition: left 0.1s linear, transform 0.2s var(--ease);
}
.progress:hover .progress-handle { transform: translate(-50%, -50%) scale(1.4); }

/* Controls row (prev / play / next / repeat) */
.player-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-top: 4px;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: var(--card-ink);
  opacity: 0.6;
  transition: opacity 0.2s var(--ease), color 0.2s var(--ease), background 0.2s var(--ease), transform 0.15s var(--ease);
}
.ctrl-btn:hover { opacity: 1; }
.ctrl-btn:active { transform: scale(0.9); }
.ctrl-btn svg { width: 26px; height: 26px; }

.play-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--card-ink);
  transition: color 0.2s var(--ease), transform 0.15s var(--ease);
}
.play-btn:hover { color: var(--gold); }
.play-btn:active { transform: scale(0.92); }

.play-btn svg { width: 28px; height: 28px; fill: currentColor; }
.play-btn .icon-pause { display: none; }
.player.is-playing .play-btn .icon-play  { display: none; }
.player.is-playing .play-btn .icon-pause { display: block; }

/* Repeat button : once (×1) by default, loop when pressed */
.repeat-btn { position: relative; }
.repeat-one {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-sans);
  font-size: 9px;
  font-weight: 600;
  line-height: 1;
  color: inherit;
  pointer-events: none;
}
.repeat-btn[aria-pressed="true"] {
  color: var(--gold);
  opacity: 1;
}
.repeat-btn[aria-pressed="true"] .repeat-one { display: none; }

/* ============================================================
   Placeholder illustration (when no image)
   ============================================================ */
.placeholder-art {
  width: 70%;
  height: 70%;
  display: grid;
  place-items: center;
  color: #8a7645;
  opacity: 0.7;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 13px;
  text-align: center;
  border: 1px dashed rgba(138, 118, 69, 0.35);
  border-radius: 4px;
  padding: 12px;
  line-height: 1.4;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 640px) {
  .top-bar {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: auto auto;
    padding: 14px 18px 12px;
    row-gap: 7vw;
    column-gap: 10px;
    justify-content: center;
    align-items: center;
  }
  .brand              { grid-row: 1; grid-column: 1 / -1; justify-self: center; }
  .toggle--collection { grid-row: 2; grid-column: 1; }
  .toggle--theme      { grid-row: 2; grid-column: 2; }

  .brand-logo { height: 43px; }
  .toggle--collection { min-width: 0; }
  .toggle-option { padding: 8px 15px; font-size: 9px; letter-spacing: 0.18em; }
  .toggle--theme { width: 49px; height: 29px; }
  .theme-option svg { width: 10px; height: 14px; }
  .deck { width: min(260px, 74vw); }
  .card-title { font-size: 22px; }
  .player {
    padding: 7px 12px 7px 7px;
    gap: 10px;
    margin: 0 14px 8px;
    border-radius: 48px;
  }
  .disc { width: 70px; height: 70px; }
  .disc-spindle { width: 10px; height: 10px; margin: -5px 0 0 -5px; }
  .player-title { font-size: 14px; }
  .ctrl-btn { width: 28px; height: 28px; }
  .ctrl-btn svg { width: 17px; height: 17px; }
  .play-btn { width: 34px; height: 34px; }
  .play-btn svg { width: 18px; height: 18px; }
  .player-controls { gap: 7px; margin-top: 2px; }
  .repeat-one { font-size: 8px; }
  .hint { margin: 18px 0 12px; }
}

@media (max-height: 680px) {
  .deck { width: min(230px, 60vw); }
  .hint { margin: 14px 0 10px; }
}

@media (min-width: 1024px) {
  .deck { width: min(420px, 34vw, 48vh); }
  .deck.is-landscape { width: min(640px, 55vw, 68vh); }
  .card-title { font-size: 32px; }
}

@media (min-width: 1400px) {
  .deck { width: min(500px, 32vw, 54vh); }
  .deck.is-landscape { width: min(760px, 52vw, 72vh); }
  .card-title { font-size: 36px; }
}

@media (max-width: 640px) {
  .deck.is-landscape { width: min(340px, 88vw); }
}

/* Prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
