/* Remote chess guest page - DEV PROTOTYPE. Mobile first; no horizontal scrolling down to 320 px. */

:root {
    --bg: #fbf5ea;
    --surface: #ffffff;
    --ink: #2a2622;
    --muted: #6f665c;
    --line: #e7dccb;
    --primary: #2f7d4f;
    --primary-ink: #ffffff;
    --primary-soft: #e1f1e6;
    --warn: #9a5b00;
    --warn-soft: #fff3d6;
    --bad: #b3261e;
    --bad-soft: #fde7e5;
    --sq-light: #f0d9b5;
    --sq-dark: #b58863;
    --frame: #7a5638;
    --radius: 18px;
    --shadow: 0 6px 18px rgba(60, 40, 20, 0.12);
    color-scheme: light;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font: 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overflow-x: hidden;
}

button,
input {
    font: inherit;
    color: inherit;
}

h1,
h2 {
    line-height: 1.15;
}

.boot {
    padding: 48px 16px;
    text-align: center;
    font-size: 1.2rem;
    color: var(--muted);
}

.screen {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.center {
    text-align: center;
}

/* ---------------------------------------------------------------- buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 52px;
    padding: 10px 16px;
    border-radius: 14px;
    border: 2px solid var(--line);
    background: var(--surface);
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn:hover:not(:disabled) {
    border-color: #d6c6ae;
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

.btn:focus-visible,
.emote:focus-visible,
.sq:focus-visible {
    outline: 3px solid #1565c0;
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-ink);
}

.btn-primary:hover:not(:disabled) {
    border-color: #23633e;
    background: #296f46;
}

.btn-danger {
    color: var(--bad);
    border-color: #efc4c0;
}

.btn-big {
    width: 100%;
    min-height: 60px;
    margin-top: 18px;
    font-size: 1.3rem;
}

.btn-link {
    background: none;
    border: none;
    min-height: 44px;
    color: var(--muted);
    text-decoration: underline;
    font-weight: 600;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.actions .btn {
    flex: 1 1 140px;
}

/* ---------------------------------------------------------------- 1. join */

.screen-join {
    max-width: 520px;
}

.hero {
    text-align: center;
    margin: 8px 0 18px;
}

.hero-icon {
    width: 88px;
    height: 88px;
}

.hero h1 {
    margin: 4px 0 6px;
    font-size: 2.1rem;
}

.hero p {
    margin: 0;
    color: var(--muted);
}

label {
    display: block;
    margin: 6px 0;
    font-size: 1.1rem;
    font-weight: 800;
}

input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--line);
    border-radius: 14px;
    background: #fffdf9;
    font-size: 1.3rem;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

#code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 0.22em;
    text-align: center;
    text-transform: uppercase;
}

#code::placeholder {
    color: #d3c5b2;
}

.hint {
    margin: 6px 0 16px;
    color: var(--muted);
    font-size: 0.95rem;
}

.error {
    margin: 14px 0 0;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--bad-soft);
    color: var(--bad);
    font-weight: 700;
}

.dev-note {
    margin-top: 18px;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

/* ---------------------------------------------------------------- 2. waiting */

.screen-wait {
    max-width: 520px;
    padding-top: 12vh;
}

.spinner {
    width: 64px;
    height: 64px;
    margin: 8px auto 16px;
    border-radius: 50%;
    border: 7px solid var(--primary-soft);
    border-top-color: var(--primary);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.wait-icon {
    font-size: 3rem;
    line-height: 1;
    margin: 4px 0 10px;
}

.wait-text {
    margin: 0 0 16px;
    font-size: 1.3rem;
    font-weight: 700;
}

.wait-text.is-error {
    color: var(--bad);
}

/* ---------------------------------------------------------------- 3. game */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    max-width: 640px;
    margin: 0 auto 10px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 800;
    white-space: nowrap;
}

.brand img {
    width: 28px;
    height: 28px;
}

.conn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 65%;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow);
    font-size: 0.85rem;
    font-weight: 700;
}

.conn #conn-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conn .dot {
    flex: none;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #9e9e9e;
}

.conn.ok .dot {
    background: #2e7d32;
}

.conn.warn .dot {
    background: #f9a825;
}

.conn.bad {
    color: var(--bad);
}

.conn.bad .dot {
    background: var(--bad);
}

.game {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 640px;
    margin: 0 auto;
}

.col-board,
.col-side {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.col-board {
    width: min(100%, max(288px, 62vh), 640px);
    align-self: center;
}

.col-side {
    gap: 12px;
}

.player {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 7px 12px;
    border: 2px solid transparent;
    border-radius: 14px;
    background: var(--surface);
}

.player.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.player .chip {
    flex: none;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #efe6d8;
}

.player .chip img {
    width: 32px;
    height: 32px;
}

.pname {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
}

.pstatus {
    flex: none;
    color: var(--muted);
    font-size: 0.9rem;
    white-space: nowrap;
}

.board-wrap {
    position: relative;
    width: 100%;
}

.board {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
    width: 100%;
    aspect-ratio: 1 / 1;
    border: 4px solid var(--frame);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow);
    background: var(--frame);
    touch-action: none; /* tap and drag on the board must not scroll the page */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.sq {
    position: relative;
    display: block;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--sq-light);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
}

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

.sq .piece {
    position: absolute;
    inset: 4%;
    width: 92%;
    height: 92%;
    z-index: 2;
    pointer-events: none;
    -webkit-user-drag: none;
}

.sq.last::before,
.sq.sel::before,
.sq.check::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
}

.sq.last::before {
    background: rgba(255, 213, 79, 0.55);
}

.sq.sel::before {
    background: rgba(30, 136, 229, 0.35);
    box-shadow: inset 0 0 0 4px rgba(21, 101, 192, 0.9);
}

.sq.check::before {
    background: radial-gradient(circle, rgba(229, 57, 53, 0.95) 0%, rgba(229, 57, 53, 0.6) 40%, rgba(229, 57, 53, 0) 75%);
}

.sq.target::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 3;
    width: 32%;
    height: 32%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgba(20, 20, 20, 0.28);
    pointer-events: none;
}

.sq.target.capture::after {
    width: 94%;
    height: 94%;
    background: transparent;
    border: 5px solid rgba(20, 20, 20, 0.3);
}

.sq.dragging .piece {
    opacity: 0.3;
}

.coord {
    position: absolute;
    z-index: 4;
    font-size: clamp(9px, 2.4vw, 13px);
    font-weight: 800;
    line-height: 1;
    pointer-events: none;
}

.coord.file {
    right: 3px;
    bottom: 2px;
}

.coord.rank {
    left: 3px;
    top: 2px;
}

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

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

.drag-ghost {
    position: fixed;
    z-index: 300;
    pointer-events: none;
    transform: translate(-50%, -60%) scale(1.15);
    filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.35));
}

.net-banner {
    position: absolute;
    left: 8px;
    right: 8px;
    top: 8px;
    z-index: 15;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--bad);
    color: #fff;
    text-align: center;
    box-shadow: var(--shadow);
}

.net-banner strong {
    display: block;
    font-size: 1.1rem;
}

.turn {
    padding: 12px 14px;
    border-radius: 14px;
    background: #efe6d8;
    text-align: center;
    font-size: 1.35rem;
    font-weight: 800;
}

.turn .sub {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    opacity: 0.9;
}

.turn.mine {
    background: var(--primary);
    color: #fff;
}

.turn.check {
    background: var(--bad);
    color: #fff;
}

.turn.warn {
    background: var(--warn-soft);
    color: var(--warn);
}

.turn.over {
    background: #e8eaf6;
    color: #283593;
}

.draw-box {
    padding: 12px;
    border: 2px solid #ffe082;
    border-radius: 14px;
    background: #fff8e1;
    text-align: center;
}

.draw-box p {
    margin: 0 0 10px;
    font-weight: 800;
}

.draw-box.subtle {
    border-color: var(--line);
    background: var(--surface);
}

.draw-box.subtle p {
    margin: 0;
    color: var(--muted);
    font-weight: 600;
}

.emotes {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.emote {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 66px;
    padding: 6px 4px;
    border: 2px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.emote .emo {
    font-size: 1.75rem;
    line-height: 1.1;
}

.emote .lbl {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
}

.emote:active:not(:disabled),
.emote.sent {
    transform: scale(0.94);
    border-color: var(--primary);
    background: var(--primary-soft);
}

.emote:disabled {
    opacity: 0.45;
    cursor: default;
}

.game-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.game-actions .btn {
    font-size: 0.95rem;
}

/* ---------------------------------------------------------------- 4. result (overlay on the board) */

.result {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border-radius: 10px;
    background: rgba(42, 38, 34, 0.45);
    overflow: auto;
}

.result-card {
    width: 100%;
    max-width: 380px;
    margin: auto;
    padding: 16px;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    text-align: center;
}

.result-icon {
    font-size: 2.8rem;
    line-height: 1;
}

.result-title {
    margin: 6px 0;
    font-size: 1.6rem;
}

.result-reason {
    margin: 0 0 6px;
    font-weight: 700;
}

.result-note {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 0.92rem;
}

/* ---------------------------------------------------------------- toasts & modal */

.toasts {
    position: fixed;
    left: 50%;
    top: max(12px, env(safe-area-inset-top));
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(420px, calc(100% - 32px));
    transform: translateX(-50%);
    pointer-events: none;
}

.toast {
    padding: 12px 16px;
    border-radius: 14px;
    background: #2a2622;
    color: #fff;
    box-shadow: var(--shadow);
    text-align: center;
    font-weight: 700;
    animation: toast-in 0.2s ease-out;
}

.toast.warn {
    background: var(--warn);
}

.toast.mine {
    background: var(--primary);
}

.toast.emote {
    border: 3px solid #ffd54f;
    background: #fff;
    color: var(--ink);
    font-size: 1.15rem;
}

.toast .big {
    display: block;
    font-size: 2.8rem;
    line-height: 1.1;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

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

.modal-card {
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 32px);
    overflow: auto;
    padding: 20px;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    text-align: center;
}

.modal-card h2 {
    margin: 0 0 8px;
    font-size: 1.4rem;
}

.modal-card p {
    margin: 0 0 16px;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.modal-actions .btn {
    flex: 1 1 140px;
}

.modal-actions.pieces .btn {
    flex: 0 0 auto;
    flex-direction: column;
    gap: 0;
    width: 64px;
    min-height: 78px;
    padding: 4px;
    font-size: 0.72rem;
}

.modal-actions.pieces img {
    width: 48px;
    height: 48px;
}

.modal-actions .btn-cancel {
    flex-basis: 100%;
}

/* ---------------------------------------------------------------- layouts */

@media (max-width: 380px) {
    body {
        font-size: 16px;
    }
    .card {
        padding: 16px;
    }
    #code {
        font-size: 1.7rem;
        letter-spacing: 0.16em;
    }
}

/* Desktop / landscape tablet: board on the left, controls on the right. */
@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
    .topbar {
        max-width: 1100px;
    }
    .game {
        --board: min(calc(100vw - 440px), max(320px, calc(100vh - 210px)), 720px);
        display: grid;
        grid-template-columns: var(--board) 340px;
        justify-content: center;
        align-items: start;
        gap: 24px;
        max-width: 1100px;
    }
    .col-board {
        width: 100%;
    }
    .col-side {
        padding-top: 54px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation-duration: 3s;
    }
    .toast {
        animation: none;
    }
}
