:root {
    --cream: #faf9f6;
    --warm-white: #f4f2ed;
    --soft-gray: #e5e3de;
    --charcoal: #2e2e2e;
    --deep-charcoal: #1a1a1a;
    --gold: #c9a962;
    --gold-warm: #b8956b;
    --muted: #8c8880;
    --panel-shadow: 0 28px 60px rgba(26, 26, 26, 0.08), 0 6px 16px rgba(201, 169, 98, 0.08);
    --radius-sm: 10px;
    --radius-md: 22px;
    --action-primary: #1f1f1f;
    --action-primary-hover: #111111;
    --action-success: #b8956b;
    --action-success-hover: #a5845f;
    --action-danger: #a24c3c;
    --action-danger-hover: #8f3f32;
    --action-warning: #856404;
    --board-bg: #f0d9b5;
    --board-border: #8b4513;
    --cell-border: rgba(139, 69, 19, 0.35);
    --cell-hover-bg: rgba(201, 169, 98, 0.12);
    --cell-selected-bg: rgba(201, 169, 98, 0.2);
    --cell-valid-bg: rgba(184, 149, 107, 0.18);
    --cell-last-move-bg: rgba(201, 169, 98, 0.26);
    --board-columns: 10;
    --board-rows: 10;
    --board-width: 600px;
    --piece-size: 82%;
}

html {
    font-family: var(--font-serif-base);
}

body {
    font-family: var(--font-serif-base);
    background: var(--cream);
    color: var(--charcoal);
    overflow: hidden;
    line-height: 1.7;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 14% 18%, rgba(201, 169, 98, 0.08), transparent 34%),
        radial-gradient(circle at 86% 80%, rgba(184, 149, 107, 0.08), transparent 34%),
        url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.02'/%3E%3C/svg%3E");
    z-index: -2;
    pointer-events: none;
}

body::after {
    content: '';
    position: fixed;
    inset: 18px;
    border: 1px solid rgba(201, 169, 98, 0.24);
    box-shadow: inset 0 0 0 8px rgba(201, 169, 98, 0.05);
    z-index: -1;
    pointer-events: none;
}

h2 {
    text-align: center;
    width: fit-content;
    margin: 0 auto;
    padding: 0 0 1rem;
    border: 0;
    color: var(--deep-charcoal);
    font-size: clamp(1.8rem, 3vw, 2.5rem);
    font-weight: 600;
    letter-spacing: 0.18em;
    line-height: 1.2;
    position: relative;
}

h2::after {
    content: '';
    display: block;
    width: 92px;
    height: 1px;
    margin: 1rem auto 0;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 34px;
}

.main {
    flex: 1;
    max-width: 1380px;
    margin: 0 auto;
    width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.section {
    background: linear-gradient(180deg, rgba(244, 242, 237, 0.94), rgba(250, 249, 246, 0.98));
    border: 1px solid rgba(201, 169, 98, 0.2);
    border-radius: var(--radius-md);
    box-shadow: var(--panel-shadow);
    padding: 2.1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: auto;
    max-height: 100vh;
    position: relative;
    backdrop-filter: blur(4px);
}

.section::before {
    content: '';
    position: absolute;
    inset: 12px;
    border: 1px solid rgba(201, 169, 98, 0.08);
    border-radius: calc(var(--radius-md) - 8px);
    pointer-events: none;
}

#room-section h2 {
    margin-bottom: 1.6rem;
}

#create-room-btn,
#join-room-btn,
.room-action-btn,
.game-btn,
.modal-btn {
    border: 1px solid transparent;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.28s ease, box-shadow 0.28s ease, border-color 0.28s ease, background-color 0.28s ease, opacity 0.28s ease;
    font-family: var(--font-serif-base);
    letter-spacing: 0.12em;
}

#create-room-btn,
#join-room-btn {
    min-height: 52px;
    padding: 0.85rem 1.7rem;
    font-size: 0.96rem;
    box-shadow: 0 8px 20px rgba(26, 26, 26, 0.08);
}

#create-room-btn {
    background: linear-gradient(135deg, var(--deep-charcoal), var(--charcoal));
    color: #fff;
    margin-bottom: 1.5rem;
}

#create-room-btn:hover,
#join-room-btn:hover,
.room-action-btn:hover:not(:disabled),
.game-btn:hover:not(:disabled),
.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 26px rgba(26, 26, 26, 0.14);
}

#join-room-btn {
    background: linear-gradient(135deg, var(--gold), var(--gold-warm));
    color: #fff;
}

.join-room {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    align-items: stretch;
}

#room-id-input {
    flex: 1;
    min-height: 52px;
    padding: 0.85rem 1.15rem;
    border: 1px solid rgba(201, 169, 98, 0.26);
    border-radius: 999px;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.78);
    color: var(--deep-charcoal);
    transition: border-color 0.28s ease, box-shadow 0.28s ease, background-color 0.28s ease;
}

#room-id-input::placeholder {
    color: rgba(140, 136, 128, 0.88);
}

#room-id-input:focus {
    outline: none;
    border-color: rgba(201, 169, 98, 0.6);
    box-shadow: 0 0 0 4px rgba(201, 169, 98, 0.12);
    background: #fff;
}

.room-info,
.game-room-info,
.turn-indicator {
    border: 1px solid rgba(201, 169, 98, 0.16);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.78);
    color: var(--deep-charcoal);
    box-shadow: 0 10px 24px rgba(26, 26, 26, 0.05);
}

.room-info,
.game-room-info {
    font-size: 0.95rem;
    font-weight: 500;
    padding: 0.9rem 1.15rem;
    text-align: center;
    width: 100%;
    margin-bottom: 0.8rem;
    max-height: 80px;
}

.room-info:empty {
    display: none;
}

.game-room-info {
    white-space: pre-line;
    line-height: 1.5;
}

.game-room-info.waiting,
.room-status.waiting {
    background: rgba(201, 169, 98, 0.12);
    color: var(--action-warning);
}

.game-room-info.playing,
.room-status.playing {
    background: rgba(46, 46, 46, 0.08);
    color: var(--deep-charcoal);
}

.room-list-container {
    margin-top: 2rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.room-list-container h3 {
    margin-bottom: 1rem;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.24em;
    text-transform: uppercase;
}

.room-list {
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    padding: 0.25rem;
}

.room-item {
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(201, 169, 98, 0.16);
    border-radius: 18px;
    padding: 1.15rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    transition: transform 0.35s ease, box-shadow 0.35s ease, border-color 0.35s ease;
    box-shadow: 0 12px 26px rgba(26, 26, 26, 0.05);
    position: relative;
    overflow: hidden;
}

.room-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, var(--gold), transparent 80%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.room-item:hover {
    transform: translateY(-4px);
    border-color: rgba(201, 169, 98, 0.34);
    box-shadow: 0 18px 36px rgba(26, 26, 26, 0.08);
}

.room-item:hover::before {
    opacity: 1;
}

.room-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid rgba(201, 169, 98, 0.14);
}

.room-id {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--deep-charcoal);
    letter-spacing: 0.08em;
}

.room-status {
    font-size: 0.76rem;
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    font-weight: 600;
    letter-spacing: 0.08em;
    background: rgba(46, 46, 46, 0.06);
    color: var(--muted);
}

.room-status.full {
    background: rgba(140, 136, 128, 0.12);
    color: var(--muted);
}

.room-item-info {
    display: flex;
    justify-content: space-around;
    gap: 0.75rem;
    flex-wrap: wrap;
    font-size: 0.9rem;
    color: var(--muted);
}

.room-item-info span {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.room-item-actions {
    display: flex;
    gap: 0.6rem;
}

.room-action-btn {
    flex: 1;
    min-height: 46px;
    padding: 0.7rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.join-btn {
    background: linear-gradient(135deg, var(--gold), var(--gold-warm));
    color: #fff;
}

.join-btn:disabled {
    background: rgba(140, 136, 128, 0.18);
    color: rgba(140, 136, 128, 0.9);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.spectate-btn {
    background: rgba(26, 26, 26, 0.92);
    color: #fff;
}

.room-list-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3.2rem 1rem;
    color: var(--muted);
    font-size: 0.95rem;
    border: 1px dashed rgba(201, 169, 98, 0.3);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.45);
}

.game-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.6rem;
    width: 100%;
    height: 100%;
}

.game-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 220px;
    max-width: 260px;
}

.left-sidebar {
    align-items: stretch;
}

.right-sidebar {
    align-items: stretch;
}

.turn-indicator {
    font-size: 1rem;
    font-weight: 600;
    padding: 0.95rem 1.15rem;
    text-align: center;
    width: 100%;
    transition: all 0.3s ease;
    letter-spacing: 0.08em;
}

.turn-indicator:not(.spectator) {
    white-space: nowrap;
}

.turn-indicator.black {
    background: rgba(26, 26, 26, 0.94);
    color: #f4f2ed;
}

.turn-indicator.white {
    background: rgba(255, 255, 255, 0.92);
    color: var(--deep-charcoal);
}

.turn-indicator.spectator {
    white-space: pre-line;
    line-height: 1.45;
}

.chessboard {
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--board-columns), 1fr);
    grid-template-rows: repeat(var(--board-rows), 1fr);
    width: var(--board-width);
    aspect-ratio: 1 / 1;
    background-color: var(--board-bg);
    border: 1px solid rgba(201, 169, 98, 0.32);
    box-shadow: 0 22px 44px rgba(26, 26, 26, 0.12), inset 0 0 0 8px rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    overflow: hidden;
}

.cell {
    position: relative;
    border: 1px solid var(--cell-border);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    height: 100%;
    aspect-ratio: 1 / 1;
    transition: background-color 0.2s ease;
}

.cell:hover {
    background-color: var(--cell-hover-bg);
}

.cell.selected {
    background-color: var(--cell-selected-bg);
}

.cell.valid-move {
    background-color: var(--cell-valid-bg);
}

.cell.last-move {
    background-color: var(--cell-last-move-bg);
}

.piece {
    width: var(--piece-size);
    height: var(--piece-size);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease, background-color 0.25s ease;
    box-shadow: 0 6px 14px rgba(26, 26, 26, 0.14);
}

.piece.black {
    background-color: #161616;
    color: #f7f5ef;
}

.piece.white {
    background-color: #fffdf8;
    color: var(--deep-charcoal);
    border: 1px solid rgba(46, 46, 46, 0.18);
}

.piece.moving {
    z-index: 100;
}

.game-buttons,
.spectator-controls {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    width: 100%;
    padding: 1rem;
    border: 1px solid rgba(201, 169, 98, 0.16);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.68);
    box-shadow: 0 10px 24px rgba(26, 26, 26, 0.05);
}

.game-btn {
    width: 100%;
    min-height: 48px;
    padding: 0.78rem 1.1rem;
    color: #fff;
    font-size: 0.96rem;
    font-weight: 600;
    border-color: rgba(255, 255, 255, 0.15);
}

.game-btn:disabled,
.game-btn.cooldown {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(26, 26, 26, 0.16);
    backdrop-filter: blur(1.5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: linear-gradient(180deg, rgba(244, 242, 237, 0.76), rgba(250, 249, 246, 0.72));
    padding: 2rem;
    border-radius: 24px;
    border: 1px solid rgba(201, 169, 98, 0.22);
    box-shadow: 0 30px 60px rgba(26, 26, 26, 0.18);
    text-align: center;
    max-width: 420px;
    width: min(92vw, 420px);
    position: relative;
    backdrop-filter: blur(6px);
}

.modal-content::before {
    content: '';
    position: absolute;
    inset: 12px;
    border: 1px solid rgba(201, 169, 98, 0.08);
    border-radius: 16px;
    pointer-events: none;
}

.modal-content h3 {
    margin-bottom: 1rem;
    color: var(--deep-charcoal);
    letter-spacing: 0.12em;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.modal-btn {
    min-height: 46px;
    padding: 0.75rem 1.65rem;
    color: #fff;
    font-size: 0.92rem;
    font-weight: 600;
}

.accept-btn {
    background: linear-gradient(135deg, var(--gold), var(--gold-warm));
}

.reject-btn {
    background: linear-gradient(135deg, #b55d4e, var(--action-danger));
}

.win-line {
    position: absolute;
    background-color: rgba(162, 76, 60, 0.55);
    z-index: 50;
}

@media (max-width: 1178px) {
    #app {
        padding: 24px;
    }

    .game-layout {
        flex-direction: column;
        gap: 1rem;
        height: auto;
    }

    .game-sidebar {
        flex-direction: column;
        justify-content: center;
        width: 100%;
        min-width: auto;
        max-width: none;
        gap: 1rem;
    }

    .left-sidebar {
        order: 1;
    }

    .chessboard {
        order: 2;
    }

    .right-sidebar {
        order: 3;
    }
}

@media (max-width: 1024px) {
    body::after {
        inset: 10px;
    }

    .chessboard {
        width: min(85vw, 85dvh);
        height: min(85vw, 85dvh);
        /* max-width: min(85vw, 85dvh);
        max-height: min(85vw, 85dvh); */
    }
}

@media (max-width: 768px) {
    #app {
        padding: 16px;
    }

    body::after {
        display: none;
    }

    .section {
        padding: 1.35rem;
        border-radius: 18px;
    }

    .join-room,
    .room-item-actions,
    .modal-buttons {
        flex-direction: column;
    }

    .room-list {
        grid-template-columns: 1fr;
    }

    .room-item-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .room-action-btn,
    #room-id-input,
    .modal-btn {
        width: 100%;
    }

    .chessboard {
        max-width: 100%;
        border-radius: 16px;
    }
}

@media (max-width: 480px) {
    h2 {
        font-size: 1.45rem;
        letter-spacing: 0.08em;
    }

    .section {
        padding: 1rem;
    }

    #create-room-btn,
    #join-room-btn,
    .room-action-btn,
    .game-btn {
        font-size: 0.85rem;
        letter-spacing: 0.08em;
    }

    #room-id-input {
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
    }

    .room-list-container h3 {
        font-size: 0.8rem;
    }

    .room-item-info {
        font-size: 0.82rem;
    }
}