:root {
  --bg: #05010f;
  --panel: rgba(12, 6, 34, 0.93);
  --neon: #4dff88;
  --neon2: #00e5ff;
  --pink: #ff4fd8;
  --yellow: #ffd23f;
  --red: #ff5a6e;
  --text: #e8e6ff;
  --muted: #9a93c9;
  --u: min(48px, calc((100vw - 24px) / 15.2));
  --g: 4px;
  --pixel: "Press Start 2P", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#stage { position: relative; flex: 1; min-height: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#screens {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(3, 1, 10, 0.35);
}
#screens.hidden { display: none; }

.screen {
  display: none;
  background: var(--panel);
  border: 2px solid var(--neon);
  border-radius: 14px;
  box-shadow: 0 0 30px rgba(77, 255, 136, 0.25), inset 0 0 30px rgba(77, 255, 136, 0.05);
  padding: 24px 28px;
  max-width: 820px;
  width: 100%;
  max-height: 100%;
  overflow: auto;
  text-align: center;
}
.screen.active { display: block; }
.screen.wide { max-width: 900px; }
.screen.narrow { max-width: 460px; }

h1, h2, .btn { font-family: var(--pixel); }

h1.logo {
  font-size: clamp(28px, 6vw, 56px);
  margin: 8px 0 6px;
  color: var(--neon);
  text-shadow: 0 0 12px var(--neon), 4px 4px 0 #0a3d1f;
  letter-spacing: 2px;
}
h1.logo span { color: var(--pink); text-shadow: 0 0 12px var(--pink), 4px 4px 0 #4a0a3d; }

h2 { font-size: clamp(16px, 3vw, 22px); color: var(--neon2); margin: 4px 0 18px; line-height: 1.5; }

.tagline { color: var(--muted); margin: 0 0 24px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; margin: 0; }

.menu-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; margin-bottom: 20px; }

.btn {
  font-size: 12px;
  line-height: 1.4;
  padding: 12px 20px;
  min-width: 240px;
  border: 2px solid var(--neon);
  background: rgba(77, 255, 136, 0.08);
  color: var(--neon);
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, box-shadow 0.15s, color 0.15s;
}
.btn:hover, .btn:focus-visible {
  background: var(--neon);
  color: var(--bg);
  box-shadow: 0 0 16px var(--neon);
  outline: none;
  transform: translateY(-1px);
}
.btn.big {
  font-size: 15px;
  padding: 16px 24px;
  min-width: 300px;
  border-color: var(--yellow);
  color: var(--yellow);
  background: rgba(255, 210, 63, 0.08);
}
.btn.big:hover, .btn.big:focus-visible { background: var(--yellow); color: var(--bg); box-shadow: 0 0 16px var(--yellow); }
.btn.small { min-width: 0; font-size: 10px; padding: 10px 12px; }
.btn.danger { border-color: var(--red); color: var(--red); background: rgba(255, 90, 110, 0.08); }
.btn.danger:hover, .btn.danger:focus-visible { background: var(--red); color: var(--bg); box-shadow: 0 0 16px var(--red); }

.row-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.row-buttons .btn { min-width: 160px; }

.lang-switch { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }

.toggle {
  font-family: var(--pixel);
  font-size: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 2px solid #4a4470;
  background: #110c26;
  color: var(--muted);
  cursor: pointer;
  min-width: 64px;
}
.toggle.on { border-color: var(--neon); color: var(--bg); background: var(--neon); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* Missions */
#level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.level-card {
  background: rgba(0, 229, 255, 0.06);
  border: 2px solid var(--neon2);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font: inherit;
  transition: transform 0.1s, box-shadow 0.15s;
}
.level-card:hover:not(:disabled) { box-shadow: 0 0 14px var(--neon2); transform: translateY(-2px); }
.level-card.locked { opacity: 0.4; cursor: not-allowed; border-color: #555; }
.lv-num { font-family: var(--pixel); font-size: 9px; color: var(--neon2); }
.lv-name { font-weight: 700; font-size: 15px; }
.lv-keys { min-height: 24px; }
.cap {
  display: inline-block;
  min-width: 22px;
  padding: 2px 5px;
  margin: 0 3px 3px 0;
  border: 1px solid var(--muted);
  border-radius: 4px;
  font-family: "Courier New", monospace;
  font-weight: 700;
  text-align: center;
}
.stars { color: var(--yellow); letter-spacing: 2px; }
.stars .off { color: #3a3460; }
.lv-stars { font-size: 18px; }

/* Options */
.opt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  gap: 12px;
  text-align: left;
}

.help-text { text-align: left; line-height: 1.6; font-size: 16px; }
.help-text p { margin: 0 0 10px; }

/* Fin de partie */
#end-stars { font-size: 44px; text-shadow: 0 0 12px var(--yellow); margin-bottom: 6px; }
#end-record { color: var(--pink); font-family: var(--pixel); font-size: 13px; animation: blink 1s infinite; min-height: 1em; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 10px 0; }
.stat { background: rgba(255, 255, 255, 0.05); border-radius: 8px; padding: 12px 8px; }
.stat .v { font-family: var(--pixel); font-size: 16px; color: var(--neon); margin-top: 8px; }
.stat .l { font-size: 13px; color: var(--muted); }

/* Clavier à l'écran */
#kbd-wrap {
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: linear-gradient(#0d0726, var(--bg));
  border-top: 2px solid rgba(77, 255, 136, 0.35);
}
#kbd-wrap.hidden { display: none; }
#finger-hint { font-family: var(--pixel); font-size: 11px; min-height: 14px; color: var(--muted); }

.kbd { display: flex; flex-direction: column; gap: var(--g); align-items: flex-start; }
.kb-row { display: flex; gap: var(--g); }
.key {
  width: calc(var(--u) - var(--g));
  height: calc(var(--u) * 0.82);
  border-radius: 6px;
  border: 2px solid var(--fc, #555);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: calc(var(--u) * 0.36);
  color: #fff;
  position: relative;
  transition: transform 0.08s, opacity 0.2s, box-shadow 0.15s;
  user-select: none;
}
.key.mod { border-color: #2a2448; background: #0d0a1e; color: #4a4470; font-size: calc(var(--u) * 0.3); }
.key.mod.ghost { border-color: transparent; background: transparent; }
.key.space { width: calc(var(--u) * 6 - var(--g)); }
.key.anchor::after {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 35%;
  width: 30%;
  height: 3px;
  background: #fff;
  border-radius: 2px;
  opacity: 0.8;
}
.key.dim { opacity: 0.22; }
.key.next {
  background: var(--fc) !important;
  color: var(--bg);
  opacity: 1;
  transform: translateY(-2px) scale(1.08);
  box-shadow: 0 0 18px var(--fc);
  animation: pulse 0.8s infinite;
  z-index: 1;
}
.key.hit { transform: scale(0.88); }
.key.miss { background: #ff3040 !important; border-color: #ff3040; }
.key.editable { cursor: pointer; }
.key.editable:hover { transform: translateY(-2px); box-shadow: 0 0 10px var(--fc); }
.key.selected { outline: 3px solid #fff; outline-offset: 2px; }

@keyframes pulse { 50% { box-shadow: 0 0 4px var(--fc); } }
@keyframes blink { 50% { opacity: 0.4; } }

/* Éditeur de clavier */
.editor-top { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; align-items: center; }
.editor-top label { display: flex; gap: 8px; align-items: center; }
select, input {
  font-size: 15px;
  padding: 8px;
  border-radius: 6px;
  border: 2px solid var(--neon2);
  background: #0b0620;
  color: var(--text);
}
#editor-kbd { margin: 14px auto; width: max-content; max-width: 100%; }
#editor-panel { min-height: 120px; background: rgba(255, 255, 255, 0.04); border-radius: 10px; padding: 14px; }
.ed-row { display: flex; gap: 16px; align-items: center; justify-content: center; flex-wrap: wrap; }
.ed-key {
  width: 64px;
  height: 64px;
  border: 3px solid var(--fc);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: 800;
}
.ed-capture { color: var(--yellow); font-family: var(--pixel); font-size: 10px; animation: blink 1s infinite; min-height: 12px; margin: 0 0 8px; }
#ed-char { width: 3em; text-align: center; font-size: 20px; font-weight: 700; }
.ed-label { margin: 12px 0 6px; color: var(--muted); }
.finger-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.finger-btn {
  border: 2px solid var(--fc);
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  padding: 6px;
  font-size: 12px;
  cursor: pointer;
}
.finger-btn.active { background: var(--fc); color: var(--bg); font-weight: 700; }
.ed-actions { display: flex; gap: 10px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 120px);
  background: var(--neon);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 8px;
  font-family: var(--pixel);
  font-size: 11px;
  transition: transform 0.3s;
  z-index: 10;
  pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .btn, .btn.big { min-width: 0; width: 100%; }
  .finger-btns { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Ambiance « Jardin » ---------- */
body.theme-garden {
  --bg: #fff0f7;
  --panel: rgba(255, 255, 255, 0.93);
  --neon: #ff4f9a;
  --neon2: #9b59d0;
  --pink: #9b59d0;
  --yellow: #c2187a;
  --red: #e53950;
  --text: #5b2c4f;
  --muted: #9b6b8e;
  --pixel: "Fredoka", "Comic Sans MS", sans-serif;
}
.theme-garden h1, .theme-garden h2, .theme-garden .btn, .theme-garden .toggle { font-weight: 700; }
.theme-garden h1.logo { text-shadow: 3px 3px 0 #ffd1e6; letter-spacing: 1px; }
.theme-garden h1.logo span { text-shadow: 3px 3px 0 #ead7f7; }
.theme-garden h2 { font-size: clamp(20px, 3.6vw, 28px); }
.theme-garden .btn { font-size: 16px; border-radius: 999px; background: #fff; }
.theme-garden .btn.big { font-size: 19px; background: #fff; }
.theme-garden .btn:hover, .theme-garden .btn:focus-visible { background: var(--neon); color: #fff; }
.theme-garden .btn.big:hover, .theme-garden .btn.big:focus-visible { background: var(--yellow); }
.theme-garden .btn.danger:hover, .theme-garden .btn.danger:focus-visible { background: var(--red); }
.theme-garden .toggle:not(.on):hover { border-color: var(--neon); color: var(--neon); }
.theme-garden .btn.small { font-size: 13px; }
.theme-garden #screens { background: rgba(255, 240, 248, 0.3); }
.theme-garden .screen {
  border-color: #ffb3d1;
  border-width: 3px;
  border-radius: 24px;
  box-shadow: 0 10px 40px rgba(255, 79, 154, 0.25);
}
.theme-garden .toggle { font-size: 13px; background: #fff; border-color: #ecd5e5; color: var(--muted); border-radius: 999px; }
.theme-garden .toggle.on { background: var(--neon); border-color: var(--neon); color: #fff; }
.theme-garden .level-card { background: #fff; border-color: #e4c1f9; border-radius: 16px; }
.theme-garden .level-card:hover:not(:disabled) { box-shadow: 0 6px 18px rgba(155, 89, 208, 0.3); }
.theme-garden .lv-num { font-size: 13px; }
.theme-garden .stars { color: #ffb300; }
.theme-garden .stars .off { color: #ecd5e5; }
.theme-garden #end-stars { text-shadow: 0 2px 0 #ffe0a3; }
.theme-garden #end-record { font-size: 18px; }
.theme-garden .stat { background: #fff5fa; }
.theme-garden .stat .v { font-size: 22px; }
.theme-garden select, .theme-garden input { background: #fff; color: var(--text); border-color: #e4c1f9; }
.theme-garden #editor-panel { background: #fff5fa; }
.theme-garden .finger-btn { background: #fff; }
.theme-garden .finger-btn.active { color: #3a1f33; }
.theme-garden .ed-capture { font-size: 14px; }
.theme-garden #kbd-wrap { background: linear-gradient(#e6f7ef, #fff0f7); border-top-color: #9be08f; }
.theme-garden #finger-hint { font-size: 15px; font-weight: 700; color: var(--text) !important; }
.theme-garden .key { color: var(--text); border-radius: 10px; }
.theme-garden .key.anchor::after { background: var(--text); }
.theme-garden .key.next { color: #3a1f33; }
.theme-garden .key.mod { background: #fff; border-color: #ecd5e5; color: #d9b8cd; }
.theme-garden .key.mod.ghost { background: transparent; border-color: transparent; }
.theme-garden #toast { color: #fff; font-size: 14px; }

/* ---------- Survie : listes de vocabulaire ---------- */
h3 { font-family: var(--pixel); font-size: 13px; color: var(--neon); margin: 26px 0 12px; line-height: 1.5; }
.theme-garden h3 { font-size: 18px; }
#list-items { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.list-item {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 12px 14px;
  border: 2px solid rgba(0, 229, 255, 0.35);
  border-radius: 10px;
  background: rgba(0, 229, 255, 0.05);
}
.li-info { flex: 1 1 260px; min-width: 0; }
.li-name { font-weight: 700; font-size: 16px; }
.li-meta { color: var(--muted); font-size: 13px; margin: 2px 0 4px; }
.li-sample { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn.go { border-color: var(--yellow); color: var(--yellow); }
.btn.go:hover, .btn.go:focus-visible { background: var(--yellow); box-shadow: 0 0 12px var(--yellow); color: var(--bg); }
.field { display: flex; gap: 10px; align-items: center; justify-content: center; margin-bottom: 8px; }
.field input { width: min(360px, 70vw); }
#list-text {
  width: 100%;
  font: 16px/1.5 "Courier New", monospace;
  padding: 10px 12px;
  border-radius: 8px;
  border: 2px solid var(--neon2);
  background: #0b0620;
  color: var(--text);
  resize: vertical;
}
.check { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 10px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; }
#list-preview { text-align: left; font-size: 14px; }
#list-preview p { margin: 6px 0; }
.warn { color: var(--yellow); }
#end-missed { margin: 8px 0; line-height: 2; }
#end-missed .cap { font-size: 15px; }
.theme-garden .list-item { background: #fff; border-color: #e4c1f9; border-radius: 16px; }
.theme-garden .btn.go:hover, .theme-garden .btn.go:focus-visible { color: #fff; }
.theme-garden #list-text { background: #fff; border-color: #e4c1f9; }
