/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
    --bg:         #1a1a2e;
    --surface:    #16213e;
    --surface2:   #0f3460;
    --accent:     #e94560;
    --accent2:    #533483;
    --text:       #eaeaea;
    --muted:      #8892a4;
    --light-sq:   #f0d9b5;
    --dark-sq:    #b58863;
    --radius:     10px;

    /* Responsive square size — overridden in media queries */
    --sq: 60px;
}

@media (max-width: 680px) { :root { --sq: clamp(38px, calc((100vw - 56px) / 8), 56px); } }

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Scrollbars ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

/* ══ LOBBY ═══════════════════════════════════════════════════════════════════ */
.lobby-container {
    max-width: 560px;
    margin: 0 auto;
    padding: 2rem 1rem 3rem;
}

.header { text-align: center; margin-bottom: 2rem; }

.header h1 {
    font-size: clamp(2rem, 8vw, 3.2rem);
    background: linear-gradient(135deg, #e94560, #533483);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header .subtitle { color: var(--muted); margin-top: .4rem; font-size: .95rem; }

.setup-card, .rooms-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.4rem;
    margin-bottom: 1.2rem;
    border: 1px solid rgba(255,255,255,0.06);
}

.setup-card h2, .rooms-card h2 { font-size: 1.1rem; margin-bottom: 1rem; }

.setup-card input {
    width: 100%;
    padding: .7rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.12);
    background: var(--surface2);
    color: var(--text);
    font-size: 1rem;
    margin-bottom: .9rem;
    outline: none;
    transition: border-color .2s;
}
.setup-card input:focus { border-color: var(--accent); }

.btn-row { display: flex; gap: .75rem; flex-wrap: wrap; }

.rooms-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .9rem;
}

.room-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .65rem .9rem;
    background: var(--surface2);
    border-radius: 8px;
    margin-bottom: .4rem;
}

.room-info { display: flex; flex-direction: column; gap: .2rem; }
.room-name { font-weight: 600; font-size: .9rem; }

.room-status {
    font-size: .7rem;
    padding: 1px 7px;
    border-radius: 10px;
    background: rgba(255,255,255,0.1);
    width: fit-content;
}
.room-status.waiting { background: rgba(255,200,0,.2); color: #ffc800; }
.room-status.playing { background: rgba(50,200,50,.2); color: #32c832; }
.room-status.open    { background: rgba(100,150,255,.2); color: #6496ff; }

.empty-msg { color: var(--muted); text-align: center; padding: 1rem .5rem; font-size: .9rem; }

/* ══ BUTTONS ═════════════════════════════════════════════════════════════════ */
.btn {
    padding: .55rem 1.1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: .88rem;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    transition: filter .15s, transform .1s;
    white-space: nowrap;
}
.btn:active { transform: scale(.97); }

.btn-primary   { background: var(--accent);  color: #fff; }
.btn-primary:hover { filter: brightness(1.15); }
.btn-bot       { background: #2d6a4f; color: #fff; }
.btn-bot:hover { filter: brightness(1.2); }
.btn-secondary { background: rgba(255,255,255,.1); color: var(--text); }
.btn-secondary:hover { background: rgba(255,255,255,.18); }
.btn-danger    { background: #c0392b; color: #fff; }
.btn-danger:hover { filter: brightness(1.15); }
.btn-info      { background: var(--accent2); color: #fff; }
.btn-info:hover { filter: brightness(1.2); }
.btn-join      { background: var(--accent2); color: #fff; padding: .35rem .75rem; font-size: .8rem; }
.btn-sm        { padding: .35rem .75rem; font-size: .8rem; background: rgba(255,255,255,.1); color: var(--text); }
.btn-sm:hover  { background: rgba(255,255,255,.18); }

/* ══ GAME LAYOUT ════════════════════════════════════════════════════════════ */
.game-layout {
    display: flex;
    gap: 1.2rem;
    padding: .75rem;
    max-width: 1050px;
    margin: 0 auto;
    align-items: flex-start;
    min-height: 100vh;
}

/* Board area (left column) */
.board-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .6rem;
    flex-shrink: 0;
}

/* Side panel (right column) */
.side-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: .8rem;
    min-width: 220px;
    max-width: 340px;
}

/* ── Player info strip ───────────────────────────────────────────────────────── */
.player-info {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .45rem .85rem;
    background: var(--surface);
    border-radius: 8px;
    width: 100%;
}

.player-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--accent2);
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-size: 1rem;
    flex-shrink: 0;
}

.player-details {
    flex: 1;
    display: flex; flex-direction: column; gap: .15rem;
    min-width: 0;
}

.player-details span:first-child {
    font-weight: 600; font-size: .88rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.player-color-badge {
    font-size: .65rem; padding: 1px 6px; border-radius: 10px; width: fit-content;
}
.player-color-badge.white { background: rgba(255,255,255,.2); color: #fff; }
.player-color-badge.black { background: rgba(0,0,0,.4); color: #aaa; border: 1px solid #555; }

.turn-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: transparent; border: 2px solid rgba(255,255,255,.2);
    transition: all .3s; flex-shrink: 0;
}
.turn-dot.active {
    background: #4caf50; border-color: #4caf50;
    box-shadow: 0 0 7px #4caf50;
}

/* ── Board wrapper + coordinates ─────────────────────────────────────────────── */
.board-wrapper {
    display: flex;
    gap: 3px;
    align-items: flex-start;
    user-select: none;
}

.coords-left {
    display: flex; flex-direction: column;
}

.coords-left .coord {
    height: var(--sq);
    display: flex; align-items: center; justify-content: center;
    font-size: .65rem; color: var(--muted);
    width: 14px; flex-shrink: 0;
}

.coords-bottom {
    display: flex;
    padding-left: 2px;
}

.coords-bottom .coord {
    width: var(--sq);
    text-align: center;
    font-size: .65rem; color: var(--muted);
    padding-top: 3px;
}

/* ── Chessboard ─────────────────────────────────────────────────────────────── */
.board {
    display: grid;
    grid-template-columns: repeat(8, var(--sq));
    grid-template-rows:    repeat(8, var(--sq));
    border: 2px solid rgba(255,255,255,.12);
    border-radius: 3px;
    overflow: hidden;
    box-shadow: 0 8px 28px rgba(0,0,0,.6);
}

.square {
    width: var(--sq); height: var(--sq);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    position: relative;
    transition: background .12s;
    -webkit-tap-highlight-color: transparent;
}

.square.light { background: var(--light-sq); }
.square.dark  { background: var(--dark-sq); }

/* Selected square */
.square.selected    { background: #5fa05f !important; }

/* Last-move tint */
.square.last-move.light { background: #cdd16a; }
.square.last-move.dark  { background: #a6a830; }

/* King in check */
.square.in-check { background: rgba(220,30,30,.75) !important; }

/* Valid-move dot (empty squares) */
.square.valid-move::after {
    content: '';
    position: absolute;
    width: 32%; height: 32%;
    border-radius: 50%;
    background: rgba(0,0,0,.22);
    pointer-events: none;
    z-index: 2;
}

/* Capture hint (enemy occupied square) — ring around the piece */
.square.capture-hint::before {
    content: '';
    position: absolute;
    inset: 1px;
    border-radius: 50%;
    border: 3px solid rgba(0,0,0,.28);
    pointer-events: none;
    z-index: 2;
}

/* Pieces */
.piece {
    font-size: calc(var(--sq) * 0.72);
    line-height: 1;
    cursor: pointer;
    user-select: none;
    position: relative;
    z-index: 1;
    filter: drop-shadow(1px 2px 2px rgba(0,0,0,.35));
    transition: transform .1s;
}
.piece:hover          { transform: scale(1.08); }
.piece.white          { color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.65); }
.piece.black          { color: #1a1a1a; text-shadow: 0 1px 2px rgba(255,255,255,.25); }

/* ── Status bar ──────────────────────────────────────────────────────────────── */
.status-bar {
    background: var(--surface);
    border-radius: 8px;
    padding: .65rem 1rem;
    font-weight: 600;
    font-size: .9rem;
    border-left: 4px solid var(--accent);
    min-height: 44px;
    display: flex; align-items: center;
}

#status-text.your-turn { color: #4caf50; }
#status-text.check     { color: #ff9800; }
#status-text.win       { color: #4caf50; }
#status-text.lose      { color: var(--accent); }
#status-text.draw      { color: var(--muted); }
#status-text.error     { color: var(--accent); }

/* ── Moves panel ─────────────────────────────────────────────────────────────── */
.panel-title {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin-bottom: .6rem;
}

.moves-panel {
    background: var(--surface);
    border-radius: 8px;
    padding: .85rem;
    flex: 1;
}

.moves-list {
    max-height: 160px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: .8rem;
}

.move-row {
    display: flex; gap: .4rem; align-items: center;
    margin-bottom: .2rem;
}

.move-num { color: var(--muted); min-width: 22px; }

.move-notation {
    padding: 1px 5px; border-radius: 3px;
}
.white-move { background: rgba(255,255,255,.1); }
.black-move { background: rgba(0,0,0,.25); }

/* ── Chat panel ──────────────────────────────────────────────────────────────── */
.chat-panel {
    background: var(--surface);
    border-radius: 8px;
    padding: .85rem;
}

.chat-messages {
    max-height: 100px;
    overflow-y: auto;
    margin-bottom: .6rem;
    display: flex; flex-direction: column; gap: .25rem;
}

.chat-msg          { font-size: .82rem; line-height: 1.4; word-break: break-word; }
.chat-msg strong   { color: var(--accent); }
.chat-msg.system   { color: var(--muted); font-style: italic; }

.chat-input-row { display: flex; gap: .4rem; }

.chat-input-row input {
    flex: 1;
    padding: .38rem .7rem;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,.1);
    background: var(--surface2);
    color: var(--text);
    font-size: .82rem;
    outline: none;
    transition: border-color .2s;
    min-width: 0;
}
.chat-input-row input:focus { border-color: var(--accent); }

/* ── Action buttons ──────────────────────────────────────────────────────────── */
.action-buttons { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Promotion modal ─────────────────────────────────────────────────────────── */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.75);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}
.modal.hidden { display: none; }

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.8rem;
    text-align: center;
}
.modal-content h3 { margin-bottom: 1.2rem; }

.promo-choices { display: flex; gap: .8rem; justify-content: center; }

.promo-piece {
    width: 66px; height: 66px;
    display: flex; align-items: center; justify-content: center;
    font-size: calc(var(--sq) * 0.72);
    background: var(--surface2);
    border-radius: 8px; cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .15s, background .15s;
}
.promo-piece:hover { border-color: var(--accent); background: var(--accent2); }

/* ── Game result banner ──────────────────────────────────────────────────────── */
.game-banner {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.82);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
}

.banner-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem 2.5rem;
    text-align: center;
    border: 2px solid var(--accent);
    display: flex; flex-direction: column; align-items: center; gap: .75rem;
}

.banner-msg {
    font-size: 1.6rem;
    font-weight: bold;
}

/* ── Waiting overlay ─────────────────────────────────────────────────────────── */
.waiting-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.82);
    display: flex; align-items: center; justify-content: center;
    z-index: 150;
}
.waiting-overlay.hidden { display: none; }

.waiting-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem 2.5rem;
    text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: .85rem;
    max-width: 340px;
}

.waiting-box p { color: var(--text); font-size: 1rem; }
.waiting-link  { font-size: .78rem; color: var(--muted); word-break: break-all; }

/* Spinner */
.spinner {
    width: 40px; height: 40px;
    border: 4px solid rgba(255,255,255,.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Bot thinking toast ──────────────────────────────────────────────────────── */
.bot-thinking {
    position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
    background: var(--surface2);
    padding: .5rem 1.2rem;
    border-radius: 999px;
    font-size: .85rem;
    z-index: 50;
    box-shadow: 0 4px 16px rgba(0,0,0,.4);
    pointer-events: none;
    transition: opacity .2s;
}
.bot-thinking.hidden { display: none; }

/* ══ RESPONSIVE ══════════════════════════════════════════════════════════════ */

/* Tablet: slightly smaller board */
@media (max-width: 900px) {
    .side-panel { max-width: 260px; }
}

/* Mobile: stack vertically */
@media (max-width: 680px) {
    .game-layout {
        flex-direction: column;
        align-items: stretch;
        padding: .4rem;
        gap: .6rem;
        min-height: unset;
    }

    .board-area { align-items: center; }

    /* Side panel becomes a row of compact panels */
    .side-panel {
        max-width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: .5rem;
    }

    .status-bar { flex: 1 1 100%; }

    .moves-panel {
        flex: 1 1 calc(50% - .25rem);
        min-width: 140px;
    }

    .moves-list { max-height: 100px; }

    .chat-panel {
        flex: 1 1 calc(50% - .25rem);
        min-width: 140px;
    }

    .chat-messages { max-height: 70px; }

    .action-buttons { flex: 1 1 100%; }

    /* Promotion modal pieces */
    .promo-piece { width: 52px; height: 52px; }
    .promo-choices { gap: .5rem; }

    /* Banner */
    .banner-content { padding: 1.5rem; }
    .banner-msg { font-size: 1.3rem; }
}

/* Very small screens */
@media (max-width: 400px) {
    .lobby-container { padding: 1rem .75rem 2rem; }
    .btn-row { flex-direction: column; }
    .btn-row .btn { width: 100%; justify-content: center; }
}
