:root {
    --cream: #f7f1e8;
    --cream-deep: #eadcc9;
    --paper: rgba(255, 255, 255, 0.88);
    --navy: #1e3347;
    --blue: #446b8e;
    --muted: #6e7d89;
    --soft: #dfe8ef;
    --green: #557a58;
    --gold: #d7a943;
    --danger: #b94a48;
    --success: #43765a;

    --light-square: #f0d9b5;
    --dark-square: #b58863;
    --light-square-selected: #f8e6a0;
    --dark-square-selected: #d6b25c;

    --shadow: 0 22px 60px rgba(30, 51, 71, 0.16);
    --shadow-small: 0 10px 24px rgba(30, 51, 71, 0.12);
    --radius-lg: 28px;
    --radius-md: 20px;
    --radius-sm: 14px;
}

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

html {
    min-height: 100%;
    background: var(--cream);
}

body {
    min-height: 100%;
    padding: 18px 14px 56px;
    color: var(--navy);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(68, 107, 142, 0.18), transparent 28rem),
        radial-gradient(circle at top right, rgba(215, 169, 67, 0.20), transparent 24rem),
        linear-gradient(180deg, #f7f1e8 0%, #edf4f6 100%);
}

button,
select,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.hidden {
    display: none !important;
}

.app-shell {
    width: min(100%, 1120px);
    margin: 0 auto;
}

.login-overlay {
    min-height: calc(100vh - 74px);
    display: grid;
    place-items: center;
}

.login-card,
.hero-card,
.panel {
    background: var(--paper);
    border: 1px solid rgba(255, 255, 255, 0.92);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.login-card {
    width: min(100%, 480px);
    padding: clamp(24px, 6vw, 40px);
}

.login-card h1,
.hero-card h1 {
    max-width: 760px;
    margin-top: 14px;
    font-size: clamp(2.45rem, 10vw, 5rem);
    line-height: 0.92;
    letter-spacing: -0.065em;
}

.login-copy,
.hero-card p,
.helper-text {
    color: var(--muted);
    line-height: 1.5;
    font-weight: 650;
}

.login-copy {
    margin: 14px 0 22px;
}

.hero-card {
    padding: clamp(22px, 5vw, 38px);
    margin-bottom: 18px;
}

.hero-topline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.app-pill,
.section-kicker {
    color: var(--blue);
    font-size: 0.76rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.app-pill {
    display: inline-flex;
    padding: 8px 12px;
    background: #e9f0f4;
    border-radius: 999px;
}

.panel {
    padding: 20px;
}

.lobby-layout,
.game-layout,
.side-column {
    display: grid;
    gap: 18px;
}

.setup-panel {
    min-width: 0;
}

.section-heading,
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}

.section-heading.compact {
    margin-bottom: 12px;
}

h2 {
    margin-top: 3px;
    font-size: 1.55rem;
    line-height: 1.05;
    letter-spacing: -0.04em;
}

.section-icon {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    flex: 0 0 auto;
    background: var(--cream-deep);
    border-radius: 19px;
    font-size: 1.75rem;
}

.form-stack,
.setup-grid {
    display: grid;
    gap: 14px;
}

.two-col {
    grid-template-columns: 1fr;
}

.full-width {
    grid-column: 1 / -1;
}

.field {
    display: grid;
    gap: 8px;
}

.field span {
    font-size: 0.92rem;
    font-weight: 850;
}

select,
input {
    min-height: 54px;
    width: 100%;
    padding: 0 15px;
    color: var(--navy);
    background-color: #fbfdff;
    border: 2px solid rgba(68, 107, 142, 0.22);
    border-radius: var(--radius-sm);
    font-weight: 800;
}

select {
    padding-right: 44px;
    background:
        linear-gradient(45deg, transparent 50%, var(--blue) 50%),
        linear-gradient(135deg, var(--blue) 50%, transparent 50%),
        #fbfdff;
    background-position:
        calc(100% - 22px) 50%,
        calc(100% - 16px) 50%;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    appearance: none;
}

input:focus,
select:focus,
button:focus-visible,
.chess-square:focus-visible {
    outline: 3px solid rgba(68, 107, 142, 0.34);
    outline-offset: 3px;
}

.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn {
    min-height: 52px;
    padding: 13px 17px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 900;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
}

.primary-btn {
    color: white;
    background: linear-gradient(135deg, var(--blue), var(--navy));
    box-shadow: 0 12px 24px rgba(30, 51, 71, 0.20);
}

.secondary-btn {
    color: var(--navy);
    background: #e9f0f4;
}

.danger-btn {
    color: white;
    background: var(--danger);
}

.ghost-btn {
    color: var(--blue);
    background: rgba(255, 255, 255, 0.65);
}

.small-btn {
    min-height: 38px;
    padding: 9px 12px;
    border-radius: 999px;
    font-size: 0.82rem;
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    opacity: 0.58;
    cursor: not-allowed;
}

.helper-text {
    margin-top: 14px;
    font-size: 0.95rem;
}

.error-message {
    color: var(--danger);
    font-weight: 850;
}

.game-panel {
    overflow: hidden;
}

.turn-card {
    min-width: 128px;
    padding: 10px 12px;
    text-align: right;
    background: #e9f0f4;
    border-radius: 18px;
}

.turn-card span {
    display: block;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.turn-card strong {
    display: block;
    margin-top: 2px;
    font-size: 1rem;
}

.inline-code-btn {
    display: inline-flex;
    align-items: center;
    min-height: auto;
    padding: 4px 8px;
    color: var(--navy);
    background: #e9f0f4;
    border: none;
    border-radius: 999px;
    font-weight: 950;
    cursor: pointer;
}

.waiting-card {
    display: grid;
    gap: 8px;
    width: min(100%, 620px);
    margin: 0 auto 16px;
    padding: 16px;
    background: #fff9e9;
    border: 2px solid rgba(215, 169, 67, 0.25);
    border-radius: 18px;
    text-align: center;
}

.waiting-card span {
    color: var(--muted);
    font-weight: 750;
}

.code-card {
    min-height: 64px;
    color: var(--navy);
    background: white;
    border: 2px dashed rgba(68, 107, 142, 0.34);
    border-radius: 16px;
    font-size: 2rem;
    font-weight: 950;
    letter-spacing: 0.16em;
    cursor: pointer;
}

.board-wrap {
    width: min(100%, 620px);
    margin: 0 auto;
}

.player-strip {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
    padding: 10px 14px;
    color: var(--navy);
    background: rgba(255, 255, 255, 0.58);
    border: 1px solid rgba(255, 255, 255, 0.78);
    font-weight: 900;
}

.opponent-strip {
    border-radius: 18px 18px 0 0;
}

.bottom-strip {
    border-radius: 0 0 18px 18px;
}

.player-strip span:last-child {
    color: var(--muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border: 8px solid rgba(30, 51, 71, 0.88);
    box-shadow: var(--shadow-small);
    touch-action: manipulation;
}

.chess-square {
    position: relative;
    display: grid;
    place-items: center;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 0;
    color: #111;
    font-size: clamp(1.85rem, 9vw, 3.75rem);
    line-height: 1;
    cursor: pointer;
    user-select: none;
}

.chess-square.light {
    background: var(--light-square);
}

.chess-square.dark {
    background: var(--dark-square);
}

.chess-square.selected.light {
    background: var(--light-square-selected);
}

.chess-square.selected.dark {
    background: var(--dark-square-selected);
}

.chess-square.last-move.light {
    box-shadow: inset 0 0 0 999px rgba(255, 242, 112, 0.22);
}

.chess-square.last-move.dark {
    box-shadow: inset 0 0 0 999px rgba(255, 242, 112, 0.26);
}

.chess-square.legal-move::after {
    content: "";
    position: absolute;
    width: 28%;
    height: 28%;
    background: rgba(30, 51, 71, 0.32);
    border-radius: 50%;
}

.chess-square.legal-capture::after {
    content: "";
    position: absolute;
    inset: 10%;
    border: 5px solid rgba(30, 51, 71, 0.32);
    border-radius: 50%;
}

.chess-square.in-check {
    box-shadow: inset 0 0 0 999px rgba(185, 74, 72, 0.34);
}

.piece {
    position: relative;
    z-index: 2;
    transform: translateY(-1px);
    filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.20));
    font-family: "Times New Roman", "Georgia", serif;
    font-style: normal;
    font-weight: 400;
    font-variant-ligatures: none;
    -webkit-font-smoothing: antialiased;
    text-rendering: geometricPrecision;
}

.piece.white-piece {
    color: #fffaf0;
    text-shadow:
        0 2px 0 rgba(30, 31, 34, 0.85),
        2px 0 0 rgba(30, 31, 34, 0.85),
        0 -2px 0 rgba(30, 31, 34, 0.85),
        -2px 0 0 rgba(30, 31, 34, 0.85),
        0 5px 7px rgba(0, 0, 0, 0.25);
}

.piece.black-piece {
    color: #1f2429;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}

.square-label {
    position: absolute;
    left: 5px;
    bottom: 4px;
    z-index: 1;
    color: rgba(30, 51, 71, 0.55);
    font-size: clamp(0.48rem, 1.8vw, 0.72rem);
    font-weight: 900;
    pointer-events: none;
}

.game-message {
    min-height: 48px;
    margin: 18px auto 0;
    padding: 13px 14px;
    width: min(100%, 620px);
    color: var(--navy);
    background: rgba(255, 255, 255, 0.66);
    border: 1px solid rgba(68, 107, 142, 0.18);
    border-radius: var(--radius-sm);
    font-weight: 800;
    line-height: 1.35;
}

.game-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    width: min(100%, 620px);
    margin: 14px auto 0;
}

.leaderboard-list,
.move-list,
.info-list {
    display: grid;
    gap: 10px;
}

.leaderboard-row,
.info-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 13px;
    background: rgba(255, 255, 255, 0.62);
    border: 1px solid rgba(68, 107, 142, 0.14);
    border-radius: 16px;
}

.leaderboard-name,
.info-label {
    font-weight: 950;
}

.leaderboard-record,
.info-value {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 850;
}

.record-pill {
    padding: 7px 10px;
    color: white;
    background: var(--navy);
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 900;
}

.status-pill {
    padding: 7px 10px;
    color: white;
    background: var(--success);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 900;
}

.move-list {
    list-style: none;
    max-height: 280px;
    overflow: auto;
}

.move-list li {
    padding: 10px 12px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.60);
    border-radius: 13px;
    font-weight: 800;
}

.move-list li strong {
    color: var(--navy);
}

@media (min-width: 720px) {
    body {
        padding: 28px 22px 72px;
    }

    .two-col {
        grid-template-columns: 1fr 1fr;
    }

    .game-actions {
        grid-template-columns: 1fr 1fr;
    }

    .lobby-layout {
        grid-template-columns: 1fr 1fr;
    }

    .leaderboard-panel {
        grid-column: 1 / -1;
    }
}

@media (min-width: 980px) {
    .game-layout {
        grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.8fr);
        align-items: start;
    }

    .game-panel {
        position: sticky;
        top: 18px;
    }

    .leaderboard-panel {
        grid-column: auto;
    }

    .lobby-layout {
        grid-template-columns: 1fr 1fr minmax(280px, 0.8fr);
        align-items: start;
    }
}
