/* ===================================
   Mensch Ärger Dich Nicht - Styles
   Holz-Brettspielabend Design
   =================================== */

/* --- Import Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Alfa+Slab+One&family=Nunito:wght@400;600;700&display=swap');

/* --- CSS Variables --- */
:root {
    /* Player Colors */
    --red: #c62828;
    --red-dark: #8e1b1b;
    --red-light: #e35d52;

    --blue: #1862ad;
    --blue-dark: #0d3f74;
    --blue-light: #5b96d6;

    --green: #2e7d32;
    --green-dark: #1b4d1f;
    --green-light: #66ad62;

    --yellow: #f0a818;
    --yellow-dark: #b07a08;
    --yellow-light: #ffd05e;

    /* Wood & Table Tokens */
    --felt: #1f3d2b;
    --felt-dark: #122318;
    --felt-light: #2a5239;
    --wood: #8a5a33;
    --wood-dark: #5e3a1e;
    --wood-light: #a9763f;
    --board-cream: #f2e3c2;
    --board-cream-dark: #e2cd9f;
    --ink: #3a2a1a;
    --paper-shadow: rgba(58, 42, 26, 0.35);
    --gold: #d9a441;

    /* Subtle paper/felt grain (inline SVG noise) */
    --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='0.045'/%3E%3C/svg%3E");

    /* Board */
    --board-bg: var(--board-cream);
    --board-border: var(--wood-dark);
    --field-light: #faf0d8;
    --field-border: rgba(58, 42, 26, 0.35);
}

/* --- Base Styles --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Nunito', sans-serif;
    background-color: var(--felt-dark);
    background-image:
        var(--noise),
        radial-gradient(ellipse at 50% 120%, rgba(0, 0, 0, 0.45) 0%, transparent 60%),
        radial-gradient(ellipse at 50% 35%, var(--felt-light) 0%, var(--felt) 45%, var(--felt-dark) 100%);
    background-attachment: fixed;
    color: var(--board-cream);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
}

/* Defensive override in case the shared main.css purple bg is ever added */
body::before {
    background-color: var(--felt-dark) !important;
    background-image: none !important;
}

/* --- Page Title --- */
#page-title {
    font-family: 'Alfa Slab One', serif;
    font-size: 2.4rem;
    color: var(--board-cream);
    text-shadow:
        0 2px 0 rgba(0, 0, 0, 0.45),
        0 6px 14px rgba(0, 0, 0, 0.4);
    letter-spacing: 1px;
    margin-bottom: 20px;
    text-align: center;
    animation: titleBounce 0.6s ease-out;
}

@keyframes titleBounce {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- Dialog Box --- */
.dialog-box {
    background:
        var(--noise),
        linear-gradient(165deg, var(--board-cream), var(--board-cream-dark));
    border: 3px solid var(--wood-dark);
    border-radius: 18px;
    padding: 25px;
    max-width: min(550px, 98vw);
    width: 100%;
    box-shadow:
        inset 0 0 0 2px rgba(255, 250, 235, 0.55),
        inset 0 0 60px rgba(138, 90, 51, 0.18),
        0 14px 40px rgba(0, 0, 0, 0.5);
    text-align: center;
    max-height: 95vh;
    overflow-y: auto;
    color: var(--ink);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

@starting-style {

    .dialog-box,
    #game-section {
        opacity: 0;
        transform: scale(0.96);
    }
}

.dialog-box h2 {
    font-family: 'Alfa Slab One', serif;
    color: var(--ink);
    margin-bottom: 20px;
    font-size: 1.7rem;
    letter-spacing: 0.5px;
}

/* --- Mode Selection Buttons --- */
.mode-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 10px;
}

.mode-btn {
    background: linear-gradient(170deg, #fbf3de, #efdfba);
    border: 2px solid rgba(94, 58, 30, 0.45);
    border-radius: 14px;
    color: var(--ink);
    padding: 20px 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    min-width: 120px;
    box-shadow: 0 3px 8px var(--paper-shadow);
}

.mode-btn i {
    font-size: 2rem;
    color: var(--wood);
}

.mode-btn small {
    font-size: 0.7rem;
    opacity: 0.7;
}

.mode-btn:hover {
    transform: translateY(-3px);
    border-color: var(--wood-dark);
    box-shadow: 0 6px 16px var(--paper-shadow);
}

.mode-btn.active {
    background: linear-gradient(170deg, #f6e4b6, #ecd49a);
    border-color: var(--gold);
    box-shadow:
        inset 0 2px 6px rgba(94, 58, 30, 0.35),
        0 0 0 3px rgba(217, 164, 65, 0.35);
}

.mode-btn.active i {
    color: var(--gold);
}

/* --- Mode Options Container --- */
.mode-options {
    animation: fadeIn 0.3s ease;
}

.mode-options h6 {
    color: var(--ink);
    font-weight: 700;
    margin-bottom: 15px;
}

/* --- Player Selection Buttons --- */
.player-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.player-btn {
    background: linear-gradient(170deg, #fbf3de, #efdfba);
    border: 2px solid rgba(94, 58, 30, 0.45);
    border-radius: 14px;
    color: var(--ink);
    padding: 15px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    min-width: 80px;
    box-shadow: 0 3px 8px var(--paper-shadow);
}

.player-btn .player-num {
    font-family: 'Alfa Slab One', serif;
    font-size: 1.8rem;
    line-height: 1;
}

.player-btn:hover {
    transform: translateY(-3px);
    border-color: var(--wood-dark);
    box-shadow: 0 6px 16px var(--paper-shadow);
}

.player-btn.active {
    background: linear-gradient(170deg, #f6e4b6, #ecd49a);
    border-color: var(--gold);
    box-shadow:
        inset 0 2px 6px rgba(94, 58, 30, 0.35),
        0 0 0 3px rgba(217, 164, 65, 0.35);
}

/* --- Online Mode Styles --- */
.lobby-actions {
    margin-top: 20px;
    background: rgba(138, 90, 51, 0.1);
    padding: 15px;
    border-radius: 15px;
    border: 1px solid rgba(94, 58, 30, 0.3);
}

.btn-online {
    background: linear-gradient(180deg, var(--wood-light), var(--wood) 55%, var(--wood-dark));
    border: 1px solid var(--wood-dark);
    border-radius: 14px;
    color: var(--board-cream);
    padding: 15px 30px;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        inset 0 1px 0 rgba(255, 245, 220, 0.35),
        0 4px 10px var(--paper-shadow);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.btn-online:hover {
    transform: translateY(-2px);
    box-shadow:
        inset 0 1px 0 rgba(255, 245, 220, 0.35),
        0 8px 18px var(--paper-shadow);
    filter: brightness(1.08);
}

.or-divider {
    color: rgba(58, 42, 26, 0.55);
    margin: 15px 0;
    font-weight: 600;
}

.join-section {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.game-code-input {
    flex: 1;
    background: #fbf3de;
    border: 2px solid rgba(94, 58, 30, 0.45);
    border-radius: 12px;
    padding: 12px 15px;
    font-family: 'Alfa Slab One', serif;
    font-size: 1.2rem;
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 3px;
    color: var(--ink);
    outline: none;
    transition: border-color 0.3s ease;
}

.game-code-input::placeholder {
    color: rgba(58, 42, 26, 0.4);
    letter-spacing: 1px;
}

.game-code-input:focus {
    border-color: var(--gold);
}

.btn-join {
    background: linear-gradient(180deg, var(--wood-light), var(--wood) 55%, var(--wood-dark));
    border: 1px solid var(--wood-dark);
    border-radius: 12px;
    color: var(--board-cream);
    padding: 12px 20px;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 5px;
    box-shadow:
        inset 0 1px 0 rgba(255, 245, 220, 0.35),
        0 4px 10px var(--paper-shadow);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.btn-join:hover {
    transform: translateY(-2px);
    box-shadow:
        inset 0 1px 0 rgba(255, 245, 220, 0.35),
        0 8px 18px var(--paper-shadow);
}

/* --- Lobby Styles --- */
.game-code-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
}

.game-code-display span {
    color: rgba(58, 42, 26, 0.7);
    font-weight: 600;
}

.code-box {
    background: #fbf3de;
    border: 2px dashed var(--wood);
    border-radius: 10px;
    padding: 10px 20px;
    font-family: 'Alfa Slab One', serif;
    font-size: 1.5rem;
    letter-spacing: 4px;
    color: var(--wood-dark);
    box-shadow: inset 0 1px 4px rgba(94, 58, 30, 0.2);
}

.btn-copy {
    background: #fbf3de;
    border: 2px solid rgba(94, 58, 30, 0.45);
    border-radius: 8px;
    color: var(--ink);
    padding: 10px 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-copy:hover {
    background: #f6e4b6;
    border-color: var(--gold);
}

.players-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 20px 0;
}

.player-slot {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(138, 90, 51, 0.08);
    padding: 12px 15px;
    border-radius: 10px;
    border: 1px dashed rgba(94, 58, 30, 0.4);
    transition: all 0.3s ease;
}

.player-slot.occupied {
    background: #fbf3de;
    border-style: solid;
    border-color: rgba(94, 58, 30, 0.5);
    box-shadow: 0 2px 6px var(--paper-shadow);
}

.slot-color {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.25);
    box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.25), inset 0 2px 3px rgba(255, 255, 255, 0.35);
}

.player-slot[data-color="red"] .slot-color {
    background: var(--red);
}

.player-slot[data-color="blue"] .slot-color {
    background: var(--blue);
}

.player-slot[data-color="green"] .slot-color {
    background: var(--green);
}

.player-slot[data-color="yellow"] .slot-color {
    background: var(--yellow);
}

.slot-name {
    color: var(--ink);
    font-weight: 600;
}

.lobby-hint {
    color: rgba(58, 42, 26, 0.6);
    font-size: 0.9rem;
    margin-bottom: 15px;
}

/* --- Color Selection --- */
.color-selection h6 {
    color: var(--ink);
    font-weight: 700;
    margin-bottom: 15px;
}

.color-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.color-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fbf3de;
    border: 1px solid rgba(94, 58, 30, 0.35);
    padding: 8px 15px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--ink);
    font-weight: 600;
}

.color-toggle:hover {
    background: #f6e4b6;
}

.color-toggle input {
    display: none;
}

.color-toggle input:checked+.color-box {
    transform: scale(1.2);
    box-shadow: 0 0 10px currentColor;
}

.color-toggle input:disabled+.color-box {
    opacity: 0.7;
}

.color-box {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 3px solid rgba(58, 42, 26, 0.3);
    transition: all 0.2s;
}

.color-box.red {
    background: var(--red);
}

.color-box.blue {
    background: var(--blue);
}

.color-box.green {
    background: var(--green);
}

.color-box.yellow {
    background: var(--yellow);
}

/* --- Buttons --- */
.btn-start {
    background: linear-gradient(180deg, var(--wood-light), var(--wood) 55%, var(--wood-dark));
    border: 1px solid var(--wood-dark);
    border-radius: 14px;
    color: var(--board-cream);
    padding: 15px 40px;
    font-family: 'Alfa Slab One', serif;
    font-size: 1.2rem;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 25px;
    display: inline-flex;
    align-items: center;
    box-shadow:
        inset 0 1px 0 rgba(255, 245, 220, 0.35),
        0 5px 14px var(--paper-shadow);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.btn-start:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow:
        inset 0 1px 0 rgba(255, 245, 220, 0.35),
        0 10px 22px var(--paper-shadow);
    filter: brightness(1.08);
}

.btn-start:active {
    transform: translateY(1px) scale(0.99);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.35);
}

.btn-start:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-back {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    margin-top: 20px;
    background: transparent !important;
    border: 2px solid rgba(94, 58, 30, 0.5) !important;
    border-radius: 12px !important;
    color: var(--ink) !important;
    padding: 10px 25px !important;
    text-decoration: none !important;
    font-family: 'Nunito', sans-serif !important;
    font-weight: 700 !important;
    font-size: 1rem !important;
    transition: all 0.3s ease !important;
    cursor: pointer !important;
    outline: none !important;
}

.btn-back:hover {
    background: rgba(138, 90, 51, 0.12) !important;
    transform: translateY(-2px) !important;
    color: var(--wood-dark) !important;
    border-color: var(--wood-dark) !important;
}

.btn-back:active {
    transform: translateY(1px) !important;
}

.btn-back i {
    margin-right: 8px;
    font-size: 1.2rem;
}

/* --- Lobby Actions --- */
.lobby-actions {
    margin-top: 25px;
    background: rgba(138, 90, 51, 0.1);
    padding: 20px;
    border-radius: 18px;
    border: 1px solid rgba(94, 58, 30, 0.3);
}

.btn-lobby {
    background: #fbf3de !important;
    border: 2px solid rgba(94, 58, 30, 0.45) !important;
    border-radius: 12px !important;
    color: var(--ink) !important;
    padding: 12px 10px !important;
    font-family: 'Nunito', sans-serif !important;
    font-weight: 700 !important;
    font-size: 0.9rem !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-lobby:hover {
    transform: translateY(-2px) !important;
    background: #f6e4b6 !important;
    border-color: var(--gold) !important;
}

.btn-lobby:active {
    transform: translateY(1px) !important;
}

/* --- Status Display --- */
.status-display {
    background:
        var(--noise),
        linear-gradient(180deg, var(--wood-light), var(--wood) 60%, var(--wood-dark));
    border: 1px solid var(--wood-dark);
    border-left: 6px solid var(--current-player, var(--gold));
    border-radius: 12px;
    padding: 12px 25px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: 'Alfa Slab One', serif;
    font-size: 1.2rem;
    color: var(--board-cream);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
    box-shadow:
        inset 0 1px 0 rgba(255, 245, 220, 0.3),
        0 6px 18px rgba(0, 0, 0, 0.4);
    flex-wrap: wrap;
    justify-content: center;
}

.turn-indicator {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid var(--board-cream);
    box-shadow:
        inset 0 -3px 6px rgba(0, 0, 0, 0.3),
        0 0 12px currentColor;
    animation: turnPulse 1.6s ease-in-out infinite;
}

@keyframes turnPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.12);
    }
}

/* --- Game Container --- */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    flex: 1;
    width: 100%;
    max-width: 800px;
}

#game-section {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* --- Game Board --- */
#game-board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(11, 1fr);
    grid-template-rows: repeat(11, 1fr);
    gap: 2px;
    padding: 12px;
    background:
        var(--noise) padding-box,
        linear-gradient(160deg, #f7eacb, var(--board-cream) 40%, var(--board-cream-dark)) padding-box,
        linear-gradient(160deg, var(--wood-light), var(--wood-dark) 55%, #7a4d28) border-box;
    border: 10px solid transparent;
    border-radius: 16px;
    box-shadow:
        inset 0 0 0 2px rgba(94, 58, 30, 0.45),
        0 18px 45px rgba(0, 0, 0, 0.55);
    width: min(90vw, calc(100dvh - 220px), 600px);
    height: min(90vw, calc(100dvh - 220px), 600px);
}

/* --- Board Cells --- */
.cell {
    aspect-ratio: 1;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.2s;
}

/* Empty cells - invisible */
.cell.empty {
    background: transparent;
    border: none;
}

/* Path cells */
.cell.path {
    background: var(--field-light);
    border: 2px solid var(--field-border);
    box-shadow: inset 0 1px 3px rgba(94, 58, 30, 0.2);
    border-radius: 50%;
}

.cell.path:hover {
    transform: scale(1.05);
    z-index: 10;
}

/* Center field */
.cell.center {
    background:
        radial-gradient(circle at 50% 45%, #fbf3de 0%, #fbf3de 55%, transparent 56%),
        conic-gradient(var(--red) 0deg 90deg, var(--blue) 90deg 180deg, var(--green) 180deg 270deg, var(--yellow) 270deg 360deg);
    border: 2px solid var(--ink);
    border-radius: 50%;
    box-shadow: inset 0 1px 4px rgba(94, 58, 30, 0.3);
}

.cell.center::after {
    content: '★';
    position: absolute;
    color: var(--gold);
    font-size: 0.9em;
    text-shadow: 0 1px 1px rgba(94, 58, 30, 0.5);
}

/* Home Areas */
.cell.home-red {
    background: color-mix(in srgb, var(--red) 30%, var(--field-light));
    border: 2px solid color-mix(in srgb, var(--red) 60%, var(--ink));
    border-radius: 50%;
}

.cell.home-blue {
    background: color-mix(in srgb, var(--blue) 30%, var(--field-light));
    border: 2px solid color-mix(in srgb, var(--blue) 60%, var(--ink));
    border-radius: 50%;
}

.cell.home-green {
    background: color-mix(in srgb, var(--green) 30%, var(--field-light));
    border: 2px solid color-mix(in srgb, var(--green) 60%, var(--ink));
    border-radius: 50%;
}

.cell.home-yellow {
    background: color-mix(in srgb, var(--yellow) 30%, var(--field-light));
    border: 2px solid color-mix(in srgb, var(--yellow) 60%, var(--ink));
    border-radius: 50%;
}

/* Goal Areas */
.cell.goal-red {
    background: color-mix(in srgb, var(--red) 55%, var(--field-light));
    border: 2px solid var(--red-dark);
    border-radius: 50%;
}

.cell.goal-blue {
    background: color-mix(in srgb, var(--blue) 55%, var(--field-light));
    border: 2px solid var(--blue-dark);
    border-radius: 50%;
}

.cell.goal-green {
    background: color-mix(in srgb, var(--green) 55%, var(--field-light));
    border: 2px solid var(--green-dark);
    border-radius: 50%;
}

.cell.goal-yellow {
    background: color-mix(in srgb, var(--yellow) 55%, var(--field-light));
    border: 2px solid var(--yellow-dark);
    border-radius: 50%;
}

/* Start fields - on the main path but colored */
.cell.start-red {
    background: var(--red);
    border: 2px solid var(--red-dark);
    border-radius: 50%;
}

.cell.start-blue {
    background: var(--blue);
    border: 2px solid var(--blue-dark);
    border-radius: 50%;
}

.cell.start-green {
    background: var(--green);
    border: 2px solid var(--green-dark);
    border-radius: 50%;
}

.cell.start-yellow {
    background: var(--yellow);
    border: 2px solid var(--yellow-dark);
    border-radius: 50%;
}

/* Start field markers */
.cell.start-red::after,
.cell.start-blue::after,
.cell.start-green::after,
.cell.start-yellow::after {
    content: '★';
    position: absolute;
    font-size: 0.6em;
    opacity: 0.9;
    color: var(--board-cream);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* --- Pieces --- */
.piece,
.ghost-piece {
    width: 70%;
    height: 70%;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 100 !important;
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.45),
        inset 0 -4px 7px rgba(0, 0, 0, 0.35),
        inset 0 3px 5px rgba(255, 255, 255, 0.35);
    position: relative;
    z-index: 5;
}

.piece::after,
.ghost-piece::after {
    content: '';
    position: absolute;
    top: 12%;
    left: 28%;
    width: 26%;
    height: 16%;
    background: rgba(255, 255, 255, 0.55);
    border-radius: 50%;
    transform: rotate(-20deg);
}

.piece:hover {
    transform: scale(1.15);
    box-shadow:
        0 6px 15px rgba(0, 0, 0, 0.5),
        0 0 20px currentColor;
}

.piece.red,
.ghost-piece.red {
    background: radial-gradient(circle at 35% 30%, var(--red-light) 0%, var(--red) 45%, var(--red-dark) 95%);
    color: var(--red);
}

.piece.blue,
.ghost-piece.blue {
    background: radial-gradient(circle at 35% 30%, var(--blue-light) 0%, var(--blue) 45%, var(--blue-dark) 95%);
    color: var(--blue);
}

.piece.green,
.ghost-piece.green {
    background: radial-gradient(circle at 35% 30%, var(--green-light) 0%, var(--green) 45%, var(--green-dark) 95%);
    color: var(--green);
}

.piece.yellow,
.ghost-piece.yellow {
    background: radial-gradient(circle at 35% 30%, var(--yellow-light) 0%, var(--yellow) 45%, var(--yellow-dark) 95%);
    color: var(--yellow);
}

.piece.selectable {
    animation: pulse 1s infinite;
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.45), 0 0 0 0 rgba(217, 164, 65, 0.75);
    }

    50% {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.45), 0 0 0 10px rgba(217, 164, 65, 0);
    }
}

/* Hidden while its ghost is animating */
.piece.piece-hidden {
    visibility: hidden;
}

/* Animation ghost (absolutely positioned on the board, driven by JS) */
.ghost-piece {
    position: absolute;
    top: 0;
    left: 0;
    cursor: default;
    pointer-events: none;
    z-index: 200 !important;
    transition: none;
    will-change: transform;
}

/* Little hop per field step ('scale' property stays independent of the
   JS-driven 'transform' slides) */
.ghost-piece.hopping {
    animation: ghostHop 0.13s ease-in-out infinite;
}

@keyframes ghostHop {

    0%,
    100% {
        scale: 1;
    }

    50% {
        scale: 1.14;
    }
}

/* --- Dice --- */
#dice-container {
    text-align: center;
    position: relative;
    z-index: 50;
}

.dice {
    width: 80px;
    height: 80px;
    background:
        var(--noise),
        linear-gradient(160deg, #f7eed8, #e3d2ac);
    border: 2px solid var(--current-player, var(--wood-dark));
    border-radius: 18%;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        0 6px 16px rgba(0, 0, 0, 0.45),
        0 0 14px color-mix(in srgb, var(--current-player, transparent) 45%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

.dice:hover {
    transform: scale(1.1);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        0 8px 24px rgba(0, 0, 0, 0.5),
        0 0 18px color-mix(in srgb, var(--current-player, var(--gold)) 55%, transparent);
}

.dice:active {
    transform: scale(0.95);
}

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

@keyframes diceRoll {
    0% {
        transform: rotate(0deg) scale(1);
    }

    25% {
        transform: rotate(90deg) scale(1.2);
    }

    50% {
        transform: rotate(180deg) scale(1);
    }

    75% {
        transform: rotate(270deg) scale(1.2);
    }

    100% {
        transform: rotate(360deg) scale(1);
    }
}

.dice.disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.dice-face {
    width: 100%;
    height: 100%;
    display: grid;
    padding: 12px;
    gap: 4px;
}

.dot {
    width: 12px;
    height: 12px;
    background: var(--ink);
    border-radius: 50%;
    box-shadow:
        inset 0 2px 3px rgba(0, 0, 0, 0.55),
        0 1px 0 rgba(255, 255, 255, 0.4);
}

/* Dice face layouts */
.dice-face[data-value="1"] {
    place-content: center;
    place-items: center;
}

.dice-face[data-value="2"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.dice-face[data-value="2"] .dot:nth-child(1) {
    grid-area: 1 / 1;
    align-self: start;
    justify-self: start;
}

.dice-face[data-value="2"] .dot:nth-child(2) {
    grid-area: 2 / 2;
    align-self: end;
    justify-self: end;
}

.dice-face[data-value="3"] {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
}

.dice-face[data-value="3"] .dot:nth-child(1) {
    grid-area: 1 / 1;
}

.dice-face[data-value="3"] .dot:nth-child(2) {
    grid-area: 2 / 2;
    justify-self: center;
    align-self: center;
}

.dice-face[data-value="3"] .dot:nth-child(3) {
    grid-area: 3 / 3;
    justify-self: end;
    align-self: end;
}

.dice-face[data-value="4"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    align-items: center;
    justify-items: center;
}

.dice-face[data-value="5"] {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
}

.dice-face[data-value="5"] .dot:nth-child(1) {
    grid-area: 1 / 1;
}

.dice-face[data-value="5"] .dot:nth-child(2) {
    grid-area: 1 / 3;
    justify-self: end;
}

.dice-face[data-value="5"] .dot:nth-child(3) {
    grid-area: 2 / 2;
    justify-self: center;
    align-self: center;
}

.dice-face[data-value="5"] .dot:nth-child(4) {
    grid-area: 3 / 1;
    align-self: end;
}

.dice-face[data-value="5"] .dot:nth-child(5) {
    grid-area: 3 / 3;
    justify-self: end;
    align-self: end;
}

.dice-face[data-value="6"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    align-items: center;
    justify-items: center;
}

.dice-hint {
    margin-top: 10px;
    color: var(--board-cream);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    font-weight: 600;
    font-size: 0.9rem;
}

/* --- Game Controls --- */
.game-controls {
    display: flex;
    gap: 15px;
    margin-top: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn-control {
    background: rgba(18, 35, 24, 0.55);
    border: 2px solid rgba(242, 227, 194, 0.35);
    border-radius: 12px;
    color: var(--board-cream);
    padding: 12px 25px;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
}

/* Mobile Dice Fix */
@media (max-width: 768px) {
    .game-controls {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    .btn-control {
        width: 100%;
        justify-content: center;
    }
}

/* Auto Roll Switch */
.auto-roll-container {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--board-cream);
    font-family: 'Nunito', sans-serif;
    font-size: 0.85rem;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.22);
    padding: 8px 15px;
    border-radius: 20px;
    margin-left: 10px;
}

/* Sound Toggle Button */
.btn-icon {
    background: rgba(0, 0, 0, 0.22);
    border: none;
    border-radius: 50%;
    color: var(--board-cream);
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: rgba(0, 0, 0, 0.38);
    transform: scale(1.08);
}

/* Toggle Switch Style */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.35);
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--board-cream);
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--gold);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--gold);
}

input:checked+.slider:before {
    transform: translateX(18px);
}

.btn-control:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    background: rgba(18, 35, 24, 0.8);
    border-color: var(--gold);
    color: var(--board-cream);
}

/* --- Winner Modal --- */
.winner-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 18, 12, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.winner-content {
    background:
        var(--noise),
        linear-gradient(165deg, var(--board-cream), var(--board-cream-dark));
    border: 3px solid var(--wood-dark);
    border-radius: 22px;
    padding: 40px;
    text-align: center;
    max-width: 400px;
    color: var(--ink);
    box-shadow:
        inset 0 0 0 2px rgba(255, 250, 235, 0.55),
        0 18px 50px rgba(0, 0, 0, 0.6);
    animation: popIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes popIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.trophy {
    font-size: 5rem;
    margin-bottom: 20px;
    animation: trophyBounce 0.6s ease infinite alternate;
}

@keyframes trophyBounce {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(-10px);
    }
}

.winner-content h2 {
    font-family: 'Alfa Slab One', serif;
    color: var(--wood-dark);
    font-size: 2rem;
    margin-bottom: 10px;
}

.winner-content p {
    color: rgba(58, 42, 26, 0.75);
    font-size: 1.1rem;
    margin-bottom: 25px;
}

.winner-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.btn-winner {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: 1px solid var(--wood-dark);
    border-radius: 12px;
    background: linear-gradient(180deg, var(--wood-light), var(--wood) 55%, var(--wood-dark));
    color: var(--board-cream);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow:
        inset 0 1px 0 rgba(255, 245, 220, 0.35),
        0 4px 10px var(--paper-shadow);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.btn-winner:hover {
    transform: translateY(-2px);
    box-shadow:
        inset 0 1px 0 rgba(255, 245, 220, 0.35),
        0 8px 18px var(--paper-shadow);
    filter: brightness(1.08);
}

.btn-winner.secondary {
    background: transparent;
    border: 2px solid rgba(94, 58, 30, 0.5);
    color: var(--ink);
    text-shadow: none;
    box-shadow: none;
}

.btn-winner.secondary:hover {
    background: rgba(138, 90, 51, 0.12);
}

/* --- Responsive --- */
@media (max-width: 600px) {
    #page-title {
        font-size: 1.6rem;
    }

    .dialog-box {
        padding: 20px;
        margin: 10px;
    }

    .player-btn {
        padding: 15px 20px;
    }

    #game-board {
        width: min(96vw, calc(100dvh - 240px), 420px);
        height: min(96vw, calc(100dvh - 240px), 420px);
        padding: 8px;
        border-width: 7px;
    }

    .dice {
        width: 72px;
        height: 72px;
    }

    .status-display {
        font-size: 1rem;
        padding: 10px 15px;
        gap: 8px;
    }

    .auto-roll-container {
        padding: 6px 10px;
        margin-left: 0;
    }
}

@media (min-width: 900px) {
    .game-container {
        flex-direction: row;
        gap: 40px;
        align-items: flex-start;
    }

    #dice-container {
        order: 1;
    }
}

/* --- Modals & Overlays --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 18, 12, 0.75);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background:
        var(--noise),
        linear-gradient(165deg, var(--board-cream), var(--board-cream-dark));
    border: 3px solid var(--wood-dark);
    border-radius: 18px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow:
        inset 0 0 0 2px rgba(255, 250, 235, 0.55),
        0 14px 40px rgba(0, 0, 0, 0.55);
    color: var(--ink);
}

.modal-content h3 {
    font-family: 'Alfa Slab One', serif;
    margin-bottom: 20px;
    color: var(--ink);
}

.modal-content p {
    color: rgba(58, 42, 26, 0.8);
    margin-bottom: 1.5rem;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.btn-modal {
    background: linear-gradient(180deg, var(--wood-light), var(--wood) 55%, var(--wood-dark));
    border: 1px solid var(--wood-dark);
    border-radius: 12px;
    color: var(--board-cream);
    padding: 10px 25px;
    font-size: 0.9rem;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.btn-modal:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--paper-shadow);
    filter: brightness(1.08);
}

.friends-invite-list {
    max-height: 300px;
    overflow-y: auto;
    text-align: left;
    padding: 5px;
    color: var(--ink);
}

.friends-invite-list::-webkit-scrollbar {
    width: 6px;
}

.friends-invite-list::-webkit-scrollbar-thumb {
    background: rgba(94, 58, 30, 0.4);
    border-radius: 3px;
}

/* --- Large Screens (2K/4K) --- */
@media (min-height: 1081px),
(min-width: 2000px) {
    .game-container {
        max-width: 1600px;
        gap: 60px;
    }

    #game-board {
        width: min(90vw, calc(100dvh - 250px), 1000px);
        height: min(90vw, calc(100dvh - 250px), 1000px);
        padding: 20px;
        gap: 4px;
        border-width: 14px;
    }

    .cell {
        border-radius: 8px;
    }

    .dice {
        width: 120px;
        height: 120px;
    }

    .dice-hint {
        font-size: 1.2rem;
    }

    .btn-control {
        font-size: 1.2rem;
        padding: 15px 35px;
    }

    .dialog-box {
        max-width: 700px;
    }

    .dialog-box h2 {
        font-size: 2.5rem;
    }

    .player-btn .player-num {
        font-size: 2.5rem;
    }
}
