/* Chinese Chess (Xiangqi) styles */

.chess-page {
    background: linear-gradient(135deg, #fdf6ec 0%, #f6e5cb 100%);
}

/* ---------- Lobby ---------- */
.chess-lobby {
    padding: 2rem 0 4rem;
    max-width: 1200px;
    margin: 0 auto;
}

.chess-lobby-hero {
    text-align: center;
    margin-bottom: 2.5rem;
}

.chess-lobby-icon {
    font-size: 4rem;
}

.chess-lobby-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (max-width: 760px) {
    .chess-lobby-cols {
        grid-template-columns: 1fr;
    }
}

.chess-card {
    padding: 1.5rem;
}

.chess-card h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
}

.chess-label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    margin: 0.9rem 0 0.35rem;
    color: var(--text-muted, #555);
}

.chess-card input[type="text"] {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 0.95rem;
    box-sizing: border-box;
}

.chess-select {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 0.95rem;
    background: #fff;
    box-sizing: border-box;
    cursor: pointer;
}

.chess-color-select {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.color-pick {
    flex: 1;
    padding: 0.7rem;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    background: #fff;
    transition: all 0.15s ease;
}

.color-pick.red.active {
    border-color: #d32f2f;
    background: #ffebee;
    color: #b71c1c;
}

.color-pick.black.active {
    border-color: #263238;
    background: #eceff1;
    color: #1b2a2e;
}

.btn-block {
    width: 100%;
}

.chess-error {
    color: #d32f2f;
    font-size: 0.85rem;
    min-height: 1.2em;
    margin: 0.5rem 0 0;
}

.chess-rules {
    padding: 1.5rem;
}

.chess-rules-list {
    margin: 0.5rem 0 0 1.2rem;
    line-height: 1.7;
}

.chess-muted {
    color: var(--text-muted, #777);
    font-size: 0.9rem;
}

/* ---------- Game page ---------- */
.chess-game {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.chess-game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin-bottom: 1.2rem;
}

.chess-title {
    margin: 0;
    font-size: 1.5rem;
}

.chess-sub {
    font-size: 0.9rem;
    color: var(--text-muted, #777);
    font-weight: 400;
}

.chess-room {
    margin-top: 0.4rem;
    font-size: 0.95rem;
}

.room-label { font-weight: 600; }

.room-code {
    background: #f1e2c4;
    border: 1px solid #d9c29a;
    border-radius: 6px;
    padding: 0.15rem 0.5rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.chess-head-right { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.chess-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 900px) {
    .chess-layout { grid-template-columns: 1fr; }
}

.chess-board-wrap {
    background: #f8e5bd;
    border: 1px solid #dcc393;
    border-radius: 12px;
    padding: 0.8rem;
    display: inline-block;
    max-width: 100%;
    box-sizing: border-box;
    box-shadow: 0 6px 20px rgba(93, 64, 55, 0.18);
    overflow-x: auto;
    overflow-y: hidden;
}

.chess-board-info { font-weight: 600; margin-bottom: 0.5rem; color: #4e342e;
        display: flex; justify-content: space-between; align-items: center; }

.zoom-controls { display: inline-flex; align-items: center; gap: 0.4rem; }

.zoom-btn {
    width: 26px; height: 26px;
    border: 1px solid #c9a95f;
    background: #fff8e7;
    color: #5d4037;
    border-radius: 6px;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease;
}

.zoom-btn:hover { background: #f1e2c4; }

.zoom-label {
    font-size: 0.8rem;
    font-weight: 700;
    min-width: 38px;
    text-align: center;
    cursor: pointer;
    color: #5d4037;
}

.zoom-sep {
    width: 1px; height: 18px;
    background: #d9c29a;
    margin: 0 0.2rem;
}

.chess-board-wrap:fullscreen {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #1f1710;
    cursor: default;
    overflow: hidden;
}

.chess-board-wrap:fullscreen .chess-board-info { width: min(92vw, 92vh); }

.chess-board-wrap:fullscreen .chess-turn {
    color: #e8c98a;
    margin-top: 0.6rem;
}

/* iOS fallback "fullscreen": a fixed overlay covering the viewport */
.chess-board-wrap.fullscreen-fallback {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    border: none;
    border-radius: 0;
    margin: 0;
    background: #1f1710;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: default;
    padding: 0.8rem;
}

.chess-board-wrap.fullscreen-fallback .chess-board-info { color: #e8c98a; }
.chess-board-wrap.fullscreen-fallback .chess-turn { color: #e8c98a; margin-top: 0.6rem; }
.chess-board-wrap.fullscreen-fallback .zoom-btn { color: #e8c98a; }

#chessCanvas {
    display: block;
    max-width: none;
    height: auto !important;
    border-radius: 6px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.chess-turn {
    margin-top: 0.7rem;
    font-weight: 700;
    color: #4e342e;
}

.chess-turn.flash-err {
    color: #b71c1c;
}

.chess-hint {
    margin-top: 0.5rem;
    font-size: 0.78rem;
    color: var(--text-muted, #887); 
}

.chess-hint code {
    background: #f1e2c4;
    border-radius: 4px;
    padding: 0.05rem 0.35rem;
}

/* ---------- Pawn promotion picker ---------- */
.chess-promo {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(30, 20, 10, 0.55);
}

.promo-box {
    background: #fffdf8;
    border: 2px solid #c9a95f;
    border-radius: 12px;
    padding: 1.2rem 1.4rem;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    max-width: 90vw;
}

.promo-box h3 {
    margin: 0 0 0.9rem;
    color: #5d4037;
}

.promo-btns {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    justify-content: center;
}

.promo-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0.6rem 0.9rem;
    border: 2px solid #d9c29a;
    border-radius: 10px;
    background: #fff8e7;
    cursor: pointer;
    font-weight: 700;
    color: #5d4037;
    transition: all 0.15s ease;
    min-width: 72px;
}

.promo-btn:hover {
    border-color: #b58863;
    background: #f1e2c4;
}

.promo-glyph {
    font-size: 1.7rem;
    line-height: 1;
    font-family: serif;
}

.chess-side { display: flex; flex-direction: column; gap: 1rem; }

.chess-panel {
    background: #fffdf8;
    border: 1px solid #e0cfae;
    border-radius: 10px;
    padding: 1rem;
    box-shadow: 0 2px 10px rgba(93, 64, 55, 0.08);
}

.chess-panel h3 {
    margin: 0 0 0.7rem;
    font-size: 1rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.4rem;
}

.player-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0;
    font-size: 0.95rem;
}

.player-row .dot {
    width: 14px; height: 14px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid #ccc;
    flex: 0 0 auto;
}

.dot.red { background: #e53935; }
.dot.black { background: #37474f; }

.pname { font-weight: 600; }

.pstatus { font-size: 0.75rem; color: #b8860b; }
.pstatus.away { color: #b71c1c; }

.chess-status { font-size: 0.92rem; color: var(--text-muted, #555); min-height: 1.2em; }

.chess-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.chess-history {
    max-height: 260px;
    overflow-y: auto;
    font-size: 0.85rem;
}

.hist-line {
    margin: 0;
    padding: 0.25rem 0;
    border-bottom: 1px dashed #eee;
}

.chess-overlay {
    background: #fffbe9;
    border: 2px solid #e8c26a;
    border-radius: 10px;
    padding: 1.2rem;
    text-align: center;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.15);
}

.chess-overlay h2 { margin: 0 0 0.4rem; color: #5d4037; }

/* ---------- Join panel ---------- */
.chess-notfound {
    background: #fff3e0;
    border: 1px solid #e0b36a;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.2rem;
    text-align: center;
}

.chess-notfound p {
    font-size: 0.95rem;
    color: var(--text-muted, #666);
    margin-bottom: 1rem;
}
.chess-join {
    background: #fff8e7;
    border: 1px dashed #c9a95f;
    border-radius: 12px;
    padding: 1.2rem;
    margin-bottom: 1.2rem;
    max-width: 420px;
}

.chess-join h3 { margin: 0 0 0.4rem; }

.chess-form-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.chess-form-row input[type="text"] {
    flex: 1;
    padding: 0.55rem 0.7rem;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 0.95rem;
}