:root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --text: var(--tg-theme-text-color, #f5f5f5);
    --hint: var(--tg-theme-hint-color, #708499);
    --accent: var(--tg-theme-button-color, #5288c1);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --card: var(--tg-theme-secondary-bg-color, #232e3c);

    --sq-dark: #b58863;
    --sq-light: #f0d9b5;
    --sq-selected: #f7ec5e;
    --sq-target: rgba(60, 160, 60, 0.9);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 36px;
}

.player {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 15px;
}

.pcount {
    color: var(--hint);
    font-weight: 400;
    font-size: 13px;
}

.turn-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--hint);
    opacity: 0.35;
    flex-shrink: 0;
}

.turn-dot.on {
    background: #4cd964;
    opacity: 1;
    box-shadow: 0 0 6px #4cd964;
}

.code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    color: var(--hint);
}

.status {
    text-align: center;
    font-size: 14px;
    color: var(--hint);
    min-height: 20px;
}

.status.hot {
    color: #e8b93c;
    font-weight: 600;
}

/* ============ Doska ============ */

.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    aspect-ratio: 1;
    width: 100%;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
    user-select: none;
}

.sq {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.sq.selected {
    background: var(--sq-selected);
}

.sq.target::after {
    content: "";
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: var(--sq-target);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.sq.selectable { cursor: pointer; }
.sq.target { cursor: pointer; }

.piece {
    width: 78%;
    height: 78%;
    border-radius: 50%;
    position: relative;
    transition: transform 0.12s ease;
}

.sq.selectable .piece:active {
    transform: scale(0.92);
}

.piece.white {
    background: radial-gradient(circle at 35% 30%, #ffffff, #d8d4cc 60%, #b8b2a6);
    box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.18), 0 2px 4px rgba(0, 0, 0, 0.35);
}

.piece.black {
    background: radial-gradient(circle at 35% 30%, #6a6058, #3a3430 60%, #26211e);
    box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.35), 0 2px 4px rgba(0, 0, 0, 0.45);
}

.piece.king::after {
    content: "♛";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(14px, 5.2vw, 24px);
    color: #d4a017;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* ============ Tugmalar ============ */

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn {
    border: none;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 14px;
    font-weight: 600;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
}

.btn.primary {
    background: var(--accent);
    color: var(--accent-text);
}

.btn.danger {
    background: #8b2e2e;
    color: #fff;
}

.btn:active {
    opacity: 0.75;
}

/* ============ Overlay ============ */

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 24px;
}

.overlay.hidden { display: none; }

.overlay-card {
    background: var(--card);
    border-radius: 16px;
    padding: 28px 24px;
    text-align: center;
    max-width: 320px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.overlay-emoji { font-size: 44px; }

.overlay-title {
    font-size: 19px;
    font-weight: 700;
    margin-top: 10px;
}

.overlay-reason {
    color: var(--hint);
    font-size: 13px;
    margin-top: 6px;
}

.overlay-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 18px;
}
