/* ===== Reset & Grundstile ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --table-green: #1a5c2a;
    --table-dark: #0e3a18;
    --card-width: 80px;
    --card-height: 120px;
    --gold: #d4a843;
    --red: #c0392b;
    --white: #ecf0f1;
    --dark: #2c3e50;
    --blue: #2980b9;
    --highlight: #f1c40f;
    --trainer-green: #27ae60;
    --trainer-orange: #e67e22;
    --trainer-red: #e74c3c;
}

body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: var(--table-dark);
    color: var(--white);
    min-height: 100vh;
    overflow: hidden;
}

.screen { display: none; width: 100vw; height: 100vh; }
.screen.active { display: flex; }

/* ===== Lobby ===== */
#lobby {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--table-dark), #1a3a2a);
    overflow-y: auto;
    padding: 2rem 0;
}

.lobby-container {
    text-align: center;
    max-width: 600px;
    width: 90%;
}

.lobby-container h1 {
    font-size: 2.5rem;
    color: var(--gold);
    margin-bottom: 0.3rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

.subtitle {
    color: #aaa;
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.game-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.game-btn {
    background: rgba(255,255,255,0.1);
    border: 2px solid rgba(255,255,255,0.2);
    color: var(--white);
    padding: 1.2rem 1.5rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 140px;
}

.game-btn:hover {
    background: rgba(255,255,255,0.2);
    border-color: var(--gold);
    transform: translateY(-3px);
}

.game-btn.selected {
    background: rgba(212,168,67,0.3);
    border-color: var(--gold);
}

.game-icon { font-size: 2rem; margin-bottom: 0.3rem; }
.game-name { font-size: 1.1rem; font-weight: bold; }
.game-desc { font-size: 0.8rem; color: #aaa; }

.setup-panel {
    background: rgba(0,0,0,0.3);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: left;
}

.setup-panel h2 { color: var(--gold); margin-bottom: 1rem; }

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.9rem;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.1);
    color: var(--white);
    font-size: 1rem;
}

.bot-controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-bot {
    padding: 0.4rem 0.8rem;
    border: 1px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.1);
    color: var(--white);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-bot:hover { background: rgba(255,255,255,0.2); }

/* Kartenrückseiten-Picker */
.card-back-picker {
    margin-top: 0.5rem;
}

.card-back-group-label {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.3rem;
    margin-top: 0.5rem;
}

.card-back-group-label:first-child {
    margin-top: 0;
}

.card-back-row {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.card-back-row::-webkit-scrollbar {
    height: 4px;
}

.card-back-row::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
}

.card-back-item {
    flex-shrink: 0;
    width: 52px;
    cursor: pointer;
    text-align: center;
    border-radius: 6px;
    padding: 3px;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.card-back-item:hover {
    border-color: rgba(255,255,255,0.3);
    transform: translateY(-2px);
}

.card-back-item.selected {
    border-color: var(--gold);
    background: rgba(212,168,67,0.15);
}

.card-back-item img {
    width: 46px;
    height: 64px;
    border-radius: 4px;
    object-fit: cover;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.4);
}

.card-back-label {
    display: block;
    font-size: 0.6rem;
    color: rgba(255,255,255,0.5);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-back-item.selected .card-back-label {
    color: var(--gold);
}

.player-list {
    margin: 1rem 0;
    min-height: 2rem;
}

.player-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.6rem;
    background: rgba(255,255,255,0.05);
    border-radius: 4px;
    margin-bottom: 0.3rem;
}

.player-list-item .remove-bot {
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 1.1rem;
}

.btn-primary {
    width: 100%;
    padding: 0.8rem;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover:not(:disabled) { background: #3498db; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    padding: 0.6rem 1.2rem;
    background: rgba(255,255,255,0.15);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    cursor: pointer;
}

.btn-secondary:hover { background: rgba(255,255,255,0.25); }

/* ===== Spieltisch ===== */
.game-table {
    width: 100vw;
    height: 100vh;
    background: radial-gradient(ellipse at center, var(--table-green), var(--table-dark));
    position: relative;
    overflow: hidden;
}

.game-info {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 2rem;
    padding: 0.5rem 1rem;
    background: rgba(0,0,0,0.4);
    font-size: 0.9rem;
    z-index: 10;
}

.game-info span {
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
}

/* Spieler-Bereiche */
.player-area {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.player-area .player-name {
    font-size: 0.85rem;
    padding: 0.2rem 0.6rem;
    background: rgba(0,0,0,0.5);
    border-radius: 4px;
    margin-bottom: 0.3rem;
    white-space: nowrap;
}

.player-area .player-name.active {
    background: var(--gold);
    color: var(--dark);
    font-weight: bold;
    animation: activePlayerPulse 1.5s ease-in-out infinite;
}

@keyframes activePlayerPulse {
    0%, 100% { box-shadow: 0 0 4px rgba(212,168,67,0.3); }
    50% { box-shadow: 0 0 12px rgba(212,168,67,0.7); }
}

.player-area .player-name.spieler {
    border: 1px solid var(--gold);
}

/* Sitzpositionen */
.player-area.bottom {
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
}

.player-area.top {
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
}

.player-area.left {
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
}

.player-area.right {
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
}

/* Karten-Container */
.player-cards {
    display: flex;
    gap: -20px;
    position: relative;
}

.player-area.left .player-cards,
.player-area.right .player-cards {
    flex-direction: column;
}

/* Einzelne Karte */
.card {
    width: var(--card-width);
    height: var(--card-height);
    border-radius: 6px;
    cursor: default;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.3s;
    position: relative;
    flex-shrink: 0;
}

.card img {
    width: 100%;
    height: 100%;
    border-radius: 6px;
    object-fit: contain;
    background: white;
    box-shadow: 1px 1px 4px rgba(0,0,0,0.4);
}

/* Eigene spielbare Karten */
.card.playable {
    cursor: pointer;
}

.card.playable:hover {
    transform: translateY(-15px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.4), 0 0 8px rgba(212,168,67,0.3);
}

.card.selected {
    transform: translateY(-20px);
    box-shadow: 0 0 15px var(--highlight);
}

/* Trainer: Empfohlene Karte */
.card.recommended {
    box-shadow: 0 0 12px var(--trainer-green), 0 0 24px var(--trainer-green);
}

.card.recommended::after {
    content: "Tipp";
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--trainer-green);
    color: white;
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 3px;
}

/* Karten-Overlap für Hand */
.player-area.bottom .card { margin-left: -15px; }
.player-area.bottom .card:first-child { margin-left: 0; }
.player-area.top .card { margin-left: -25px; }
.player-area.top .card:first-child { margin-left: 0; }
.player-area.left .card { margin-top: -30px; }
.player-area.left .card:first-child { margin-top: 0; }
.player-area.right .card { margin-top: -30px; }
.player-area.right .card:first-child { margin-top: 0; }

/* Verdeckte Karten (Gegner) */
.card.face-down img {
    background: transparent;
}

/* Stichbereich */
.trick-area {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.trick-cards {
    display: flex;
    gap: 5px;
    position: relative;
}

.trick-card {
    width: var(--card-width);
    height: var(--card-height);
    transition: all 0.3s ease;
    animation: trickCardEnter 0.3s ease-out;
}

@keyframes trickCardEnter {
    from { opacity: 0; transform: translateY(25px) scale(0.85); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.trick-card img {
    width: 100%;
    height: 100%;
    border-radius: 6px;
    object-fit: contain;
    background: white;
    box-shadow: 2px 2px 8px rgba(0,0,0,0.5);
}

/* Stich-Gewinner Highlight */
.trick-card.winner {
    box-shadow: 0 0 15px var(--gold);
}

.trick-card.trick-won {
    box-shadow: 0 0 20px var(--gold), 0 0 40px rgba(212,168,67,0.3);
}

/* Aktions-Leiste */
.action-bar {
    position: absolute;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
    z-index: 20;
    flex-wrap: wrap;
    justify-content: center;
}

.action-bar button {
    padding: 0.5rem 1rem;
    border: 1px solid rgba(255,255,255,0.3);
    background: rgba(0,0,0,0.6);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.action-bar button:hover {
    background: rgba(255,255,255,0.2);
}

.action-bar button.primary {
    background: var(--blue);
    border-color: var(--blue);
}

/* Trainer-Overlay */
.trainer-overlay {
    position: absolute;
    top: 40px;
    right: 10px;
    z-index: 15;
}

.trainer-hint {
    background: rgba(0,0,0,0.8);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    border-left: 3px solid var(--trainer-green);
    max-width: 280px;
    font-size: 0.85rem;
    line-height: 1.4;
}

.trainer-hint.warning {
    border-left-color: var(--trainer-orange);
}

.trainer-hint.error {
    border-left-color: var(--trainer-red);
}

/* ===== Dialoge ===== */
.dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.dialog-content {
    background: var(--dark);
    padding: 2rem;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.dialog-content h2 {
    color: var(--gold);
    margin-bottom: 1rem;
}

.dialog-content h3 {
    color: var(--white);
    margin: 1rem 0 0.5rem;
}

/* === Bid-Dialog: leichter Overlay, oben positioniert === */
#bid-dialog {
    background: rgba(0,0,0,0.3);
    align-items: flex-start;
    padding-top: 12vh;
}

#bid-dialog .dialog-content {
    background: rgba(44, 62, 80, 0.95);
    border: 1px solid rgba(212,168,67,0.4);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    max-width: 380px;
    padding: 1.5rem;
}

#bid-options {
    transition: opacity 0.15s ease;
}

/* Bidding-Optionen */
.bid-option {
    display: block;
    width: 100%;
    padding: 0.6rem 1rem;
    margin-bottom: 0.5rem;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--white);
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    font-size: 0.95rem;
}

.bid-option:hover {
    background: rgba(212,168,67,0.3);
    border-color: var(--gold);
}

/* "Ich spiele!" Button */
.bid-play {
    font-size: 1.15rem;
    padding: 1rem;
    background: rgba(41,128,185,0.3);
    border: 2px solid var(--blue);
    text-align: center;
    font-weight: bold;
}

.bid-play:hover {
    background: rgba(41,128,185,0.5);
    border-color: #3498db;
}

/* Kategorie-Grid (Schritt 2) */
.bid-category-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.bid-category-btn {
    padding: 0.8rem 0.6rem;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--white);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    text-align: center;
    transition: all 0.2s;
}

.bid-category-btn:hover {
    background: rgba(212,168,67,0.3);
    border-color: var(--gold);
    transform: translateY(-2px);
}

.bid-category-btn.bid-tout {
    background: rgba(192,57,43,0.2);
    border-color: rgba(192,57,43,0.5);
}

.bid-category-btn.bid-tout:hover {
    background: rgba(192,57,43,0.4);
    border-color: var(--red);
}

/* Farbwahl-Grid (Schritt 3) */
.bid-suit-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.bid-suit-btn {
    padding: 1rem;
    background: rgba(255,255,255,0.08);
    border: 2px solid rgba(255,255,255,0.2);
    color: var(--white);
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1rem;
    text-align: center;
    transition: all 0.2s;
}

.bid-suit-btn:hover {
    background: rgba(212,168,67,0.2);
    transform: scale(1.04);
}

/* Zurück-Button */
.bid-back-btn {
    display: block;
    width: 100%;
    padding: 0.5rem;
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.5);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    transition: all 0.2s;
}

.bid-back-btn:hover {
    color: var(--white);
    border-color: rgba(255,255,255,0.4);
}

/* Announce-Optionen (Watten Schlag/Trumpf) */
.announce-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.announce-btn {
    padding: 0.8rem;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--white);
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    font-size: 0.95rem;
}

.announce-btn:hover {
    background: rgba(212,168,67,0.3);
    border-color: var(--gold);
}

/* Turn-Indicator */
.turn-indicator {
    color: var(--gold);
    font-size: 0.9rem;
    font-weight: bold;
    text-align: center;
    animation: turnBounce 1s ease-in-out infinite;
    margin-bottom: 0.3rem;
}

@keyframes turnBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* Result-Untertitel */
.result-subtitle {
    text-align: center;
    color: rgba(255,255,255,0.5);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

#result-title {
    font-size: 2rem;
    text-align: center;
    margin-bottom: 0.3rem;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#result-dialog .btn-primary { margin-top: 1.5rem; margin-bottom: 0.5rem; }

/* Bilanz-Zeile hervorgehoben */
.result-row.balance {
    font-size: 1.05rem;
    font-weight: bold;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 2px solid rgba(255,255,255,0.2);
    border-bottom: none;
}

/* Ergebnis-Details */
.result-row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.result-positive { color: #2ecc71; }
.result-negative { color: #e74c3c; }

/* Spielanalyse */
.analysis-move {
    padding: 0.5rem;
    margin-bottom: 0.3rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

.analysis-move.optimal { background: rgba(46,204,113,0.2); border-left: 3px solid #2ecc71; }
.analysis-move.akzeptabel { background: rgba(230,126,34,0.2); border-left: 3px solid #e67e22; }
.analysis-move.unguenstig { background: rgba(231,76,60,0.2); border-left: 3px solid #e74c3c; }

/* ===== Deck-Typ Picker ===== */
.deck-type-picker {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.3rem;
}

.deck-type-btn {
    padding: 0.4rem 0.9rem;
    border: 2px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.08);
    color: var(--white);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.deck-type-btn:hover {
    background: rgba(255,255,255,0.18);
    border-color: rgba(255,255,255,0.4);
}

.deck-type-btn.selected {
    border-color: var(--gold);
    background: rgba(212,168,67,0.25);
    color: var(--gold);
    font-weight: bold;
}

/* ===== Card SVG (Wirtshaus Sprite) ===== */
.card-svg {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 6px;
}

.trick-card .card-svg {
    width: var(--card-width);
    height: var(--card-height);
}

/* ===== Rustikal-Theme ===== */
[data-theme="rustikal"] {
    --table-green: #3a2010;
    --table-dark: #1a120c;
    --gold: #caa24a;
    --dark: #2a1a0e;
}

[data-theme="rustikal"] body,
body[data-theme="rustikal"] {
    background: linear-gradient(135deg, #1a120c, #2a1a0e);
}

[data-theme="rustikal"] #lobby,
body[data-theme="rustikal"] #lobby {
    background: linear-gradient(135deg, #1a120c, #2d1e12);
}

[data-theme="rustikal"] .game-table,
body[data-theme="rustikal"] .game-table {
    background:
        radial-gradient(ellipse at center, rgba(255,255,255,0.04), transparent 70%),
        linear-gradient(135deg, #3a2010, #5b3518);
}

[data-theme="rustikal"] .dialog-content,
body[data-theme="rustikal"] .dialog-content {
    background: linear-gradient(180deg, #2a1a0e, #1a120c);
    border-color: rgba(202,162,74,0.3);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    :root {
        --card-width: 55px;
        --card-height: 82px;
    }

    .lobby-container h1 { font-size: 1.8rem; }
    .game-btn { min-width: 100px; padding: 0.8rem; }
    .game-info { font-size: 0.75rem; gap: 0.5rem; }

    .player-area.bottom .card { margin-left: -20px; }
    .player-area.top .card { margin-left: -30px; }
}

@media (max-width: 480px) {
    :root {
        --card-width: 45px;
        --card-height: 67px;
    }
}
