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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f0f1a;
    color: #e0e0e0;
    line-height: 1.6;
    min-height: 100vh;
}

main {
    max-width: 820px;
    margin: 0 auto;
    padding: 1rem;
}

h1 {
    text-align: center;
    color: #4ecca3;
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

/* ---- breadcrumb ---- */
.breadcrumb {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 0.75rem;
}
.breadcrumb a { color: #4ecca3; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ---- game tip ---- */
.game-tip {
    background: #1a1a2e;
    border: 1px solid #2a2a4e;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.game-tip summary { cursor: pointer; color: #4ecca3; }

/* ---- game container ---- */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
    position: relative;
}

/* ---- mode selector ---- */
.mode-selector {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}
.mode-btn {
    padding: 0.45rem 1rem;
    font-size: 0.9rem;
    background: #1a1a2e;
    color: #e0e0e0;
    border: 2px solid #4ecca3;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}
.mode-btn:hover { background: #2a2a3e; }
.mode-btn.active { background: #4ecca3; color: #0f0f1a; font-weight: 600; }

/* ---- online controls ---- */
#online-controls {
    width: 100%;
    max-width: 400px;
    background: #1a1a2e;
    border: 1px solid #2a2a4e;
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}
.online-setup-btns {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 0.75rem;
}
.online-btn {
    padding: 0.5rem 1.25rem;
    font-size: 0.95rem;
    background: #4ecca3;
    color: #0f0f1a;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s;
}
.online-btn:hover { background: #3db892; }
.online-btn.secondary {
    background: #1a1a2e;
    color: #4ecca3;
    border: 2px solid #4ecca3;
}
.online-btn.secondary:hover { background: #2a2a3e; }
.join-row {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
}
#join-code-input {
    padding: 0.45rem 0.75rem;
    font-size: 1.1rem;
    font-family: monospace;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: #0f0f1a;
    color: #e0e0e0;
    border: 2px solid #4ecca3;
    border-radius: 4px;
    width: 130px;
    text-align: center;
}
#room-code-display {
    font-size: 2rem;
    font-family: monospace;
    letter-spacing: 0.15em;
    color: #4ecca3;
    display: block;
    margin: 0.5rem 0;
}
#online-status-text {
    color: #aaa;
    font-size: 0.9rem;
    margin-top: 0.4rem;
}
#copy-code-btn {
    padding: 0.3rem 0.8rem;
    font-size: 0.85rem;
    background: #1a1a2e;
    color: #4ecca3;
    border: 1px solid #4ecca3;
    border-radius: 4px;
    cursor: pointer;
}
#copy-code-btn:hover { background: #4ecca3; color: #0f0f1a; }

/* ---- game info bar ---- */
.game-info {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    font-size: 1rem;
}
#turn-indicator {
    font-weight: 600;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    background: #1a1a2e;
}
#turn-indicator.white-turn { color: #f0f0f0; border: 2px solid #f0f0f0; }
#turn-indicator.black-turn { color: #aaa; border: 2px solid #555; }
#check-indicator {
    color: #e94560;
    font-weight: 700;
    animation: blink 0.8s ease-in-out infinite alternate;
}
@keyframes blink { from { opacity: 1; } to { opacity: 0.4; } }

/* ---- chess board ---- */
.board-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    user-select: none;
}
.rank-labels {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: calc(8 * var(--sq));
    font-size: 0.72rem;
    color: #666;
    padding: 2px 0;
    line-height: 1;
}
.file-labels {
    display: flex;
    justify-content: space-around;
    width: calc(8 * var(--sq));
    font-size: 0.72rem;
    color: #666;
    margin-top: 3px;
    margin-left: calc(18px + 4px); /* rank label width + gap */
}
:root { --sq: 54px; }

#chess-board {
    display: grid;
    grid-template-columns: repeat(8, var(--sq));
    grid-template-rows: repeat(8, var(--sq));
    border: 2px solid #4ecca3;
    border-radius: 4px;
    overflow: hidden;
}
.sq {
    width: var(--sq);
    height: var(--sq);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--sq) * 0.72);
    cursor: pointer;
    position: relative;
    transition: background-color 0.1s;
    line-height: 1;
}
.sq.light { background: #f0d9b5; }
.sq.dark  { background: #b58863; }
.sq.selected { background: #f6f669 !important; }
.sq.legal-move::after {
    content: '';
    position: absolute;
    width: 34%;
    height: 34%;
    border-radius: 50%;
    background: rgba(0,0,0,0.18);
    pointer-events: none;
}
.sq.legal-capture::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 0;
    border: 4px solid rgba(0,0,0,0.20);
    background: transparent;
    pointer-events: none;
}
.sq.last-move { background: rgba(155, 199, 0, 0.41) !important; }
.sq.in-check  { background: rgba(233, 69, 96, 0.55) !important; }
.sq.piece-white { color: #fff; text-shadow: 0 0 2px #222, 0 1px 3px rgba(0,0,0,0.7); }
.sq.piece-black { color: #1a1a1a; text-shadow: 0 0 2px #fff4, 0 1px 2px rgba(255,255,255,0.2); }

/* Highlight for captured square in en passant */
.sq.ep-target::after {
    content: '';
    position: absolute;
    width: 34%;
    height: 34%;
    border-radius: 50%;
    background: rgba(0,0,0,0.18);
    pointer-events: none;
}

/* ---- promotion dialog ---- */
#promo-dialog {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
#promo-dialog.hidden { display: none; }
.promo-box {
    background: #1a1a2e;
    border: 2px solid #4ecca3;
    border-radius: 10px;
    padding: 1.5rem 2rem;
    text-align: center;
}
.promo-box p { margin-bottom: 1rem; color: #4ecca3; font-weight: 600; }
.promo-choices {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}
.promo-btn {
    font-size: 2.8rem;
    background: #0f0f1a;
    border: 2px solid #4ecca3;
    border-radius: 6px;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    line-height: 1;
    transition: background 0.15s;
}
.promo-btn:hover { background: #4ecca3; }

/* ---- game over overlay ---- */
.overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(15,15,26,0.97);
    padding: 2rem;
    border-radius: 8px;
    border: 2px solid #4ecca3;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    z-index: 20;
    text-align: center;
    min-width: 220px;
}
.overlay.hidden { display: none; }
.overlay p { font-size: 1.4rem; color: #4ecca3; font-weight: 700; }
.overlay .sub { font-size: 0.9rem; color: #aaa; }
.overlay button {
    padding: 0.65rem 2rem;
    font-size: 1rem;
    background: #4ecca3;
    color: #0f0f1a;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}
.overlay button:hover { background: #3db892; }

/* ---- controls row ---- */
.controls-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}
.new-game-btn {
    padding: 0.45rem 1.25rem;
    font-size: 0.9rem;
    background: #1a1a2e;
    color: #4ecca3;
    border: 2px solid #4ecca3;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}
.new-game-btn:hover { background: #4ecca3; color: #0f0f1a; }
.flip-btn {
    padding: 0.45rem 0.9rem;
    font-size: 0.85rem;
    background: #1a1a2e;
    color: #aaa;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}
.flip-btn:hover { border-color: #4ecca3; color: #4ecca3; }

/* ---- move history ---- */
.move-history {
    width: 100%;
    max-width: 400px;
    background: #1a1a2e;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}
.move-history .label { color: #4ecca3; font-weight: 600; margin-bottom: 0.3rem; }
#moves-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.5rem;
    max-height: 80px;
    overflow-y: auto;
    color: #aaa;
    font-family: monospace;
}
.move-pair { color: #e0e0e0; }
.move-num { color: #555; }

/* ---- content ---- */
.content {
    padding-top: 1.5rem;
    border-top: 1px solid #2a2a3e;
}
.content h2 { color: #4ecca3; font-size: 1.2rem; margin: 1.25rem 0 0.6rem; }
.content h2:first-child { margin-top: 0.5rem; }
.content p { margin-bottom: 0.7rem; color: #ccc; }
.content ul { margin: 0.4rem 0 0.9rem 1.4rem; }
.content li { margin-bottom: 0.4rem; color: #ccc; }
.last-updated { color: #666; font-size: 0.8rem; margin-bottom: 0.75rem; }
.faq dt { font-weight: 600; color: #e0e0e0; margin-top: 0.75rem; }
.faq dd { color: #aaa; margin-left: 1rem; }
.related-games h3 { color: #4ecca3; font-size: 1rem; margin: 1rem 0 0.5rem; }
.game-links { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.game-links a {
    padding: 0.3rem 0.75rem;
    background: #1a1a2e;
    border: 1px solid #2a2a4e;
    border-radius: 4px;
    color: #4ecca3;
    text-decoration: none;
    font-size: 0.85rem;
}
.game-links a:hover { border-color: #4ecca3; background: #2a2a3e; }

/* ---- responsive ---- */
@media (min-width: 600px) {
    main { padding: 2rem; }
    h1 { font-size: 2rem; }
    :root { --sq: 62px; }
}
@media (max-width: 480px) {
    :root { --sq: 42px; }
    .rank-labels { font-size: 0.65rem; }
    .file-labels { font-size: 0.65rem; }
}
@media (max-width: 360px) {
    :root { --sq: 36px; }
}
@media (orientation: landscape) and (max-height: 500px) {
    main { padding-top: 0.5rem; }
    h1 { font-size: 1.5rem; }
}
