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

body {
    background: #f7f6f2;
    color: #111;
    font-family: system-ui, -apple-system, 'Helvetica Neue', sans-serif;
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.hidden { display: none !important; }

.logged-in-indicator {
    font-size: 11px;
    color: #999;
    letter-spacing: 0.04em;
    text-align: center;
    width: 100%;
    margin-bottom: -4px;
}

.back-link {
    position: fixed;
    top: 18px;
    left: 20px;
    font-size: 12px;
    color: #aaa;
    text-decoration: none;
    letter-spacing: 0.04em;
    z-index: 200;
    transition: color 0.15s;
}
.back-link:hover { color: #111; }

/* ===== LOBBY / WAITING ===== */

#lobby, #waiting {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
}

.lobby-box {
    background: #fff;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    padding: 48px 40px;
    width: 360px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.logo {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #111;
    margin-bottom: 8px;
}

input[type="text"] {
    width: 100%;
    padding: 12px 16px;
    background: #f7f6f2;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    color: #111;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: #111; }
input[type="text"]::placeholder { color: #bbb; }

.btn-primary {
    width: 100%;
    padding: 12px 24px;
    background: #111;
    color: #fff;
    border: none;
    border-radius: 2px;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.75; }
.btn-primary:active { opacity: 0.6; }

.btn-secondary {
    padding: 10px 20px;
    background: transparent;
    color: #111;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s;
}
.btn-secondary:hover { border-color: #111; }
.btn-secondary:active { opacity: 0.7; }

.divider {
    color: #bbb;
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-align: center;
    width: 100%;
    position: relative;
    padding: 0 4px;
}
.divider::before, .divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 28%;
    height: 1px;
    background: #d8d5cc;
}
.divider::before { left: 0; }
.divider::after { right: 0; }

.join-row {
    display: flex;
    gap: 8px;
    width: 100%;
}
.join-row input {
    flex: 1;
    text-transform: uppercase;
    letter-spacing: 3px;
    font-weight: 700;
}

.error-msg { color: #c0392b; font-size: 0.85rem; min-height: 1.2em; text-align: center; }

.game-code {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 8px;
    color: #111;
    background: #f7f6f2;
    padding: 16px 32px;
    border-radius: 2px;
    border: 1px solid #d8d5cc;
    user-select: all;
}

.copy-btn { width: 100%; }

.muted { color: #999; font-size: 0.88rem; }

.spinner {
    width: 28px; height: 28px;
    border: 2px solid #d8d5cc;
    border-top-color: #111;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== GAME LAYOUT ===== */

#game {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    padding: 20px 16px;
}

.game-layout {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 16px;
    max-width: 880px;
    width: 100%;
}

/* ===== BOARD COLUMN ===== */

.board-col {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    flex-shrink: 0;
}

#boardWrap {
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    line-height: 0;
    position: relative;
}

#board { width: 480px; }

/* ===== PLAYER CARDS ===== */

.player-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    padding: 8px 14px;
    width: 480px;
    gap: 10px;
    transition: border-color 0.2s, background 0.2s;
}

.player-card.active-turn {
    border-color: #111;
    background: #f7f6f2;
}

.player-card-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.player-piece-icon {
    font-size: 1.3rem;
    line-height: 1;
}

.player-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #111;
}

.player-captured {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1px;
    flex: 1;
    justify-content: flex-end;
}

.player-captured img {
    width: 16px;
    height: 16px;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.15));
}

/* ===== STATUS ===== */

.status {
    font-size: 0.82rem;
    color: #888;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-align: left;
    min-height: 1.4em;
    padding-left: 2px;
}

/* ===== ACTION BUTTONS ===== */

.action-btns {
    display: flex;
    gap: 8px;
    margin-top: 2px;
}

.btn-forfeit {
    padding: 7px 16px;
    background: transparent;
    color: #c0392b;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s;
}
.btn-forfeit:hover { border-color: #c0392b; }
.btn-forfeit:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-draw {
    padding: 7px 16px;
    background: transparent;
    color: #555;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s;
}
.btn-draw:hover { border-color: #555; }
.btn-draw:disabled { opacity: 0.35; cursor: not-allowed; }

/* ===== DRAW BANNER ===== */

.draw-banner {
    width: 480px;
    background: #fff;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.88rem;
    color: #111;
    font-weight: 500;
}

.draw-banner-btns { display: flex; gap: 8px; }

.btn-accept {
    padding: 5px 14px;
    background: transparent;
    color: #2d7a2d;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s;
}
.btn-accept:hover { border-color: #2d7a2d; }

.btn-decline {
    padding: 5px 14px;
    background: transparent;
    color: #c0392b;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s;
}
.btn-decline:hover { border-color: #c0392b; }

/* ===== SIDE PANEL ===== */

.side-panel {
    width: 300px;
    flex-shrink: 0;
    background: #fff;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 576px;
}

.tab-bar {
    display: flex;
    border-bottom: 1px solid #d8d5cc;
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 12px 8px;
    background: transparent;
    color: #bbb;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.tab-btn.active {
    color: #111;
    border-bottom-color: #111;
}
.tab-btn:hover:not(.active) { color: #555; }

.tab-btn.chat-flash { animation: chatFlash 0.5s ease 3; }
@keyframes chatFlash {
    0%, 100% { color: #bbb; }
    50% { color: #111; }
}

.tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== MOVE HISTORY ===== */

.moves-table-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.moves-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.moves-table thead th {
    position: sticky;
    top: 0;
    background: #fff;
    color: #bbb;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid #d8d5cc;
}

.moves-table tbody tr { transition: background 0.1s; }
.moves-table tbody tr:nth-child(even) { background: #f7f6f2; }
.moves-table tbody tr:hover { background: #f0eee9; }
.moves-table tbody tr.current-move { background: #f0eee9; font-weight: 700; }

.moves-table td { padding: 5px 10px; color: #555; }
.moves-table td:first-child { color: #ccc; width: 32px; }

/* ===== CHAT ===== */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-msg { display: flex; flex-direction: column; gap: 2px; }

.chat-msg-header {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.chat-sender {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.chat-sender.me { color: #111; }
.chat-sender.them { color: #aaa; }

.chat-ts { font-size: 10px; color: #ccc; }

.chat-text {
    font-size: 0.88rem;
    color: #333;
    word-break: break-word;
    line-height: 1.4;
}

.chat-input-row {
    display: flex;
    gap: 6px;
    padding: 10px;
    border-top: 1px solid #d8d5cc;
    flex-shrink: 0;
}

.chat-input-row input {
    flex: 1;
    padding: 8px 12px;
    font-size: 0.88rem;
    background: #f7f6f2;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    color: #111;
    outline: none;
}
.chat-input-row input:focus { border-color: #111; }
.chat-input-row input:disabled { opacity: 0.4; }

.btn-send {
    padding: 8px 14px;
    background: #111;
    color: #fff;
    border: none;
    border-radius: 2px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: opacity 0.2s;
}
.btn-send:hover { opacity: 0.75; }
.btn-send:disabled { opacity: 0.35; cursor: not-allowed; }

/* ===== LEGAL MOVE INDICATORS ===== */

.legal-dot {
    position: absolute;
    width: 28%;
    height: 28%;
    background: rgba(0, 0, 0, 0.18);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 10;
}

.legal-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 4px solid rgba(0, 0, 0, 0.18);
    box-sizing: border-box;
    top: 0; left: 0;
    pointer-events: none;
    z-index: 10;
}

.selected-sq { background: rgba(80, 140, 70, 0.4) !important; }

/* ===== LAST MOVE HIGHLIGHTS ===== */

.highlight-from { background: rgba(160, 120, 40, 0.25) !important; }
.highlight-to   { background: rgba(160, 120, 40, 0.45) !important; }

/* ===== MODALS ===== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal-box {
    background: #fff;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    padding: 36px 32px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    min-width: 280px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.07);
}

.modal-title { font-size: 1.2rem; font-weight: 700; color: #111; letter-spacing: -0.01em; }
.modal-msg { font-size: 0.9rem; color: #888; line-height: 1.5; }

.modal-btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.btn-rematch {
    padding: 10px 24px;
    background: #111;
    color: #fff;
    border: none;
    border-radius: 2px;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: opacity 0.2s;
}
.btn-rematch:hover { opacity: 0.75; }
.btn-rematch:disabled { opacity: 0.35; cursor: not-allowed; }

/* ===== PROMOTION MODAL ===== */

.promotion-box { gap: 20px; }
.promotion-pieces { display: flex; gap: 10px; }

.promo-btn {
    background: #f7f6f2;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    padding: 8px;
    cursor: pointer;
    transition: border-color 0.15s;
}
.promo-btn:hover { border-color: #111; }
.promo-btn img { width: 52px; height: 52px; display: block; }

/* ===== SCROLLBARS ===== */

.chat-messages::-webkit-scrollbar,
.moves-table-wrap::-webkit-scrollbar { width: 3px; }
.chat-messages::-webkit-scrollbar-track,
.moves-table-wrap::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb,
.moves-table-wrap::-webkit-scrollbar-thumb { background: #d8d5cc; border-radius: 2px; }

/* ===== SPECTATOR BANNER ===== */

.spectator-banner {
    width: 480px;
    background: #f7f6f2;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    padding: 8px 14px;
    font-size: 10px;
    font-weight: 700;
    color: #bbb;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    text-align: center;
}

/* ===== ACTIVE GAMES IN LOBBY ===== */

.active-games-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.active-games-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.active-game-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f7f6f2;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    padding: 10px 14px;
    font-size: 0.85rem;
    color: #555;
    gap: 10px;
}

.active-game-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-watch {
    padding: 6px 14px;
    background: transparent;
    color: #111;
    border: 1px solid #d8d5cc;
    border-radius: 2px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: border-color 0.15s;
}
.btn-watch:hover { border-color: #111; }

/* ===== RESPONSIVE ===== */

@media (max-width: 768px) {
    #game { padding: 12px 8px; }
    .game-layout { flex-direction: column; align-items: center; gap: 12px; }
    #board { width: 340px; }
    .player-card { width: 340px; }
    .draw-banner { width: 340px; }
    .action-btns { width: 340px; }
    .side-panel { width: 340px; height: 360px; }
    .spectator-banner { width: 340px; }
    .back-link { display: none; }
}

@media (max-width: 380px) {
    #board { width: 290px; }
    .player-card { width: 290px; }
    .draw-banner { width: 290px; }
    .action-btns { width: 290px; }
    .side-panel { width: 290px; }
    .spectator-banner { width: 290px; }
}
