:root {
    --bg-dark: #0a0f1c; --bg-panel: rgba(18, 25, 43, 0.75);
    --primary: #8fa2e4; --accent: #9d4edd;
    --text-main: #e8edf5; --text-muted: #aab7cc;
    --success: #10b981; --danger: #ef4444; --warning: #f59e0b;
    --line: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.37);
    --font-main: 'Outfit', sans-serif; --font-title: 'Space Grotesk', sans-serif;
}

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

body {
    font-family: var(--font-main); color: var(--text-main); line-height: 1.6;
    min-height: 100vh; display: flex; flex-direction: column; overflow-x: hidden;
    background-color: var(--bg-dark);
    background-image:
        radial-gradient(circle at 15% 50%, rgba(157, 78, 221, 0.08), transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(143, 162, 228, 0.12), transparent 50%);
}

h1, h2, h3 { font-family: var(--font-title); }
h1 {
    font-size: clamp(2.5rem, 5vw, 4rem); text-align: center; margin-bottom: 1rem;
    background: linear-gradient(to right, var(--primary), var(--accent));
    -webkit-background-clip: text; background-clip: text; color: transparent;
    text-shadow: 0 0 30px rgba(157, 78, 221, 0.3);
}

header {
    padding: 1.5rem; display: flex; justify-content: space-between; align-items: center; z-index: 10;
    .header-group { display: flex; gap: 1rem; }
}

main { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding: 1rem; }

.screen {
    display: none; width: 100%; max-width: 800px; animation: fadeIn 0.5s ease;
    &.active { display: block; }
}

.glass-panel {
    background: var(--bg-panel); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(143, 162, 228, 0.2); border-radius: 24px; padding: 2.5rem;
    box-shadow: var(--glass-shadow); text-align: center; position: relative; overflow: hidden;
    &::before {
        content: ''; position: absolute; inset: 0 0 auto 0; height: 2px; opacity: 0.5;
        background: linear-gradient(90deg, transparent, var(--primary), transparent);
    }
}

button {
    font-family: var(--font-title); cursor: pointer; border: none; outline: none; transition: all 0.3s ease;
    &:disabled { opacity: 0.4; cursor: not-allowed; }
}

.btn-primary {
    background: rgba(143, 162, 228, 0.1); color: var(--primary); border: 1px solid var(--primary);
    padding: 1rem 2.5rem; font-size: 1.2rem; border-radius: 50px;
    text-transform: uppercase; letter-spacing: 2px;
    &:hover:not(:disabled), &:focus:not(:disabled) {
        background: var(--primary); color: var(--bg-dark); transform: translateY(-2px);
        box-shadow: 0 0 25px rgba(143, 162, 228, 0.4);
    }
}

.btn-icon {
    background: none; color: var(--text-muted); font-size: 1.5rem;
    &:hover { color: var(--primary); }
}

.btn-success, .btn-danger { padding: 0.8rem 1.5rem; border-radius: 8px; border: 1px solid; }
.btn-success { background: rgba(16, 185, 129, 0.1); border-color: var(--success); color: var(--success); }
.btn-danger { background: rgba(239, 68, 68, 0.1); border-color: var(--danger); color: var(--danger); }
.btn-small { padding: 0.5rem 1rem; font-size: 0.9rem; border-radius: 8px; }

.intro-text { font-size: 1.2rem; color: var(--text-muted); margin: 0 auto 2.5rem; max-width: 600px; }

.game-header {
    display: flex; justify-content: space-between; margin-bottom: 2rem;
    font-family: var(--font-title); color: var(--primary);
}

.progress-container {
    height: 6px; background: var(--line); border-radius: 10px; margin-bottom: 3rem; overflow: hidden;
    .progress-bar {
        height: 100%; width: 0%; transition: width 0.4s ease;
        background: linear-gradient(90deg, var(--primary), var(--accent));
    }
}

.question-text {
    font-size: clamp(1.5rem, 3vw, 2.2rem); font-weight: 600; margin-bottom: 3rem;
    min-height: 100px; display: flex; align-items: center; justify-content: center;
}

.answers-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem;
    @media (max-width: 500px) { grid-template-columns: 1fr; }
}

.btn-answer {
    background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); color: var(--text-main);
    padding: 1.2rem; font-size: 1.1rem; border-radius: 12px; border-left: 4px solid transparent;
    &:hover:not(:disabled), &:focus:not(:disabled) { background: rgba(255, 255, 255, 0.08); transform: translateY(-2px); }
    &[data-val="1"]:hover { border-left-color: var(--success); }
    &[data-val="-1"]:hover { border-left-color: var(--danger); }
    &[data-val="0"]:hover { border-left-color: var(--text-muted); }
    &[data-val="0.5"]:hover { border-left-color: var(--warning); }
}

.character-reveal { font-size: 1.2rem; color: var(--primary); text-transform: uppercase; letter-spacing: 1px; }
.character-name { font-size: 3rem; font-weight: 800; color: #fff; text-shadow: 0 0 20px rgba(255, 255, 255, 0.2); }
.character-icon { font-size: 5rem; color: var(--accent); margin: 2rem 0; filter: drop-shadow(0 0 15px rgba(157, 78, 221, 0.4)); }
.confidence { font-size: 0.95rem; color: var(--text-muted); margin: 1rem 0 2rem; font-family: var(--font-title); }
.action-buttons { display: flex; gap: 1rem; justify-content: center; margin-top: 2rem; flex-wrap: wrap; }

.easter-egg {
    display: none; margin-top: 1.5rem; padding: 1rem; font-size: 0.9rem; color: var(--warning);
    background: rgba(245, 158, 11, 0.1); border: 1px dashed var(--warning); border-radius: 8px;
    animation: slideUp 0.5s ease;
}

.alt-guesses {
    text-align: left; margin: 2rem 0; padding: 1.5rem; background: rgba(0, 0, 0, 0.25); border-radius: 12px;
    li {
        list-style: none; padding: 0.5rem 0; display: flex; align-items: center; gap: 10px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        &:last-child { border: none; }
    }
}

.recap-list .recap-row {
    flex-direction: column; align-items: stretch; gap: 0.5rem;
    .recap-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
    .recap-votes { display: flex; gap: 0.8rem; flex-shrink: 0; font-size: 0.85rem; font-family: var(--font-title); }
    .recap-you { color: var(--warning); }
    .recap-crowd { color: var(--primary); }
    .recap-choice {
        display: flex; gap: 2px; align-self: flex-end;
        button {
            padding: 0.35rem 0.9rem; font-size: 0.8rem; color: var(--text-muted);
            background: rgba(255, 255, 255, 0.06); border: 1px solid transparent;
            &:first-child { border-radius: 8px 0 0 8px; }
            &:last-child { border-radius: 0 8px 8px 0; }
            &.active[data-decide="keep"] { background: rgba(245, 158, 11, 0.2); color: var(--warning); border-color: var(--warning); }
            &.active[data-decide="wrong"] { background: rgba(143, 162, 228, 0.2); color: var(--primary); border-color: var(--primary); }
        }
    }
}

.input-group { display: flex; margin-top: 2rem; gap: 0.5rem; }

input[type="text"], input[type="search"], select {
    flex: 1; padding: 1rem; color: white; border-radius: 8px; font-family: var(--font-main);
    background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
    &:focus { outline: none; border-color: var(--primary); }
    option { background: var(--bg-dark); }
}
select { flex: 0 1 auto; cursor: pointer; }

.stats-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; margin-bottom: 2rem;
    .stat-card { background: rgba(0, 0, 0, 0.25); padding: 1.5rem; border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.05); }
    .stat-val { font-size: 2.5rem; font-family: var(--font-title); color: var(--primary); font-weight: 700; }
    .stat-label { font-size: 0.9rem; color: var(--text-muted); text-transform: uppercase; }
}

.screen.wide { max-width: 1100px; }

.login-panel {
    max-width: 420px;
    margin: 12vh auto 0;
    padding: 3rem 2.5rem;

    .login-icon {
        font-size: 3rem; color: var(--primary); margin-bottom: 1.5rem;
        filter: drop-shadow(0 0 12px rgba(143, 162, 228, 0.35));
    }
    .login-form { display: flex; flex-direction: column; gap: 1rem; margin-top: 2rem; }
    .password-field {
        display: flex; align-items: center; gap: 0.6rem; padding: 0 0.9rem;
        background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 10px;
        transition: border-color 0.2s ease;
        &:focus-within { border-color: var(--primary); box-shadow: 0 0 12px rgba(143, 162, 228, 0.15); }
        .fa-lock { color: var(--text-muted); }
        input { flex: 1; background: none; border: none; padding: 0.95rem 0.2rem; color: var(--text-main); font-family: var(--font-main); }
        input:focus { outline: none; }
        .btn-icon { font-size: 1rem; }
    }
    .login-error { color: var(--danger); font-size: 0.85rem; text-align: left; }
    .login-submit { width: 100%; padding: 0.9rem; font-size: 1rem; border-radius: 10px; letter-spacing: 1px; }
    &.shake { animation: shake 0.4s ease; }
}

@keyframes shake {
    25% { transform: translateX(-7px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-3px); }
}

.tab-count {
    background: rgba(143, 162, 228, 0.15); color: var(--primary);
    border-radius: 10px; padding: 0 8px; font-size: 0.8rem; margin-left: 4px;
}

.editor-panel {
    text-align: left;

    .editor-header {
        display: flex; justify-content: space-between; align-items: center; gap: 1rem;
        flex-wrap: wrap; margin-bottom: 0.3rem;
    }

    .editor-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
    .editor-tab {
        background: none; color: var(--text-muted); padding: 0.7rem 1.2rem; font-size: 1rem;
        border-bottom: 2px solid transparent;
        &:hover { color: var(--text-main); }
        &.active { color: var(--primary); border-bottom-color: var(--primary); }
    }

    .editor-toolbar {
        display: flex; gap: 0.5rem; margin-bottom: 1rem; align-items: center; flex-wrap: wrap;
        input, select { padding: 0.6rem 1rem; }
    }

    .item-list { display: flex; flex-direction: column; gap: 0.5rem; max-height: 62vh; overflow-y: auto; padding-right: 4px; }
    .item-row {
        background: rgba(0, 0, 0, 0.25); border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 10px;
        transition: border-color 0.2s ease;
        &:hover { border-color: rgba(143, 162, 228, 0.35); }
        &.open { border-color: var(--primary); }
        &.open .item-body { display: block; }
    }
    .item-head {
        display: flex; align-items: center; gap: 0.8rem; padding: 0.7rem 1rem; cursor: pointer; user-select: none;
        &:hover { background: rgba(255, 255, 255, 0.04); border-radius: 10px; }
        .fa-solid { color: var(--accent); width: 22px; text-align: center; }
    }
    .item-title { flex: 1; font-weight: 600; }
    .item-meta { font-size: 0.85rem; color: var(--text-muted); font-family: var(--font-title); }
    .item-body { display: none; padding: 1rem; border-top: 1px solid rgba(255, 255, 255, 0.06); }

    .field-row {
        display: flex; gap: 0.5rem; margin-bottom: 0.8rem; align-items: center; flex-wrap: wrap;
        label { min-width: 60px; color: var(--text-muted); font-size: 0.9rem; }
        input[type="text"] { padding: 0.5rem 0.8rem; }
    }
    .icon-preview { font-size: 1.4rem; color: var(--accent); width: 30px; text-align: center; }

    .sig-block {
        display: flex; flex-direction: column; gap: 0.5rem;
        margin-top: 0.8rem; padding: 0.6rem 0.9rem;
        background: rgba(157, 78, 221, 0.08); border: 1px solid rgba(157, 78, 221, 0.4); border-radius: 10px;
        .sig-label { color: var(--accent); font-family: var(--font-title); font-size: 0.85rem; }
        .sig-row {
            display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap;
            input[type="text"] { flex: 1; min-width: 200px; padding: 0.5rem 0.8rem; }
        }
    }

    .vote-score {
        background: none; border: none; min-width: 42px; text-align: right;
        font-size: 0.85rem; color: var(--text-muted); font-family: var(--font-title);
        cursor: pointer;
        &:hover { color: var(--primary); text-decoration: underline; }
    }

    input[type="number"] {
        color: white; border-radius: 8px; font-family: var(--font-main);
        background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
        &:focus { outline: none; border-color: var(--primary); }
    }

    .attr-grid { display: flex; flex-direction: column; gap: 4px; margin-top: 0.8rem; }
    .attr-row {
        display: flex; align-items: center; gap: 0.8rem; padding: 0.35rem 0.5rem; border-radius: 6px;
        &:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
        .attr-label { flex: 1; font-size: 0.9rem; }
    }

    .tri-state {
        display: flex; gap: 2px;
        button {
            padding: 0.3rem 0.8rem; font-size: 0.8rem; color: var(--text-muted);
            background: rgba(255, 255, 255, 0.06); border: 1px solid transparent;
            &:first-child { border-radius: 6px 0 0 6px; }
            &:last-child { border-radius: 0 6px 6px 0; }
            &.active[data-v="1"] { background: rgba(16, 185, 129, 0.25); color: var(--success); border-color: var(--success); }
            &.active[data-v="0"] { background: rgba(170, 183, 204, 0.2); color: var(--text-main); border-color: var(--text-muted); }
            &.active[data-v="-1"] { background: rgba(239, 68, 68, 0.25); color: var(--danger); border-color: var(--danger); }
        }
    }

    /* Personnages : vue maître-détail */
    .char-layout {
        display: grid; grid-template-columns: 260px 1fr; gap: 1rem; align-items: start;
        @media (max-width: 760px) { grid-template-columns: 1fr; }
    }
    .char-side {
        display: flex; flex-direction: column; gap: 0.5rem;
        input[type="search"] { padding: 0.55rem 0.9rem; }
        .char-side-row { display: flex; gap: 0.5rem; select { flex: 1; padding: 0.45rem 0.6rem; } }
    }
    .char-picker {
        display: flex; flex-direction: column; gap: 2px; max-height: 60vh; overflow-y: auto; padding-right: 4px;
    }
    .char-item {
        display: flex; align-items: center; gap: 0.6rem; text-align: left;
        padding: 0.5rem 0.7rem; border-radius: 8px; font-family: var(--font-main); font-size: 0.9rem;
        background: none; color: var(--text-main); border: 1px solid transparent;
        .fa-solid { color: var(--accent); width: 18px; text-align: center; }
        .char-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .char-item-wins { font-size: 0.75rem; color: var(--warning); .fa-trophy { margin-right: 2px; font-size: 0.7rem; } }
        &:hover { background: rgba(255, 255, 255, 0.05); }
        &.active { background: rgba(143, 162, 228, 0.15); border-color: var(--primary); }
    }
    .char-detail {
        background: rgba(0, 0, 0, 0.2); border: 1px solid rgba(255, 255, 255, 0.06);
        border-radius: 12px; padding: 1.2rem; max-height: 68vh; overflow-y: auto;
    }
    .detail-header {
        display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
        padding-bottom: 1rem; border-bottom: 1px solid var(--line);
        .detail-icon { font-size: 2.6rem; color: var(--accent); width: 52px; text-align: center; }
        .detail-fields {
            flex: 1; display: flex; gap: 1rem; flex-wrap: wrap; min-width: 260px;
            label {
                display: flex; flex-direction: column; gap: 0.2rem; flex: 1; min-width: 120px;
                font-size: 0.75rem; color: var(--text-muted);
                input { padding: 0.5rem 0.8rem; }
            }
        }
        .detail-side { display: flex; align-items: center; gap: 1rem; text-align: right; }
    }
    .attr-toolbar {
        display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1rem;
        input[type="search"] { max-width: 260px; padding: 0.5rem 0.9rem; }
    }
    .attr-unset .attr-label { color: var(--text-muted); }
    .ai-mark { font-size: 0.85rem; cursor: help; filter: drop-shadow(0 0 4px rgba(157, 78, 221, 0.6)); }
    .player-badge { color: var(--warning); font-size: 0.75rem; }
    .triage-header {
        display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
        padding: 0.6rem 0; margin-bottom: 0.5rem; border-bottom: 1px solid var(--line);
        .triage-title { flex: 1; min-width: 200px; display: flex; flex-direction: column; strong { font-size: 0.95rem; } span { font-size: 0.8rem; } }
    }
    .player-origin {
        margin-top: 0.8rem; padding: 0.5rem 0.9rem; font-size: 0.82rem; color: var(--warning);
        background: rgba(245, 158, 11, 0.08); border: 1px dashed rgba(245, 158, 11, 0.5); border-radius: 8px;
    }

    /* Questions : cartes structurées */
    .q-text-line {
        display: flex; gap: 0.5rem; align-items: center; padding: 0.7rem 0.9rem 0.3rem;
        input { flex: 1; padding: 0.5rem 0.8rem; }
        .btn-icon { font-size: 0.95rem; &:hover { color: var(--danger); } }
    }
    .q-section {
        font-size: 1rem; color: var(--primary); margin: 1rem 0 0.2rem;
        padding-bottom: 0.3rem; border-bottom: 1px solid var(--line);
        span { font-size: 0.8rem; font-family: var(--font-main); font-weight: 400; }
    }
    .q-group-title {
        font-family: var(--font-title); font-size: 0.85rem; color: var(--accent);
        margin-top: 0.4rem; text-transform: uppercase; letter-spacing: 1px;
    }
    .q-sub-title { font-size: 0.8rem; color: var(--text-muted); margin: 0.2rem 0 0 1.5rem; }
    .q-nested { margin-left: 1.5rem; border-left: 2px solid rgba(157, 78, 221, 0.4); }
    .q-meta-row {
        display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap;
        padding: 0 0.9rem 0.7rem;
        label {
            display: flex; align-items: center; gap: 0.4rem;
            font-size: 0.75rem; color: var(--text-muted); white-space: nowrap;
            input, select { width: 110px; padding: 0.25rem 0.5rem; font-size: 0.8rem; flex: 0; }
            input[type="number"] { width: 58px; }
        }
        .item-meta { margin-left: auto; }
    }
    .q-badge-error {
        color: var(--danger); font-size: 0.75rem; font-family: var(--font-title);
        background: rgba(239, 68, 68, 0.12); border-radius: 6px; padding: 0.1rem 0.4rem;
    }

    .data-actions {
        display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin-top: 1rem;
        button { width: 100%; }
        @media (max-width: 500px) { grid-template-columns: 1fr; }
    }
    .data-info {
        background: rgba(0, 0, 0, 0.25); border-radius: 10px; padding: 1rem;
        font-size: 0.9rem; color: var(--text-muted); margin-top: 1rem; line-height: 1.8;
    }
}

#toast-container {
    position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
    display: flex; flex-direction: column; gap: 0.5rem; z-index: 100; width: min(90vw, 420px);
    .toast {
        padding: 0.8rem 1.2rem; border-radius: 10px; font-size: 0.95rem; color: var(--text-main);
        background: rgba(18, 25, 43, 0.97); border: 1px solid var(--primary); box-shadow: var(--glass-shadow);
        animation: slideUp 0.3s ease;
        &.success { border-color: var(--success); }
        &.error { border-color: var(--danger); }
        &.warning { border-color: var(--warning); }
    }
}

@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } }
@keyframes pop { 50% { transform: scale(1.05); } }
@keyframes spin { to { transform: rotate(360deg); } }

.question-transition { animation: slideUp 0.3s ease; }
.win-effect { animation: pop 0.6s ease; }
.spin { animation: spin 4s linear infinite; }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
