/* DomaChess (spec C01). Diseño del insumo (tablero oscuro, magenta para la
   selección y las jugadas posibles), con los tokens de global.css. Mobile-first:
   el tablero ocupa el ancho; el 10×8 entra en 390 px con casillas de ~37 px. */

.ch-body { background: radial-gradient(circle at top, rgba(var(--color-brand-rgb), 0.12) 0%, var(--color-bg) 60%); }

.ch { width: 100%; max-width: 760px; margin: 0 auto; padding: var(--space-4, 16px) var(--space-3, 12px) var(--space-6, 24px); }
.ch-screen { display: none; flex-direction: column; gap: var(--space-3, 12px); }
.ch-screen.is-active { display: flex; }

.ch-logo { display: flex; align-items: center; justify-content: center; gap: 6px; margin: var(--space-4, 16px) 0; font-size: clamp(2.4rem, 11vw, 3.4rem); font-weight: var(--font-black); color: var(--color-text); }
.ch-logo-tag { padding: 0 12px; border-radius: var(--radius-md); background: var(--color-brand); color: var(--color-text); box-shadow: var(--shadow-brand); }

.ch-panel {
    display: flex; flex-direction: column; gap: var(--space-4, 16px); width: 100%; max-width: 500px; margin: 0 auto;
    padding: var(--space-5, 20px); background: var(--color-surface); border: 1px solid var(--border-default); border-radius: var(--radius-xl);
}
.ch-group { display: flex; flex-direction: column; gap: var(--space-2, 8px); flex: 1; min-width: 0; }
.ch-row { display: flex; gap: var(--space-3, 12px); }
.ch-label { font-size: var(--text-xs); font-weight: var(--font-bold); letter-spacing: 2px; text-transform: uppercase; color: var(--color-text-muted); }
.ch-note { margin: 0; font-size: var(--text-xs); color: var(--color-brand); }

.ch-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--space-2, 8px); }
.ch-seg-opt {
    min-height: 48px; padding: var(--space-2, 8px); border-radius: var(--radius-md);
    background: var(--color-surface-2); border: 2px solid var(--border-hover); color: var(--color-text-muted);
    font: inherit; font-size: var(--text-sm); font-weight: var(--font-bold); cursor: pointer;
}
.ch-seg-opt[aria-checked="true"] { background: var(--color-brand); border-color: var(--color-brand); color: var(--color-text); }
.ch-seg-opt:disabled { opacity: 0.4; cursor: not-allowed; }

.ch-select {
    min-height: 48px; padding: 0 var(--space-3, 12px); border-radius: var(--radius-sm);
    background: var(--color-bg); border: 1px solid var(--border-hover); color: var(--color-text); font: inherit;
}
.ch-select:focus { outline: none; border-color: var(--color-brand); }

.ch-btn {
    min-height: 48px; padding: 0 var(--space-4, 16px); border-radius: var(--radius-md);
    background: var(--color-surface-2); border: 1px solid var(--border-hover); color: var(--color-text);
    font: inherit; font-weight: var(--font-bold); cursor: pointer;
}
.ch-btn--primary { background: var(--color-brand); border-color: var(--color-brand); font-size: var(--text-lg); box-shadow: var(--shadow-brand); }
.ch-btn--danger { color: var(--color-danger); border-color: rgba(255, 82, 82, 0.4); }
.ch-btn:disabled { opacity: 0.4; cursor: default; }
.ch-icon-btn { width: 44px; height: 44px; flex: none; display: flex; align-items: center; justify-content: center; background: var(--color-surface-2); border: 1px solid var(--border-default); border-radius: var(--radius-sm); color: var(--color-text); cursor: pointer; }

/* HUD */
.ch-hud { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2, 8px); min-height: 40px; }
.ch-player { display: flex; align-items: center; gap: var(--space-2, 8px); min-width: 0; }
.ch-player-name { font-weight: var(--font-bold); color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-clock {
    padding: 4px 12px; border-radius: var(--radius-sm); background: var(--color-surface); border: 1px solid var(--border-default);
    font-family: var(--font-mono); font-size: var(--text-lg); color: var(--color-text-muted); font-variant-numeric: tabular-nums;
}
.ch-clock.is-running { color: var(--color-brand); border-color: var(--color-brand); }
.ch-clock.is-low { color: var(--color-danger); border-color: var(--color-danger); }
.ch-status { font-size: var(--text-sm); font-weight: var(--font-bold); color: var(--color-text-muted); text-align: right; }
.ch-status.is-check { color: var(--color-danger); }

/* Tablero */
.ch-board-wrap { width: 100%; }
.ch-board {
    display: grid; width: 100%; border: 4px solid var(--color-surface-3); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg); overflow: hidden; touch-action: manipulation; user-select: none;
}
/* El tablero entra en la pantalla con el HUD y los botones (~340 px) sin tener que bajar. */
.ch-board[data-cols="8"] { grid-template-columns: repeat(8, 1fr); max-width: min(600px, calc(100dvh - 340px)); margin: 0 auto; }
.ch-board[data-cols="10"] { grid-template-columns: repeat(10, 1fr); max-width: min(100%, calc((100dvh - 340px) * 1.25)); margin: 0 auto; }
.ch-sq {
    position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
    padding: 0; border: 0; cursor: pointer; font: inherit;
    background: color-mix(in srgb, var(--color-text) 20%, var(--color-surface-2));   /* casilla clara */
}
.ch-sq.is-dark { background: color-mix(in srgb, var(--color-brand) 10%, var(--color-surface-2)); }
.ch-sq.is-last::before { content: ''; position: absolute; inset: 0; background: rgba(var(--color-brand-rgb), 0.22); }
.ch-sq.is-selected { background: rgba(var(--color-brand-rgb), 0.55); }
.ch-sq.is-check { background: rgba(255, 82, 82, 0.55); }
.ch-sq.is-target::after { content: ''; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgba(var(--color-brand-rgb), 0.85); box-shadow: 0 0 8px var(--color-brand-glow); }
.ch-sq.is-target.has-piece::after { width: auto; height: auto; inset: 0; border-radius: 0; background: none; border: 4px solid rgba(var(--color-brand-rgb), 0.85); box-shadow: none; }
.ch-sq:focus-visible { outline: 2px solid var(--color-brand); outline-offset: -2px; }
.ch-coord { position: absolute; font-size: 9px; color: var(--color-text-muted); opacity: 0.7; pointer-events: none; }
.ch-coord--file { right: 3px; bottom: 1px; }
.ch-coord--rank { left: 3px; top: 1px; }

/* Piezas: glifos Unicode como el insumo. Canciller y arzobispo = torre o alfil con un caballito. */
.ch-piece { position: relative; z-index: 1; line-height: 1; font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif; font-size: clamp(1.4rem, 7.6vw, 3rem); pointer-events: none; }
.ch-board[data-cols="10"] .ch-piece { font-size: clamp(1.2rem, 6.2vw, 2.6rem); }
.ch-piece.is-w { color: var(--color-text); filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.95)) drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6)); }
.ch-piece.is-b { color: var(--color-bg); filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.95)) drop-shadow(0 0 2px rgba(255, 255, 255, 0.35)); }
.ch-piece-mini { position: absolute; right: -0.25em; bottom: -0.15em; font-size: 0.5em; }

/* Historial */
.ch-history { display: flex; align-items: center; gap: var(--space-2, 8px); }
.ch-moves {
    display: flex; flex: 1; gap: 4px; min-width: 0; margin: 0; padding: 6px; list-style: none;
    overflow-x: auto; background: var(--color-surface); border: 1px solid var(--border-default); border-radius: var(--radius-sm);
    scrollbar-width: thin;
}
.ch-move { flex: none; padding: 2px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: var(--text-sm); color: var(--color-text-muted); cursor: pointer; }
.ch-move.is-current { background: var(--color-brand); color: var(--color-text); }
.ch-move-n { flex: none; padding: 2px 0 2px 4px; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-text-dim); }

.ch-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: var(--space-2, 8px); }

/* Modal (promoción, fin de partida) */
.ch-modal { position: fixed; inset: 0; z-index: 2147480000; display: flex; align-items: center; justify-content: center; padding: var(--space-4, 16px); background: rgba(0, 0, 0, 0.85); backdrop-filter: var(--blur-sm); -webkit-backdrop-filter: var(--blur-sm); }
.ch-modal[hidden] { display: none; }
.ch-modal-card { width: 100%; max-width: 420px; padding: var(--space-6, 24px); text-align: center; background: var(--color-surface-2); border: 2px solid var(--color-brand); border-radius: var(--radius-lg); box-shadow: var(--shadow-brand); }
.ch-modal-title { margin: 0 0 var(--space-3, 12px); font-size: var(--text-2xl); font-weight: var(--font-black); letter-spacing: 1px; text-transform: uppercase; color: var(--color-brand); }
.ch-modal-body { color: var(--color-text-muted); }
.ch-modal-actions { display: flex; flex-direction: column; gap: var(--space-2, 8px); margin-top: var(--space-4, 16px); }
.ch-promo { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3, 12px); }
.ch-promo-btn { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; background: var(--color-surface); border: 2px solid var(--color-brand); border-radius: var(--radius-md); cursor: pointer; }
.ch-promo-btn .ch-piece { font-size: 2.6rem; }

@media (min-width: 768px) {
    .ch { padding-top: var(--space-6, 24px); }
}
