/* CAP MOTS — Mot mystère | CAP SAVOIRS
   Feuille de style unique de l'application et de l'administration. */

:root {
    --brand: #5A4BE0;
    --brand-dark: #4234B8;
    --brand-soft: #ECE9FF;
    --brand-softer: #F6F5FF;
    --accent: #FFB020;
    --accent-soft: #FFF4DE;
    --green: #16A34A;
    --green-soft: #E6F7ED;
    --red: #E11D48;
    --red-soft: #FDEAEE;
    --blue: #0EA5E9;
    --bg: #F4F3FB;
    --card: #FFFFFF;
    --ink: #1E1B33;
    --ink-soft: #4A4763;
    --muted: #6F6C86;
    --line: #E7E5F2;
    --radius: 18px;
    --radius-sm: 12px;
    --radius-lg: 24px;
    --shadow: 0 4px 16px rgba(30, 27, 51, .06);
    --shadow-lg: 0 10px 30px rgba(30, 27, 51, .10);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.2; font-weight: 800; letter-spacing: -.01em; }
h1 { font-size: 26px; }
h2 { font-size: 21px; }
h3 { font-size: 18px; }
h4 { font-size: 16px; }
p { margin: 0 0 10px; }
a { color: var(--brand); text-decoration: none; }
img { max-width: 100%; height: auto; }
svg { display: block; }
[hidden] { display: none !important; }

/* ---------- Barre de titre ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}

.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo {
    width: 38px; height: 38px; border-radius: 12px;
    background: var(--brand); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 15px; flex: 0 0 auto;
}
.topbar-title { font-weight: 800; font-size: 16px; line-height: 1.1; }
.topbar-sub { font-size: 12px; color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
    background: #fff; color: var(--ink); display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: transform .12s ease, background .2s ease;
}
.icon-btn:active { transform: scale(.95); }
.icon-btn.is-off { background: var(--brand-soft); border-color: var(--brand-soft); color: var(--brand); }

/* ---------- Structure ---------- */
.page {
    max-width: 1080px;
    margin: 0 auto;
    padding: 16px 16px calc(96px + env(safe-area-inset-bottom, 0px));
}
.page-narrow { max-width: 720px; }
.section { margin-bottom: 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 800; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Cartes ---------- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 14px;
}
.card-tight { padding: 14px; }
.card-soft { background: var(--brand-softer); box-shadow: none; border: 1px solid var(--line); }
.card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.card-head h3 { margin: 0; }
.card-icon {
    width: 42px; height: 42px; border-radius: 14px; flex: 0 0 auto;
    background: var(--brand-soft); color: var(--brand);
    display: flex; align-items: center; justify-content: center;
}
.card-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 14px 20px; border-radius: 14px; border: 1px solid transparent;
    background: var(--brand); color: #fff; font-weight: 700; font-size: 16px;
    font-family: inherit; cursor: pointer; width: 100%;
    transition: transform .12s ease, filter .2s ease, background .2s ease;
    text-align: center;
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--brand); border-color: var(--brand); }
.btn-ghost { background: var(--brand-soft); color: var(--brand-dark); }
.btn-soft { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-danger { background: var(--red); color: #fff; }
.btn-accent { background: var(--accent); color: #3A2B00; }
.btn-small { padding: 10px 14px; font-size: 14px; border-radius: 12px; width: auto; }
.btn-large { padding: 18px 22px; font-size: 18px; border-radius: 16px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { width: auto; flex: 1 1 160px; }

/* ---------- Etiquettes ---------- */
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px; border-radius: 999px;
    background: var(--brand-soft); color: var(--brand-dark);
    font-size: 13px; font-weight: 700;
}
.chip-accent { background: var(--accent-soft); color: #7A5200; }
.chip-green { background: var(--green-soft); color: var(--green); }
.chip-red { background: var(--red-soft); color: var(--red); }
.chip-grey { background: #F1F0F7; color: var(--muted); }
.chip-level { background: #fff; border: 1px solid var(--line); color: var(--ink-soft); }

/* ---------- Formulaires ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; color: var(--ink-soft); }
.input, .select, .textarea {
    width: 100%; padding: 14px; border-radius: 14px;
    border: 1.5px solid var(--line); background: #fff; color: var(--ink);
    font-size: 16px; font-family: inherit;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.textarea { min-height: 120px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.help { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* ---------- Barre de navigation du bas ---------- */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    display: flex; justify-content: space-around; align-items: stretch;
    gap: 4px; padding: 8px 6px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
}
.nav-item {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    padding: 6px 2px; border-radius: 14px; border: none; background: transparent;
    color: var(--muted); font-size: 11px; font-weight: 700; font-family: inherit;
    cursor: pointer; text-align: center;
    transition: transform .12s ease, background .2s ease, color .2s ease;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item:active { transform: scale(.95); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); }
.nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* ---------- Accueil ---------- */
.hero {
    background: linear-gradient(160deg, var(--brand) 0%, #7B6CF6 55%, #9C8BFF 100%);
    color: #fff; border-radius: var(--radius-lg); padding: 26px 20px;
    box-shadow: var(--shadow-lg); margin-bottom: 16px; position: relative; overflow: hidden;
}
.hero h1 { font-size: 30px; margin-bottom: 6px; }
.hero p { color: rgba(255, 255, 255, .92); }
.hero-badge {
    display: inline-block; padding: 6px 12px; border-radius: 999px;
    background: rgba(255, 255, 255, .18); font-size: 12px; font-weight: 700; margin-bottom: 12px;
}
.hero-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.hero-actions .btn { background: #fff; color: var(--brand-dark); }
.hero-actions .btn-ghost { background: rgba(255, 255, 255, .16); color: #fff; border: 1px solid rgba(255, 255, 255, .35); }
.hero-emojis { display: flex; gap: 6px; margin-top: 16px; }
.hero-emojis span {
    width: 40px; height: 40px; border-radius: 12px; background: rgba(255, 255, 255, .18);
    display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 17px;
}
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat-card { background: #fff; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); text-align: center; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--brand); }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.feature-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.step-list { counter-reset: step; display: flex; flex-direction: column; gap: 10px; }
.step {
    display: flex; gap: 12px; align-items: flex-start; background: #fff;
    border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.step-num {
    width: 32px; height: 32px; flex: 0 0 auto; border-radius: 10px;
    background: var(--brand-soft); color: var(--brand); font-weight: 800;
    display: flex; align-items: center; justify-content: center;
}
.example-board { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.example-board span {
    width: 38px; height: 44px; border-radius: 10px; background: var(--brand-soft);
    color: var(--brand-dark); font-weight: 800; font-size: 18px;
    display: flex; align-items: center; justify-content: center;
}

/* ---------- Jeu ---------- */
.game-stage { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 20px 16px; }
.game-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.game-progress { display: flex; gap: 6px; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dot.done { background: var(--green); }
.dot.miss { background: var(--red); }
.dot.current { background: var(--brand); transform: scale(1.25); }
.letter-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 18px 0; }
.letter-box {
    min-width: 44px; height: 56px; padding: 0 8px; border-radius: 14px;
    background: var(--brand-soft); color: var(--brand-dark);
    display: flex; align-items: center; justify-content: center;
    font-size: 26px; font-weight: 800; letter-spacing: 0; text-transform: uppercase;
}
.answer-zone {
    border: 2px dashed var(--line); border-radius: var(--radius);
    background: var(--brand-softer); padding: 14px; text-align: center; margin-bottom: 14px;
}
.answer-slots { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; min-height: 56px; align-items: center; }
.answer-slot {
    width: 42px; height: 52px; border-radius: 12px; background: #fff; border: 1.5px solid var(--line);
    display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 800; color: var(--brand-dark);
}
.answer-slot.filled { background: var(--brand); color: #fff; border-color: var(--brand); }
.answer-slot.cursor { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.answer-input {
    width: 100%; text-align: center; font-size: 24px; font-weight: 800; letter-spacing: 2px;
    text-transform: uppercase; padding: 14px; border-radius: 14px; border: 1.5px solid var(--line);
    font-family: inherit; color: var(--brand-dark);
}
.answer-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.pool { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 16px; }
.tile {
    min-width: 50px; height: 58px; padding: 0 12px; border-radius: 14px; border: none;
    background: #fff; color: var(--ink); font-size: 24px; font-weight: 800; font-family: inherit;
    box-shadow: var(--shadow); cursor: pointer; text-transform: uppercase;
    transition: transform .12s ease, opacity .2s ease, background .2s ease;
}
.tile:active { transform: scale(.94); }
.tile.used { opacity: .25; background: #EFEEF6; box-shadow: none; pointer-events: none; }
.tile.correct { background: var(--green); color: #fff; }
.tile.wrong { background: var(--red); color: #fff; }
.feedback { border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.feedback-ok { background: var(--green-soft); border: 1px solid #BBE7CC; }
.feedback-no { background: var(--red-soft); border: 1px solid #F6C6D1; }
.feedback-title { font-weight: 800; font-size: 20px; margin-bottom: 4px; }
.feedback-ok .feedback-title { color: #0F7A38; }
.feedback-no .feedback-title { color: #B0143A; }
.solution-word {
    display: inline-block; margin-top: 8px; padding: 8px 14px; border-radius: 12px;
    background: #fff; border: 1.5px solid var(--line);
    font-size: 22px; font-weight: 800; letter-spacing: 2px; color: var(--brand-dark);
}
.hint-box { background: var(--accent-soft); border-radius: var(--radius-sm); padding: 12px; color: #7A5200; font-weight: 600; }

/* ---------- Progression ---------- */
.progress-track { height: 12px; border-radius: 999px; background: #EDEBF7; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--brand); transition: width .5s ease; }
.progress-fill.green { background: var(--green); }
.progress-fill.accent { background: var(--accent); }
.badge-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.badge-item { background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); text-align: center; }
.badge-item.locked { opacity: .55; }
.badge-icon {
    width: 46px; height: 46px; margin: 0 auto 8px; border-radius: 14px;
    background: var(--accent-soft); color: #A97000;
    display: flex; align-items: center; justify-content: center;
}
.badge-item.locked .badge-icon { background: #F1F0F7; color: var(--muted); }
.badge-name { font-weight: 800; font-size: 14px; }
.level-row { margin-bottom: 12px; }
.level-row-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 6px; font-weight: 700; font-size: 14px; }
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding: 8px 0; }
.bar-col { flex: 1 1 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.bar {
    width: 100%; border-radius: 8px 8px 4px 4px; background: var(--brand-soft); position: relative;
    min-height: 4px; display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden;
}
.bar-correct { background: var(--brand); width: 100%; }
.bar-label { font-size: 10px; color: var(--muted); font-weight: 700; }

/* ---------- Listes ---------- */
.list-row {
    display: flex; align-items: center; gap: 12px; padding: 14px;
    background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px;
}
.list-row-main { min-width: 0; flex: 1; }
.list-row-title { font-weight: 800; font-size: 15px; }
.list-row-sub { font-size: 13px; color: var(--muted); }
.avatar {
    width: 42px; height: 42px; border-radius: 50%; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 16px;
}
.rank {
    width: 30px; height: 30px; border-radius: 10px; background: var(--brand-soft); color: var(--brand);
    display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; flex: 0 0 auto;
}
.review-word { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 12px; background: #fff; border-radius: var(--radius-sm); box-shadow: var(--shadow); margin-bottom: 8px; }
.review-word strong { font-size: 17px; letter-spacing: 1px; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
table.table th, table.table td { padding: 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #FAFAFD; position: sticky; top: 0; }
table.table tr:last-child td { border-bottom: none; }
.table-empty { padding: 26px; text-align: center; color: var(--muted); }

/* ---------- Administration ---------- */
.admin-shell { background: #F7F7FC; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; -webkit-overflow-scrolling: touch; }
.tab {
    flex: 0 0 auto; padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line);
    background: #fff; color: var(--ink-soft); font-weight: 700; font-size: 14px; font-family: inherit; cursor: pointer;
    transition: transform .12s ease, background .2s ease;
}
.tab:active { transform: scale(.97); }
.tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tab-panel { animation: fadeIn .25s ease; }
.admin-lock { max-width: 420px; margin: 40px auto; }
.danger-zone { border: 1px solid #F6C6D1; background: #FFF7F9; border-radius: var(--radius); padding: 16px; }

/* ---------- Modale / toasts ---------- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 200; background: rgba(24, 20, 45, .55);
    display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal {
    background: #fff; width: 100%; max-width: 560px; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 20px; max-height: 92vh; overflow-y: auto;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    animation: slideUp .25s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.toast-wrap {
    position: fixed; left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    z-index: 300; display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
    background: var(--ink); color: #fff; border-radius: 14px; padding: 12px 16px;
    font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg); animation: fadeIn .2s ease;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
.loader { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 24px; color: var(--muted); }
.spinner {
    width: 22px; height: 22px; border-radius: 50%;
    border: 3px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .8s linear infinite;
}
.skeleton { background: linear-gradient(90deg, #EFEEF6 25%, #F7F6FC 50%, #EFEEF6 75%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 12px; height: 16px; margin-bottom: 8px; }

/* ---------- Splash (application installée) ---------- */
#app-splash {
    display: none; position: fixed; inset: 0; z-index: 99999; pointer-events: none;
    flex-direction: column; align-items: center; justify-content: center; gap: 14px;
    background: #5A4BE0; color: #fff;
}
#app-splash.show { display: flex; animation: splashOut .4s ease 1.2s forwards; }
#app-splash .splash-name { font-size: 20px; font-weight: 800; letter-spacing: .04em; }
@keyframes splashOut { to { opacity: 0; visibility: hidden; } }

/* ---------- PWA ---------- */
.install-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.install-icons { display: flex; gap: 10px; align-items: center; }
.install-icons svg { width: 26px; height: 26px; }

/* ---------- Animations ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes slideUp { from { transform: translateY(24px); } to { transform: none; } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes pop { 0% { transform: scale(.9); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
.reveal { opacity: 0; transform: translateY(14px); transition: opacity .5s ease, transform .5s ease; }
.reveal.in { opacity: 1; transform: none; }
.pop { animation: pop .35s ease; }
.pulse { animation: pulse 1.6s ease infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }

/* ---------- Mobile ---------- */
@media (max-width: 767px) {
    h1 { font-size: 24px; }
    .hero h1 { font-size: 26px; }
    .letter-box { min-width: 40px; height: 52px; font-size: 23px; }
    .tile { min-width: 46px; height: 54px; font-size: 22px; }
    table.table { min-width: 520px; }
}

/* ---------- Écrans larges ---------- */
@media (min-width: 768px) {
    .page { padding: 24px 24px 96px; }
    .hero { padding: 40px 34px; }
    .hero-actions { flex-direction: row; flex-wrap: wrap; }
    .hero-actions .btn { width: auto; }
    .card-grid { grid-template-columns: repeat(2, 1fr); }
    .feature-grid { grid-template-columns: repeat(3, 1fr); }
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
    .badge-grid { grid-template-columns: repeat(4, 1fr); }
    .form-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid .field-full { grid-column: 1 / -1; }
    .bottom-nav { justify-content: center; gap: 10px; }
    .nav-item { flex: 0 0 auto; min-width: 108px; }
    .modal-backdrop { align-items: center; padding: 20px; }
    .modal { border-radius: var(--radius-lg); }
    .letter-box { min-width: 52px; height: 66px; font-size: 30px; }
    .tile { min-width: 56px; height: 64px; font-size: 26px; }
}
