* {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    --bg: #111;
    --panel: #1b1b1b;
    --panel-2: #252525;
    --border: #444;
    --text: #eee;
    --muted: #aaa;
    --accent: #55dd88;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, sans-serif;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
    border: 1px solid #666;
    border-radius: 7px;
    background: #333;
    color: #fff;
    padding: 9px 14px;
}

button:hover:not(:disabled) {
    background: #444;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

input {
    border: 1px solid #555;
    border-radius: 7px;
    background: #202020;
    color: #fff;
    padding: 10px 12px;
}

/* Pod Playorą pasek narzędzi zjeżdża pod jej nagłówek, żeby nie przykrywać marki ani nicka konta. */
html:has(.playora-header) #utilityBar {
    top: var(--playora-header-height, 64px);
}

#utilityBar {
    position: fixed;
    z-index: 70;
    top: 0;
    left: 0;
    right: 0;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 7px 14px;
    border-bottom: 1px solid #303030;
    background: rgba(20, 20, 20, 0.97);
    backdrop-filter: blur(8px);
}

#connectionStatus {
    color: var(--muted);
    font-size: 13px;
}

#languageSwitcher {
    display: inline-flex;
    overflow: hidden;
    border: 1px solid #555;
    border-radius: 8px;
    background: #1d1d1d;
}

#languageSwitcher button {
    min-width: 46px;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 5px 8px;
    color: #aaa;
    font-size: 12px;
    font-weight: 700;
}

#languageSwitcher button + button {
    border-left: 1px solid #555;
}

#languageSwitcher button.language-active {
    background: var(--accent);
    color: #07140c;
}

.view-panel {
    width: min(560px, calc(100% - 32px));
    margin: 64px auto 0;
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--panel);
}

.view-panel h1,
.view-panel h2 {
    margin-top: 0;
}

.view-description,
.room-hint {
    color: var(--muted);
}

.lobby-form {
    display: grid;
    gap: 10px;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    margin-top: 8px;
}

.secondary-button {
    margin-left: auto;
}

.solo-button {
    border-color: #5f8f68;
    background: linear-gradient(180deg, #31553a, #24452e);
}

.solo-button:hover {
    background: linear-gradient(180deg, #3a6545, #2b5035);
}

.solo-launch-row {
    display: flex;
    align-items: end;
    gap: 10px;
    margin-top: 2px;
    padding: 10px;
    border: 1px solid #36503c;
    border-radius: 10px;
    background: rgba(49, 85, 58, 0.16);
}

.solo-difficulty {
    display: grid;
    gap: 6px;
    min-width: 160px;
}

.solo-difficulty label {
    color: #d7dfd9;
    font-size: 13px;
    font-weight: 700;
}

.solo-launch-row .solo-button {
    flex: 1;
    min-height: 42px;
}

@media (max-width: 520px) {
    .solo-launch-row {
        align-items: stretch;
        flex-direction: column;
    }

    .solo-difficulty {
        min-width: 0;
    }
}

#playersList div {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 6px 0;
    padding: 6px;
    border-radius: 6px;
    background: #333;
}

.player-ready-label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-left: auto;
    color: #ddd;
    font-size: 14px;
}

#gameView {
    overflow: hidden;
    padding-top: 50px;
}

#gameTopBar {
    display: flex;
    align-items: center;
    gap: 18px;
    min-height: 45px;
    padding: 8px 12px;
    background: #181818;
    border-bottom: 1px solid #333;
}

#turnInfo {
    font-size: 18px;
    font-weight: 700;
}

#selectionInfo {
    min-width: 160px;
    color: #bbb;
}

.small-button {
    margin-left: auto;
    padding: 6px 10px;
}

#zoomControls {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

#zoomControls .small-button {
    margin-left: 0;
    min-width: 34px;
}

#zoomControls .zoom-reset-button {
    min-width: 58px;
    font-variant-numeric: tabular-nums;
}

#zoomLevel {
    display: inline-block;
    min-width: 38px;
}

#gameCanvas {
    display: block;
    border-top: 1px solid #444;
    background: #06101c url('assets/starfield.webp') center / cover no-repeat;
}

#barCanvas {
    display: block;
    width: 100%;
    max-width: 100%;
    background: #222;
    cursor: pointer;
    user-select: none;
    touch-action: none;
}

/* Chat */
#chatPanel {
    position: fixed;
    z-index: 50;
    right: 14px;
    bottom: 14px;
    width: min(340px, calc(100vw - 28px));
    height: 390px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #555;
    border-radius: 12px;
    background: rgba(24, 24, 24, 0.97);
}

#chatPanel[hidden] {
    display: none;
}

#chatPanel.chat-collapsed {
    width: min(220px, calc(100vw - 28px));
    height: 44px;
    min-height: 44px;
}

#chatPanel.chat-collapsed #chatMessages,
#chatPanel.chat-collapsed #chatComposer {
    display: none;
}

#chatHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 42px;
    padding: 8px 10px;
    border-bottom: 1px solid #444;
    background: #202020;
    cursor: pointer;
    user-select: none;
}


.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

#chatUnread {
    min-width: 22px;
    padding: 2px 6px;
    border-radius: 999px;
    background: #c33;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
}

#btnChatToggle {
    width: 34px;
    height: 30px;
    padding: 0;
    touch-action: manipulation;
    font-size: 20px;
    line-height: 1;
}

#chatMessages {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.chat-message {
    margin-bottom: 9px;
    overflow-wrap: anywhere;
}

.chat-message-meta {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 2px;
    font-size: 12px;
    color: #aaa;
}

.chat-message-nick {
    font-weight: 700;
}

.chat-message-text {
    white-space: pre-wrap;
}

.chat-system-message {
    margin: 7px 0;
    padding: 6px 8px;
    border-left: 3px solid #777;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.04);
    color: #bbb;
    font-size: 13px;
    font-style: italic;
}

.chat-system-message.chat-turn-skipped {
    border-left-color: #e4b84a;
    color: #e8cf8c;
}

.chat-system-message.chat-game-over,
.chat-system-message.chat-game-over-draw {
    border-left-color: var(--accent);
    color: #d8ffe6;
    font-weight: 700;
}

.chat-system-message.chat-player-eliminated {
    border-left-color: #e05a5a;
    color: #ffb3b3;
    font-weight: 700;
}

#chatComposer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 7px;
    padding: 9px;
    border-top: 1px solid #444;
}

#chatInput {
    min-width: 0;
}

/* Modal zasad */
.modal-backdrop {
    position: fixed;
    z-index: 100;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(0, 0, 0, 0.72);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-window {
    width: min(760px, 100%);
    max-height: min(820px, calc(100vh - 36px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #666;
    border-radius: 14px;
    background: #1b1b1b;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid #444;
}

.modal-header h2 {
    margin: 0;
}

#btnRulesClose {
    width: 38px;
    height: 34px;
    padding: 0;
    font-size: 24px;
}

.modal-content {
    overflow-y: auto;
    padding: 18px 24px 28px;
    line-height: 1.55;
}

.modal-content h3 {
    margin-bottom: 5px;
    color: var(--accent);
}

.modal-content ul {
    padding-left: 22px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

@media (max-width: 620px) {
    #utilityBar {
        min-height: 46px;
        padding: 5px 8px;
        justify-content: space-between;
    }

    .secondary-button {
        margin-left: 0;
    }

    #gameView {
        padding-top: 46px;
    }

    #gameTopBar {
        flex-wrap: wrap;
        gap: 5px 10px;
        min-height: 40px;
        padding: 5px 8px;
    }

    #turnInfo {
        font-size: 15px;
    }

    .small-button {
        padding: 5px 7px;
        font-size: 11px;
    }

    #zoomControls {
        order: 3;
        margin-left: 0;
    }

    #zoomControls .zoom-reset-button {
        min-width: 52px;
    }

    #btnLeaveFinishedGameTop {
        margin-left: 0;
    }

    #selectionInfo {
        min-width: 0;
    }

    #chatPanel {
        right: 8px;
        bottom: 8px;
        width: calc(100vw - 16px);
        height: 46vh;
    }

    #chatPanel.chat-collapsed {
        width: min(220px, calc(100vw - 16px));
        height: 44px;
        min-height: 44px;
    }
}


/* Ekran końcowy */
.end-game-overlay {
    position: fixed;
    z-index: 80;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background:
        radial-gradient(
            circle at center,
            rgba(255, 255, 255, 0.08),
            rgba(0, 0, 0, 0.88) 62%
        );
    backdrop-filter: blur(4px);
}

.end-game-overlay[hidden] {
    display: none;
}

.end-game-card {
    --winner-color: #55dd88;

    width: min(520px, 100%);
    padding: 34px 28px;
    border: 3px solid var(--winner-color);
    border-radius: 18px;
    background: #151515;
    text-align: center;
    box-shadow:
        0 0 32px color-mix(
            in srgb,
            var(--winner-color) 55%,
            transparent
        );
}

#endGamePlayerLabel {
    margin: 0;
    color: var(--winner-color);
    font-size: clamp(22px, 5vw, 38px);
    font-weight: 800;
    overflow-wrap: anywhere;
}

#endGameTitle {
    margin: 12px 0;
    color: #fff;
    font-size: clamp(42px, 9vw, 78px);
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#endGameReason {
    min-height: 24px;
    margin: 16px 0 24px;
    color: #bbb;
}

.end-game-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}


.room-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
}

.room-actions button {
    min-width: 150px;
}

@media (max-width: 560px) {
    .room-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
    }

    .room-actions button {
        min-width: 0;
        width: 100%;
    }
}

.leave-room-button {
    border-color: #b94b4b;
    background: #6f2929;
}

.leave-room-button:hover:not(:disabled) {
    background: #893535;
}

#btnLeaveFinishedGameTop {
    margin-left: 0;
}

#btnLeaveFinishedGameTop[hidden] {
    display: none;
}

#btnShowFinalBoard {
    border-color: var(--winner-color);
}


/* AdSense-ready layout */
#desktopAdRails[hidden],
.desktop-ad-rail[hidden],
.mobile-inline-ad[hidden] {
    display: none !important;
}

.desktop-ad-rail {
    position: fixed;
    z-index: 12;
    top: 86px;
    width: 160px;
    min-height: 600px;
    overflow: hidden;
}

.desktop-ad-rail-left {
    left: 10px;
}

.desktop-ad-rail-right {
    right: 10px;
}

body.ads-desktop-active #gameView {
    margin-inline: 180px;
}

.mobile-inline-ad {
    width: min(100%, 420px);
    min-height: 50px;
    margin: 8px auto;
    overflow: hidden;
    text-align: center;
}

@media (max-width: 1359px) {
    .desktop-ad-rail,
    #desktopAdRails {
        display: none !important;
    }

    body.ads-desktop-active #gameView {
        margin-inline: 0;
    }
}

@media (max-width: 620px) {
    #connectionStatus {
        max-width: 155px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: right;
        font-size: 11px;
    }

    #languageSwitcher button {
        min-width: 42px;
        padding: 5px 7px;
    }
}

/* Room creation options and public room browser */
select {
    border: 1px solid #555;
    border-radius: 7px;
    background: #202020;
    color: #fff;
    padding: 10px 12px;
    font: inherit;
}

.lobby-options-grid {
    display: grid;
    grid-template-columns: minmax(110px, 0.75fr) minmax(180px, 1.25fr);
    gap: 12px;
}

.lobby-option {
    display: grid;
    gap: 7px;
}

#roomCapacityDisplay {
    margin-left: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
}

.room-browser-window {
    width: min(780px, calc(100vw - 28px));
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-header-actions .small-button {
    margin-left: 0;
}

.room-browser-content {
    padding-top: 12px;
}

.room-browser-hint,
.room-browser-empty {
    color: var(--muted);
}

.room-browser-columns,
.room-browser-row {
    display: grid;
    grid-template-columns: minmax(130px, 1fr) 90px 120px 94px;
    align-items: center;
    gap: 10px;
}

.room-browser-columns {
    padding: 0 12px 7px;
    color: #999;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

#roomBrowserList {
    display: grid;
    gap: 7px;
}

.room-browser-row {
    min-height: 55px;
    padding: 8px 10px;
    border: 1px solid #484848;
    border-radius: 9px;
    background: #242424;
    cursor: pointer;
    user-select: none;
}

.room-browser-row:hover,
.room-browser-row:focus-visible {
    border-color: #777;
    background: #2d2d2d;
    outline: none;
}

.room-browser-row.room-unavailable {
    cursor: default;
    opacity: 0.64;
}

.room-browser-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
}

.room-browser-key {
    margin-right: 7px;
    font-size: 16px;
}

.room-browser-count {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.room-browser-status {
    color: #bdbdbd;
    font-size: 13px;
}

.room-browser-join {
    width: 100%;
    padding: 7px 10px;
}

@media (max-width: 620px) {
    .lobby-options-grid {
        grid-template-columns: 1fr;
    }

    .room-browser-columns {
        display: none;
    }

    .room-browser-row {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 6px 10px;
    }

    .room-browser-name {
        grid-column: 1;
        grid-row: 1;
    }

    .room-browser-count {
        grid-column: 2;
        grid-row: 1;
    }

    .room-browser-status {
        grid-column: 1;
        grid-row: 2;
    }

    .room-browser-join {
        grid-column: 2;
        grid-row: 2;
        min-width: 84px;
    }
}


/* Estetyczne okno hasła do pokoju */
.password-modal-backdrop {
    z-index: 130;
    backdrop-filter: blur(5px);
    background: rgba(0, 0, 0, 0.78);
}

.password-modal-window {
    width: min(430px, calc(100vw - 28px));
    padding: 26px;
    border: 1px solid rgba(232, 190, 86, 0.55);
    border-radius: 18px;
    background:
        radial-gradient(circle at top, rgba(232, 190, 86, 0.13), transparent 42%),
        linear-gradient(180deg, #242424, #171717);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.62);
    text-align: center;
}

.password-modal-icon {
    display: grid;
    width: 58px;
    height: 58px;
    margin: 0 auto 14px;
    place-items: center;
    border: 1px solid rgba(232, 190, 86, 0.7);
    border-radius: 50%;
    background: rgba(232, 190, 86, 0.12);
    font-size: 27px;
    box-shadow: 0 0 24px rgba(232, 190, 86, 0.16);
}

.password-modal-window h2 {
    margin: 0 0 8px;
    color: #f4d47b;
    font-size: clamp(22px, 5vw, 28px);
}

.password-modal-description {
    margin: 0 0 20px;
    color: #c9c9c9;
    line-height: 1.45;
}

#roomPasswordForm {
    display: grid;
    gap: 9px;
    text-align: left;
}

#roomPasswordForm > label {
    color: #f1f1f1;
    font-size: 13px;
    font-weight: 800;
}

.password-input-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    overflow: hidden;
    border: 1px solid #5d5d5d;
    border-radius: 10px;
    background: #101010;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.password-input-shell:focus-within {
    border-color: #e8be56;
    box-shadow: 0 0 0 3px rgba(232, 190, 86, 0.14);
}

#roomBrowserPasswordInput {
    min-width: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 13px 14px;
    color: #fff;
    font-size: 16px;
    outline: none;
}

.password-toggle {
    min-width: 76px;
    margin: 0;
    border: 0;
    border-left: 1px solid #444;
    border-radius: 0;
    background: #2b2b2b;
    color: #f2d783;
    font-size: 13px;
    font-weight: 800;
}

.password-modal-error {
    margin: 1px 0 0;
    padding: 9px 11px;
    border: 1px solid rgba(255, 104, 104, 0.45);
    border-radius: 8px;
    background: rgba(145, 26, 26, 0.2);
    color: #ffaaaa;
    font-size: 13px;
    font-weight: 700;
}

.password-modal-error[hidden] {
    display: none;
}

.password-modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 12px;
}

.password-modal-actions button {
    width: 100%;
    min-height: 44px;
}

.password-modal-actions .secondary-button {
    border: 1px solid #555;
    background: #292929;
    color: #ddd;
}

@media (max-width: 420px) {
    .password-modal-window {
        padding: 22px 17px 18px;
    }
}

/* Walidacja formularza wejściowego bez przeglądarkowych alertów. */
.lobby-field-error,
.lobby-general-error {
    margin: -3px 2px 2px;
    color: #ff9a9a;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
}

.lobby-field-error[hidden],
.lobby-general-error[hidden] {
    display: none;
}

.lobby-general-error {
    margin: 2px 0 0;
    padding: 8px 10px;
    border: 1px solid rgba(255, 105, 105, 0.55);
    border-radius: 7px;
    background: rgba(130, 25, 25, 0.24);
}

.lobby-input-invalid {
    border-color: #ff6969 !important;
    box-shadow:
        0 0 0 2px rgba(255, 105, 105, 0.16),
        0 0 12px rgba(255, 70, 70, 0.18);
}

@keyframes lobby-input-shake {
    0%, 100% { transform: translateX(0); }
    18% { transform: translateX(-7px); }
    36% { transform: translateX(6px); }
    54% { transform: translateX(-5px); }
    72% { transform: translateX(3px); }
    88% { transform: translateX(-1px); }
}

.lobby-input-shake {
    animation: lobby-input-shake 380ms ease-in-out;
}

@media (prefers-reduced-motion: reduce) {
    .lobby-input-shake {
        animation: none;
    }
}

/* Discord and persistent lobby counters */
#utilityActions {
    display: inline-flex;
    align-items: center;
    gap: 9px;
}

#discordLink {
    width: 38px;
    height: 32px;
    display: inline-grid;
    place-items: center;
    border: 1px solid #7380f2;
    border-radius: 8px;
    background: #5865f2;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.05) inset;
    transition: transform 120ms ease, background 120ms ease;
}

#discordLink:hover,
#discordLink:focus-visible {
    background: #6d78f5;
    transform: translateY(-1px);
    outline: none;
}

#discordLink img {
    width: 22px;
    height: 18px;
    display: block;
}

.lobby-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 22px;
    margin-top: 22px;
    padding-top: 15px;
    border-top: 1px solid #343434;
    color: #d8d8d8;
}

.lobby-stat {
    min-width: 92px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 7px 11px;
    border: 1px solid #414141;
    border-radius: 999px;
    background: rgba(255,255,255,0.035);
}

.lobby-stat img {
    width: 22px;
    height: 22px;
    display: block;
}

.lobby-stat strong {
    min-width: 2ch;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 620px) {
    #utilityActions {
        gap: 6px;
    }

    #discordLink {
        width: 34px;
        height: 30px;
    }

    #discordLink img {
        width: 20px;
        height: 17px;
    }

    .lobby-stats {
        gap: 10px;
        margin-top: 18px;
    }

    .lobby-stat {
        min-width: 0;
        flex: 1 1 0;
        max-width: 150px;
        padding-inline: 8px;
    }
}


.utility-icon-link,
#homeLink {
    min-width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    border: 1px solid #555;
    border-radius: 8px;
    background: #1d1d1d;
    color: #eee;
    font-size: 22px;
    line-height: 1;
    text-decoration: none;
}
.utility-icon-link:hover,
#homeLink:hover { background: #333; color: #fff; }


/* RULES35: kolejka samouczka AI */
.ai-queue-notice {
  margin: 10px auto 2px;
  max-width: 720px;
  padding: 10px 14px;
  border: 1px solid rgba(214, 200, 79, 0.55);
  border-radius: 10px;
  background: rgba(214, 200, 79, 0.10);
  color: #f3e8a6;
  font-weight: 700;
  text-align: center;
}

.ai-queue-notice[hidden] {
  display: none !important;
}


/* Replay browser */
.replay-page {
    width: min(1500px, 100%);
    margin: 0 auto;
    padding: 64px 14px 28px;
}

.replay-heading {
    width: auto;
    max-width: none;
    margin-bottom: 14px;
}

.replay-layout {
    display: grid;
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}

.replay-list-panel,
.replay-player-panel {
    border: 1px solid #444;
    border-radius: 12px;
    background: #1b1b1b;
    overflow: hidden;
}

.replay-list-panel {
    max-height: calc(100vh - 180px);
    overflow-y: auto;
}

.replay-list-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-bottom: 1px solid #3d3d3d;
    background: #1b1b1b;
}

.replay-list-header h2 {
    margin: 0;
    font-size: 18px;
}

.replay-list-header .small-button {
    margin-left: auto;
}

#replayListStatus {
    padding: 12px;
}

.replay-list {
    display: grid;
    gap: 8px;
    padding: 10px;
}

.replay-list-item {
    display: grid;
    gap: 4px;
    width: 100%;
    padding: 10px 12px;
    text-align: left;
    border: 1px solid #444;
    border-radius: 9px;
    background: #252525;
}

.replay-list-item:hover,
.replay-list-item:focus-visible {
    border-color: #777;
    background: #303030;
}

.replay-list-item span {
    color: #bbb;
    font-size: 12px;
}

.replay-empty-player {
    min-height: 360px;
    display: grid;
    place-items: center;
    padding: 24px;
    color: #aaa;
}

.replay-empty-player[hidden],
#replayPlayer[hidden] {
    display: none !important;
}

.replay-meta-line {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid #444;
}

.replay-meta-line span {
    color: #bbb;
    font-size: 13px;
}

.replay-canvas-wrap {
    position: relative;
    overflow: hidden;
    background: #06101c url('assets/starfield.webp') center / cover no-repeat;
}

#replayCanvas {
    display: block;
    width: 100%;
    background: transparent;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

#replayCanvas.replay-panning {
    cursor: grabbing;
}

.replay-view-controls {
    position: absolute;
    right: 10px;
    top: 10px;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px;
    border: 1px solid rgba(255,255,255,.24);
    border-radius: 9px;
    background: rgba(18,18,18,.82);
    backdrop-filter: blur(3px);
}

.replay-view-controls button {
    min-width: 34px;
    min-height: 34px;
    padding: 4px 9px;
    font-weight: 800;
}

#replayZoomLevel {
    min-width: 48px;
    color: #eee;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
}

.replay-controls {
    display: grid;
    grid-template-columns: auto auto auto minmax(120px, 1fr);
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    border-top: 1px solid #444;
    border-bottom: 1px solid #444;
}

#replayRange {
    width: 100%;
}

.replay-event-panel {
    display: grid;
    gap: 5px;
    padding: 10px 12px 14px;
}

#replayFrameLabel {
    color: #aaa;
    font-size: 12px;
}

#replayEventText {
    min-height: 24px;
    font-weight: 700;
}

@media (max-width: 820px) {
    .replay-page {
        padding-top: 56px;
    }

    .replay-layout {
        grid-template-columns: 1fr;
    }

    .replay-list-panel {
        max-height: 300px;
    }

    .replay-controls {
        grid-template-columns: repeat(3, 1fr);
    }

    #replayRange {
        grid-column: 1 / -1;
    }
}

.build-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: -4px 0 12px;
    padding: 5px 9px;
    border: 1px solid #5f8f68;
    border-radius: 999px;
    background: rgba(49, 85, 58, 0.24);
    color: #d9f2df;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

/* Quick Match */
.quick-match-launch {
    display: grid;
    gap: 7px;
    margin: 4px 0 8px;
    padding: 12px;
    border: 1px solid #638a70;
    border-radius: 12px;
    background: rgba(69, 126, 85, 0.14);
}

.quick-match-launch p,
.quick-match-status,
.quick-waiting-replay-panel p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.quick-match-button {
    min-height: 52px;
    border-color: #78b88a;
    background: linear-gradient(180deg, #3d7450, #29583a);
    font-size: 18px;
    font-weight: 800;
}

.quick-match-button:hover:not(:disabled) {
    background: linear-gradient(180deg, #49885e, #326a46);
}

.manual-room-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 7px 0 1px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.manual-room-divider::before,
.manual-room-divider::after {
    content: '';
    height: 1px;
    flex: 1;
    background: var(--border);
}

.quick-match-view {
    width: min(1220px, calc(100% - 32px));
    text-align: center;
}

.quick-match-wait-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.quick-match-wait-actions button[aria-pressed="true"],
.quick-match-wait-actions .quick-view-active {
    border-color: #78b88a;
    background: #315a3e;
}

.quick-waiting-replay-panel {
    margin-top: 16px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #171717;
    text-align: left;
}

.quick-waiting-replay-panel[hidden] {
    display: none !important;
}

.quick-waiting-replay-panel > p {
    margin: 0 0 10px;
    text-align: center;
}

.quick-waiting-replay-frame {
    display: block;
    width: 100%;
    height: min(690px, 72vh);
    min-height: 500px;
    border: 1px solid #3f4b46;
    border-radius: 10px;
    background: #0b1014;
}

/* Replay viewer embedded inside the Quick Match waiting room. */
body.replay-embedded {
    overflow-x: hidden;
}

body.replay-embedded #utilityBar,
body.replay-embedded .replay-heading {
    display: none !important;
}

body.replay-embedded .replay-page {
    width: 100%;
    margin: 0;
    padding: 8px;
}

body.replay-embedded .replay-layout {
    grid-template-columns: minmax(190px, 260px) minmax(0, 1fr);
    gap: 8px;
}

body.replay-embedded .replay-list-panel {
    max-height: calc(100vh - 16px);
}

body.replay-embedded .replay-empty-player {
    min-height: 420px;
}

body.replay-embedded .replay-list-item-active {
    border-color: #78b88a;
    background: #2c4434;
}

body.replay-tutorial-mode .replay-list-header .small-button {
    display: none !important;
}

.room-limit-control {
    display: grid;
    grid-template-columns: auto 82px 1fr;
    align-items: center;
    gap: 9px;
    margin-top: 12px;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
}

.room-limit-control small { color: var(--muted); }

@media (max-width: 560px) {
    .room-limit-control {
        grid-template-columns: 1fr 82px;
    }
    .room-limit-control small {
        grid-column: 1 / -1;
    }
    .quick-match-wait-actions {
        display: grid;
    }
    .quick-waiting-replay-frame {
        height: 650px;
        min-height: 460px;
    }
    body.replay-embedded .replay-layout {
        grid-template-columns: 1fr;
    }
    body.replay-embedded .replay-list-panel {
        max-height: 210px;
    }
}

.tutorial-group-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.tutorial-group-nav[hidden] { display: none !important; }
.tutorial-group-nav .tutorial-group-active {
  outline: 2px solid rgba(255,255,255,.75);
  outline-offset: 2px;
}

/* Stable 5: keep secondary lobby actions on their own final row. */
.lobby-bottom-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 6px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.lobby-bottom-actions .secondary-button {
    margin-left: 0;
    min-width: 170px;
}

/* Stable 5: persistent replay/tutorial mode tabs. */
.tutorial-group-nav {
    align-items: center;
}
.tutorial-tab-button {
    min-width: 132px;
    border: 1px solid #59645d;
    background: linear-gradient(180deg, #303a35, #252d29);
    color: #f4f6f4;
    font-weight: 800;
}
.tutorial-tab-button:hover {
    background: linear-gradient(180deg, #3a4740, #2b3530);
}
.tutorial-tab-button.tutorial-group-active {
    border-color: #95c67a;
    background: linear-gradient(180deg, #45643b, #314b2b);
    outline: 2px solid rgba(149,198,122,.35);
    outline-offset: 2px;
}
@media (max-width: 560px) {
    .lobby-bottom-actions .secondary-button,
    .tutorial-tab-button {
        width: 100%;
    }
    .tutorial-group-nav {
        display: grid;
        grid-template-columns: 1fr;
    }
}

.rules-tutorial-modal-cta {
    display: flex;
    justify-content: center;
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}
.rules-tutorial-modal-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 9px 16px;
    border: 1px solid #647267;
    border-radius: 8px;
    background: linear-gradient(180deg, #354139, #29322d);
    color: #fff;
    font-weight: 800;
    text-decoration: none;
}
.rules-tutorial-modal-link:hover {
    background: linear-gradient(180deg, #415044, #303b34);
}

/* Stable 5.3 hotfix: starfield belongs to the replay viewport, canvas stays transparent. */
.replay-canvas-wrap {
    isolation: isolate;
    background-color: #06101c;
    background-image: url('assets/starfield.webp');
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
}
#replayCanvas {
    position: relative;
    z-index: 1;
    width: 100%;
    background: transparent !important;
}

/* Stable 5.3: dedicated mobile replay layout. */
.replay-list-panel,
.replay-player-panel {
    min-width: 0;
}

.replay-meta-line > * {
    min-width: 0;
    overflow-wrap: anywhere;
}

@media (max-width: 820px) {
    .replay-page {
        width: 100%;
        padding: 54px 8px 16px;
    }

    .replay-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
    }

    .replay-list-panel {
        max-height: 190px;
    }

    .replay-list-header {
        padding: 8px 10px;
    }

    .replay-list-header h2 {
        font-size: 16px;
    }

    .replay-list {
        padding: 7px;
        gap: 6px;
    }

    .replay-list-item {
        padding: 8px 10px;
    }

    .replay-meta-line {
        gap: 4px 10px;
        padding: 7px 9px;
        font-size: 12px;
    }

    .replay-canvas-wrap {
        width: 100%;
        min-width: 0;
    }

    #replayCanvas {
        width: 100% !important;
        max-width: 100%;
    }

    .replay-view-controls {
        right: 6px;
        top: 6px;
        gap: 3px;
        padding: 4px;
    }

    .replay-view-controls button {
        min-width: 31px;
        min-height: 31px;
        padding: 3px 7px;
    }

    #replayZoomLevel {
        min-width: 40px;
        font-size: 11px;
    }

    .replay-controls {
        position: sticky;
        bottom: 0;
        z-index: 5;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        padding: 8px;
        background: rgba(27, 27, 27, 0.97);
        backdrop-filter: blur(4px);
    }

    .replay-controls button {
        min-width: 0;
        width: 100%;
        padding: 8px 4px;
        font-size: 12px;
        white-space: nowrap;
    }

    #replayRange {
        grid-column: 1 / -1;
        width: 100%;
        min-width: 0;
        margin: 2px 0 0;
    }

    .replay-event-panel {
        padding: 8px 10px 10px;
    }
}

@media (max-width: 420px) {
    .replay-heading {
        margin-bottom: 8px;
        padding: 10px;
    }

    .replay-heading h1 {
        font-size: 22px;
    }

    .replay-heading .view-description {
        display: none;
    }

    .replay-list-panel {
        max-height: 165px;
    }

    .replay-controls button {
        font-size: 11px;
    }
}

@media (max-width: 560px) {
    body.replay-embedded .replay-page {
        padding: 4px;
    }

    body.replay-embedded .replay-layout {
        grid-template-columns: minmax(0, 1fr);
        gap: 6px;
    }

    body.replay-embedded .replay-list-panel {
        max-height: 150px;
    }

    body.replay-embedded .replay-empty-player {
        min-height: 250px;
    }
}

/* Stable 5.3: selectable PowerUp game mode */
.powerup-mode-option {
    display: grid;
    gap: 5px;
    margin: 4px 0 10px;
    padding: 10px 12px;
    border: 1px solid #4f5f73;
    border-radius: 10px;
    background: rgba(73, 93, 122, 0.13);
}

.powerup-mode-label {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 800;
    cursor: pointer;
}

.powerup-mode-label input {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: #8b63d9;
}

.powerup-mode-option small {
    color: var(--muted);
    line-height: 1.35;
}

.room-mode-display {
    width: fit-content;
    margin: 4px 0 10px;
    padding: 5px 9px;
    border: 1px solid #6e5a9e;
    border-radius: 999px;
    background: rgba(105, 77, 158, 0.18);
    color: #e6dbff;
    font-size: 12px;
    font-weight: 800;
}

.room-mode-display.powerups-disabled {
    border-color: #666;
    background: rgba(100, 100, 100, 0.14);
    color: #d0d0d0;
}

.room-browser-status {
    display: grid;
    gap: 2px;
}

.room-browser-mode {
    color: #aaa;
    font-size: 11px;
    font-weight: 700;
}

/* Stable 5.9: mutually exclusive server-side time controls */
.time-control-option {
    display: grid;
    gap: 6px;
    margin: 4px 0 12px;
    padding: 10px 12px;
    border: 1px solid #4f5f73;
    border-radius: 10px;
    background: rgba(73, 93, 122, 0.10);
}

.time-control-option > label {
    font-weight: 800;
}

.time-control-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.time-control-value {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.time-control-value[hidden] {
    display: none !important;
}

.time-control-value input {
    width: 82px;
}

.time-control-option small {
    color: var(--muted);
    line-height: 1.35;
}

.room-mode-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 4px 0 10px;
}

.room-mode-summary .room-mode-display {
    margin: 0;
}

#gameTimerPanel {
    padding: 4px 8px;
    border: 1px solid #4b6177;
    border-radius: 8px;
    background: rgba(64, 88, 112, 0.18);
    color: #e7f2ff;
    font-size: 13px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#gameTimerPanel[hidden] {
    display: none !important;
}

@media (max-width: 620px) {
    .time-control-row {
        grid-template-columns: 1fr;
    }

    .time-control-value {
        justify-content: flex-start;
    }

    #gameTimerPanel {
        order: 2;
        width: 100%;
        overflow-x: auto;
        font-size: 12px;
    }

    #selectionInfo {
        order: 3;
    }
}

/* Stable 5.9 — flexible Quick Match preferences */
.quick-match-preferences {
    display: grid;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid rgba(120,184,138,.45);
    border-radius: 10px;
    background: rgba(18,34,24,.52);
    text-align: left;
}

.quick-match-preferences > strong {
    font-size: 14px;
}

.quick-preference-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px 14px;
}

.quick-preference-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 30px;
    cursor: pointer;
}

.quick-preference-grid input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.quick-time-master {
    grid-column: 1 / -1;
    font-weight: 700;
}

.quick-time-children {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px 14px;
    padding-left: 24px;
    transition: opacity .15s ease;
}

.quick-time-children.quick-time-disabled {
    opacity: .45;
}

.quick-match-preferences small {
    color: var(--muted);
    line-height: 1.35;
}

.quick-match-preferences-waiting {
    width: min(720px, 100%);
    margin: 14px auto 0;
}

@media (max-width: 620px) {
    .quick-preference-grid,
    .quick-time-children {
        grid-template-columns: 1fr;
    }

    .quick-time-children {
        padding-left: 18px;
    }
}
