* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    background:
        radial-gradient(circle at 20% 0%, rgba(120, 80, 220, 0.18), transparent 55%),
        radial-gradient(circle at 85% 100%, rgba(77, 171, 247, 0.14), transparent 55%),
        linear-gradient(135deg, #16131f 0%, #1a1a2e 60%, #14131f 100%);
    min-height: 100vh; min-height: 100dvh;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px) + 12px);
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.user-bar { margin: 0 auto 12px; }

.ch-game { max-width: 460px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }

.ch-tabs {
    display: flex; gap: 8px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px; padding: 5px;
}
.ch-tab {
    flex: 1; padding: 11px; border: none; border-radius: 10px;
    background: transparent; color: rgba(255,255,255,0.65);
    font-size: 15px; font-weight: 700; cursor: pointer; transition: .15s;
}
.ch-tab.active { background: linear-gradient(135deg, #b197fc, #7950f2); color: #fff; box-shadow: 0 4px 14px rgba(121,80,242,0.35); }

.ch-strip {
    display: flex; justify-content: space-between; align-items: center;
    padding: 4px 6px; min-height: 30px;
}
.ch-name { font-size: 14px; font-weight: 700; color: rgba(255,255,255,0.85); }
.ch-clock {
    font-variant-numeric: tabular-nums;
    font-size: 16px; font-weight: 800; letter-spacing: 0.5px;
    background: rgba(255,255,255,0.08); border-radius: 8px; padding: 4px 10px;
}
.ch-clock.low { color: #ff8a8a; }
/* The running clock pulses so it's obvious whose time is burning */
.ch-clock.ticking {
    background: rgba(121,80,242,0.35);
    animation: chClockPulse 1s ease-in-out infinite;
}
@keyframes chClockPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(177,151,252,0.55); }
    50%      { box-shadow: 0 0 0 5px rgba(177,151,252,0); }
}
/* Under a minute → same idea, but red and faster */
.ch-clock.ticking.low {
    background: rgba(226,90,90,0.32);
    animation: chClockPulseLow 0.6s ease-in-out infinite;
}
@keyframes chClockPulseLow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,110,110,0.65); }
    50%      { box-shadow: 0 0 0 6px rgba(255,110,110,0); }
}

/* Board */
.ch-board-wrap { width: 100%; }
.ch-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr); /* equal-height rows regardless of content */
    width: 100%; aspect-ratio: 1;
    border-radius: 10px; overflow: hidden;
    border: 2px solid rgba(255,255,255,0.12);
    touch-action: manipulation;
}
.ch-sq {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.ch-sq .pc {
    width: 92%; height: 92%; display: block;
    pointer-events: none; /* taps land on the square */
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3));
}
.ch-sq.light { background: #e9d8b6; }
.ch-sq.dark  { background: #a97a4f; }
/* opponent's move flash — pulses the from/to squares so it's easy to spot */
.ch-sq.opp-flash { animation: ch-opp-flash 1.2s ease-out; }
@keyframes ch-opp-flash {
    0%   { box-shadow: inset 0 0 0 100px rgba(121, 80, 242, 0.65); }
    60%  { box-shadow: inset 0 0 0 100px rgba(121, 80, 242, 0.35); }
    100% { box-shadow: inset 0 0 0 100px rgba(255, 220, 80, 0.28); }
}
.ch-sq.sel      { outline: 3px solid #7950f2; outline-offset: -3px; }
.ch-sq.lastmove { box-shadow: inset 0 0 0 100px rgba(255, 220, 80, 0.28); }
.ch-sq.check    { box-shadow: inset 0 0 0 100px rgba(255, 60, 60, 0.4); }
.ch-sq .dot {
    position: absolute; width: 26%; height: 26%;
    border-radius: 50%; background: rgba(30,30,30,0.35);
    pointer-events: none;
}
.ch-sq .ring {
    position: absolute; inset: 4%;
    border: 4px solid rgba(30,30,30,0.35); border-radius: 50%;
    pointer-events: none;
}

.ch-status {
    text-align: center; font-size: 14px; font-weight: 700;
    color: rgba(255,255,255,0.85); min-height: 20px;
    transition: color .15s;
}
/* Your move — impossible to miss: green pulsing badge, uppercase */
.ch-status.my-turn {
    align-self: center;              /* shrink to content inside the flex column */
    font-size: 16px; font-weight: 800;
    text-transform: uppercase; letter-spacing: 0.6px;
    color: #b9ffcf;
    background: linear-gradient(135deg, rgba(105,219,124,0.24), rgba(60,180,90,0.12));
    border: 1px solid rgba(105,219,124,0.55);
    border-radius: 10px; padding: 7px 14px;
    animation: chTurnPulse 1.4s ease-in-out infinite;
}
@keyframes chTurnPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(105,219,124,0.5); }
    50%      { box-shadow: 0 0 0 7px rgba(105,219,124,0); }
}
/* Opponent's move — deliberately quiet so the contrast reads instantly */
.ch-status.opp-turn { color: rgba(255,255,255,0.45); font-weight: 600; }

.ch-panel {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px; padding: 14px;
    display: flex; flex-direction: column; gap: 10px;
}
#chOnlineIdle, #chOnlineWaiting, #chOnlineActive, #chOnlineAccept { display: flex; flex-direction: column; gap: 10px; align-items: center; }
#chOnlineIdle .ch-action, #chOnlineWaiting .ch-action, #chOnlineAccept .ch-action, #chOnlineActive .ch-action { width: 100%; }

.ch-action {
    width: 100%; padding: 14px; border: none; border-radius: 13px;
    background: linear-gradient(135deg, #b197fc, #7950f2); color: #fff;
    font-size: 16px; font-weight: 800; cursor: pointer;
    box-shadow: 0 5px 16px rgba(121,80,242,0.35);
}
.ch-action:active { transform: scale(0.98); }
.ch-action:disabled { opacity: 0.5; cursor: default; box-shadow: none; }
.ch-action--ghost { background: rgba(255,255,255,0.08); color: #fff; box-shadow: none; font-size: 15px; padding: 12px; }

.ch-hint { font-size: 12.5px; color: rgba(255,255,255,0.6); text-align: center; line-height: 1.5; }
.ch-wait-title { font-size: 16px; font-weight: 800; text-align: center; }
.ch-wait-sub { font-size: 13px; color: rgba(255,255,255,0.65); text-align: center; }
.ch-spinner {
    width: 38px; height: 38px; border-radius: 50%;
    border: 4px solid rgba(255,255,255,0.15); border-top-color: #b197fc;
    animation: ch-rot 0.9s linear infinite;
}
@keyframes ch-rot { to { transform: rotate(360deg); } }
.ch-link {
    width: 100%; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px; padding: 9px 12px; font-size: 12px; word-break: break-all; text-align: center;
}
#chInviteBox { width: 100%; display: flex; flex-direction: column; gap: 10px; }

/* In-app toast (opponent moved, etc.) */
.ch-toast {
    position: fixed; top: calc(env(safe-area-inset-top, 0px) + 64px);
    left: 50%; transform: translate(-50%, -16px);
    background: rgba(28, 26, 43, 0.96);
    border: 1px solid rgba(177, 151, 252, 0.45);
    border-radius: 12px; padding: 10px 18px;
    font-size: 14px; font-weight: 700; color: #fff;
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
    opacity: 0; pointer-events: none; z-index: 1400;
    transition: opacity .25s, transform .25s;
}
.ch-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Game over modal */
.ch-modal {
    position: fixed; inset: 0; display: none;
    align-items: center; justify-content: center;
    background: rgba(0,0,0,0.55); backdrop-filter: blur(3px); z-index: 1300;
    padding: 16px;
}
.ch-modal.show { display: flex; }
.ch-modal-box {
    width: 100%; max-width: 320px; text-align: center;
    background: #1c1a2b; border: 1px solid rgba(255,255,255,0.12);
    border-radius: 18px; padding: 24px 22px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}
.ch-modal-box h2 { margin-bottom: 8px; font-size: 22px; }
.ch-modal-box p { margin-bottom: 16px; font-size: 14.5px; line-height: 1.45; color: rgba(255,255,255,0.8); }
/* Stacked action buttons (game-over modal) shouldn't touch each other */
.ch-modal-box .ch-action + .ch-action { margin-top: 10px; }

/* Slim "tournament live" strip — tap opens tournament modal */
.ch-tourn-strip {
    width: 100%; border: 1px solid rgba(255,199,44,0.45); border-radius: 12px;
    background: linear-gradient(135deg, rgba(255,199,44,0.16), rgba(255,140,0,0.09));
    color: #fff; font-size: 13.5px; font-weight: 600; text-align: left;
    padding: 10px 14px; cursor: pointer;
    display: flex; align-items: center; gap: 6px;
    animation: tournStripGlow 1.8s ease-in-out infinite;
    -webkit-tap-highlight-color: transparent;
}
.ch-tourn-strip b { color: #ffd24a; }
.ch-tourn-strip-txt { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ch-tourn-strip-title { font-size: 12.5px; }
.ch-tourn-strip-timer {
    font-size: 22px; font-weight: 900; color: #ffd24a;
    font-variant-numeric: tabular-nums; letter-spacing: 0.5px; line-height: 1.1;
    text-shadow: 0 2px 10px rgba(255,168,37,0.35);
}
.ch-tourn-strip-timer.urgent { color: #ff8a8a; text-shadow: 0 2px 10px rgba(255,80,80,0.4); }
.ch-tourn-strip-go { margin-left: auto; color: #ffd24a; font-weight: 800; font-size: 18px; }
@keyframes tournStripGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,199,44,0.35); }
    50%      { box-shadow: 0 0 14px 2px rgba(255,199,44,0.18); }
}

/* ── Tournament header button + modal ─────────────────────────────────────── */
.user-bar .top-up-btn.ch-thdr-btn {
    background: linear-gradient(135deg, #ffd24a, #f7a600);
    box-shadow: 0 2px 10px rgba(255, 199, 44, 0.5), inset 0 1px 0 rgba(255,255,255,0.35);
    font-size: 15px;
    animation: chThdrPulse 1.8s ease-in-out infinite;
}
@keyframes chThdrPulse {
    0%, 100% { box-shadow: 0 2px 10px rgba(255,199,44,0.5), 0 0 0 0 rgba(255,199,44,0.45); }
    50%      { box-shadow: 0 2px 10px rgba(255,199,44,0.5), 0 0 0 7px rgba(255,199,44,0); }
}

.ch-tm-box {
    max-width: 370px; max-height: 84vh; overflow-y: auto;
    text-align: left; position: relative; padding: 20px 18px;
}
.ch-tm-close {
    position: absolute; top: 4px; right: 4px; z-index: 3;
    background: none; border: none; color: rgba(255,255,255,0.6);
    font-size: 20px; cursor: pointer; padding: 0;
    width: 44px; height: 44px; line-height: 44px; text-align: center;
    -webkit-tap-highlight-color: transparent;
}
.ch-tm-close:active { color: #fff; transform: scale(0.9); }
.ch-tm-head { text-align: center; margin-bottom: 6px; }
.ch-tm-trophy { font-size: 46px; line-height: 1.1; filter: drop-shadow(0 4px 16px rgba(255,199,44,0.55)); }
.ch-tm-head h2 { font-size: 20px; margin: 2px 0; }
.ch-tm-when { font-size: 12.5px; color: #ffd24a; font-weight: 700; }

.ch-tm-podium { display: flex; gap: 8px; align-items: flex-end; margin: 14px 0 2px; }
.ch-tm-pod {
    flex: 1; text-align: center; border-radius: 12px 12px 7px 7px;
    padding: 10px 4px 8px;
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
}
.ch-tm-pod .m { font-size: 24px; line-height: 1.2; }
.ch-tm-pod .a { font-size: 13px; font-weight: 800; color: #ffd24a; }
.ch-tm-pod.first {
    padding: 18px 4px 12px;
    background: linear-gradient(180deg, rgba(255,199,44,0.24), rgba(255,199,44,0.05));
    border-color: rgba(255,199,44,0.55);
    box-shadow: 0 6px 20px rgba(255,168,37,0.25);
}
.ch-tm-pod.first .m { font-size: 32px; }
.ch-tm-pod.first .a { font-size: 15.5px; }

.ch-tm-sec {
    margin: 16px 0 7px; font-size: 11px; font-weight: 800;
    letter-spacing: 0.7px; text-transform: uppercase; color: rgba(255,255,255,0.5);
}
.ch-tm-rows { display: flex; flex-direction: column; gap: 3px; }
.ch-tm-row {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 9px; border-radius: 9px;
    background: rgba(255,255,255,0.045); font-size: 13.5px;
}
.ch-tm-row.me { background: rgba(121,80,242,0.32); }
.ch-tm-row .pl { width: 26px; text-align: center; flex-shrink: 0; }
.ch-tm-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.ch-tm-row .wl { font-size: 12px; color: rgba(255,255,255,0.6); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.ch-tm-row .pz { font-size: 12.5px; font-weight: 800; color: #ffd24a; flex-shrink: 0; }
.ch-tm-empty { font-size: 13px; color: rgba(255,255,255,0.55); padding: 4px 2px; }
.ch-tm-me { margin-top: 7px; font-size: 12.5px; color: #b197fc; font-weight: 700; }
.ch-tm-rules { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.ch-tm-rules li { font-size: 12.5px; line-height: 1.5; color: rgba(255,255,255,0.78); }
.ch-tm-rules b { color: #fff; }

/* Background-search strip (bot mode): matchmaking continues while you play */
.ch-search-strip {
    width: 100%; border: 1px solid rgba(77, 171, 247, 0.45); border-radius: 12px;
    background: linear-gradient(135deg, rgba(77, 171, 247, 0.16), rgba(121, 80, 242, 0.10));
    color: #fff; font-size: 13px; font-weight: 600; text-align: left;
    padding: 10px 14px; cursor: pointer;
    display: flex; align-items: center; gap: 9px;
    -webkit-tap-highlight-color: transparent;
}
.ch-search-strip b { color: #8ecbff; font-weight: 700; }
.ch-search-strip .ch-tourn-strip-go { color: #8ecbff; }
.ch-mini-spinner {
    width: 14px; height: 14px; flex-shrink: 0;
    border: 2px solid rgba(142, 203, 255, 0.35); border-top-color: #8ecbff;
    border-radius: 50%; animation: chMiniSpin 0.9s linear infinite;
}
@keyframes chMiniSpin { to { transform: rotate(360deg); } }

/* Opponent identity in the strip (name + colored initials avatar) */
.ch-oppinfo { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ch-oppav { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; object-fit: cover; }
