:root {
    --bg: #06080b;
    --panel: #11161d;
    --panel2: #0c1117;
    --line: #28303a;
    --text: #f5f7fb;
    --muted: #8f99a8;
    --red: #f13b4d;
    --blue: #4f8cff;
    --gold: #e3b652;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 50% 0, rgba(227, 182, 82, 0.08), transparent 26%),
        linear-gradient(180deg, #090c10, #05070a);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
.hidden { display: none !important; }

.chess-topbar {
    min-height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 4px max(16px, calc((100vw - 1180px) / 2));
    position: sticky;
    top: 0;
    z-index: 40;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(6, 8, 11, 0.88);
    backdrop-filter: blur(16px);
}

.chess-brand { display: flex; align-items: center; text-decoration: none; min-width: 0; }
.chess-brand-logo { display: block; width: auto; max-width: 42vw; height: 54px; object-fit: contain; }
.top-actions { display: flex; gap: 8px; }
.chess-account { display: flex; align-items: center; gap: 8px; padding: 4px 5px 4px 10px; border: 1px solid rgba(227, 182, 82, 0.3); border-radius: 10px; background: rgba(227, 182, 82, 0.07); }
.chess-account span { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #f0cf7a; font-size: 11px; font-weight: 900; }
.chess-account b { color: #f1c15d; white-space: nowrap; font-size: 11px; }
.chess-account a { color: #8db3ff; font-size: 10px; font-weight: 900; text-decoration: none; }
.chess-account button { min-height: 28px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; background: #0d1218; color: #e7ebf2; font-size: 9px; font-weight: 900; cursor: pointer; }
.small-btn {
    min-height: 38px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #0d1218;
    color: #e7ebf2;
    text-decoration: none;
    font-size: 12px;
    font-weight: 900;
}

.chess-page { width: min(1220px, calc(100% - 28px)); margin: auto; }
.chess-hero { padding: 24px 0 14px; text-align: center; }
.eyebrow, .section-heading span, .panel-label {
    color: #d7b66a;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}
#weeklyDuelLabel { text-transform: none; }
.chess-hero h1 {
    margin: 7px 0 6px;
    font-size: clamp(34px, 5.5vw, 58px);
    line-height: 0.94;
    letter-spacing: -0.055em;
}
.chess-hero h1 span {
    display: block;
    background: linear-gradient(180deg, #fff1b2, #d49b37 58%, #7e4d17);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.chess-hero p { margin: 0 auto; max-width: 680px; color: var(--muted); font-size: 14px; line-height: 1.4; }
.game-active .chess-hero { padding: 8px 0 6px; }
.game-active .chess-hero .eyebrow,
.game-active .chess-hero p { display: none; }
.game-active .chess-hero h1 { margin: 0; font-size: clamp(26px, 3.5vw, 38px); line-height: 1; }
.game-active .chess-hero h1 span { display: inline; margin-left: 0.18em; }
.chess-overview { margin: 0 auto 20px; }
.chess-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.chess-kpis article { border: 1px solid var(--line); border-radius: 12px; padding: 13px 15px; background: linear-gradient(145deg, #101721, #0b1017); }
.chess-kpis span { display: block; color: var(--gold); font-size: 9px; letter-spacing: .11em; font-weight: 900; }
.chess-kpis strong { display: block; margin-top: 7px; color: #fff; font-size: clamp(12px, 1.5vw, 17px); }
.leaderboard-card { margin-top: 10px; border: 1px solid var(--line); border-radius: 12px; background: #0b1118; overflow: hidden; }
.leaderboard-card summary { cursor: pointer; list-style: none; padding: 13px 16px; color: var(--gold); font-weight: 900; font-size: 10px; letter-spacing: .1em; display: flex; justify-content: space-between; }
.leaderboard-card summary small { color: var(--muted); }
.leaderboard-table-wrap { overflow: auto; border-top: 1px solid #202b38; }
.leaderboard-card table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.leaderboard-card th, .leaderboard-card td { text-align: left; padding: 10px 13px; border-bottom: 1px solid #1b2632; font-size: 11px; }
.leaderboard-card th { color: #91a3b9; font-size: 9px; letter-spacing: .08em; }
.leaderboard-card td:first-child, .leaderboard-card td:nth-child(4) { color: var(--gold); font-weight: 900; }
.tournament-leaderboards { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 10px; padding: 12px; border-top: 1px solid #202b38; }
.tournament-board { min-width: 0; padding: 13px; border: 1px solid #26384b; border-radius: 10px; background: #081019; }
.tournament-board h3 { margin: 0 0 4px; color: var(--gold); font-size: 11px; letter-spacing: .08em; }
.tournament-board > small { color: var(--muted); font-size: 9px; }
.tournament-place { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px solid #1d2a37; font-size: 10px; }
.tournament-place b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tournament-place span { color: #82b9ff; }
.matchmaking-panel { width: min(900px,100%); margin: 0 auto 18px; padding: 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border: 1px solid #315c82; border-radius: 15px; background: radial-gradient(circle at 85% 10%,rgba(62,144,217,.16),transparent 40%),linear-gradient(145deg,#111d2b,#090f16); }
.matchmaking-panel span,.matchmaking-panel small { display: block; }
.matchmaking-panel span { color: #82b9ff; font-size: 9px; font-weight: 950; letter-spacing: .12em; }
.matchmaking-panel strong { display: block; margin: 6px 0 4px; }
.matchmaking-panel small { color: var(--muted); }
.matchmaking-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.ai-heading { margin-top: 8px; }
.ai-heading h3 { margin: 4px 0 0; }
.section-heading { text-align: center; margin-bottom: 18px; }
.section-heading h2 { margin: 7px 0; font-size: clamp(28px, 5vw, 44px); letter-spacing: -0.035em; }

.chess-auth-gate { padding: 14px 0 62px; }
.chess-auth-card {
    width: min(520px, 100%);
    margin: auto;
    padding: 28px;
    border: 1px solid rgba(227, 182, 82, 0.34);
    border-radius: 22px;
    background:
        radial-gradient(circle at 50% 0, rgba(227, 182, 82, 0.13), transparent 38%),
        linear-gradient(180deg, #141a22, #0a0f15);
    text-align: center;
    box-shadow: var(--shadow);
}
.auth-lock { display: block; margin-bottom: 8px; color: #f0cf7a; font-size: 42px; line-height: 1; }
.chess-auth-card h2 { margin: 8px 0; font-size: clamp(25px, 5vw, 38px); line-height: 1; }
.chess-auth-card > p { margin: 0; color: var(--muted); }
.chess-auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 22px 0 14px; padding: 5px; border-radius: 12px; background: #080c11; }
.chess-auth-tabs button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 950; cursor: pointer; }
.chess-auth-tabs button.active { background: linear-gradient(135deg, #f0ce73, #ad6d20); color: #171108; }
.chess-auth-form { display: grid; gap: 12px; text-align: left; }
.chess-auth-form label { display: grid; gap: 6px; }
.chess-auth-form label > span { color: #b6bfcc; font-size: 9px; font-weight: 900; letter-spacing: 0.1em; }
.chess-auth-form input { width: 100%; min-height: 46px; padding: 0 13px; border: 1px solid var(--line); border-radius: 10px; outline: none; background: #090e14; color: #f5f7fb; }
.chess-auth-form input:focus { border-color: #d7b66a; box-shadow: 0 0 0 3px rgba(227, 182, 82, 0.1); }
.chess-register-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chess-register-fields label:first-child { grid-column: 1 / -1; }
.chess-auth-form .primary-btn { margin-top: 4px; }
.chess-auth-notice { min-height: 20px; margin: 0; color: #ff8591; text-align: center; font-size: 12px; line-height: 1.4; }

.fighter-select { padding: 28px 0 54px; }
.fighter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; width: min(900px, 100%); margin: auto; }
.fighter-card {
    min-width: 0;
    display: grid;
    place-items: center;
    gap: 8px;
    padding: 24px 18px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: linear-gradient(180deg, #151b23, #0b1016);
    color: #fff;
    cursor: pointer;
    box-shadow: var(--shadow);
}
.fighter-card img { width: 210px; max-width: 78%; height: 210px; object-fit: contain; }
.fighter-card .rank {
    min-width: 34px;
    padding: 4px 8px;
    border-radius: 7px;
    background: linear-gradient(135deg, #f0ce73, #ad6d20);
    color: #171108;
    font-size: 11px;
    font-weight: 950;
}
.fighter-card strong { font-size: clamp(30px, 5vw, 46px); line-height: 1; }
.fighter-card small { color: var(--muted); font-weight: 800; letter-spacing: 0.08em; }
.fighter-card b { margin-top: 8px; padding: 11px 15px; border: 1px solid currentColor; border-radius: 10px; font-size: 12px; }
.fighter-card.ride { color: #ff6675; box-shadow: inset 0 0 0 1px rgba(241, 59, 77, 0.12), 0 20px 55px rgba(241, 59, 77, 0.08); }
.fighter-card.onestr { color: #79a7ff; box-shadow: inset 0 0 0 1px rgba(79, 140, 255, 0.13), 0 20px 55px rgba(79, 140, 255, 0.08); }

.game-section { padding: 20px 0 60px; }
.battle-status { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; margin-bottom: 18px; }
.commander {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #0d1218;
}
.commander-avatar { position: relative; flex: 0 0 60px; width: 60px; height: 60px; }
.commander img { display: block; width: 60px; height: 60px; object-fit: contain; border-radius: 12px; }
.pvp-mode .commander img { object-fit: cover; border: 1px solid rgba(255, 255, 255, 0.14); }
.commander-fallback {
    width: 60px;
    height: 60px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid rgba(227, 182, 82, 0.35);
    border-radius: 12px;
    background: linear-gradient(145deg, #17202c, #0a0f15);
    color: #f0cf7a;
    font-size: 11px;
    font-weight: 950;
    letter-spacing: .04em;
    text-align: center;
}
.commander-fallback.hidden { display: none; }
.commander > div { min-width: 0; }
.commander span, .turn-box span { display: block; color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: 0.1em; }
.commander strong { display: block; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.commander-ride strong { color: #ff5e6e; }
.commander-1str { justify-content: flex-end; text-align: right; }
.commander-1str strong { color: #78a7ff; }
.turn-box { text-align: center; padding: 10px 16px; border: 1px solid rgba(227, 182, 82, 0.28); border-radius: 12px; background: rgba(227, 182, 82, 0.06); }
.turn-box strong { display: block; margin-top: 4px; color: #f0cf7a; }
.turn-countdown { display: block; margin-top: 5px; color: #9fc7f3; font-size: 12px; font-weight: 950; letter-spacing: .08em; }
.turn-countdown.hidden { display: none; }
.turn-countdown.urgent { color: #ff6675; animation: turn-clock-pulse 1s ease-in-out infinite; }
@keyframes turn-clock-pulse { 50% { opacity: .58; } }

.game-layout {
    display: grid;
    grid-template-columns: minmax(130px, 0.6fr) minmax(0, 660px) minmax(130px, 0.6fr);
    gap: 16px;
    align-items: start;
    justify-content: center;
}
.side-column { min-width: 0; display: grid; gap: 16px; align-content: start; }
.captured-panel { min-width: 0; min-height: 180px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: #0b1016; }
.captured-list { display: grid; gap: 8px; margin-top: 10px; }
.captured-item { padding: 8px 9px; border-radius: 9px; background: rgba(255, 255, 255, 0.035); font-size: 11px; }
.captured-item strong { display: block; }
.captured-item small { color: var(--muted); }
.coffee-support {
    min-height: 150px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 3px;
    padding: 16px 10px;
    overflow: hidden;
    border: 1px solid rgba(227, 182, 82, 0.34);
    border-radius: 14px;
    background:
        radial-gradient(circle at 50% 15%, rgba(240, 205, 113, 0.16), transparent 45%),
        linear-gradient(180deg, #11161d, #090d12);
    color: #f5d77f;
    text-align: center;
    text-decoration: none;
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.28);
    transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.coffee-support:hover,
.coffee-support:focus-visible { transform: translateY(-2px); border-color: #f0cd71; box-shadow: 0 18px 48px rgba(227, 182, 82, 0.14); outline: none; }
.coffee-cup { font-size: 52px; line-height: 1; filter: drop-shadow(0 7px 10px rgba(0, 0, 0, 0.5)); }
.coffee-support strong { margin-top: 5px; font-size: 13px; letter-spacing: 0.08em; }
.coffee-support small { color: #f5f7fb; font-size: 10px; font-weight: 850; letter-spacing: 0.12em; }
.board-zone {
    width: min(100%, 660px, calc(100dvh - 190px));
    min-width: 0;
    margin-inline: auto;
}
.chess-board {
    width: 100%;
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    border: 3px solid #252d37;
    border-radius: 12px;
    overflow: hidden;
    background: #202631;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}
.square {
    position: relative;
    min-width: 0;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    padding: 2px;
    cursor: pointer;
    color: #111;
}
.square.light { background: linear-gradient(135deg, #b8a876, #d2c297); }
.square.dark { background: linear-gradient(135deg, #343c46, #262d35); }
.square.selected { box-shadow: inset 0 0 0 4px #f0cd71; }
.square.legal::after { content: ""; width: 22%; height: 22%; border-radius: 50%; background: rgba(255, 229, 135, 0.7); position: absolute; z-index: 1; }
.square.legal.capture::after { width: 76%; height: 76%; border: 4px solid rgba(255, 229, 135, 0.75); background: transparent; }
.square.last-move { box-shadow: inset 0 0 0 3px rgba(227, 182, 82, 0.5); }
.square.own-piece { cursor: pointer; }
.square.opponent-piece { cursor: not-allowed; }
.piece {
    width: 98%;
    height: 98%;
    min-width: 0;
    position: relative;
    z-index: 2;
    overflow: hidden;
    border-radius: 10px;
    user-select: none;
    pointer-events: none;
    text-align: center;
}
.piece-avatar-wrap { position: absolute; inset: 0; display: block; }
.piece-avatar { display: block; width: 100%; height: 100%; object-fit: cover; }
.piece-avatar-wrap::after { content: ""; position: absolute; inset: 48% 0 0; background: linear-gradient(transparent, rgba(0, 0, 0, 0.86)); }
.piece-role { position: absolute; z-index: 2; top: 3px; right: 3px; display: grid; place-items: center; min-width: 23px; height: 23px; padding: 1px 4px; border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 6px; background: rgba(5, 7, 10, 0.86); color: #f5d77f; font-size: clamp(13px, 1.9vw, 19px); line-height: 1; text-shadow: 0 1px 3px #000; }
.piece-name { position: absolute; z-index: 3; right: 2px; bottom: 4px; left: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 2px 3px; border-radius: 4px; color: #fff; background: rgba(0, 0, 0, 0.5); text-shadow: 0 1px 3px #000; font-size: clamp(6px, 1vw, 9px); font-weight: 950; line-height: 1.05; }
.piece.ride { color: #fff; background: linear-gradient(180deg, rgba(128, 19, 31, 0.9), rgba(49, 6, 12, 0.92)); border: 1px solid rgba(255, 98, 112, 0.45); }
.piece.onestr { color: #fff; background: linear-gradient(180deg, rgba(39, 87, 168, 0.92), rgba(12, 31, 67, 0.94)); border: 1px solid rgba(116, 166, 255, 0.48); }
.board-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.primary-btn, .secondary-btn { min-height: 48px; padding: 0 17px; border-radius: 11px; font-weight: 950; cursor: pointer; }
.primary-btn { border: 0; background: linear-gradient(135deg, #f1d27e, #b87827); color: #171108; }
.secondary-btn { border: 1px solid var(--line); background: #0d1218; color: #e7ebf2; }
.piece-info { margin: 16px auto 0; width: min(660px, 100%); padding: 13px 16px; border: 1px solid var(--line); border-radius: 12px; background: #0c1117; text-align: center; }
.piece-info span { display: block; color: #d7b66a; font-size: 9px; font-weight: 900; letter-spacing: 0.12em; }
.piece-info strong { display: block; margin-top: 5px; }

.end-screen { padding: 30px 0 70px; }
.end-card {
    width: min(650px, 100%);
    margin: auto;
    padding: 32px 20px;
    border: 1px solid rgba(241, 59, 77, 0.35);
    border-radius: 22px;
    background: radial-gradient(circle at 50% 15%, rgba(241, 59, 77, 0.16), transparent 38%), linear-gradient(180deg, #15191f, #0b0f14);
    text-align: center;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}
.end-card img { width: 190px; height: 190px; object-fit: contain; }
.end-card > span { display: block; color: #d7b66a; font-size: 12px; font-weight: 950; letter-spacing: 0.16em; }
.end-card h2 { margin: 8px 0; color: #ff5d6e; font-size: clamp(36px, 7vw, 64px); line-height: 0.95; }
.end-card p { color: var(--muted); }
.end-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.token-shop { width: min(900px, 100%); margin: 24px auto; border: 1px solid #58451e; border-radius: 16px; padding: 24px; background: linear-gradient(145deg, #17140d, #0c1118); text-align: center; }
.token-shop p { color: #aab5c4; }
.token-packages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px 0; }
.token-package { border: 1px solid #604b23; border-radius: 12px; background: #11151b; padding: 18px 12px; color: #fff; cursor: pointer; }
.token-package strong, .token-package small { display: block; }
.token-package strong { font-size: 21px; color: var(--gold); }
.token-package small { margin-top: 6px; color: #aab5c4; }
.paypal-token-link { display: inline-block; padding: 13px 22px; border-radius: 9px; background: #ffc439; color: #111; text-decoration: none; font-weight: 950; }
.token-help { font-size: 11px; }
.chess-footer { width: min(900px, calc(100% - 28px)); margin: auto; padding: 26px 0 45px; border-top: 1px solid var(--line); color: #778191; text-align: center; font-size: 11px; line-height: 1.6; }

@media (max-width: 900px) {
    .tournament-leaderboards { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .game-layout { grid-template-columns: 1fr; }
    .captured-panel { min-height: auto; }
    .captured-list { grid-template-columns: repeat(3, 1fr); }
    .board-zone { order: -1; }
    .coffee-support { min-height: 120px; }
}

@media (max-width: 680px) {
    .matchmaking-panel { align-items: stretch; flex-direction: column; }
    .matchmaking-actions button { flex: 1; }
    .chess-kpis { grid-template-columns: 1fr; gap: 6px; }
    .chess-kpis article { padding: 9px 12px; }
    .token-packages { grid-template-columns: 1fr; }
    .chess-topbar { min-height: 54px; }
    .chess-brand-logo { width: auto; max-width: 42vw; height: 46px; }
    .top-actions .small-btn { padding: 0 9px; font-size: 10px; }
    .chess-account span { display: none; }
    .chess-auth-card { padding: 22px 16px; }
    .fighter-grid { grid-template-columns: 1fr; }
    .battle-status { grid-template-columns: 1fr 1fr; }
    .turn-box { grid-column: 1 / -1; grid-row: 2; order: 3; }
    .commander { padding: 7px 8px; }
    .commander img { width: 46px; height: 46px; }
    .captured-list { grid-template-columns: repeat(2, 1fr); }
    .piece-name { bottom: 2px; padding: 1px 2px; font-size: clamp(5px, 1.7vw, 7px); }
    .piece-role { top: 2px; right: 2px; min-width: 17px; height: 17px; padding: 1px 2px; font-size: clamp(10px, 3.3vw, 14px); }
}

@media (max-width: 390px) {
    .tournament-leaderboards { grid-template-columns: 1fr; }
    .chess-page { width: calc(100% - 14px); }
    .chess-topbar { padding-inline: 8px; }
    .chess-brand-logo { width: auto; height: 42px; }
    .top-actions { gap: 5px; }
    .top-actions .small-btn { min-height: 40px; padding: 0 7px; }
    .chess-register-fields { grid-template-columns: 1fr; }
    .chess-register-fields label:first-child { grid-column: auto; }
    .piece-name { font-size: 6px; }
    .piece-role { min-width: 15px; height: 15px; font-size: 10px; }
    .board-controls { grid-template-columns: 1fr; }
}
