/* === CSS Variables === */
:root {
    --feuer: #e63946;
    --feuer-light: #ff8a8a;
    --feuer-bg: #fff0f0;
    --wasser: #1d3557;
    --wasser-light: #457b9d;
    --wasser-bg: #e8f4f8;
    --erde: #2d6a4f;
    --erde-light: #74c69d;
    --erde-bg: #f0f7f0;
    --luft: #6c757d;
    --luft-light: #a8dadc;
    --luft-bg: #f1faee;
    --bg: #1a1a2e;
    --panel-bg: #16213e;
    --text: #eee;
    --text-muted: #aaa;
    --gold: #f4a261;
    --crystal: #a855f7;
    --field-aktion: #f5f5dc;
    --field-straf: #4a0e0e;
    --field-tuer: #ffd700;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    padding: 12px 0;
    background: linear-gradient(135deg, var(--feuer), var(--wasser), var(--erde), var(--luft-light));
    background-size: 300% 300%;
    animation: headerGradient 8s ease infinite;
}

@keyframes headerGradient {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

/* === Main Layout === */
main {
    flex: 1;
    display: flex;
    flex-direction: row;
    justify-content: center;
    padding: 10px;
    gap: 16px;
}

/* === Board === */
#board-container {
    width: 600px;
    min-width: 400px;
    aspect-ratio: 1;
    flex-shrink: 1;
}

#game-board {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    background: #2a2a3e;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

/* === Sidebar === */
#sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 240px;
    min-width: 200px;
}

#dice-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

#dice {
    width: 64px;
    height: 64px;
    background: linear-gradient(145deg, #ffffff, #e6e6e6);
    color: #333;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    box-shadow: 3px 3px 10px rgba(0,0,0,0.4), inset -1px -1px 3px rgba(0,0,0,0.1), inset 1px 1px 3px rgba(255,255,255,0.8);
    transition: transform 0.3s;
    perspective: 600px;
    position: relative;
}

#dice::before {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 8px;
    border: 2px solid rgba(0,0,0,0.06);
    pointer-events: none;
}

#dice.rolling {
    animation: diceRoll3D 0.6s ease-in-out;
}

@keyframes diceRoll3D {
    0%   { transform: perspective(600px) rotateX(0deg) rotateY(0deg) scale(1); }
    20%  { transform: perspective(600px) rotateX(180deg) rotateY(90deg) scale(1.15); }
    40%  { transform: perspective(600px) rotateX(360deg) rotateY(180deg) scale(0.95); }
    60%  { transform: perspective(600px) rotateX(540deg) rotateY(270deg) scale(1.1); }
    80%  { transform: perspective(600px) rotateX(680deg) rotateY(340deg) scale(1.05); }
    100% { transform: perspective(600px) rotateX(720deg) rotateY(360deg) scale(1); }
}

#roll-btn {
    padding: 8px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: var(--gold);
    color: #333;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

#roll-btn:hover:not(:disabled) {
    background: #e6924e;
    transform: scale(1.05);
}

#roll-btn:disabled {
    background: #555;
    color: #888;
    cursor: not-allowed;
}

#message-log {
    background: var(--panel-bg);
    border-radius: 8px;
    padding: 10px 12px;
    min-height: 50px;
    display: flex;
    align-items: center;
}

#current-message {
    font-size: 0.85rem;
    line-height: 1.4;
}

/* === Players Panel === */
#players-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.player-card {
    background: var(--panel-bg);
    border-radius: 10px;
    padding: 8px 10px;
    border: 2px solid transparent;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.player-card.active {
    box-shadow: 0 0 12px rgba(244, 162, 97, 0.6);
}

.player-card .player-name {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.player-card .player-name .color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.player-card .player-realm {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.player-card .player-crystals {
    font-size: 0.9rem;
    color: var(--crystal);
    margin-bottom: 4px;
}

.player-card .player-fortresses {
    font-size: 0.8rem;
    display: flex;
    gap: 4px;
}

.fortress-slot {
    width: 20px;
    height: 20px;
    border: 1px dashed #555;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
}

.fortress-slot.built {
    border: 1px solid var(--gold);
    background: rgba(244, 162, 97, 0.2);
}

.player-card .skip-badge {
    font-size: 0.75rem;
    color: #ff6b6b;
    margin-top: 4px;
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    z-index: 100;
    padding: 60px 20px 20px 20px;
    pointer-events: none;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--panel-bg);
    border-radius: 16px;
    padding: 20px 24px;
    max-width: 320px;
    width: 280px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    text-align: center;
    pointer-events: auto;
    border: 1px solid rgba(255,255,255,0.1);
}

.modal h2 {
    margin-bottom: 12px;
    font-size: 1.4rem;
}

.modal p {
    margin-bottom: 16px;
    color: var(--text-muted);
}

.setup-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.setup-btn {
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: 2px solid var(--gold);
    border-radius: 10px;
    background: transparent;
    color: var(--gold);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.setup-btn:hover {
    background: var(--gold);
    color: #333;
}

/* Modal buttons for in-game choices */
.modal-btn {
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    border: 2px solid var(--gold);
    border-radius: 8px;
    background: transparent;
    color: var(--gold);
    cursor: pointer;
    margin: 4px;
    transition: background 0.2s, color 0.2s;
}

.modal-btn:hover {
    background: var(--gold);
    color: #333;
}

.modal-btn.primary {
    background: var(--gold);
    color: #333;
}

/* Direction chooser */
.direction-buttons {
    display: grid;
    grid-template-areas:
        ". up ."
        "left . right"
        ". down .";
    gap: 8px;
    justify-items: center;
    margin: 16px auto;
    width: 200px;
}

.dir-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid var(--gold);
    background: transparent;
    color: var(--text);
    font-size: 1.4rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dir-btn:hover {
    background: var(--gold);
    color: #333;
}

.dir-btn.up { grid-area: up; }
.dir-btn.left { grid-area: left; }
.dir-btn.right { grid-area: right; }
.dir-btn.down { grid-area: down; }

.dir-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Card display in modal */
.card-display {
    background: linear-gradient(135deg, #f5f5dc, #e8e0c8);
    color: #333;
    border-radius: 14px;
    padding: 20px 16px;
    margin: 12px 0;
    border: 3px solid var(--gold);
    font-size: 1.05rem;
    font-weight: 600;
    min-height: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: relative;
    box-shadow: 0 4px 16px rgba(244,162,97,0.3);
}

.card-display .card-icon {
    font-size: 1.8rem;
    line-height: 1;
}

.card-display .card-text {
    font-size: 1rem;
    text-align: center;
    line-height: 1.3;
}

.card-display.penalty {
    background: linear-gradient(135deg, #3a0a0a, #1a0505);
    color: #ff6b6b;
    border-color: #ff4444;
    box-shadow: 0 4px 16px rgba(255,68,68,0.3);
}

.card-display.penalty .card-icon {
    filter: drop-shadow(0 0 4px rgba(255,68,68,0.5));
}

/* Crystal change floating animation */
.crystal-change {
    position: absolute;
    font-size: 1.1rem;
    font-weight: 700;
    pointer-events: none;
    animation: crystalFloat 1.2s ease-out forwards;
    z-index: 50;
}

.crystal-change.gain {
    color: #22c55e;
    text-shadow: 0 0 6px rgba(34,197,94,0.5);
}

.crystal-change.loss {
    color: #ef4444;
    text-shadow: 0 0 6px rgba(239,68,68,0.5);
}

@keyframes crystalFloat {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    70% { opacity: 1; transform: translateY(-28px) scale(1.1); }
    100% { opacity: 0; transform: translateY(-40px) scale(0.8); }
}

/* Fight display */
.fight-display {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin: 16px 0;
}

.fight-player {
    text-align: center;
}

.fight-dice {
    width: 50px;
    height: 50px;
    background: white;
    color: #333;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: bold;
    margin: 8px auto;
}

.fight-vs {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gold);
}

/* === Responsive === */
@media (max-width: 780px) {
    main {
        flex-direction: column;
        align-items: center;
    }
    #board-container {
        width: 100%;
        max-width: 500px;
        min-width: unset;
    }
    #sidebar {
        width: 100%;
        max-width: 500px;
        flex-direction: row;
        flex-wrap: wrap;
    }
    #dice-area {
        flex-direction: row;
        gap: 12px;
    }
    #message-log { flex: 1; min-width: 200px; }
    #players-panel {
        flex-direction: row;
        flex-wrap: wrap;
    }
    .player-card { flex: 1; min-width: 120px; }
}

@media (max-width: 480px) {
    body {
        overflow-x: hidden;
    }
    header {
        padding: 6px 0;
    }
    header h1 {
        font-size: 1rem;
        letter-spacing: 1px;
    }
    main {
        padding: 4px;
        gap: 8px;
    }
    #board-container {
        width: 100vw;
        max-width: 100%;
        min-width: unset;
    }
    #sidebar {
        flex-direction: column;
        width: 100%;
        gap: 8px;
        padding: 0 4px;
    }
    #dice-area {
        flex-direction: row;
        gap: 12px;
        align-items: center;
    }
    #message-log {
        min-height: 36px;
        padding: 6px 10px;
    }
    #current-message {
        font-size: 0.8rem;
    }
    #players-panel {
        flex-direction: column;
        gap: 6px;
    }

    /* Touch-optimierte Buttons */
    #roll-btn {
        min-height: 48px;
        min-width: 120px;
        font-size: 1.1rem;
        touch-action: manipulation;
    }
    .setup-buttons {
        flex-direction: column;
        gap: 10px;
    }
    .setup-btn {
        min-height: 48px;
        width: 100%;
        font-size: 1.1rem;
        touch-action: manipulation;
    }
    .modal-btn {
        min-height: 48px;
        min-width: 44px;
        padding: 12px 20px;
        font-size: 1rem;
        margin: 6px 4px;
        touch-action: manipulation;
    }
    .dir-btn {
        width: 64px;
        height: 64px;
        font-size: 1.6rem;
        touch-action: manipulation;
    }
    .direction-buttons {
        width: 220px;
    }

    /* Mobile Modal */
    .modal-overlay {
        align-items: flex-end;
        justify-content: center;
        padding: 10px;
        background: rgba(0, 0, 0, 0.5);
    }
    .modal {
        max-width: 100%;
        width: 100%;
        border-radius: 16px 16px 8px 8px;
        padding: 16px;
        max-height: 80vh;
        overflow-y: auto;
    }
    .modal h2 {
        font-size: 1.2rem;
    }
    .card-display {
        padding: 14px 12px;
        min-height: 70px;
    }
    .card-display .card-icon {
        font-size: 1.5rem;
    }
    .card-display .card-text {
        font-size: 0.95rem;
    }

    /* Kompakte Spieler-Panels */
    .player-card {
        padding: 6px 10px;
        cursor: pointer;
    }
    .player-card .player-realm,
    .player-card .player-fortresses,
    .player-card .skip-badge {
        display: none;
    }
    .player-card.active .player-realm,
    .player-card.active .player-fortresses,
    .player-card.active .skip-badge,
    .player-card.expanded .player-realm,
    .player-card.expanded .player-fortresses,
    .player-card.expanded .skip-badge {
        display: flex;
    }
    .player-card .player-crystals {
        font-size: 0.8rem;
    }
    .player-card .player-name {
        font-size: 0.85rem;
    }
}

/* Begrenzte Höhe auf kurzen Bildschirmen */
@media (max-height: 700px) and (max-width: 480px) {
    header {
        padding: 3px 0;
    }
    header h1 {
        font-size: 0.9rem;
    }
    #board-container {
        max-height: 55vh;
        width: auto;
        aspect-ratio: 1;
        margin: 0 auto;
    }
}
