:root {
    --bg: #1b1512;
    --text: #f1e9dc;
    --muted: #b8a993;
    --accent: #e0a63a;
    --frame: #5b3a21;
    --felt: #1f4d33;
    --bar: #4a2f1b;
    --tray: #3a2415;
    --point-light: #d9c39a;
    --point-dark: #9a3a25;
    --white-checker: #f4eee3;
    --white-edge: #8d8274;
    --black-checker: #2a2624;
    --black-edge: #050505;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Botones y controles comunes */

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--frame);
    background: var(--tray);
    color: var(--text);
    touch-action: manipulation;
}

.icon-button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.menu-button,
.controls button {
    min-height: 48px;
    padding: 0 18px;
    border-radius: 10px;
    border: 1px solid var(--frame);
    background: var(--tray);
    color: var(--text);
    font-size: 1rem;
    touch-action: manipulation;
}

.menu-button.primary,
.controls button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #2a1a0c;
    font-weight: 600;
}

/* Acciones secundarias (rendirse, cancelar): texto, sin ocupar un botón grande. */
.controls button.link-button {
    min-height: 32px;
    padding: 0;
    border: none;
    background: none;
    color: var(--muted);
    font-size: 0.9rem;
}

.controls button:disabled {
    opacity: 0.4;
}

.language {
    min-height: 40px;
    background: var(--tray);
    color: var(--text);
    border: 1px solid var(--frame);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 1rem;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    font-size: 0.95rem;
    cursor: pointer;
}

.toggle input {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    accent-color: var(--accent);
}

.hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.85rem;
}

/* Menú (vertical) */

.menu {
    display: flex;
    flex-direction: column;
    gap: 18px;
    max-width: 480px;
    min-height: 100dvh;
    margin: 0 auto;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.menu-header h1 {
    margin: 24px 0 8px;
    text-align: center;
    font-size: 1.9rem;
    letter-spacing: 0.04em;
}

.menu-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border: 1px solid #3a2c22;
    border-radius: 12px;
    background: #241c17;
}

.menu-section h2 {
    margin: 0;
    color: var(--muted);
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

/* Cuenta y formularios */

.account-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    min-height: 32px;
}

.account-name {
    font-weight: 600;
}

.link-button {
    padding: 4px 6px;
    border: none;
    background: none;
    color: var(--accent);
    font-size: 0.95rem;
    text-decoration: underline;
    cursor: pointer;
}

.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.tab {
    min-height: 40px;
    border: 1px solid var(--frame);
    border-radius: 8px;
    background: none;
    color: var(--muted);
    font-size: 0.95rem;
}

.tab.active {
    background: var(--tray);
    color: var(--text);
    font-weight: 600;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.9rem;
}

.form-field input {
    min-height: 44px;
    padding: 8px 10px;
    border: 1px solid var(--frame);
    border-radius: 8px;
    background: #1f1814;
    color: var(--text);
    font-size: 1rem;
}

.form-error {
    margin: 0;
    color: #e57373;
    font-size: 0.9rem;
}

.form-separator {
    margin: 0;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

a.menu-button {
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

/* Menú principal y pantallas secundarias */

.menu-entries {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.menu-entry {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 14px 16px;
    border: 1px solid #3a2c22;
    border-radius: 12px;
    background: #241c17;
    color: var(--text);
    text-align: left;
    font-size: 1.05rem;
    touch-action: manipulation;
}

.menu-entry small {
    color: var(--muted);
    font-size: 0.82rem;
}

.menu-entry:disabled {
    opacity: 0.45;
}

.page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.page-header h1 {
    margin: 0;
    font-size: 1.3rem;
}

.choice-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.choice {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-height: 56px;
    padding: 8px;
    border: 1px solid var(--frame);
    border-radius: 10px;
    background: var(--tray);
    color: var(--text);
    touch-action: manipulation;
}

.choice small {
    color: var(--muted);
}

.choice.selected {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.challenge {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid #3a2c22;
}

.challenge-actions,
.toast-actions {
    display: flex;
    gap: 8px;
}

.challenge-actions button,
.toast-actions button:not(.link-button) {
    min-height: 40px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid var(--frame);
    background: var(--tray);
    color: var(--text);
}

.challenge-actions button.primary,
.toast-actions button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #2a1a0c;
    font-weight: 600;
}

.searching {
    align-items: center;
    text-align: center;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #3a2c22;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Avisos (desafíos recibidos, respuestas) */

.toasts {
    position: fixed;
    left: 50%;
    bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(440px, calc(100% - 24px));
    transform: translateX(-50%);
}

.toast {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
    border: 1px solid var(--accent);
    border-radius: 12px;
    background: #2a2019;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

/* Juego: tablero a toda la altura y panel lateral */

.game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 180px;
    align-items: center;
    gap: 10px;
    max-width: 1280px;
    height: 100dvh;
    margin: 0 auto;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.game-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-self: stretch;
    overflow-y: auto;
}

.game-panel-top {
    display: flex;
    justify-content: space-between;
}

.status {
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: center;
    font-size: 0.9rem;
}

.chip {
    padding: 4px 8px;
    border-radius: 999px;
    border: 2px solid transparent;
    white-space: nowrap;
}

.chip.white {
    background: var(--white-checker);
    color: #2a2624;
}

.chip.black {
    background: var(--black-checker);
    color: var(--text);
}

.chip.on-turn {
    border-color: var(--accent);
}

.status .chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.chip .clock {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.chip .clock .delay {
    margin-right: 6px;
    color: var(--accent);
}

.chip.white .clock .delay {
    color: #9a6a12;
}

.chip .clock.low {
    color: #d9534f;
}

.game-panel .toggle {
    min-height: 32px;
    font-size: 0.85rem;
}

.match-score {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.match-score small {
    color: var(--accent);
    font-weight: 600;
}

.seat {
    position: relative;
    display: flex;
    flex-direction: column;
}

.chip-name {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.presence {
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    border-radius: 50%;
}

.presence.online { background: #5ccf7c; }
.presence.offline { background: #8a7d70; }

.speech {
    align-self: center;
    margin-top: 4px;
    padding: 3px 10px;
    border-radius: 10px;
    background: var(--accent);
    color: #2a1a0c;
    font-size: 0.85rem;
    font-weight: 600;
}

.quick-message-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 6px;
}

.quick-message-list button {
    min-height: 36px;
    border: 1px solid var(--frame);
    border-radius: 8px;
    background: var(--tray);
    color: var(--text);
    font-size: 0.85rem;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Celular en vertical sin pantalla completa: se pide girarlo. */

.rotate-overlay {
    display: none;
}

@media (orientation: portrait) and (max-width: 700px) {
    .rotate-overlay {
        position: fixed;
        inset: 0;
        z-index: 50;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 14px;
        padding: 24px;
        background: var(--bg);
        text-align: center;
    }

    .rotate-overlay p {
        margin: 0 0 8px;
        font-size: 1.15rem;
    }

    .rotate-overlay .menu-button {
        width: min(100%, 320px);
    }

    .rotate-icon {
        width: 72px;
        height: 72px;
        fill: none;
        stroke: var(--accent);
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }
}

/* Tablero */

.board {
    display: block;
    width: 100%;
    height: auto;
    max-height: calc(100dvh - 16px);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.board .frame { fill: var(--frame); }
.board .felt { fill: var(--felt); }
.board .bar { fill: var(--bar); }
.board .tray { fill: var(--tray); }
.board .point-light { fill: var(--point-light); }
.board .point-dark { fill: var(--point-dark); }

.board .point-label {
    fill: var(--muted);
    font-size: 11px;
    text-anchor: middle;
    dominant-baseline: central;
}

.board .highlight { pointer-events: none; }
.board .highlight.movable { fill: rgba(224, 166, 58, 0.18); }
.board .highlight.selected { fill: rgba(224, 166, 58, 0.45); }
.board .highlight.target { fill: rgba(90, 220, 130, 0.38); }

.board .checker {
    transition: transform 260ms ease-out;
    pointer-events: none;
}

.board .checker.white circle, .board .checker.white rect {
    fill: var(--white-checker);
    stroke: var(--white-edge);
    stroke-width: 2;
}

.board .checker.black circle, .board .checker.black rect {
    fill: var(--black-checker);
    stroke: var(--black-edge);
    stroke-width: 2;
}

.board .checker circle.inner {
    fill: none;
    stroke-width: 1.5;
    opacity: 0.55;
}

.board .die rect { stroke-width: 1.5; }
.board .die.white rect { fill: var(--white-checker); stroke: var(--white-edge); }
.board .die.white circle { fill: #2a2624; }
.board .die.black rect { fill: var(--black-checker); stroke: #6b625b; }
.board .die.black circle { fill: var(--white-checker); }
.board .die { cursor: pointer; }
.board .die.used { opacity: 0.3; }
.board .die.unusable { opacity: 0.3; filter: grayscale(1); }
.board .die.next rect { stroke: var(--accent); stroke-width: 3.5; }
.board .die.blocked { opacity: 0.6; }
.board .die.blocked rect { stroke: #d9534f; stroke-width: 3.5; }

.board .cube rect {
    fill: #f7f2e8;
    stroke: #6b625b;
}

.board .cube text {
    fill: #2a2624;
    font-size: 17px;
    font-weight: 700;
    text-anchor: middle;
}

.board .hit {
    fill: transparent;
    cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
    .board .checker { transition: none; }
}

/* Plantilla de Blazor: error y progreso de carga */

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    color: #222;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
    }

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto 0 auto;
}

    .loading-progress circle {
        fill: none;
        stroke: #3a2c22;
        stroke-width: 0.6rem;
        transform-origin: 50% 50%;
        transform: rotate(-90deg);
    }

        .loading-progress circle:last-child {
            stroke: var(--accent);
            stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
            transition: stroke-dasharray 0.05s ease-in-out;
        }

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

    .loading-progress-text:after {
        content: var(--blazor-load-percentage-text, "Loading");
    }
