:root {
  color-scheme: dark;
  --gold: #f1d592;
  --gold-strong: #ffe7a9;
  --ink: #080b18;
  --panel: rgba(9, 12, 28, 0.94);
  --panel-border: rgba(241, 213, 146, 0.38);
  --blue-glow: rgba(81, 169, 255, 0.72);
  --violet-glow: rgba(176, 93, 255, 0.65);
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-right: max(18px, env(safe-area-inset-right));
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
}

button { font: inherit; }

.app {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
  background: #050711;
}

.scene-backdrop {
  position: absolute;
  inset: -4%;
  z-index: -2;
  background-position: center;
  background-size: cover;
  filter: blur(28px) brightness(.78) saturate(1.08);
  transform: scale(1.08);
  transition: background-image .5s ease, opacity .5s ease;
}

.scene-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, transparent 58%, rgba(2, 3, 10, .20) 100%);
}

.scene {
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
}

.scene-stage {
  position: relative;
  width: min(100vw, 177.683vh);
  height: min(100vh, 56.28vw);
  aspect-ratio: 1672 / 941;
  overflow: hidden;
  background: #090b17;
  box-shadow: 0 0 42px rgba(0, 0, 0, .24);
}

.scene-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform .72s cubic-bezier(.2,.72,.2,1), filter .5s ease;
}

.scene-stage.is-entering .scene-image {
  animation: sceneEnter .72s cubic-bezier(.2,.72,.2,1) both;
}

@keyframes sceneEnter {
  from { opacity: .2; transform: scale(1.035); filter: blur(2px); }
  to { opacity: 1; transform: scale(1); filter: blur(0); }
}

.hotspots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Zone de clic invisible : volontairement un peu plus généreuse que la lueur. */
.hotspot {
  position: absolute;
  z-index: 3;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  height: var(--h);
  padding: 0;
  border: 1px solid transparent;
  border-radius: 18px;
  color: white;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  outline: none;
}

.hotspot:focus-visible {
  border-color: rgba(255, 230, 168, .9);
  box-shadow: 0 0 0 3px rgba(80, 150, 255, .42), 0 0 30px rgba(176, 93, 255, .55);
}

.hotspot:hover,
.hotspot:focus-visible { z-index: 6; }

/* Lueur décorative indépendante de la zone de clic. */
.hotspot-glow {
  position: absolute;
  z-index: 2;
  left: var(--gx);
  top: var(--gy);
  width: var(--gw);
  height: var(--gh);
  transform: rotate(var(--gr)) scale(.985);
  transform-origin: center;
  border: 1px solid rgba(255, 232, 177, .82);
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(circle at center,
    rgba(255, 236, 176, .10),
    rgba(104, 188, 255, .065) 46%,
    rgba(151, 85, 255, .035) 64%,
    transparent 78%);
  box-shadow:
    inset 0 0 18px rgba(255, 228, 158, .10),
    0 0 28px rgba(255, 222, 145, .48),
    0 0 52px rgba(91, 168, 255, .48),
    0 0 78px rgba(165, 94, 255, .38);
  transition: opacity .14s ease, transform .16s ease, filter .16s ease;
  filter: brightness(1.05) saturate(1.08);
}

.hotspot-glow.is-active {
  opacity: 1;
  transform: rotate(var(--gr)) scale(1.02);
  filter: brightness(1.22) saturate(1.18);
}

.hotspot-glow--rounded { border-radius: 22px; }
.hotspot-glow--ellipse { border-radius: 50%; }
.hotspot-glow--arch {
  border-radius: 48% 48% 18% 18% / 42% 42% 12% 12%;
  clip-path: polygon(11% 12%, 21% 2%, 79% 2%, 89% 12%, 100% 30%, 100% 100%, 0 100%, 0 30%);
}
.hotspot-glow--diamond {
  clip-path: polygon(50% 0, 92% 24%, 100% 70%, 50% 100%, 0 70%, 8% 24%);
}
.hotspot-glow--path {
  border-radius: 999px;
  box-shadow:
    inset 0 0 12px rgba(255, 231, 164, .08),
    0 0 22px rgba(255, 222, 145, .56),
    0 0 38px rgba(91, 168, 255, .42);
}
.hotspot-glow--stair {
  border-radius: 22px 34px 28px 18px;
  clip-path: polygon(8% 0, 100% 0, 100% 100%, 28% 100%, 18% 83%, 18% 66%, 10% 52%, 10% 34%, 0 20%);
}

/* Mode technique : touche C ou ?calibrate=1. */
.is-calibrating .hotspot {
  border: 2px dashed rgba(255, 85, 85, .95);
  background: rgba(255, 40, 40, .12);
}
.is-calibrating .hotspot::after {
  content: attr(data-hotspot-id);
  position: absolute;
  left: 4px;
  bottom: 4px;
  max-width: calc(100% - 8px);
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(20, 0, 0, .82);
  color: #ffd9d9;
  font: 600 9px/1.15 system-ui, sans-serif;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.is-calibrating .hotspot-glow {
  opacity: .52;
  border-color: rgba(77, 196, 255, .95);
}
.is-calibrating .hotspot-glow.is-active { opacity: 1; }

.hotspot-tooltip {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -115%);
  max-width: min(220px, 88%);
  padding: 7px 11px;
  border: 1px solid rgba(255, 232, 177, .36);
  border-radius: 999px;
  background: rgba(7, 9, 21, .86);
  color: #fff4d3;
  font: 600 clamp(10px, .78vw, 14px)/1.15 system-ui, sans-serif;
  text-align: center;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,.38);
}

.hotspot:hover .hotspot-tooltip,
.hotspot:focus-visible .hotspot-tooltip {
  opacity: 1;
  transform: translate(-50%, -125%);
}


.hotspot-tooltip--left { left: auto; right: 0; transform: translate(0, -115%); }
.hotspot:hover .hotspot-tooltip--left,
.hotspot:focus-visible .hotspot-tooltip--left { transform: translate(0, -125%); }

.hotspot-tooltip--right { left: 0; transform: translate(0, -115%); }
.hotspot:hover .hotspot-tooltip--right,
.hotspot:focus-visible .hotspot-tooltip--right { transform: translate(0, -125%); }

.hotspot-tooltip--below { top: 100%; transform: translate(-50%, 10px); }
.hotspot:hover .hotspot-tooltip--below,
.hotspot:focus-visible .hotspot-tooltip--below { transform: translate(-50%, 14px); }
.hotspot-tooltip--below.hotspot-tooltip--left { left: auto; right: 0; transform: translate(0, 10px); }
.hotspot:hover .hotspot-tooltip--below.hotspot-tooltip--left,
.hotspot:focus-visible .hotspot-tooltip--below.hotspot-tooltip--left { transform: translate(0, 14px); }
.hotspot-tooltip--below.hotspot-tooltip--right { left: 0; transform: translate(0, 10px); }
.hotspot:hover .hotspot-tooltip--below.hotspot-tooltip--right,
.hotspot:focus-visible .hotspot-tooltip--below.hotspot-tooltip--right { transform: translate(0, 14px); }

.hotspot.is-learned::after {
  content: "✓";
  position: absolute;
  top: 7%;
  right: 7%;
  display: grid;
  place-items: center;
  width: clamp(22px, 2vw, 32px);
  aspect-ratio: 1;
  border: 1px solid rgba(255, 231, 169, .58);
  border-radius: 50%;
  color: #fff2be;
  background: rgba(12, 37, 35, .86);
  font: 700 clamp(12px, 1vw, 17px)/1 system-ui, sans-serif;
  box-shadow: 0 0 18px rgba(84, 255, 202, .34);
}

.top-navigation {
  position: fixed;
  z-index: 40;
  top: var(--safe-top);
  right: var(--safe-right);
  display: flex;
  gap: 8px;
}

.nav-button,
.close-panel {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(245, 216, 150, .62);
  border-radius: 50%;
  color: #fff1c6;
  background: rgba(8, 11, 27, .68);
  backdrop-filter: blur(12px);
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(0,0,0,.35), inset 0 0 12px rgba(255, 225, 154, .06);
  transition: transform .2s ease, background .2s ease, box-shadow .2s ease;
}

.nav-button:hover,
.nav-button:focus-visible,
.close-panel:hover,
.close-panel:focus-visible {
  transform: translateY(-1px) scale(1.04);
  background: rgba(22, 29, 58, .88);
  box-shadow: 0 0 24px var(--blue-glow), inset 0 0 16px rgba(255, 226, 157, .12);
  outline: none;
}

.nav-button svg {
  width: 21px;
  fill: currentColor;
}

.progress-badge {
  position: fixed;
  z-index: 35;
  top: var(--safe-top);
  left: max(18px, env(safe-area-inset-left));
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 10px 15px;
  border: 1px solid rgba(245, 216, 150, .32);
  border-radius: 999px;
  background: rgba(7, 9, 21, .72);
  backdrop-filter: blur(12px);
  color: #fff0c8;
  box-shadow: 0 6px 22px rgba(0,0,0,.3);
}

#progressText { font-weight: 700; }
.progress-label { font: 500 12px/1 system-ui, sans-serif; opacity: .8; }

.transition-curtain {
  position: fixed;
  z-index: 70;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at center, rgba(137, 191, 255, .12), rgba(7, 8, 19, .96) 70%);
}

.transition-curtain.is-active {
  animation: curtain .68s ease both;
}

@keyframes curtain {
  0% { opacity: 0; }
  45% { opacity: 1; }
  100% { opacity: 0; }
}

.panel-overlay {
  position: fixed;
  z-index: 79;
  inset: 0;
  background: rgba(0, 2, 11, .38);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .32s ease;
}

.panel-overlay.is-open { opacity: 1; }

.lesson-panel {
  position: fixed;
  z-index: 80;
  top: 0;
  right: 0;
  width: min(520px, 92vw);
  height: 100dvh;
  border-left: 1px solid var(--panel-border);
  background:
    linear-gradient(180deg, rgba(35, 28, 61, .35), transparent 28%),
    var(--panel);
  box-shadow: -24px 0 70px rgba(0,0,0,.5);
  transform: translateX(104%);
  transition: transform .38s cubic-bezier(.2,.75,.2,1);
  overflow: hidden;
}

.lesson-panel.is-open { transform: translateX(0); }

.lesson-scroll {
  height: 100%;
  overflow-y: auto;
  padding: clamp(30px, 5vw, 58px) clamp(24px, 5vw, 52px) 46px;
  scrollbar-width: thin;
  scrollbar-color: rgba(241,213,146,.45) transparent;
}

.close-panel {
  position: absolute;
  z-index: 2;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 38px;
  height: 38px;
  font: 300 27px/1 system-ui, sans-serif;
}

.lesson-eyebrow {
  margin: 0 48px 10px 0;
  color: #b9b5ff;
  font: 700 12px/1.2 system-ui, sans-serif;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.lesson-panel h1 {
  margin: 0 0 17px;
  color: var(--gold-strong);
  font-size: clamp(31px, 5vw, 50px);
  line-height: .98;
  font-weight: 500;
  text-wrap: balance;
}

.lesson-intro {
  margin: 0 0 30px;
  color: rgba(255,255,255,.88);
  font: 400 17px/1.65 system-ui, sans-serif;
}

.lesson-section {
  margin-top: 25px;
  padding-top: 21px;
  border-top: 1px solid rgba(241, 213, 146, .16);
}

.lesson-section h2 {
  margin: 0 0 11px;
  color: #f3d792;
  font-size: 18px;
  font-weight: 600;
}

.lesson-section p,
.lesson-section li {
  color: rgba(255,255,255,.82);
  font: 400 15px/1.62 system-ui, sans-serif;
}

.lesson-section ul { margin: 0; padding-left: 20px; }
.lesson-section li + li { margin-top: 8px; }

.lesson-example,
.lesson-exercise,
.lesson-recall {
  padding: 18px;
  border: 1px solid rgba(241,213,146,.15);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
}

.lesson-exercise { background: rgba(69, 118, 168, .09); }
.lesson-recall { background: rgba(132, 73, 175, .09); }

.lesson-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 30px;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 11px 15px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}

.primary-button {
  border: 1px solid rgba(255, 229, 162, .7);
  color: #17121f;
  background: linear-gradient(135deg, #ffe6a4, #cfaa59);
  font-weight: 700;
}

.primary-button.is-learned {
  color: #e6fff7;
  border-color: rgba(101, 255, 210, .45);
  background: rgba(29, 96, 77, .58);
}

.secondary-button {
  border: 1px solid rgba(177, 162, 255, .35);
  color: #eeeaff;
  background: rgba(89, 72, 147, .24);
}

.primary-button:hover,
.secondary-button:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(0,0,0,.28); }


.calibration-badge {
  position: fixed;
  z-index: 90;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  padding: 9px 12px;
  border: 1px solid rgba(255, 110, 110, .7);
  border-radius: 10px;
  background: rgba(38, 4, 8, .88);
  color: #ffe0e0;
  font: 700 12px/1.25 system-ui, sans-serif;
  box-shadow: 0 8px 30px rgba(0,0,0,.45);
  pointer-events: none;
}

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border: 1px solid rgba(241,213,146,.34);
  border-radius: 999px;
  background: rgba(7, 10, 24, .9);
  color: #fff2cd;
  font: 600 13px/1.2 system-ui, sans-serif;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

[hidden] { display: none !important; }

@media (max-width: 740px) {
  .nav-button { width: 50px; height: 50px; }
  .progress-label { display: none; }
  .progress-badge { padding: 10px 13px; }

  .lesson-panel {
    top: auto;
    bottom: 0;
    width: 100%;
    height: min(84dvh, 760px);
    border-left: 0;
    border-top: 1px solid var(--panel-border);
    border-radius: 22px 22px 0 0;
    transform: translateY(104%);
  }

  .lesson-panel.is-open { transform: translateY(0); }
  .lesson-scroll { padding: 50px 22px max(34px, env(safe-area-inset-bottom)); }
  .lesson-actions { grid-template-columns: 1fr; }
  .hotspot-tooltip { display: none; }
}

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