/* ===========================================================================
   QuizClash – Design-System (verspielt & farbenfroh, hell/dunkel)
   =========================================================================== */

:root {
    --grad: linear-gradient(135deg, #7c3aed 0%, #ec4899 100%);
    --grad-soft: linear-gradient(135deg, #7c3aed22, #ec489922);
    --c-primary: #7c3aed;
    --c-pink: #ec4899;
    --c-teal: #14b8a6;
    --c-amber: #f59e0b;
    --c-green: #22c55e;
    --c-red: #ef4444;

    --radius-lg: 20px;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 10px 30px -12px rgba(31, 36, 48, .25);
    --shadow-lg: 0 24px 60px -20px rgba(31, 36, 48, .35);
    --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    --tap: 44px;
}

:root[data-theme="light"] {
    --bg: #f4f5fb;
    --bg-2: #eceef7;
    --surface: #ffffff;
    --surface-2: #f7f8fc;
    --text: #1c2030;
    --muted: #6b7280;
    --border: #e6e8f0;
    --ring: #7c3aed33;
}

:root[data-theme="dark"] {
    --bg: #0e0f1d;
    --bg-2: #14152a;
    --surface: #1b1d34;
    --surface-2: #232545;
    --text: #f1f2fb;
    --muted: #a2a6c6;
    --border: #2c2f52;
    --ring: #a78bfa44;
    --shadow: 0 10px 30px -12px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 800; letter-spacing: -.02em; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
a { color: var(--c-primary); text-decoration: none; }
p { margin: 0 0 1em; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.row { display: flex; gap: 12px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.mt { margin-top: 16px; }
.mt-lg { margin-top: 28px; }

/* --- Brand --- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.2rem; }
.brand-mark {
    display: grid; place-items: center; width: 38px; height: 38px;
    border-radius: 12px; background: var(--grad); color: #fff; box-shadow: var(--shadow);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-lg { font-size: 1.6rem; }
.gradient-text {
    background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--tap); padding: 10px 18px; border: 0; border-radius: var(--radius);
    font-family: inherit; font-size: .98rem; font-weight: 700; cursor: pointer;
    background: var(--surface-2); color: var(--text); transition: transform .08s, box-shadow .2s, background .2s;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 8px 20px -8px var(--c-primary); }
.btn-ghost { background: transparent; border: 1.5px solid var(--border); }
.btn-danger { background: var(--c-red); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.icon-btn {
    display: grid; place-items: center; width: var(--tap); height: var(--tap);
    border: 0; border-radius: 12px; background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; display: inline-flex; gap: 6px; align-items: center; font: inherit; }
.link-btn:hover { color: var(--text); }

/* --- Forms --- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 10px; }
input, select, textarea {
    width: 100%; margin-top: 6px; padding: 11px 14px; font: inherit;
    color: var(--text); background: var(--surface-2);
    border: 1.5px solid var(--border); border-radius: var(--radius-sm); outline: none;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--c-primary); box-shadow: 0 0 0 4px var(--ring); }
textarea { resize: vertical; min-height: 90px; }
.field-row { display: flex; gap: 12px; } .field-row > * { flex: 1; }
.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: auto; margin: 0; }

/* --- Cards --- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow);
}
.card-pad { padding: 22px; }
.tile {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 16px;
}

/* --- Badges / chips / pills --- */
.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
    border-radius: 999px; font-size: .72rem; font-weight: 700; background: var(--surface-2); color: var(--muted);
}
.badge-primary { background: var(--grad-soft); color: var(--c-primary); }
.badge-green { background: #22c55e22; color: #16a34a; }
.badge-red { background: #ef444422; color: #dc2626; }
.badge-amber { background: #f59e0b22; color: #b45309; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c-amber); display: inline-block; }

/* --- Avatare --- */
.avatar {
    width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex: none;
    display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .95rem; overflow: hidden;
}
.avatar-lg { width: 72px; height: 72px; font-size: 1.5rem; }
.avatar-sm { width: 32px; height: 32px; font-size: .8rem; }

/* --- Loading / Errors --- */
.loading { padding: 40px; text-align: center; color: var(--muted); }
.spinner {
    width: 34px; height: 34px; border-radius: 50%; margin: 0 auto 12px;
    border: 3px solid var(--border); border-top-color: var(--c-primary); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { background: #ef444418; color: #dc2626; padding: 12px 14px; border-radius: var(--radius-sm); font-size: .9rem; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty svg { width: 46px; height: 46px; opacity: .5; margin-bottom: 10px; }

/* --- Modal --- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(10, 12, 25, .55); backdrop-filter: blur(4px);
    display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
    width: 100%; max-width: 520px; max-height: 90vh; overflow: auto;
    background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    animation: pop .18s cubic-bezier(.2, 1.2, .4, 1);
}
@keyframes pop { from { transform: scale(.94); opacity: .6; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-close { background: none; border: 0; font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; }
.modal-body { padding: 20px; }

/* --- Toast --- */
.toast {
    position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
    background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 999px;
    font-weight: 600; font-size: .9rem; box-shadow: var(--shadow-lg); opacity: 0;
    transition: all .3s cubic-bezier(.2, 1.2, .4, 1); z-index: 200; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-success { background: var(--c-green); color: #fff; }
.toast-error { background: var(--c-red); color: #fff; }

/* --- Auth-Ansicht (Login/Registrierung) --- */
.auth-view {
    min-height: 100vh; display: grid; place-items: center; padding: 20px;
    background: radial-gradient(900px 500px at 15% -10%, #7c3aed33, transparent),
                radial-gradient(800px 500px at 110% 10%, #ec489933, transparent), var(--bg);
}
.auth-card {
    width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 30px; box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column; gap: 14px;
}
.auth-card .brand { justify-content: center; }
.auth-switch { text-align: center; font-size: .9rem; }
.auth-switch button { background: none; border: 0; color: var(--c-primary); font: inherit; font-weight: 700; cursor: pointer; }

/* ===========================================================================
   App-Shell (Spiel + Admin teilen das Grundlayout)
   =========================================================================== */
.app-view { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 20px 14px; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 6px 8px 16px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a {
    display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px;
    color: var(--muted); font-weight: 600; position: relative;
}
.nav a svg { width: 20px; height: 20px; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--grad-soft); color: var(--c-primary); }
.nav .nav-badge { margin-left: auto; background: var(--c-pink); color: #fff; border-radius: 999px; font-size: .7rem; font-weight: 800; padding: 1px 7px; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 12px; padding: 14px 22px;
    border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 20;
}
.topbar h2 { margin: 0; }
.content { padding: 24px; max-width: 1100px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

.menu-toggle { display: none; }
.backdrop { display: none; }

/* --- Tabs --- */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs button {
    background: none; border: 0; padding: 12px 14px; font: inherit; font-weight: 700; color: var(--muted);
    cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs button.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }

/* --- Tabellen --- */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.table tr:hover td { background: var(--surface-2); }

/* --- Statistik-Kacheln --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat .num { font-size: 1.8rem; font-weight: 800; }
.stat .lbl { color: var(--muted); font-size: .82rem; }

/* --- Grid für Karten --- */
.grid { display: grid; gap: 16px; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* ===========================================================================
   Responsive
   =========================================================================== */
@media (max-width: 860px) {
    .app-view { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 60;
        transform: translateX(-100%); transition: transform .25s ease; height: 100%;
    }
    .sidebar.open { transform: translateX(0); }
    .menu-toggle { display: grid; }
    .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 50; }
    .content { padding: 16px; }
    .field-row { flex-direction: column; }
    .scoreboard .avatar-lg { width: 56px; height: 56px; font-size: 1.2rem; }
}

/* ===========================================================================
   Spiel-spezifisch
   =========================================================================== */
.section-title { margin: 6px 0 12px; font-size: 1rem; }
.avatar.has-img { background-size: cover !important; background-position: center; }

/* Benachrichtigungen */
.notif-wrap { position: relative; }
.notif-badge, .nav-badge {
    position: absolute; top: 6px; right: 6px; background: var(--c-pink); color: #fff;
    font-size: .65rem; font-weight: 800; min-width: 17px; height: 17px; border-radius: 999px;
    display: grid; place-items: center; padding: 0 4px;
}
.nav-badge { position: static; }
.notif-panel {
    position: absolute; right: 0; top: 52px; width: 340px; max-width: 92vw; max-height: 70vh; overflow: auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 40;
}
.notif-item { display: flex; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: flex-start; }
.notif-item svg { width: 20px; height: 20px; color: var(--c-primary); flex: none; margin-top: 2px; }
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: var(--grad-soft); }

/* Clash-Karten (Startseite) */
.clash-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; cursor: pointer; transition: transform .1s, box-shadow .2s; display: flex; flex-direction: column; gap: 12px;
}
.clash-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.clash-card.highlight { border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--ring); }
.clash-card-foot { display: flex; align-items: center; justify-content: space-between; }
.clash-card .score { font-size: 1.4rem; font-weight: 800; }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--grad); border-radius: 999px; transition: width .3s; }

/* Punktestand */
.scoreboard {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; margin: 14px 0;
}
.scoreboard .player { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.scoreboard .pts { font-size: 1.8rem; font-weight: 900; }
.scoreboard .vs { text-align: center; color: var(--muted); font-weight: 800; }
.cat-progress { display: flex; gap: 5px; margin-top: 8px; justify-content: center; }
.cat-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); }
.cat-dot.on { background: var(--grad); border: 0; }

/* Kategorieauswahl */
.category-choice {
    display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 26px 16px;
    border: 2px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); cursor: pointer;
    font: inherit; color: var(--text); font-weight: 800; transition: transform .1s, border-color .15s, box-shadow .2s;
}
.category-choice:hover { transform: translateY(-3px); border-color: var(--cat); box-shadow: var(--shadow); }
.cat-icon { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 18px; background: var(--cat, var(--grad)); color: #fff; }
.cat-icon svg { width: 28px; height: 28px; }

/* Runden-Banner */
.round-banner {
    display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--cat); margin-bottom: 16px;
}
.round-banner .cat-icon { width: 38px; height: 38px; border-radius: 11px; }
.round-banner .cat-icon svg { width: 20px; height: 20px; }
.round-banner .muted { margin-left: auto; }

/* Frage + Timer */
.q-progress { text-align: center; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.timer-ring { position: relative; width: 84px; height: 84px; margin: 0 auto 16px; }
.timer-ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.timer-ring circle { fill: none; stroke-width: 8; }
.timer-ring .bg { stroke: var(--surface-2); }
.timer-ring .fg { stroke: var(--c-primary); stroke-linecap: round; transition: stroke-dashoffset .1s linear; }
.timer-ring.urgent .fg { stroke: var(--c-red); }
.timer-ring.done .fg { stroke: var(--c-teal); }
.timer-num { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.5rem; font-weight: 900; }
.q-image { height: 180px; background-size: contain; background-repeat: no-repeat; background-position: center; margin-bottom: 14px; }
.question-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 24px; font-size: 1.25rem; font-weight: 700; text-align: center; margin-bottom: 16px;
}
.answers { display: grid; gap: 12px; }
.answer-opt {
    padding: 16px 18px; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface);
    font: inherit; font-weight: 600; font-size: 1.02rem; color: var(--text); cursor: pointer; text-align: left;
    min-height: var(--tap); transition: transform .08s, border-color .15s, background .15s;
}
.answer-opt:hover:not(:disabled) { border-color: var(--c-primary); transform: translateY(-1px); }
.answer-opt:disabled { cursor: default; }
.answer-opt.selected { border-color: var(--c-primary); }
.answer-opt.correct { border-color: var(--c-green); background: #22c55e22; }
.answer-opt.wrong { border-color: var(--c-red); background: #ef444422; }

/* Feedback */
.feedback { display: flex; align-items: center; gap: 10px; margin-top: 16px; font-size: 1.1rem; font-weight: 800; }
.feedback.ok { color: var(--c-green); }
.feedback.no { color: var(--c-red); }
.feedback svg { width: 26px; height: 26px; }
.explanation { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; margin-top: 10px; color: var(--muted); }
.rate-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.rate-btn { width: 42px; height: 42px; border: 1.5px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; color: var(--muted); }
.rate-btn:hover { color: var(--text); border-color: var(--c-primary); }
.rate-btn.active { background: var(--grad); color: #fff; border: 0; }

/* Warten / Ergebnis */
.waiting-box svg { width: 48px; height: 48px; color: var(--c-primary); margin-bottom: 8px; }
.result-banner { text-align: center; padding: 30px; border-radius: var(--radius-lg); margin-bottom: 6px; }
.result-banner h1 { font-size: 2.4rem; margin: 0; }
.result-banner.win { background: linear-gradient(135deg, #22c55e22, #14b8a622); }
.result-banner.loss { background: var(--surface-2); }
.result-banner.draw { background: #f59e0b22; }

/* Rundenüberblick */
.review-round { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.review-dots { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.review-dots .muted { min-width: 90px; font-size: .85rem; }
.answer-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--surface-2); }
.answer-dot.ok { background: var(--c-green); }
.answer-dot.no { background: var(--c-red); }
.answer-dot.pending { background: var(--surface-2); border: 1px dashed var(--border); }

/* Freunde */
.friend-row {
    display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--surface); width: 100%; font: inherit; color: var(--text); text-align: left; cursor: pointer;
}
button.friend-row:hover { border-color: var(--c-primary); }
.friend-code {
    font-family: ui-monospace, monospace; font-size: 1.6rem; font-weight: 800; letter-spacing: .25em;
    background: var(--grad-soft); color: var(--c-primary); padding: 14px; border-radius: var(--radius); text-align: center; cursor: pointer; margin-top: 10px;
}

/* Statistik */
.cat-bar { margin-top: 12px; }
.cat-bar .bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 5px; }
.cat-bar .bar-fill { height: 100%; border-radius: 999px; transition: width .4s; }
.h2h { display: flex; justify-content: center; gap: 28px; margin-top: 14px; }
.h2h .num { font-size: 2rem; font-weight: 900; display: block; }
.h2h .lbl { color: var(--muted); font-size: .8rem; }
.me-row td { background: var(--grad-soft); }

/* Theme-Umschalter */
.theme-toggle { display: flex; gap: 8px; margin-top: 10px; }
.theme-opt { flex: 1; padding: 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); font: inherit; font-weight: 700; cursor: pointer; color: var(--text); }
.theme-opt.active { background: var(--grad); color: #fff; border: 0; }
