:root {
    --bg: #f4f5f9;
    --surface: #ffffff;
    --surface-soft: #f8f8fc;
    --text: #171a27;
    --muted: #687083;
    --line: #e3e6ee;
    --primary: #635bff;
    --primary-dark: #4d46db;
    --success: #177a50;
    --warning: #9a6410;
    --danger: #b42318;
    --shadow: 0 12px 32px rgba(24, 29, 48, 0.08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1.04; letter-spacing: -0.04em; }
h2 { margin-bottom: 8px; font-size: 1.3rem; letter-spacing: -0.02em; }

.container { width: min(1120px, calc(100% - 32px)); margin-inline: auto; }
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(20, 24, 39, 0.96); backdrop-filter: blur(14px); color: white; }
.nav-wrap { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; color: white; font-weight: 800; font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; background: rgba(255,255,255,.12); }
.nav-actions { display: flex; align-items: center; gap: 18px; }
.nav-actions > a:not(.button), .nav-actions .link-button { color: #eef0ff; }
.main-content { padding-block: 36px 72px; }
.footer { padding-bottom: 30px; color: var(--muted); font-size: .85rem; text-align: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.eyebrow { margin-bottom: 8px; color: var(--primary-dark); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); }
.hero-row, .page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 32px; }
.hero-row > div:first-child { max-width: 720px; }
.action-cluster { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.section-block { margin-top: 34px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.section-heading p { margin-bottom: 0; }

.button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 10px 17px; border: 1px solid var(--primary);
    border-radius: 12px; background: var(--primary); color: white; font-weight: 750;
    text-decoration: none; box-shadow: 0 8px 18px rgba(99, 91, 255, .18);
}
.button:hover { background: var(--primary-dark); border-color: var(--primary-dark); text-decoration: none; }
.button-secondary { background: white; color: var(--text); border-color: var(--line); box-shadow: none; }
.button-secondary:hover { background: var(--surface-soft); color: var(--text); border-color: #cfd3df; }
.button-small { min-height: 36px; padding: 7px 12px; border-radius: 10px; font-size: .9rem; }
.button-full { width: 100%; }
.button-danger-outline { background: white; color: var(--danger); border-color: #f0c7c3; box-shadow: none; }
.button-danger-outline:hover { background: #fff3f1; color: var(--danger); border-color: #e6aca6; }
.link-button { padding: 0; border: 0; background: transparent; color: var(--primary-dark); font-weight: 700; }
.inline-form { display: inline; margin: 0; }
.danger-text { color: var(--danger); }

.flash-stack { display: grid; gap: 10px; margin-bottom: 22px; }
.flash { padding: 13px 15px; border-radius: 12px; border: 1px solid; background: white; }
.flash-success { color: #11613f; border-color: #b7e4cf; background: #effbf5; }
.flash-warning { color: #80520c; border-color: #efd39d; background: #fff9e9; }
.flash-danger { color: #8f1f16; border-color: #efc1bd; background: #fff2f0; }
.flash-info { color: #294a80; border-color: #c6d6ef; background: #f2f6ff; }

.auth-shell { min-height: calc(100vh - 200px); display: grid; place-items: center; }
.auth-card { width: min(460px, 100%); padding: 30px; }
.auth-card h1 { font-size: 2.2rem; }
.auth-switch { margin: 20px 0 0; text-align: center; color: var(--muted); }
.form-stack { display: grid; gap: 16px; }
.form-layout { display: grid; gap: 18px; }
.form-section { padding: 24px; }
.form-section > h2:first-child { margin-bottom: 16px; }
label { display: grid; gap: 7px; color: #363b4a; font-size: .92rem; font-weight: 700; }
input, select {
    width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #ced3df;
    border-radius: 11px; background: white; color: var(--text); outline: none;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 91, 255, .13); }
.field-help { color: var(--muted); font-weight: 500; font-size: .8rem; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.compact-label { min-width: 210px; }

.game-choice-grid, .player-choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.choice-card { position: relative; display: block; cursor: pointer; }
.choice-card input { position: absolute; opacity: 0; pointer-events: none; }
.choice-card > span { display: grid; gap: 4px; min-height: 100%; padding: 16px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); }
.choice-card strong { color: var(--text); }
.choice-card small { color: var(--muted); font-weight: 500; }
.choice-card input:checked + span { border-color: var(--primary); background: #f2f0ff; box-shadow: 0 0 0 2px rgba(99,91,255,.12); }
.choice-disabled { cursor: default; opacity: .75; }
.sticky-action-bar { position: sticky; bottom: 14px; z-index: 10; display: flex; justify-content: flex-end; gap: 10px; padding: 13px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,255,255,.92); box-shadow: var(--shadow); backdrop-filter: blur(12px); }

.filter-row { padding: 20px; display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.filter-row h2 { margin-bottom: 0; }
.stats-grid { margin-top: 14px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stat-card { padding: 20px; display: grid; gap: 10px; }
.stat-card span { color: var(--muted); font-size: .88rem; }
.stat-card strong { font-size: 2rem; line-height: 1; }
.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.session-card { display: grid; gap: 6px; padding: 18px; color: var(--text); }
.session-card:hover { text-decoration: none; transform: translateY(-1px); }
.session-card-top { display: flex; justify-content: space-between; gap: 12px; }
.join-code-small { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--primary-dark); font-weight: 800; letter-spacing: .08em; }

.table-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); background: var(--surface-soft); font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.rank-col, .winner-col { width: 54px; text-align: center; }
.table-action { text-align: right; }
.winner-row { background: #f0faf5; }
.tiny-badge { margin-left: 7px; padding: 3px 6px; border-radius: 999px; background: #eceaff; color: var(--primary-dark); font-size: .68rem; vertical-align: middle; }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 999px; background: #aab0be; }
.dot-live { background: #29a66f; box-shadow: 0 0 0 4px rgba(41,166,111,.12); }
.empty-state { padding: 28px; color: var(--muted); text-align: center; }

.history-list { display: grid; gap: 10px; }
.history-item { display: grid; grid-template-columns: 42px minmax(180px, 1fr) minmax(180px, .8fr) 20px; align-items: center; gap: 10px; padding: 16px; color: var(--text); }
.history-item:hover { text-decoration: none; }
.winner-slot { min-height: 28px; display: grid; place-items: center; }
.history-main, .history-winner { display: grid; }
.chevron { color: var(--muted); font-size: 1.8rem; }

.badge { display: inline-flex; width: fit-content; padding: 5px 9px; border-radius: 999px; font-size: .74rem; font-weight: 800; }
.badge-live, .badge-active { color: #11613f; background: #dcf6e9; }
.badge-completed { color: #3044a8; background: #e7eaff; }
.badge-aborted, .badge-expired { color: #6f4f1b; background: #f5ead8; }
.session-hero { padding: 24px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.session-hero h1 { margin: 8px 0; font-size: clamp(2rem, 4vw, 3rem); }
.status-line { display: flex; align-items: center; gap: 10px; }
.join-panel { min-width: 220px; padding: 16px; display: grid; justify-items: center; gap: 4px; border: 1px dashed #c9c7f8; border-radius: 14px; background: #f5f4ff; }
.join-panel strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 2rem; letter-spacing: .14em; }
.join-code-input { text-align: center; text-transform: uppercase; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.65rem; font-weight: 800; letter-spacing: .2em; }
.inline-add-form { display: flex; align-items: end; gap: 8px; }
.inline-add-form select { min-width: 210px; }
.split-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .6fr); gap: 16px; align-items: start; }
.round-entry-list { display: grid; gap: 12px; }
.round-player-box { margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); }
.round-player-box legend { padding: 0 7px; color: var(--text); font-weight: 800; }
.self-entry-card { position: sticky; top: 88px; }
.round-history { display: grid; gap: 10px; }
.round-card { overflow: hidden; }
.round-card summary { padding: 16px 18px; display: flex; justify-content: space-between; gap: 14px; cursor: pointer; list-style: none; }
.round-card summary::-webkit-details-marker { display: none; }
.round-card-body { padding: 0 16px 16px; }
.round-card-body .table-scroll { margin-bottom: 12px; border: 1px solid var(--line); border-radius: 12px; }
.session-actions { margin-top: 34px; padding: 22px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.session-actions p { margin-bottom: 0; }
.winner-check { display: inline-grid; place-items: center; cursor: pointer; }
.winner-check input { position: absolute; opacity: 0; }
.winner-check span { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; filter: grayscale(1); opacity: .4; }
.winner-check input:checked + span { border-color: #e0b233; background: #fff8d9; filter: none; opacity: 1; box-shadow: 0 0 0 3px rgba(224,178,51,.13); }
.finish-table input { min-width: 100px; }

@media (max-width: 820px) {
    .nav-actions > a:not(.button), .nav-actions .link-button { display: none; }
    .hero-row, .page-head, .session-hero, .session-actions { align-items: stretch; flex-direction: column; }
    .action-cluster .button { flex: 1; }
    .stats-grid, .card-grid, .game-choice-grid, .player-choice-grid, .split-grid { grid-template-columns: 1fr; }
    .history-item { grid-template-columns: 36px 1fr 20px; }
    .history-winner { grid-column: 2; }
    .chevron { grid-row: 1 / span 2; grid-column: 3; }
    .filter-row, .section-heading { align-items: stretch; flex-direction: column; }
    .compact-label, .inline-add-form select { min-width: 0; }
    .inline-add-form { align-items: stretch; }
    .self-entry-card { position: static; }
    .join-panel { width: 100%; }
}

@media (max-width: 520px) {
    .container { width: min(100% - 20px, 1120px); }
    .main-content { padding-top: 22px; }
    .topbar .button { min-height: 34px; padding: 6px 9px; font-size: .82rem; }
    .brand span:last-child { display: none; }
    .auth-card, .form-section, .session-hero { padding: 20px; }
    .field-row { grid-template-columns: 1fr; }
    .sticky-action-bar { justify-content: stretch; }
    .sticky-action-bar .button { flex: 1; }
    th, td { padding: 12px; }
}

.badge-mode { color: #4f5565; background: #eceef4; }
.uno-round-card { overflow: hidden; }
.uno-finish-list { display: grid; gap: 10px; margin-top: 18px; }
.uno-player-row {
    display: grid;
    grid-template-columns: minmax(120px, .6fr) minmax(160px, 1fr) minmax(90px, auto);
    align-items: center;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--surface-soft);
}
.uno-player-finished { background: #f1faf6; border-color: #cce8da; }
.placement-slot { min-width: 110px; }
.placement-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    padding: 7px 10px;
    border-radius: 999px;
    background: #e8ebf4;
    font-weight: 850;
}
.placement-first { color: #725600; background: #fff1b8; }
.placement-waiting { color: var(--muted); font-size: .86rem; font-weight: 700; }
.uno-row-action { display: flex; justify-content: flex-end; }
.uno-help { margin: 16px 0 0; }
.self-entry-card-flat { max-width: 620px; }
.collaborative-wait-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}
.collaborative-wait-card p { margin-bottom: 0; }
.saved-hint { margin: 14px 0 0; color: var(--success); }

@media (max-width: 620px) {
    .uno-player-row { grid-template-columns: 1fr auto; }
    .placement-slot { grid-column: 1 / -1; min-width: 0; }
    .collaborative-wait-card { align-items: stretch; flex-direction: column; }
}

/* Historieneinträge mit separater, sicherer Löschaktion */
.history-item {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 0;
    overflow: hidden;
}
.history-link {
    min-width: 0;
    display: grid;
    grid-template-columns: 42px minmax(180px, 1fr) minmax(180px, .8fr) 20px;
    align-items: center;
    gap: 10px;
    padding: 16px;
    color: var(--text);
}
.history-link:hover { text-decoration: none; background: var(--surface-soft); }
.history-delete { padding: 10px 12px 10px 0; }
.history-delete-button {
    width: 42px;
    height: 42px;
    border: 1px solid #f0c7c3;
    border-radius: 11px;
    background: white;
    font-size: 1rem;
}
.history-delete-button:hover { background: #fff3f1; border-color: #e6aca6; }
.danger-zone { border-color: #efc1bd; background: #fffafa; }

@media (max-width: 820px) {
    .history-link { grid-template-columns: 36px 1fr 20px; }
    .history-link .history-winner { grid-column: 2; }
    .history-link .chevron { grid-row: 1 / span 2; grid-column: 3; }
}

@media (max-width: 520px) {
    .history-delete { padding-right: 8px; }
    .history-delete-button { width: 38px; height: 38px; }
}

/* Version 3 */
.version-pill {
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
    color: #dfe2ff;
    font-size: .65rem;
    font-weight: 800;
}
.admin-pill {
    padding: 4px 8px;
    border-radius: 999px;
    background: #fff1b8;
    color: #624b00;
    font-size: .72rem;
    font-weight: 850;
}
.mode-section > p { margin-bottom: 16px; }
.mode-card em {
    width: fit-content;
    margin-top: 8px;
    padding: 4px 8px;
    border-radius: 999px;
    background: #e8eaf2;
    color: #555d70;
    font-size: .72rem;
    font-style: normal;
    font-weight: 800;
}
.mode-card input:checked + span em { background: #dedbff; color: var(--primary-dark); }
.between-round-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 22px;
    padding: 24px;
    border-color: #c9dcca;
    background: linear-gradient(135deg, #ffffff, #f3fbf6);
}
.between-round-card p { margin-bottom: 0; }
.uno-player-row strong { min-width: 0; }

@media (max-width: 820px) {
    .between-round-card { align-items: stretch; flex-direction: column; }
    .version-pill { display: none; }
}
