:root {
  --blue: #48a9f8;
  --green: #38c979;
  --orange: #ffb020;
  --red: #ff5c75;
  --violet: #6c63ff;
  --ink: #172033;
  --muted: #657086;
  --paper: #f6f7fb;
  --card: rgba(255, 255, 255, .86);
  --line: rgba(23, 32, 51, .09);
  --shadow: 0 20px 60px rgba(28, 34, 64, .16);
  --radius-xl: 32px;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(108,99,255,.25), transparent 32%),
    radial-gradient(circle at 88% 12%, rgba(72,169,248,.24), transparent 30%),
    linear-gradient(135deg, #fbfcff 0%, var(--paper) 100%);
}
button, input, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 999px;
  padding: 14px 20px;
  font-weight: 850;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}
button:active { transform: scale(.98); }
button:disabled { opacity: .55; cursor: not-allowed; }
.primary { background: linear-gradient(135deg, var(--violet), #4cb3ff); color: white; box-shadow: 0 14px 30px rgba(108,99,255,.26); }
.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); box-shadow: 0 10px 24px rgba(28,34,64,.08); }
.danger { background: #fff0f3; color: #a51e38; border: 1px solid #ffd0da; }
.app { width: min(1180px, 100%); margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 14px 18px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 18px; background: #fff; box-shadow: 0 10px 26px rgba(28,34,64,.10); font-size: 1.45rem; }
h1 { margin: 0; font-size: clamp(1.6rem, 4vw, 3.6rem); letter-spacing: -.05em; line-height: .95; }
p { margin: 6px 0; }
.brand p { color: var(--muted); font-weight: 650; }
.parent-access { flex: 0 0 auto; background: rgba(255,255,255,.75); color: var(--ink); border: 1px solid var(--line); box-shadow: 0 10px 26px rgba(28,34,64,.08); }
.screen { display: none; }
.screen.active { display: block; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(190px, 240px); gap: 16px; align-items: stretch; }
.story-card, .voice-panel, .panel, .modal-card {
  background: var(--card);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.story-card {
  min-height: clamp(390px, 62vh, 690px);
  padding: 16px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.story-card::before {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 26px;
  border: 1px dashed rgba(108,99,255,.2);
  pointer-events: none;
}
.story-image { width: 100%; height: 100%; max-height: 72vh; object-fit: contain; border-radius: 24px; display: none; position: relative; z-index: 1; }
.empty-story { display: grid; gap: 10px; text-align: center; color: var(--muted); padding: 24px; font-size: clamp(1rem, 2vw, 1.35rem); }
.empty-story strong { color: var(--ink); font-size: 1.35em; }
.voice-panel { padding: 14px; display: flex; flex-direction: column; gap: 12px; min-height: 390px; }
.voice-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.voice-title { font-weight: 900; color: var(--muted); }
#levelText { font-size: 1.5rem; letter-spacing: -.04em; }
.meter-wrap { display: grid; grid-template-columns: 64px minmax(82px, 1fr); gap: 10px; flex: 1; min-height: 290px; }
.meter-track { border-radius: 999px; background: #eef2f8; position: relative; overflow: hidden; box-shadow: inset 0 0 0 3px rgba(23,32,51,.06); }
.target-band { position: absolute; left: 0; right: 0; bottom: 30%; height: 25%; background: rgba(56,201,121,.20); border-top: 2px solid rgba(56,201,121,.5); border-bottom: 2px solid rgba(56,201,121,.5); z-index: 1; }
.meter-fill { position: absolute; z-index: 2; bottom: 0; width: 100%; height: 0%; background: linear-gradient(to top, var(--blue) 0 30%, var(--green) 30% 55%, var(--orange) 55% 75%, var(--red) 75% 100%); transition: height .08s linear; }
.meter-zones { display: flex; flex-direction: column; gap: 7px; font-weight: 950; color: white; text-align: center; }
.zone { flex: 1; display: grid; place-items: center; border-radius: 18px; padding: 8px 6px; font-size: .88rem; line-height: 1.05; }
.zone.blue { background: var(--blue); }
.zone.green { background: var(--green); }
.zone.orange { background: var(--orange); }
.zone.red { background: var(--red); }
.voice-feedback { text-align: center; border-radius: 18px; padding: 10px 12px; font-weight: 950; color: white; }
.voice-feedback.blue { background: var(--blue); }
.voice-feedback.green { background: var(--green); }
.voice-feedback.orange { background: var(--orange); }
.voice-feedback.red { background: var(--red); }
.hint { color: var(--muted); font-size: .92rem; }
.story-nav { display: flex; justify-content: center; gap: 14px; align-items: center; margin-top: 14px; font-size: 1.25rem; font-weight: 950; }
.story-nav button { min-width: 68px; }
.parent-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.panel { padding: 22px; }
.panel h2 { margin: 0 0 14px; letter-spacing: -.03em; }
.panel.wide { grid-column: 1 / -1; }
.hero-panel { background: linear-gradient(145deg, rgba(255,255,255,.92), rgba(238,242,255,.84)); }
label { display: block; margin-top: 14px; margin-bottom: 6px; font-weight: 850; }
textarea, input[type="text"], input[inputmode="numeric"] { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 14px 16px; outline: none; }
textarea:focus, input:focus { box-shadow: 0 0 0 4px rgba(108,99,255,.14); border-color: rgba(108,99,255,.5); }
input[type="range"] { width: 100%; accent-color: var(--violet); }
.status { min-height: 1.3em; font-weight: 850; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; margin: 12px 0; }
.thumb { border-radius: 20px; overflow: hidden; background: #f4f7fb; position: relative; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 110px; object-fit: cover; display: block; }
.thumb button { position: absolute; right: 6px; top: 6px; padding: 6px 9px; border-radius: 12px; background: rgba(255,255,255,.9); }
.floating { margin-top: 16px; }
.modal { position: fixed; inset: 0; background: rgba(23,32,51,.45); display: grid; place-items: center; padding: 20px; z-index: 10; }
.hidden { display: none; }
.modal-card { width: min(420px, 100%); padding: 24px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 14px; }
.error { color: #b33434; font-weight: 850; }
@media (max-width: 760px) {
  .app { padding-left: 10px; padding-right: 10px; }
  .topbar { align-items: flex-start; }
  .brand { flex-direction: row-reverse; text-align: right; margin-left: auto; }
  .logo { display: none; }
  .brand p { display: none; }
  .parent-access { padding: 12px 14px; }
  .parent-access span { display: inline; }
  .game-layout { grid-template-columns: minmax(0, 1fr) 116px; gap: 10px; align-items: stretch; }
  .story-card { min-height: calc(100svh - 174px); padding: 8px; border-radius: 24px; }
  .story-card::before { inset: 8px; border-radius: 20px; }
  .story-image { max-height: calc(100svh - 190px); border-radius: 18px; }
  .voice-panel { min-height: calc(100svh - 174px); border-radius: 24px; padding: 9px; gap: 8px; }
  .voice-header { flex-direction: column; gap: 0; }
  .voice-title { font-size: .8rem; }
  #levelText { font-size: 1.25rem; }
  .meter-wrap { grid-template-columns: 40px 1fr; gap: 7px; min-height: 0; }
  .zone { border-radius: 12px; padding: 4px 2px; font-size: .66rem; writing-mode: vertical-rl; transform: rotate(180deg); }
  .voice-feedback { padding: 8px 4px; font-size: .78rem; border-radius: 13px; }
  .voice-panel .primary { padding: 10px 7px; font-size: .72rem; white-space: normal; }
  .hint { font-size: .68rem; line-height: 1.15; text-align: center; }
  .story-nav { margin-top: 10px; gap: 10px; font-size: 1rem; }
  .story-nav button { min-width: 56px; padding: 12px 16px; }
  .parent-grid { grid-template-columns: 1fr; }
  .panel.wide { grid-column: auto; }
}
@media (max-width: 380px) {
  .game-layout { grid-template-columns: minmax(0, 1fr) 104px; }
  .zone { font-size: .6rem; }
  .voice-panel .primary { font-size: .68rem; }
}

/* V3 - Branding + score étoiles */
h1 span {
  display: inline-block;
  margin-left: .18em;
  font-size: .42em;
  letter-spacing: -.03em;
  color: var(--violet);
  vertical-align: middle;
  white-space: nowrap;
}
.score-card {
  background: rgba(255,255,255,.72);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 12px;
  box-shadow: 0 10px 24px rgba(28,34,64,.07);
}
.score-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-weight: 900;
  font-size: .86rem;
}
.score-top strong {
  color: var(--ink);
  font-size: 1rem;
}
.stars {
  margin-top: 3px;
  font-size: clamp(1.45rem, 3vw, 2rem);
  letter-spacing: .04em;
  line-height: 1;
  color: #ffb020;
  text-shadow: 0 4px 12px rgba(255,176,32,.22);
  white-space: nowrap;
}
.score-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.15;
  font-weight: 650;
}
@media (max-width: 760px) {
  h1 span { display: block; margin-left: 0; margin-top: 2px; font-size: .5em; }
  .score-card { padding: 8px 6px; border-radius: 15px; }
  .score-top { flex-direction: column; gap: 0; font-size: .66rem; text-align: center; }
  .score-top strong { font-size: .82rem; }
  .stars { font-size: 1.02rem; letter-spacing: 0; text-align: center; }
  .score-card small { display: none; }
}

/* V5 - calibrage micro + distance + score figé pendant les pauses */
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 20px;
  padding: 14px 16px;
  outline: none;
  font-weight: 800;
  color: var(--ink);
}
select:focus { box-shadow: 0 0 0 4px rgba(108,99,255,.14); border-color: rgba(108,99,255,.5); }
.mini-secondary {
  margin-top: 8px;
  width: 100%;
  padding: 8px 10px;
  font-size: .78rem;
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--line);
  box-shadow: none;
}
@media (max-width: 760px) {
  .mini-secondary { display: none; }
}


/* V6 - Info & Aide */
.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}
.help-access {
  flex: 0 0 auto;
  background: rgba(255,255,255,.75);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 10px 26px rgba(28,34,64,.08);
}
.help-card {
  width: min(760px, 100%);
  max-height: min(86svh, 820px);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.help-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 22px 24px 14px;
  border-bottom: 1px solid var(--line);
}
.help-head h2 { margin: 0; letter-spacing: -.03em; }
.help-subtitle {
  margin: 4px 0 0;
  color: var(--violet);
  font-weight: 950;
}
.icon-close {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 14px;
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--line);
  box-shadow: 0 8px 18px rgba(28,34,64,.08);
}
.help-scroll {
  overflow: auto;
  padding: 16px 24px 2px;
}
.help-section {
  background: rgba(255,255,255,.64);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  margin-bottom: 14px;
}
.help-section.highlight {
  background: linear-gradient(145deg, rgba(238,242,255,.92), rgba(255,255,255,.82));
  border-color: rgba(108,99,255,.18);
}
.help-section h3 {
  margin: 0 0 8px;
  letter-spacing: -.02em;
}
.help-section p { line-height: 1.45; }
.help-section ul, .help-section ol {
  margin: 8px 0 0;
  padding-left: 22px;
}
.help-section li {
  margin: 6px 0;
  line-height: 1.35;
}
.help-card .modal-actions {
  padding: 14px 24px 22px;
  border-top: 1px solid var(--line);
}
@media (max-width: 760px) {
  .top-actions { flex-direction: column; gap: 7px; align-items: stretch; }
  .parent-access, .help-access { padding: 10px 12px; font-size: .78rem; }
  .help-access span, .parent-access span { display: inline; }
  .help-card { max-height: 92svh; border-radius: 24px; }
  .help-head { padding: 16px 16px 10px; }
  .help-scroll { padding: 12px 16px 0; }
  .help-section { padding: 13px; border-radius: 18px; }
  .help-section p, .help-section li { font-size: .9rem; }
  .help-card .modal-actions { padding: 12px 16px 16px; }
}
@media (max-width: 420px) {
  .topbar { gap: 8px; }
  .top-actions { max-width: 116px; }
  .parent-access, .help-access { font-size: .72rem; padding: 9px 8px; }
}
