.risk-lobby,
.risk-game,
.risk-modal {
    --risk-surface: var(--card-bg, #fff);
    --risk-soft: #f3f7f4;
    --risk-text: var(--title, #172027);
    --risk-muted: var(--text-light, #64717a);
    --risk-border: var(--border-color, #e4eaee);
    --risk-gold: #f0c34b;
    --risk-red: #d94b4b;
    --risk-green: #159a72;
    --risk-blue: #2f77d0;
    --risk-ink: #121a22;
    direction: rtl;
    color: var(--risk-text);
    font-family: inherit;
}

.risk-hero {
    position: relative;
    display: grid;
    align-items: end;
    min-height: 310px;
    margin: 14px auto;
    padding: 24px;
    border-radius: 8px;
    overflow: hidden;
    color: #fff;
    background:
        linear-gradient(135deg, rgba(13, 28, 38, .82), rgba(18, 120, 92, .55)),
        radial-gradient(circle at 72% 36%, rgba(240, 195, 75, .28), transparent 28%),
        linear-gradient(145deg, #20333f, #13664f);
}

.risk-hero::after {
    content: "";
    position: absolute;
    inset: 12% 7% 9% 45%;
    opacity: .72;
    background: linear-gradient(135deg, #d6b06a, #5f986b 42%, #c99b57);
    clip-path: polygon(16% 18%, 31% 8%, 47% 12%, 63% 19%, 77% 18%, 91% 34%, 86% 48%, 94% 64%, 81% 78%, 74% 94%, 56% 88%, 42% 97%, 29% 86%, 20% 76%, 11% 61%, 15% 45%, 7% 32%);
}

.risk-hero > div,
.risk-primary-action {
    position: relative;
    z-index: 2;
}

.risk-hero span {
    display: inline-grid;
    place-items: center;
    min-height: 28px;
    padding: 0 12px;
    border-radius: 999px;
    background: var(--risk-gold);
    color: #171717;
    font-weight: 900;
}

.risk-hero h1 {
    max-width: 640px;
    margin: 12px 0;
    font-size: clamp(1.7rem, 4vw, 3.4rem);
    font-weight: 900;
    line-height: 1.25;
}

.risk-hero p {
    max-width: 560px;
    margin: 0;
    color: rgba(255,255,255,.88);
    line-height: 1.9;
}

.risk-primary-action {
    position: absolute;
    left: 24px;
    bottom: 24px;
    display: grid;
    place-items: center;
    min-width: 132px;
    min-height: 44px;
    padding: 0 16px;
    border: 0;
    border-radius: 8px;
    background: var(--risk-gold);
    color: #161616;
    font-weight: 900;
    text-decoration: none;
    cursor: pointer;
}

.risk-panel,
.risk-rules {
    margin: 14px 0;
    padding: 16px;
    border: 1px solid var(--risk-border);
    border-radius: 8px;
    background: var(--risk-surface);
}

.risk-panel h2,
.risk-rules h2 {
    margin: 0 0 12px;
    font-size: 1.08rem;
    font-weight: 900;
}

.risk-table {
    width: 100%;
    border-collapse: collapse;
}

.risk-table th,
.risk-table td {
    padding: 10px;
    border-bottom: 1px solid var(--risk-border);
    text-align: right;
    white-space: nowrap;
}

.risk-table th {
    color: var(--risk-muted);
}

.risk-join-link,
.risk-join-btn,
.risk-create button {
    display: inline-grid;
    place-items: center;
    min-height: 36px;
    padding: 0 13px;
    border: 0;
    border-radius: 8px;
    background: var(--risk-gold);
    color: #171717;
    font-weight: 900;
    text-decoration: none;
    cursor: pointer;
}

.risk-empty,
.risk-alert {
    padding: 12px;
    border-radius: 8px;
    background: var(--risk-soft);
    color: var(--risk-muted);
}

.risk-alert {
    background: #fff2f2;
    color: #a91616;
}

.risk-rank-list {
    display: grid;
    gap: 8px;
}

.risk-rank-row {
    display: grid;
    grid-template-columns: 34px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-radius: 8px;
    background: var(--risk-soft);
}

.risk-modal {
    border: 1px solid var(--risk-border);
    border-radius: 8px;
    background: var(--risk-surface);
    color: var(--risk-text);
}

.risk-modal .modal-header {
    border-bottom-color: var(--risk-border);
}

.risk-modal .modal-title {
    color: var(--risk-text);
}

.risk-create {
    display: grid;
    gap: 10px;
}

.risk-create label {
    margin: 0;
    font-weight: 900;
}

.risk-create input,
.risk-create select {
    min-height: 42px;
    padding: 0 12px;
    border: 1px solid var(--risk-border);
    border-radius: 8px;
    background: var(--risk-surface);
    color: var(--risk-text);
}

.risk-create input::placeholder {
    color: var(--risk-muted);
}

.risk-game-head {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 10px 0;
    padding: 8px;
    border-radius: 8px;
    background: linear-gradient(135deg, #17232d, #214c42);
    color: #fff;
}

.risk-game-head > div {
    display: grid;
    gap: 2px;
    min-height: 46px;
    align-content: center;
    padding: 6px 10px;
    border-radius: 6px;
    background: rgba(255,255,255,.08);
}

.risk-game-head span {
    color: rgba(255,255,255,.68);
    font-size: .75rem;
}

.risk-game-head strong {
    font-weight: 900;
}

.risk-players {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.risk-player {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 62px;
    padding: 8px;
    border: 2px solid transparent;
    border-radius: 8px;
    background: var(--risk-soft);
}

.risk-player.is-turn {
    border-color: var(--risk-gold);
    background: #fff8df;
}

.risk-player img {
    width: 38px;
    height: 38px;
    object-fit: contain;
}

.risk-player strong,
.risk-player small {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.risk-player small {
    color: var(--risk-muted);
    font-size: .76rem;
}

.risk-player-emoji {
    position: absolute;
    left: 6px;
    top: -12px;
    z-index: 3;
    display: grid;
    place-items: center;
    min-width: 30px;
    min-height: 30px;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 6px 18px rgba(0,0,0,.18);
}

.risk-player-emoji:empty {
    display: none;
}

.risk-turn-seconds {
    display: none;
    width: fit-content;
    min-width: 28px;
    margin-top: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--risk-ink);
    color: #fff;
    font-size: .78rem;
}

.risk-player.is-turn .risk-turn-seconds {
    display: inline-grid;
    place-items: center;
}

.risk-play-area {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 12px;
    align-items: start;
}

.risk-map-wrap {
    display: grid;
    gap: 10px;
}

.risk-map {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 11;
    min-height: 420px;
    border: 1px solid rgba(18, 26, 34, .15);
    border-radius: 8px;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(206, 232, 236, .95), rgba(235, 241, 233, .98)),
        #dfeee9;
    box-shadow: 0 18px 42px rgba(18, 28, 38, .16);
}

.risk-map-bg {
    position: absolute;
    inset: 7% 6% 6% 8%;
    background: linear-gradient(135deg, #d6b06a, #7fb071 34%, #c99b57 67%, #5f986b);
    clip-path: polygon(16% 18%, 31% 8%, 47% 12%, 63% 19%, 77% 18%, 91% 34%, 86% 48%, 94% 64%, 81% 78%, 74% 94%, 56% 88%, 42% 97%, 29% 86%, 20% 76%, 11% 61%, 15% 45%, 7% 32%);
    opacity: .72;
    filter: saturate(1.05);
}

.risk-map-bg::after {
    content: "";
    position: absolute;
    inset: 2%;
    clip-path: inherit;
    background:
        radial-gradient(circle at 28% 23%, rgba(255,255,255,.25), transparent 16%),
        radial-gradient(circle at 68% 66%, rgba(255,255,255,.22), transparent 17%),
        linear-gradient(135deg, rgba(255,255,255,.18), transparent);
}

.risk-map-lines {
    position: absolute;
    inset: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
}

.risk-map-lines line {
    stroke: rgba(20, 28, 36, .22);
    stroke-width: .42;
    stroke-dasharray: 1 1;
}

.risk-map-lines line.is-owned {
    stroke: rgba(255,255,255,.42);
    stroke-dasharray: none;
}

.risk-territory {
    position: absolute;
    z-index: 4;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 28px;
    align-items: center;
    gap: 5px;
    min-width: 112px;
    max-width: 136px;
    min-height: 42px;
    padding: 5px 6px 5px 5px;
    border: 2px solid rgba(255,255,255,.82);
    border-radius: 8px;
    color: #fff;
    box-shadow: 0 8px 18px rgba(0,0,0,.2);
    transform: translate(-50%, -50%);
    cursor: pointer;
}

.risk-territory span {
    min-width: 0;
    overflow: hidden;
    font-size: .76rem;
    font-weight: 900;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.risk-territory strong {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,.92);
    color: #111820;
    font-weight: 900;
}

.risk-territory.is-selected {
    outline: 3px solid #111820;
    outline-offset: 2px;
    transform: translate(-50%, -50%) scale(1.05);
}

.risk-territory.is-mine {
    border-color: #fff4ba;
}

.seat-1.risk-territory,
.risk-player.seat-1 { background: linear-gradient(135deg, #d94b4b, #a92134); }
.seat-2.risk-territory,
.risk-player.seat-2 { background: linear-gradient(135deg, #2f77d0, #164f9c); }
.seat-3.risk-territory,
.risk-player.seat-3 { background: linear-gradient(135deg, #159a72, #0d6d52); }
.seat-4.risk-territory,
.risk-player.seat-4 { background: linear-gradient(135deg, #7b5bd6, #4d35a2); }
.seat-5.risk-territory,
.risk-player.seat-5 { background: linear-gradient(135deg, #d28b26, #a35814); }

.risk-player.seat-1,
.risk-player.seat-2,
.risk-player.seat-3,
.risk-player.seat-4,
.risk-player.seat-5 {
    color: #fff;
}

.risk-player.seat-1 small,
.risk-player.seat-2 small,
.risk-player.seat-3 small,
.risk-player.seat-4 small,
.risk-player.seat-5 small {
    color: rgba(255,255,255,.78);
}

.risk-side {
    display: grid;
    gap: 10px;
}

.risk-command,
.risk-toast,
.risk-log {
    padding: 12px;
    border-radius: 8px;
    background: var(--risk-surface);
    border: 1px solid var(--risk-border);
}

.risk-command strong {
    display: block;
    margin-bottom: 6px;
    font-weight: 900;
}

.risk-command p {
    min-height: 44px;
    margin: 0 0 10px;
    color: var(--risk-muted);
    line-height: 1.7;
}

.risk-command-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.risk-command-grid button,
.risk-action-btn,
.risk-close-btn {
    display: grid;
    place-items: center;
    min-height: 42px;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: var(--risk-gold);
    color: #171717;
    font-weight: 900;
    cursor: pointer;
}

.risk-command-grid button:disabled {
    background: #d8dde2;
    color: #66717a;
    cursor: not-allowed;
}

.risk-action-bot {
    background: #75c7f4;
}

.risk-close-btn {
    background: var(--risk-red);
    color: #fff;
}

.risk-board-actions {
    display: grid;
    gap: 8px;
}

.risk-toast {
    display: none;
    background: var(--risk-ink);
    color: #fff;
    text-align: center;
    font-weight: 900;
}

.risk-toast.show {
    display: block;
}

.risk-log {
    display: grid;
    gap: 8px;
    max-height: 260px;
    overflow-y: auto;
}

.risk-log-row {
    display: grid;
    gap: 2px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--risk-border);
    font-size: .85rem;
}

.risk-log-row strong {
    font-weight: 900;
}

.risk-log-row small {
    color: var(--risk-muted);
}

.risk-emojis {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.risk-emojis button {
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    background: var(--risk-soft);
    font-size: 1.15rem;
}

.risk-event-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    place-items: center;
    padding: 18px;
    background: rgba(8, 14, 20, .32);
    pointer-events: none;
}

.risk-event-overlay.show {
    display: grid;
}

.risk-event-overlay > div {
    display: grid;
    gap: 8px;
    min-width: min(320px, 86vw);
    padding: 18px;
    border: 2px solid var(--risk-gold);
    border-radius: 8px;
    background: var(--risk-surface);
    color: var(--risk-text);
    text-align: center;
    box-shadow: 0 22px 60px rgba(0,0,0,.32);
    animation: riskEventPop .24s ease both;
}

.risk-event-overlay span {
    font-size: 2.2rem;
    line-height: 1;
}

.risk-event-overlay em {
    color: var(--risk-muted);
    font-style: normal;
    font-weight: 900;
}

.risk-event-overlay p {
    margin: 0;
    line-height: 1.8;
}

.risk-event-overlay.capture > div,
.risk-event-overlay.attack > div {
    border-color: var(--risk-red);
}

.risk-event-overlay.winner > div,
.risk-event-overlay .winner > div {
    border-color: var(--risk-gold);
}

@keyframes riskEventPop {
    from { opacity: 0; transform: translateY(12px) scale(.94); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.theme-dark .risk-lobby,
.theme-dark .risk-game,
.theme-dark .risk-modal,
body.theme-dark .risk-lobby,
body.theme-dark .risk-game,
body.theme-dark .risk-modal {
    --risk-surface: #1f2933;
    --risk-soft: #273541;
    --risk-text: #f5f7fa;
    --risk-muted: #b8c1cc;
    --risk-border: rgba(255,255,255,.12);
}

.theme-dark .risk-modal,
body.theme-dark .risk-modal {
    background: #1f2933;
    color: #f5f7fa;
    box-shadow: 0 20px 60px rgba(0,0,0,.38);
}

.theme-dark .risk-modal .btn-close,
body.theme-dark .risk-modal .btn-close {
    filter: invert(1) grayscale(1);
}

.theme-dark .risk-create input,
.theme-dark .risk-create select,
body.theme-dark .risk-create input,
body.theme-dark .risk-create select {
    background: #273541;
    color: #f5f7fa;
    border-color: rgba(255,255,255,.16);
}

.theme-dark .risk-player.is-turn,
body.theme-dark .risk-player.is-turn {
    background: rgba(240, 195, 75, .18);
}

@media (max-width: 900px) {
    .risk-play-area {
        grid-template-columns: 1fr;
    }

    .risk-players {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .risk-hero {
        min-height: 230px;
        padding: 16px;
    }

    .risk-hero h1 {
        max-width: 72%;
        font-size: 1.35rem;
    }

    .risk-hero p {
        max-width: 68%;
        font-size: .78rem;
        line-height: 1.65;
    }

    .risk-primary-action {
        left: 14px;
        bottom: 14px;
        min-width: 98px;
        min-height: 38px;
        font-size: .82rem;
    }

    .risk-game-head {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        padding: 6px;
    }

    .risk-game-head > div {
        min-height: 40px;
        padding: 5px;
    }

    .risk-game-head span {
        font-size: .64rem;
    }

    .risk-game-head strong {
        overflow: hidden;
        font-size: .74rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .risk-players {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .risk-player {
        min-height: 58px;
        padding: 7px;
    }

    .risk-player img {
        width: 30px;
        height: 30px;
    }

    .risk-player strong {
        font-size: .76rem;
    }

    .risk-player small {
        font-size: .62rem;
    }

    .risk-map {
        min-height: 520px;
        aspect-ratio: 10 / 13;
    }

    .risk-territory {
        grid-template-columns: minmax(0, 1fr) 24px;
        min-width: 84px;
        max-width: 104px;
        min-height: 36px;
        padding: 4px;
    }

    .risk-territory span {
        font-size: .62rem;
    }

    .risk-territory strong {
        width: 24px;
        height: 24px;
        font-size: .78rem;
    }

    .risk-table thead {
        display: none;
    }

    .risk-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, .9fr) minmax(0, .55fr) minmax(0, .55fr) minmax(52px, .55fr);
        gap: 4px;
        padding: 6px;
        border: 1px solid var(--risk-border);
        border-radius: 8px;
        background: var(--risk-soft);
    }

    .risk-table td {
        min-width: 0;
        overflow: hidden;
        padding: 0;
        border-bottom: 0;
        font-size: .62rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .risk-table-compact tr {
        grid-template-columns: minmax(0, .7fr) minmax(0, 1fr) minmax(0, .55fr) minmax(0, .65fr) minmax(52px, .55fr);
    }
}
