:root {
  --bg: #0f1115;
  --fg: #e8e8ec;
  --muted: #8a8f9c;
  --accent: #6ee7b7;
  --accent-2: #fbbf24;
  --danger: #f87171;
  --panel: #181b22;
  --panel-2: #222732;
  --border: #2a2f3a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 14px 16px 28px;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}

/* ---- En-tête / menu ---- */

header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 800px;
}
.topbar { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; position: relative; }
h1 { margin: 0; font-size: 1.4rem; letter-spacing: 0.15em; text-transform: uppercase; }
.topbar #btn-history { position: absolute; right: 0; top: 50%; transform: translateY(-50%); }
.hint { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; text-align: center; }

.daily-btn {
  margin-top: 4px;
  padding: 12px 28px;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: 999px;
  border-color: var(--accent-2);
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.18), rgba(251, 191, 36, 0.05));
  box-shadow: 0 6px 24px rgba(251, 191, 36, 0.15);
}
.daily-btn:hover { background: rgba(251, 191, 36, 0.25); }
.daily-btn.active { background: var(--accent-2); color: #0f1115; }

.free { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.free-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }

.menu { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.menu button, .chips button, button.small {
  min-width: 0;
  padding: 7px 14px;
  font-size: 0.9rem;
  border-radius: 999px;
}
.menu button .ico { margin-right: 6px; }
.menu button.active, .chips button.active, button.small.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f1115;
  font-weight: 600;
}
.menu.modes button { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.85rem; }
.menu.levels button { font-size: 0.8rem; padding: 5px 12px; color: var(--muted); }
.menu.levels button.active { color: #0f1115; }
button.small { font-size: 0.8rem; padding: 5px 12px; }

/* ---- Panneaux (historique, défi) ---- */

.panel {
  width: 100%;
  max-width: 800px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.panel h2 { margin: 0; font-size: 1.1rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; width: 100%; }

.history { list-style: none; margin: 0; padding: 0; width: 100%; max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.history li { display: grid; grid-template-columns: 24px 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; background: var(--panel-2); font-size: 0.9rem; }
.hist-meta { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.hist-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.daily-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; width: 100%; }
.daily-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 8px; min-width: 0; border-radius: 12px;
  border: 1px solid var(--border); background: var(--panel-2);
}
.daily-card:not(:disabled):hover { border-color: var(--accent-2); }
.daily-card:disabled { opacity: 1; cursor: default; }
.daily-card.won { border-color: var(--accent); }
.daily-card.lost { border-color: var(--danger); }
.daily-icon { font-size: 1.8rem; }
.daily-label { font-weight: 600; }
.daily-state { font-size: 0.8rem; color: var(--muted); }
.daily-card.won .daily-state { color: var(--accent); }
.daily-card.lost .daily-state { color: var(--danger); }
.daily-boxes { font-size: 0.75rem; letter-spacing: 1px; }
.daily-answer { font-size: 0.75rem; color: var(--muted); text-align: center; }

/* ---- Zone de jeu ---- */

.play {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 800px;
}

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 160px;
}

.frame { position: relative; max-width: 100%; }

#cover {
  display: block;
  max-width: 100%;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  background: var(--panel);
}
body[data-mode="depixel"] #cover { cursor: pointer; }

.title {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.75);
  color: var(--accent);
  font-size: 1.2rem;
  font-weight: 600;
  text-align: center;
  backdrop-filter: blur(6px);
  animation: pop 0.3s ease-out;
}

@keyframes pop {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.progress { width: 100%; height: 6px; border-radius: 3px; background: var(--panel); overflow: hidden; }
.bar { height: 100%; width: 0%; background: var(--accent); transition: width 0.25s linear; }

.exit-full { display: none; }

/* ---- Plein écran (natif ou simulé) : image + contrôles ---- */

.play:fullscreen, .play.pseudo-full {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  max-width: none;
  gap: 6px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: #000;
  z-index: 100;
  overflow: hidden;
}
.play:fullscreen .stage, .play.pseudo-full .stage { flex: 1; min-height: 0; gap: 6px; }
.play:fullscreen #cover, .play.pseudo-full #cover { border-radius: 0; box-shadow: none; }
.play:fullscreen .progress, .play.pseudo-full .progress { height: 4px; }
.play:fullscreen .title, .play.pseudo-full .title { bottom: 24px; font-size: 1.5rem; }
.play:fullscreen .exit-full, .play.pseudo-full .exit-full {
  display: block;
  position: absolute;
  top: 8px; right: 8px;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0.5;
  z-index: 2;
}
.play:fullscreen .exit-full:hover, .play.pseudo-full .exit-full:hover { opacity: 1; }
.play:fullscreen .mode-panel, .play.pseudo-full .mode-panel { gap: 6px; }
.play:fullscreen .options, .play.pseudo-full .options { display: none; }
.play:fullscreen button, .play.pseudo-full button { padding: 8px 14px; font-size: 0.9rem; }
.play:fullscreen #guess-input, .play:fullscreen #depixel-input,
.play.pseudo-full #guess-input, .play.pseudo-full #depixel-input { padding: 8px 12px; }
.play:fullscreen .status, .play.pseudo-full .status { font-size: 0.75rem; }

/* ---- Boutons génériques ---- */

button {
  padding: 11px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--fg);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  min-width: 100px;
  transition: background 0.15s, transform 0.1s;
}
button:hover { background: var(--panel-2); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: default; transform: none; }
button.primary { border-color: var(--accent); }

.status, .error, .footer, .result-line { margin: 0; color: var(--muted); font-size: 0.85rem; text-align: center; }
.error { color: var(--danger); max-width: 560px; }
.result-line { color: var(--fg); font-size: 1rem; }
.footer { margin-top: auto; padding-top: 12px; font-size: 0.72rem; line-height: 1.6; }
.footer a { color: var(--muted); }

/* ---- Contrôles des modes ---- */

.mode-panel { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; max-width: 600px; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.options { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; }
.chips-label { color: var(--muted); font-size: 0.8rem; margin-right: 4px; min-width: 48px; text-align: right; }
.chips button { padding: 5px 11px; font-size: 0.82rem; }

.clues { display: flex; gap: 6px; justify-content: center; }
.clues button { min-width: 38px; padding: 6px 0; font-size: 0.9rem; border-radius: 6px; }
.clues button.current { border-color: var(--accent); color: var(--accent); }
.clues button.wrong { background: rgba(248, 113, 113, 0.15); border-color: var(--danger); color: var(--danger); }
.clues button:disabled { opacity: 0.35; }

.hints { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.hints li { padding: 4px 12px; border-radius: 999px; background: rgba(251, 191, 36, 0.12); border: 1px solid rgba(251, 191, 36, 0.4); color: var(--accent-2); font-size: 0.85rem; }

.guess-form { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; width: 100%; }
.guess-field { position: relative; flex: 1 1 240px; }
.guess-field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--fg);
  font-size: 1rem;
  font-family: inherit;
}
.guess-field input:focus { outline: none; border-color: var(--accent); }
.guess-field input:disabled { opacity: 0.5; }
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 20;
  max-height: 260px;
  overflow-y: auto;
  text-align: left;
}
.suggestions li { padding: 8px 14px; cursor: pointer; font-size: 0.95rem; }
.suggestions li:hover, .suggestions li.active { background: rgba(110, 231, 183, 0.15); }

.guesses { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.guesses:empty { display: none; }
.guesses li {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: var(--danger);
  font-size: 0.85rem;
  text-decoration: line-through;
}

.result { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.result p { margin: 0; font-size: 1.05rem; }

/* ---- Vérification « humain » ---- */

.human-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 17, 21, 0.92);
  padding: 16px;
}
.human-box {
  width: 100%; max-width: 380px;
  padding: 24px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--panel);
  display: flex; flex-direction: column; gap: 14px;
}
.human-box h2 { margin: 0; font-size: 1.1rem; }
.human-check {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer; font-size: 1rem;
}
.human-check input { width: 22px; height: 22px; accent-color: var(--accent); cursor: pointer; }
.human-check.checking { border-color: var(--accent-2); }
.human-check.checking input { visibility: hidden; }
.human-check.checking::before {
  content: ""; width: 18px; height: 18px; margin-right: -30px;
  border: 3px solid var(--accent-2); border-top-color: transparent; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.human-check.ok { border-color: var(--accent); }
.human-note { margin: 0; color: var(--muted); font-size: 0.8rem; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 520px) {
  button { padding: 10px 14px; min-width: 0; }
  .topbar #btn-history { position: static; transform: none; }
  .topbar { flex-wrap: wrap; }
  .chips-label { min-width: 0; text-align: center; width: 100%; }
}
