/* ==========================================================
   NETPHYSIC — Design system
   ========================================================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --paper: #FFFDF6;
  --paper-border: #E3D5B3;
  --ink: #2C2A26;
  --ink-soft: #5A554C;
  --blue: #2E86DE;
  --blue-dark: #1B5FAA;
  --green: #27AE60;
  --green-dark: #1E8449;
  --red: #E74C3C;
  --red-soft: #FDEDEB;
  --green-soft: #EAF7EF;
  --gold: #F0B429;
  --radius: 14px;
  --shadow-card: 0 10px 30px rgba(20, 20, 40, 0.25);
  --font-main: 'Nunito', 'Avenir Next', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font-main);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: var(--font-main); cursor: pointer; }
input, select { font-family: var(--font-main); }

/* ==========================================================
   MISSION SCENE LAYOUT
   ========================================================== */
.scene {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.scene-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.scene-bg svg { display: block; width: 100%; height: 100%; }

/* ---------- Top bar ---------- */
.topbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 253, 0.95);
  border: 2px solid rgba(190, 165, 110, 0.55);
  border-radius: 999px;
  padding: 7px 16px;
  z-index: 40;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
}
.topbar .home-link {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  text-decoration: none;
  border-radius: 9px;
  border: none;
  background: linear-gradient(160deg, #FFD84D, #F0A429);
  box-shadow: 0 2px 0 #B57F14, 0 3px 10px rgba(240,164,41,.35);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.topbar .home-link svg { width: 15px; height: 15px; }
.topbar .home-link:hover {
  filter: brightness(1.07);
  transform: translateY(-1px);
  box-shadow: 0 3px 0 #B57F14, 0 6px 14px rgba(240,164,41,.45);
}
.topbar .home-link:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #B57F14, 0 2px 6px rgba(240,164,41,.3);
}
.page-dots { display: flex; gap: 6px; align-items: flex-end; }
.page-dot {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 9px;
  border: 2px solid #CBBB94;
  background: #F6F0DF;
  color: #8D8264;
  font-weight: 800;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, box-shadow .15s, background .15s, color .15s;
  will-change: width, height;
  position: relative;
}
.page-dot:hover {
  border-color: var(--gold);
  box-shadow: 0 3px 8px rgba(240,180,41,.3);
}
.page-dot:active { transform: scale(.95); }
.page-dot.current {
  background: linear-gradient(160deg, #FFD84D, #F0A429);
  border-color: #C8901B;
  color: #6B4E00;
  box-shadow: 0 3px 8px rgba(240,164,41,.5);
}
.page-dot.done {
  background: var(--green);
  border-color: var(--green-dark);
  color: #fff;
}
.page-dot.done::after {
  content: '✓';
  position: absolute;
  top: -7px;
  right: -5px;
  width: 14px;
  height: 14px;
  background: var(--gold);
  color: #6B4E00;
  font-size: 9px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #fff;
}
.mission-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-soft);
  padding-right: 6px;
  border-right: 1.5px solid #DDD3BC;
  white-space: nowrap;
}

/* ---------- Main problem card ---------- */
.stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 74px 240px 60px 60px;
  z-index: 10;
}
.problem-card {
  width: min(760px, 100%);
  max-height: 100%;
  background: var(--paper);
  border: 2.5px solid var(--paper-border);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: cardIn .45s cubic-bezier(.2,.9,.3,1.15);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(26px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.problem-head {
  padding: 16px 26px 12px;
  border-bottom: 2px dashed #EADFC4;
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-shrink: 0;
}
.problem-head h1 {
  font-size: 21px;
  font-weight: 900;
  color: var(--ink);
  letter-spacing: .2px;
}
.problem-head .chip {
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.problem-body {
  padding: 18px 26px 22px;
  overflow-y: auto;
  font-size: 15px;
  line-height: 1.62;
}
.problem-body::-webkit-scrollbar { width: 9px; }
.problem-body::-webkit-scrollbar-thumb { background: #D9CCA8; border-radius: 9px; }
.problem-body::-webkit-scrollbar-track { background: transparent; }

.story p { margin-bottom: 10px; }
.story .quote {
  background: #F4F8FE;
  border-left: 4px solid var(--blue);
  padding: 10px 14px;
  border-radius: 0 10px 10px 0;
  margin: 10px 0;
  font-style: italic;
  color: #29486B;
}
.story .data-box {
  background: #FBF6E9;
  border: 1.5px solid #EADFC4;
  border-radius: 10px;
  padding: 10px 16px;
  margin: 12px 0;
}
.story .data-box ul { margin-left: 18px; }
.story .data-box li { margin: 2px 0; }
.story strong { color: #14487F; }

.figure-wrap {
  display: flex;
  justify-content: center;
  margin: 14px 0;
}
.figure-wrap svg {
  max-width: 100%;
  height: auto;
  background: #FDFBF4;
  border: 1.5px solid #EDE4CC;
  border-radius: 12px;
}
.fig-caption {
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
  font-style: italic;
  margin-top: -8px;
  margin-bottom: 10px;
}

/* formula display */
.formula {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-style: italic;
  background: #F7F3E8;
  border-radius: 8px;
  padding: 2px 8px;
  white-space: nowrap;
}
.formula sup, .formula sub { font-style: normal; font-size: .72em; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; line-height: 1.15; margin: 0 2px; }
.frac > span:first-child { border-bottom: 1.2px solid currentColor; padding: 0 4px; }
.frac > span:last-child { padding: 0 4px; }

/* ---------- Interactions ---------- */
.interaction { margin-top: 14px; }
.answer-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0;
}
.answer-line label { font-weight: 800; font-size: 14.5px; }
.num-input {
  width: 130px;
  height: 40px;
  border: 2px solid #C9BD9C;
  border-radius: 10px;
  background: #fff;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
  outline: none;
  transition: border .15s, box-shadow .15s;
}
.num-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46,134,222,.18);
}
.num-input.ok { border-color: var(--green); background: var(--green-soft); }
.num-input.bad { border-color: var(--red); background: var(--red-soft); animation: shake .3s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.unit-tag { font-weight: 800; color: var(--ink-soft); font-size: 14.5px; }

.mcq-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.mcq-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border: 2px solid #E2D8BC;
  border-radius: 12px;
  background: #FFFEFA;
  cursor: pointer;
  transition: all .12s;
  font-size: 14.5px;
  line-height: 1.45;
  text-align: left;
  width: 100%;
}
.mcq-option:hover { border-color: var(--blue); background: #F4F9FF; }
.mcq-option .mcq-letter {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: #EFE7D2;
  color: #7A6E4E;
  font-weight: 900;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mcq-option.selected { border-color: var(--blue); background: #EAF3FE; }
.mcq-option.selected .mcq-letter { background: var(--blue); color: #fff; }
.mcq-option.ok { border-color: var(--green); background: var(--green-soft); }
.mcq-option.ok .mcq-letter { background: var(--green); color: #fff; }
.mcq-option.bad { border-color: var(--red); background: var(--red-soft); }
.mcq-option.bad .mcq-letter { background: var(--red); color: #fff; }

table.fill-table {
  border-collapse: collapse;
  margin: 10px auto;
}
table.fill-table th, table.fill-table td {
  border: 1.5px solid #DCD0AE;
  padding: 7px 12px;
  text-align: center;
  font-size: 14px;
}
table.fill-table th { background: #F3EDDB; font-weight: 800; }
table.fill-table .num-input { width: 96px; height: 34px; font-size: 14px; }

/* slider explorer */
.slider-box {
  background: #F4F8FE;
  border: 1.5px solid #CFE0F5;
  border-radius: 12px;
  padding: 12px 18px;
  margin: 12px 0;
}
.slider-box .slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.slider-box input[type=range] { flex: 1; accent-color: var(--blue); height: 26px; }
.slider-box .slider-val {
  min-width: 92px;
  text-align: center;
  font-weight: 900;
  color: var(--blue-dark);
  background: #fff;
  border: 1.5px solid #CFE0F5;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 14px;
}
.slider-readout {
  margin-top: 8px;
  font-size: 14px;
  font-weight: 700;
  color: #29486B;
  text-align: center;
}

/* ---------- Action bar / feedback ---------- */
.action-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 26px;
  border-top: 2px dashed #EADFC4;
  background: #FCF9F0;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.btn-ok {
  background: linear-gradient(180deg, #FFD84D, #F0A429);
  color: #6B4E00;
  border: none;
  border-radius: 999px;
  padding: 11px 34px;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 1px;
  box-shadow: 0 4px 0 #B57F14, 0 8px 16px rgba(240,164,41,.35);
  transition: transform .1s, box-shadow .1s, filter .1s;
}
.btn-ok:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 5px 0 #B57F14, 0 10px 20px rgba(240,164,41,.45); }
.btn-ok:active { transform: translateY(3px); box-shadow: 0 1px 0 #B57F14; }
.btn-ok:disabled { opacity: .45; cursor: default; }
.btn-hint, .btn-solution {
  background: #FFF;
  border: 2px solid #E0D6B8;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 800;
  color: #8A7B52;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-hint:hover { border-color: var(--gold); color: #A07800; background: #FFFBEE; }
.btn-solution { color: #6B5E8E; }
.btn-solution:hover { border-color: #9B8AC4; background: #F7F4FC; }

.feedback-msg {
  flex: 1 1 220px;
  font-weight: 800;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 10px;
  display: none;
  animation: cardIn .3s;
}
.feedback-msg.show { display: block; }
.feedback-msg.good { background: var(--green-soft); color: var(--green-dark); border: 1.5px solid #A9DFC0; }
.feedback-msg.bad { background: var(--red-soft); color: #A83226; border: 1.5px solid #F2B8B1; }
.feedback-msg.partial { background: #FFF7E0; color: #8A6D00; border: 1.5px solid #F0DD9A; }

.hint-panel, .solution-panel {
  margin-top: 12px;
  border-radius: 12px;
  padding: 13px 17px;
  font-size: 14px;
  line-height: 1.6;
  display: none;
  animation: cardIn .3s;
}
.hint-panel.show, .solution-panel.show { display: block; }
.hint-panel {
  background: #FFFBEE;
  border: 1.5px solid #F0DD9A;
  color: #6E5A10;
}
.hint-panel .hint-tag { font-weight: 900; color: #A07800; }
.solution-panel {
  background: #F7F4FC;
  border: 1.5px solid #D8CDEE;
  color: #453763;
}
.solution-panel h4 { margin-bottom: 6px; font-size: 15px; color: #5B4A85; }
.solution-panel ol { margin: 4px 0 4px 20px; }
.solution-panel li { margin: 5px 0; }
.solution-panel .final {
  margin-top: 8px;
  background: #EDE7F8;
  border-radius: 8px;
  padding: 7px 12px;
  font-weight: 800;
  color: #4A3A75;
}

/* ---------- Character (mentor) ---------- */
.mentor {
  position: absolute;
  left: calc(50% + 300px);
  right: auto;
  top: 50%;
  transform: translateY(-50%);
  bottom: auto;
  width: 240px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.mentor .mentor-svg {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  filter: drop-shadow(0 8px 14px rgba(0,0,0,.3));
  animation: mentorFloat 4.5s ease-in-out infinite;
}
@keyframes mentorFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}
.mentor .name-plate {
  background: rgba(20, 24, 40, 0.82);
  color: #FFE9AC;
  font-size: 12.5px;
  font-weight: 800;
  padding: 5px 16px;
  border-radius: 999px;
  letter-spacing: .4px;
  text-align: center;
  line-height: 1.3;
}
.mentor .name-plate small {
  display: block;
  color: #B9C4E0;
  font-weight: 700;
  font-size: 10.5px;
}
.speech {
  position: absolute;
  left: calc(50% + 550px);
  right: auto;
  top: 30%;
  bottom: auto;
  width: 190px;
  background: #fff;
  border: 2px solid #D8CBA8;
  border-radius: 14px;
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.5;
  color: #4A4437;
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
  z-index: 29;
  animation: cardIn .5s .3s backwards;
}
.speech::after {
  content: '';
  position: absolute;
  left: -11px;
  bottom: 20px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-left: 2px solid #D8CBA8;
  border-bottom: 2px solid #D8CBA8;
  transform: rotate(45deg);
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: absolute;
  bottom: 16px;
  left: calc(50% - 90px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  z-index: 40;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 4px 0 rgba(110,75,10,.5), 0 8px 20px rgba(0,0,0,.3);
}
.bottom-nav button, .bottom-nav a {
  background: linear-gradient(180deg, #FFD84D, #F0A429);
  border: none;
  color: #6B4E00;
  font-weight: 800;
  font-size: 13.5px;
  padding: 11px 18px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  transition: filter .15s, transform .12s;
}
.bottom-nav button:hover, .bottom-nav a:hover { filter: brightness(1.08); }
.bottom-nav button:active, .bottom-nav a:active { transform: scale(.96); }
.bottom-nav button:disabled { opacity: .4; cursor: default; transform: none; }
.bottom-nav .nav-page-label {
  background: #D9A62B;
  padding: 11px 16px;
  color: #5A3F00;
  font-weight: 800;
  font-size: 13.5px;
}

/* ---------- Flash réussite/échec (contour de l'interface) ---------- */
.answer-flash {
  position: fixed;
  inset: 10px;
  border-radius: 26px;
  pointer-events: none;
  z-index: 95;
  opacity: 0;
  border: 3px solid transparent;
}
.answer-flash.good {
  border-color: #3FD97F;
  box-shadow: inset 0 0 60px rgba(63,217,127,.22), 0 0 34px rgba(63,217,127,.35);
  animation: flashPulse 1.6s ease forwards;
}
.answer-flash.bad {
  border-color: #E4B33C;
  box-shadow: inset 0 0 60px rgba(228,179,60,.22), 0 0 34px rgba(228,179,60,.35);
  animation: flashPulse 1.3s ease forwards;
}
@keyframes flashPulse {
  0% { opacity: 0; }
  12% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}
/* hochement "oui" : la carte acquiesce de haut en bas */
.problem-card.nod-yes { animation: nodYes .7s cubic-bezier(.3,.7,.4,1); }
@keyframes nodYes {
  0%, 100% { transform: translateY(0); }
  22% { transform: translateY(-12px); }
  45% { transform: translateY(2px); }
  68% { transform: translateY(-6px); }
  85% { transform: translateY(1px); }
}
/* hochement "non" : la carte fait non de gauche à droite */
.problem-card.nod-no { animation: nodNo .6s ease; }
@keyframes nodNo {
  0%, 100% { transform: translateX(0); }
  18% { transform: translateX(-12px); }
  38% { transform: translateX(10px); }
  58% { transform: translateX(-7px); }
  78% { transform: translateX(5px); }
}

/* ---------- Success burst ---------- */
.burst {
  position: fixed;
  pointer-events: none;
  width: 10px;
  height: 10px;
  z-index: 90;
}
.burst span {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  animation: burstFly .8s ease-out forwards;
}
@keyframes burstFly {
  from { transform: translate(0,0) rotate(0); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) rotate(320deg); opacity: 0; }
}

/* mission complete overlay */
.mission-complete {
  position: fixed;
  inset: 0;
  background: rgba(12, 16, 34, .72);
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
}
.mission-complete.show { display: flex; }
.mc-card {
  background: var(--paper);
  border-radius: 22px;
  padding: 38px 48px;
  text-align: center;
  max-width: 460px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  animation: cardIn .5s cubic-bezier(.2,.9,.3,1.2);
}
.mc-card .mc-medal { font-size: 64px; line-height: 1; margin-bottom: 10px; }
.mc-card h2 { font-size: 26px; font-weight: 900; margin-bottom: 8px; }
.mc-card p { color: var(--ink-soft); font-size: 15px; margin-bottom: 22px; }
.mc-card .mc-actions { display: flex; gap: 12px; justify-content: center; }
.mc-card .mc-actions a {
  text-decoration: none;
  font-weight: 800;
  padding: 11px 22px;
  border-radius: 999px;
  font-size: 14.5px;
}
.mc-btn-primary { background: var(--blue); color: #fff; box-shadow: 0 3px 0 var(--blue-dark); }
.mc-btn-ghost { background: #F1EBDA; color: #7A6E4E; }

/* ==========================================================
   RESPONSIVE
   ========================================================== */
/* sur grand écran, la carte est décalée de -90px (marge mentor) :
   on aligne la topbar sur le même axe */
@media (min-width: 1101px) {
  .topbar { left: calc(50% - 90px); }
}
@media (max-width: 1100px) {
  .stage { padding: 70px 30px 60px; }
  .mentor { width: 130px; right: 12px; bottom: 60px; }
  .mentor .mentor-svg { width: 112px; }
  .speech { display: none; }
}
@media (max-width: 700px) {
  .topbar { gap: 6px; padding: 6px 10px; max-width: 96vw; }
  .mission-label { display: none; }
  .page-dot { width: 25px; height: 25px; font-size: 11px; }
  .stage { padding: 64px 10px 58px; }
  .problem-body { padding: 14px 16px 18px; }
  .mentor { display: none; }
}
