/* ═══════════════════════════════════════════
   Variables & Reset
═══════════════════════════════════════════ */
:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --surface2: #21262d;
  --border:   #30363d;
  --accent:   #f97316;
  --accent2:  #fbbf24;
  --green:    #3fb950;
  --red:      #f85149;
  --yellow:   #d29922;
  --text:     #e6edf3;
  --muted:    #7d8590;
  --radius:   10px;
  --mono: 'Fira Code', 'Cascadia Code', 'Courier New', monospace;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}

/* ═══════════════════════════════════════════
   HOME SCREEN
═══════════════════════════════════════════ */
#screen-home {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 24px 40px;
  gap: 48px;
  background:
    radial-gradient(ellipse at 25% 25%, rgba(249,115,22,.14) 0%, transparent 55%),
    radial-gradient(ellipse at 75% 75%, rgba(249,115,22,.07) 0%, transparent 55%);
}

.home-hero { text-align: center; }

.home-logo {
  font-size: 2.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
}

.home-sub { color: var(--muted); font-size: 1.05rem; }

.home-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  max-width: 860px;
  width: 100%;
}

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 38px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  transition: transform .18s, border-color .18s, box-shadow .18s;
}

.game-card:hover           { transform: translateY(-4px); }
.game-card.html-card:hover { border-color: #f97316; box-shadow: 0 12px 40px rgba(249,115,22,.18); }
.game-card.css-card:hover  { border-color: #f97316; box-shadow: 0 12px 40px rgba(249,115,22,.18); }

.game-card-icon { font-size: 3rem; }
.game-card h2   { font-size: 1.5rem; }
.game-card p    { color: var(--muted); font-size: .9rem; line-height: 1.65; flex: 1; }

.game-card-meta {
  font-size: .9rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.btn-play {
  align-self: flex-start;
  background: rgba(249,115,22,.15);
  border: 1px solid rgba(249,115,22,.4);
  border-radius: 8px;
  color: #f97316;
  font-weight: 700;
  font-size: .9rem;
  padding: 9px 20px;
  cursor: pointer;
  transition: background .15s;
}
.btn-play:hover         { background: rgba(249,115,22,.25); }
.btn-play.css-btn       { background: rgba(249,115,22,.15); border-color: rgba(249,115,22,.4); color: #f97316; }
.btn-play.css-btn:hover { background: rgba(249,115,22,.25); }

/* ═══════════════════════════════════════════
   EN-TÊTE DES JEUX
═══════════════════════════════════════════ */
.game-header {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 11px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-back {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: .9rem;
  padding: 6px 13px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.btn-back:hover { color: #fff; border-color: var(--accent); }

.header-title {
  font-weight: 700;
  font-size: .95rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.progress-wrap { flex: 1; }

.progress-bg {
  background: var(--border);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
}

.progress-fill {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  height: 100%;
  width: 0;
  border-radius: 99px;
  transition: width .5s ease;
}

.progress-label { font-size: .82rem; color: var(--muted); margin-top: 3px; text-align: center; }

.header-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

.lives      { display: flex; gap: 3px; }
.heart      { font-size: .95rem; transition: opacity .25s; }
.heart.lost { opacity: .2; filter: grayscale(1); }

.score-badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px 13px;
  font-size: .9rem;
  color: var(--accent2);
  font-weight: 600;
}

.btn-help {
  background: rgba(255,229,102,.12);
  border: 1px solid rgba(255,229,102,.35);
  border-radius: 6px;
  color: #ffe566;
  font-size: .88rem;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-help:hover { background: rgba(255,229,102,.22); border-color: rgba(255,229,102,.55); }

/* ═══════════════════════════════════════════
   CARTE CHALLENGE
═══════════════════════════════════════════ */
.challenge-card {
  flex-shrink: 0;
  background: rgba(251,146,60,.12);
  border: 2px solid rgba(251,146,60,.45);
  border-radius: 10px;
  margin: 12px 14px;
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: background .4s, border-color .4s;
}

/* Actions dans le header de l'éditeur */
.editor-hdr-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-validate-hdr {
  font-size: .85rem;
  padding: 4px 14px;
  border-radius: 5px;
}

.btn-reset-float {
  position: absolute;
  top: 7px;
  right: 7px;
  z-index: 5;
  background: rgba(0,0,0,.06);
  border: 1px solid rgba(0,0,0,.15);
  border-radius: 5px;
  color: #94a3b8;
  font-size: .85rem;
  padding: 2px 8px;
  cursor: pointer;
  transition: background .15s, color .15s;
  line-height: 1.6;
}
.btn-reset-float:hover { background: rgba(0,0,0,.13); color: #1e293b; }

.challenge-card.validated {
  background: rgba(74,222,128,.12);
  border-color: rgba(74,222,128,.5);
}

.lvl-badge {
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 6px;
  padding: 4px 11px;
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #fff;
  margin-top: 2px;
}

.challenge-text h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 6px; color: #fff; }

.challenge-text p {
  color: #fff;
  font-size: .93rem;
  line-height: 1.7;
}

.ht {
  display: inline-block;
  background: rgba(0,0,0,.3);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 3px;
  padding: 0 6px;
  font-family: var(--mono);
  font-size: .79rem;
  color: #fde68a;
}

/* ═══════════════════════════════════════════
   COMPOSANTS PARTAGÉS
═══════════════════════════════════════════ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.panel-hdr {
  flex-shrink: 0;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.dot        { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-red    { background: #f87171; }
.dot-yellow { background: #fbbf24; }
.dot-green  { background: #4ade80; }
.dot-orange { background: #f97316; }

.panel-body { flex: 1; padding: 16px 18px; overflow-y: auto; }

.btn {
  border: none;
  border-radius: 7px;
  font-weight: 600;
  font-size: .88rem;
  padding: 9px 20px;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn:hover  { opacity: .9; }
.btn:active { transform: scale(.97); }

.btn-primary  { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.btn-success  { background: linear-gradient(135deg, #22c55e, #16a34a); color: #fff; }
.btn-outline { background: var(--surface2); border: 1px solid var(--accent); color: var(--accent); }
.btn-ghost   { background: none; border: none; color: var(--muted); font-size: .88rem; cursor: pointer; text-decoration: underline; }

.feedback {
  flex-shrink: 0;
  margin: 0 14px 0;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: .95rem;
  font-weight: 600;
  line-height: 1.6;
  display: none;
}
.feedback.show { display: block; }
.feedback.ok   { background: rgba(74,222,128,.12);  border: 2px solid rgba(74,222,128,.5);  color: #4ade80; }
.feedback.err  { background: rgba(248,113,113,.12); border: 2px solid rgba(248,113,113,.5); color: #f87171; }
.feedback.info { background: rgba(139,92,246,.12);  border: 2px solid rgba(139,92,246,.4);  color: #a78bfa; }
.feedback.warn { background: rgba(251,191,36,.12);  border: 2px solid rgba(251,191,36,.4);  color: var(--yellow); }


/* ═══════════════════════════════════════════
   ZONE DE TRAVAIL (grille 50/50)
═══════════════════════════════════════════ */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

/* ═══════════════════════════════════════════
   PANNEAU ÉDITEUR
═══════════════════════════════════════════ */
.editor-panel {
  display: flex;
  flex-direction: column;
  background: #1a1d27;
  border-right: 1px solid var(--border);
  min-height: 0;
}

.editor-panel .panel-hdr {
  background: #13151f;
  border-bottom-color: var(--border);
}

.editor-code-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #ffffff;
  margin: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  position: relative;
}

.editor-label { flex-shrink: 0; }

/* Feedback inline dans le panel-hdr */
.panel-hdr .feedback {
  flex: 1;
  margin: 0;
  padding: 2px 10px;
  font-size: .88rem;
  border-radius: 5px;
  display: none;
}
.panel-hdr .feedback.show { display: block; }
.panel-hdr:has(.feedback.show) .editor-label { display: none; }

.editor-actions { display: flex; gap: 7px; align-items: center; flex-shrink: 0; }

.editor-expl { flex-shrink: 0; padding: 0 14px 12px; }

/* ═══════════════════════════════════════════
   PANNEAU APERÇU — objectif en haut, résultat en bas
═══════════════════════════════════════════ */
.preview-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.preview-half {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.preview-half + .preview-half { border-top: 2px solid var(--border); }

.preview-half-label {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 7px 12px;
  font-size: .9rem;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .1em;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.preview-half-body {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #fff;
}

.preview-half-body::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  border: 3px solid transparent;
  transition: border-color .6s;
}

.preview-half-body.border-ok::after  { border-color: var(--green); }
.preview-half-body.border-err::after { border-color: var(--red); }

.preview-half-body iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* Iframe de validation — hors écran, invisible */
.iframe-hidden {
  position: fixed;
  top: -9999px;
  left: -9999px;
  width: 900px;
  height: 700px;
  border: none;
  visibility: hidden;
  pointer-events: none;
}

/* ═══════════════════════════════════════════
   TIROIR D'AIDE (dans le bloc-note)
═══════════════════════════════════════════ */
.help-drawer {
  position: absolute;
  bottom: 34px; /* hauteur du btn-help-inline */
  left: 0;
  right: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height .35s ease;
  background: #0d1117;
  z-index: 10;
}

.help-drawer.open { max-height: 260px; }

.help-drawer-inner {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 260px;
  scrollbar-width: none;
}

.help-drawer-inner::-webkit-scrollbar { display: none; }

.btn-help-inline {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fb923c;
  border: none;
  border-top: 2px solid 0d1117;
  color: #0d1117;
  padding: 7px 0;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 700;
  font-family: inherit;
  border-radius: 0 0 8px 8px;
  transition: background .15s;
  z-index: 11;
}
.btn-help-inline:hover { background: #0d1117; color: #fb923c}

.help-chip {
  background: #fff;
  border: 1px solid #f59332;
  border-left: 3px solid #f97316;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color .15s;
}

.help-chip:hover { border-color: #f97316; }

/* Couleur de la bordure gauche selon le type */
.help-chip--property { border-left-color: #f97316; }
.help-chip--value    { border-left-color: #fb923c; }
.help-chip--selector { border-left-color: #f59e0b; }
.help-chip--pseudo   { border-left-color: #f59e0b; }
.help-chip--unit     { border-left-color: #fb923c; }
.help-chip--color    { border-left-color: #f97316; }
.help-chip--tag      { border-left-color: #f97316; }
.help-chip--attr     { border-left-color: #3b82f6; }

/* Badge de type */
.tip-type {
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 2px 7px;
  border-radius: 3px;
  align-self: flex-start;
  line-height: 1.6;
}

.tip-type--property { background: #fdc878; color: #c2410c; }
.tip-type--value    { background: #fdc878; color: #c2410c; }
.tip-type--selector { background: #fef9c3; color: #92400e; }
.tip-type--pseudo   { background: #fef9c3; color: #92400e; }
.tip-type--unit     { background: #fdc878; color: #c2410c; }
.tip-type--color    { background: #fdc878; color: #c2410c; }
.tip-type--tag      { background: #fdc878; color: #c2410c; }
.tip-type--attr     { background: #bfdbfe; color: #1d4ed8; }

.help-code {
  font-family: var(--mono);
  font-size: .95rem;
  color: #7c2d12;
  background: #fdc878;
  border-radius: 4px;
  padding: 2px 8px;
  display: inline-block;
  cursor: pointer;
  user-select: none;
  transition: background .15s, color .15s;
}
.help-code:hover { background: #f59332; color: #fff; }
.help-code.copied { background: #16a34a; color: #fff; }

.help-chip--attr .help-code { background: #bfdbfe; color: #1d4ed8; }
.help-chip--attr .help-code:hover { background: #3b82f6; color: #fff; }

.help-chip-attrs {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(59,130,246,.3);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-attr-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  padding-left: 8px;
  border-left: 2px solid #bfdbfe;
}

.help-attr-item .help-desc { font-size: .9rem; }

.help-code--attr { background: #bfdbfe; color: #1d4ed8; font-size: .85rem; }
.help-code--attr:hover { background: #3b82f6; color: #fff; }

.help-desc {
  font-size: .9rem;
  color: #57534e;
  line-height: 1.5;
}

.tip-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.tip-example {
  font-family: var(--mono);
  font-size: .9rem;
  color: #6d28d9;
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
  border-radius: 4px;
  padding: 1px 6px;
  cursor: pointer;
  user-select: none;
  transition: background .15s, color .15s;
}
.tip-example:hover  { background: #7c3aed; color: #fff; border-color: #7c3aed; }
.tip-example.copied { background: #16a34a; color: #fff; border-color: #16a34a; }

/* ═══════════════════════════════════════════
   ÉCRAN DE FIN (modal)
═══════════════════════════════════════════ */
#end-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,17,23,.92);
  backdrop-filter: blur(6px);
  z-index: 300;
  align-items: center;
  justify-content: center;
}

#end-screen.show { display: flex; }

.end-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 52px;
  text-align: center;
  max-width: 420px;
  width: 90%;
}

.end-card .trophy { font-size: 3.5rem; margin-bottom: 14px; }
.end-card h2      { font-size: 1.6rem; margin-bottom: 8px; }
.end-card p       { color: var(--muted); margin-bottom: 20px; font-size: .9rem; }
.end-score        { font-size: 2.2rem; font-weight: 700; color: var(--accent2); margin-bottom: 26px; }

.btn-home-end { padding: 12px 30px; font-size: 1rem; }

.home-nav {
  width: 100%;
  max-width: 860px;
  align-self: center;
}

.back-to-home {
  font-size: .9rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  transition: color .15s;
}
.back-to-home:hover { color: var(--text); }

/* ═══════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════ */
@media (max-width: 700px) {
  .home-cards   { grid-template-columns: 1fr; }
  .workspace    { grid-template-columns: 1fr; }
  .preview-half { min-height: 200px; }
  .end-card     { padding: 32px 22px; }
  .help-panel   { width: 85%; right: -85%; }
}

/* ── Footer ─────────────────────────────── */
.site-footer {
  text-align: center;
  padding: 12px 24px;
  font-size: .75rem;
  color: #7d8590;
  border-top: 1px solid #21262d;
}
