/*
 * The shell around the canvas: everything that happens before and between games.
 * Colours come from Telegram's theme so the app matches the client the player
 * is running, with values of our own as a fallback outside Telegram.
 */

:root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --card: var(--tg-theme-secondary-bg-color, #1c2a3a);
    --text: var(--tg-theme-text-color, #f5f5f5);
    --muted: var(--tg-theme-hint-color, #8b9aa9);
    --accent: var(--tg-theme-button-color, #3a8ee6);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overscroll-behavior: none;
}

[hidden] {
    display: none !important;
}

/* ------------------------------------------------------------------ shell */

.shell {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    padding-top: calc(24px + var(--tg-safe-area-inset-top, 0px));
    padding-bottom: calc(24px + var(--tg-safe-area-inset-bottom, 0px));
    z-index: 10;
}

.shell__card {
    width: 100%;
    max-width: 380px;
    background: var(--card);
    border-radius: 20px;
    padding: 32px 24px;
    text-align: center;
}

.shell__dice {
    font-size: 48px;
    line-height: 1;
    margin-bottom: 12px;
}

.shell__title {
    margin: 0 0 8px;
    font-size: 22px;
    font-weight: 600;
}

.shell__text {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.5;
    white-space: pre-line;
}

.shell__spinner {
    width: 28px;
    height: 28px;
    margin: 20px auto 0;
    border: 3px solid color-mix(in srgb, var(--muted) 35%, transparent);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

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

.shell__actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 24px;
}

.btn {
    appearance: none;
    border: 0;
    border-radius: 12px;
    padding: 14px 18px;
    font-size: 16px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    background: color-mix(in srgb, var(--text) 10%, transparent);
    color: var(--text);
}

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

.btn:active {
    opacity: 0.75;
}

.shell__stats {
    display: flex;
    justify-content: space-around;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid color-mix(in srgb, var(--muted) 25%, transparent);
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat__value {
    font-size: 20px;
    font-weight: 600;
}

.stat__label {
    font-size: 12px;
    color: var(--muted);
}

/* ------------------------------------------------------------------ board */

.view-game {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: #000;
}

/*
 * The board is drawn on a fixed 1360x840 coordinate space. The shared library's
 * sizeHandler() tries to scale an element called #maincanvas, which does not
 * exist here — the old project sized the canvas from its own game-centre script
 * instead. So the fitting is done here, in CSS.
 *
 * Intrinsic size comes from the canvas width/height attributes, so capping both
 * dimensions scales it down proportionally and letterboxes it. CreateJS maps
 * pointer coordinates through the element's bounding rect, so clicks still land
 * on the right point after scaling.
 */
#canvas {
    display: block;
    position: absolute;
    inset: 0;
    margin: auto;
    max-width: 100%;
    max-height: 100%;
}

/*
 * "Please rotate your device", shown over everything.
 *
 * The stylesheet it comes with gives it no display rule at all, so it is visible
 * from the start and only ever hidden by _checkOrientation() — which does
 * nothing unless the client is a phone. On desktop, where the window cannot be
 * rotated, that left a permanent black screen. Hidden by default here; the
 * game's own script still shows it inline on a phone held the wrong way.
 */
.orientation-msg-container {
    display: none;
}

#block_game {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    display: none;
}

/*
 * Fixed strip over the board.
 *
 * Each player sees their own checkers rendered light and the opponent's dark,
 * whichever colour they were actually dealt — so the board alone never says who
 * is who or who is to move. This does.
 */
.hud {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px;
    padding-top: calc(8px + var(--tg-safe-area-inset-top, 0px));
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
    color: #fff;
    font-size: 13px;
    pointer-events: none;
}

.hud__side {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.hud__side--right {
    justify-content: flex-end;
}

.hud__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 30vw;
}

.hud__dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex: none;
    border: 1px solid rgba(0, 0, 0, 0.5);
}

/* Matches the pieces on the board: yours are always the light ones. */
.hud__dot--you {
    background: #f2ede3;
}

.hud__dot--them {
    background: #a3242b;
}

.hud__middle {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.hud__turn {
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    font-weight: 600;
    white-space: nowrap;
}

.hud__clock {
    font-variant-numeric: tabular-nums;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Last thirty seconds: worth noticing without being alarming. */
.hud__clock--low {
    color: #ffb74d;
}

.hud__clock--critical {
    color: #ff6b6b;
    animation: clock-pulse 1s steps(2, end) infinite;
}

@keyframes clock-pulse {
    50% {
        opacity: 0.35;
    }
}

@media (prefers-reduced-motion: reduce) {
    .hud__clock--critical {
        animation: none;
    }
}

.hud__turn--yours {
    background: #2e7d32;
}

.hud__turn--theirs {
    background: rgba(255, 255, 255, 0.14);
}

.hud__turn--over {
    background: #8e6d1f;
}

/* A short-lived banner over the board: whose turn it is, connection state. */
.toast {
    position: fixed;
    left: 50%;
    top: calc(12px + var(--tg-safe-area-inset-top, 0px));
    transform: translateX(-50%);
    z-index: 20;
    max-width: 90vw;
    padding: 10px 18px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    font-size: 14px;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.toast--visible {
    opacity: 1;
}
