/* ==========================================================================
   Galgenmännchen Multiplayer – Styles
   ========================================================================== */
:root {
    --bg: #eceef1;              /* Gesamtlobby: hellgrau */
    --card: #ffffff;
    --text: #1f2430;
    --muted: #6b7280;
    --line: #e2e5ea;
    --accent: #3b5bdb;
    --ok: #2f9e44;
    --ok-pale: #b7ebc0;
    --warn-pale: #f8c9c4;
    --idle: #d5d9df;
    --radius: 14px;
    --shadow: 0 6px 20px rgba(20, 30, 50, .08);
    --lobby: #8a94a6;           /* wird per JS auf die Lobbyfarbe gesetzt */
    --lobby-pale: #eceef1;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    transition: background .4s ease;
}
body.in-lobby { background: var(--lobby-pale); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
h1 { margin: 8px 0 4px; font-size: 1.8rem; }
h2 { margin: 0 0 12px; font-size: 1.05rem; }
.sub { margin: 0 0 20px; color: var(--muted); }
.hall-intro { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; }
.hall-intro .sub { margin: 0; max-width: 560px; }

/* Kopfzeile ---------------------------------------------------------------- */
.topbar {
    position: sticky; top: 0; z-index: 25;
    display: flex; align-items: center; gap: 16px;
    padding: 10px 20px;
    background: #1f2430; color: #fff;
}
.brand { font-weight: 700; letter-spacing: .3px; }
.brand span { font-weight: 400; opacity: .7; }
.where {
    margin: 0 auto;
    padding: 6px 16px; border-radius: 999px;
    font-weight: 700; text-transform: uppercase; letter-spacing: .8px; font-size: .9rem;
    white-space: nowrap;
    background: rgba(255, 255, 255, .12);
}
body.in-lobby .where { background: var(--lobby); color: #fff; }
.me { font-size: .9rem; opacity: .85; min-width: 80px; text-align: right; }

.connection { background: #c92a2a; color: #fff; text-align: center; padding: 6px; }
.toast {
    position: fixed; left: 50%; top: 64px; transform: translateX(-50%);
    background: #1f2430; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 30;
    box-shadow: var(--shadow);
}

.screen { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }
.card {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 18px;
}

/* Buttons ------------------------------------------------------------------ */
.btn {
    font: inherit; font-weight: 600; border: 0; border-radius: 10px;
    padding: 10px 18px; cursor: pointer; transition: transform .05s, filter .15s, background .2s;
}
.btn:active { transform: translateY(1px); }
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: rgba(0, 0, 0, .06); color: var(--text); }

/* Gesamtlobby -------------------------------------------------------------- */
.hall { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 22px; align-items: start; }

/* Training-Karte */
.train-card {
    display: flex; align-items: center; gap: 12px; padding: 12px 18px; cursor: pointer;
    font: inherit; color: var(--text); text-align: left;
    background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
    transition: transform .12s, box-shadow .12s;
}
.train-card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(20, 30, 50, .12); }
.train-card b { display: block; }
.train-card small { color: var(--muted); }
.train-icon { font-size: 1.6rem; }

/* Lobby-Liste */
.lobby-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.lobby-row { display: flex; gap: 8px; align-items: stretch; }
.lobby-tile {
    flex: 1; display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name count" "seats seats"; gap: 8px 10px;
    padding: 12px 16px 12px 18px; border-radius: 14px; cursor: pointer; text-align: left;
    font: inherit; color: var(--text);
    background: linear-gradient(100deg, var(--c-pale) 0%, #fff 85%);
    border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
    border-left: 6px solid var(--c);
    box-shadow: 0 2px 6px rgba(20, 30, 50, .05);
    transition: transform .12s, box-shadow .15s, border-color .15s;
}
.lobby-tile:hover { transform: translateX(3px); box-shadow: 0 6px 16px rgba(20, 30, 50, .10); }
.lobby-row.selected .lobby-tile { border-color: var(--c); box-shadow: 0 0 0 2px var(--c), 0 8px 20px rgba(20, 30, 50, .12); }
.lobby-name { grid-area: name; font-weight: 700; font-size: 1.05rem; color: var(--c-dark); }
.lobby-count { grid-area: count; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--muted); }
.seats { grid-area: seats; display: flex; gap: 5px; }
.seat { width: 12px; height: 12px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--c) 45%, transparent); }
.seat.taken { background: var(--c); border-color: var(--c); }
.join-btn {
    background: var(--c); color: var(--c-text, #fff); padding: 0 20px; border-radius: 14px;
    opacity: 0; transform: translateX(-8px); pointer-events: none; transition: opacity .15s, transform .15s;
}
.lobby-row.selected .join-btn { opacity: 1; transform: none; pointer-events: auto; }

/* Lobby-Details */
.details { border-top: 6px solid var(--c, var(--line)); min-height: 220px; display: flex; flex-direction: column; gap: 16px; }
.details-head { display: flex; justify-content: space-between; align-items: center; }
.details-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 600; }
.details-head h2 { margin: 2px 0 0; font-size: 1.6rem; color: var(--c-dark); }
.details-count { font-size: 1.1rem; font-weight: 700; padding: 6px 14px; border-radius: 999px; background: var(--c-pale); color: var(--c-dark); }
.avatars { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.avatars li { display: flex; align-items: center; gap: 8px; padding: 4px 14px 4px 4px; border-radius: 999px; background: var(--c-pale); font-weight: 600; }
.avatar {
    width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center;
    background: var(--c, var(--lobby)); color: var(--c-text, #fff); font-weight: 700; font-size: .95rem;
}
.empty-note { margin: 0; color: var(--muted); padding: 18px; border: 2px dashed var(--line); border-radius: 12px; text-align: center; }
.details-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.join-big { background: var(--c); color: var(--c-text, #fff); padding: 12px 24px; }

/* Spiellobby --------------------------------------------------------------- */
.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.lobby-head h1 { color: var(--lobby-dark, var(--text)); }
.settings { display: flex; flex-wrap: wrap; align-items: end; gap: 16px; border-top: 6px solid var(--lobby); }
.settings label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; }
select, input {
    font: inherit; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: #fff; min-width: 120px;
}
.ready-btn { margin-left: auto; min-width: 140px; padding: 12px 22px; }
.ready-btn.idle { background: var(--idle); color: #333; }
.ready-btn.ready { background: var(--ok-pale); color: #1b5e20; box-shadow: inset 0 0 0 2px var(--ok); }
.ready-btn.reset { background: var(--warn-pale); color: #8a1c12; }
.hint { margin: 10px 4px 18px; font-size: .9rem; }
.member-list { list-style: none; margin: 0; padding: 0; }
.member-list li {
    display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line);
}
.member-list li:last-child { border-bottom: 0; }
.member-name { font-weight: 600; }
.member-list .avatar { --c: var(--lobby); }
.member-name .you { font-weight: 400; color: var(--muted); }
.stars { color: #f59f00; letter-spacing: 1px; }
.change-tag { background: #fff3bf; color: #7a5a00; padding: 3px 10px; border-radius: 999px; font-size: .85rem; }
.status { margin-left: auto; font-size: .85rem; padding: 4px 10px; border-radius: 999px; background: var(--idle); }
.status.ready { background: var(--ok-pale); color: #1b5e20; }
.status.reset { background: var(--warn-pale); color: #8a1c12; }
.offline { opacity: .5; }

/* Spiel -------------------------------------------------------------------- */
.game-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; font-size: 1.05rem; }
.clock { font-variant-numeric: tabular-nums; font-weight: 700; background: var(--card); padding: 6px 14px; border-radius: 10px; box-shadow: var(--shadow); }
.game { display: grid; grid-template-columns: 1fr 260px; gap: 20px; align-items: start; }
.game.solo { grid-template-columns: 1fr; }
.game.solo .progress { display: none; }
.play { display: flex; flex-direction: column; align-items: center; gap: 16px; border-top: 6px solid var(--lobby); }
.gallows-wrap { display: flex; flex-direction: column; align-items: center; }
#gallows { width: 200px; height: 218px; overflow: visible; }
#gallows .ground { fill: #e9e4dc; }
#gallows .part { opacity: 0; transition: opacity .35s ease, transform .35s ease; transform-box: fill-box; transform-origin: center; transform: scale(.92); }
#gallows .part.on { opacity: 1; transform: none; }
#gallows .wood { opacity: .1; transform: none; }
#gallows .wood.on { opacity: 1; }
#gallows .rope { stroke: #c49a5a; stroke-width: 4; fill: none; stroke-linecap: round; }
#gallows .body { stroke: #2b2f3a; stroke-width: 5; stroke-linecap: round; fill: none; }
#gallows .head { fill: #fffaf3; stroke-width: 4; }
#gallows #face { stroke: #2b2f3a; stroke-width: 2.4; fill: #2b2f3a; stroke-linecap: round; }
#gallows #face path { fill: none; }
#gallows #figure { transform-origin: 158px 24px; }
#gallows #figure.swing { animation: swing 2.4s ease-in-out infinite; }
#gallows.won .head { fill: #e6fcf5; }
@keyframes swing { 0%, 100% { transform: rotate(3deg); } 50% { transform: rotate(-3deg); } }
@keyframes draw { from { opacity: 0; } to { opacity: 1; } }
.mistakes { color: var(--muted); }
.word-mask { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; min-height: 56px; }
.word-mask span {
    width: 38px; height: 50px; display: grid; place-items: center;
    font-size: 1.7rem; font-weight: 700; border-bottom: 4px solid #c3c8d1;
}
.word-mask span.filled { border-color: var(--lobby); animation: pop .25s ease-out; }
.word-mask span.sep { border-color: transparent; width: 16px; }
.word-mask.lost span.revealed { color: #c92a2a; }
@keyframes pop { from { transform: scale(.6); } to { transform: scale(1); } }
.message { min-height: 1.6em; font-weight: 700; font-size: 1.2rem; }
.message.win { color: var(--ok); }
.message.lose { color: #c92a2a; }
.alphabet { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 6px; width: 100%; max-width: 560px; }
.alphabet button {
    font: inherit; font-weight: 700; padding: 10px 0; border: 0; border-radius: 8px; cursor: pointer;
    background: #eef0f4; color: var(--text);
}
.alphabet button:hover:not(:disabled) { background: #dfe3ea; }
.alphabet button.hit { background: var(--ok-pale); color: #1b5e20; }
.alphabet button.miss { background: #f1f2f4; color: #b0b4bb; text-decoration: line-through; }
.alphabet button:disabled { cursor: default; }
.alphabet button.pending { opacity: .5; }
.progress-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.progress-list .pname { font-weight: 600; display: flex; justify-content: space-between; }
.pips { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.pip { width: 16px; height: 16px; border-radius: 4px; background: #e6e8ec; }
.pip.ok { background: var(--ok); }
.pip.bad { background: #e03131; }
.pip.now { background: transparent; box-shadow: inset 0 0 0 2px var(--lobby); }

/* Ergebnis ----------------------------------------------------------------- */
.results { display: grid; grid-template-columns: 1fr 260px; gap: 20px; align-items: start; margin-bottom: 20px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 10px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
td.name { text-align: left; font-weight: 600; }
td.sum { font-weight: 800; font-size: 1.1rem; }
tr.first td { background: #fff9db; }
td.pos { color: var(--ok); }
td.neg { color: #e03131; }
.result-words { margin: 0; padding-left: 22px; line-height: 1.9; font-weight: 600; letter-spacing: .5px; }
.difficulty { font-size: .72rem; font-weight: 600; letter-spacing: 0; padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.difficulty.leicht { background: #d3f9d8; color: #2b8a3e; }
.difficulty.mittel { background: #fff3bf; color: #8f6b00; }
.difficulty.schwer { background: #ffe3e3; color: #c92a2a; }

/* Overlays ----------------------------------------------------------------- */
.overlay {
    position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
    background: rgba(20, 24, 32, .55); backdrop-filter: blur(3px);
}
.overlay-box { background: #fff; border-radius: 18px; padding: 28px 34px; text-align: center; box-shadow: var(--shadow); min-width: 280px; max-width: 92vw; }
.overlay-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 8px; }
.overlay-count { font-size: 4rem; font-weight: 800; color: var(--lobby); font-variant-numeric: tabular-nums; }
.overlay-text { color: var(--muted); }
.modal { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.modal input { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.error { color: #c92a2a; min-height: 1.2em; font-size: .9rem; }

/* Mobil -------------------------------------------------------------------- */
@media (max-width: 760px) {
    .hall, .game, .results { grid-template-columns: 1fr; }
    .topbar { padding: 8px 12px; gap: 8px; }
    .brand span { display: none; }
    .where { font-size: .75rem; padding: 5px 10px; }
    .ready-btn { margin-left: 0; width: 100%; }
    .alphabet { grid-template-columns: repeat(8, minmax(0, 1fr)); }
    .word-mask span { width: 28px; height: 40px; font-size: 1.3rem; }
    #gallows { width: 150px; height: 164px; }
}

/* Versionsnummer: klein und unaufdringlich unten rechts */
.version { position: fixed; right: 8px; bottom: 6px; font-size: .7rem; color: var(--muted); opacity: .55; pointer-events: none; z-index: 1; }

/* Navigation */
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.home-btn {
    font: inherit; font-size: .9rem; font-weight: 600; color: #fff; cursor: pointer;
    background: rgba(255, 255, 255, .14); border: 0; border-radius: 999px; padding: 6px 14px;
}
.home-btn:hover { background: rgba(255, 255, 255, .24); }
body:not([data-screen="hall"]) .brand { display: none; }
.btn.danger { background: #e03131; color: #fff; }
.result-actions { display: flex; flex-wrap: wrap; gap: 12px; }
@media (max-width: 760px) {
    .home-btn { padding: 5px 10px; font-size: .8rem; }
    .train-card { width: 100%; }
}
