/* UF — Xadrez Fantasy (chess-fantasy.js). Celular: tabuleiro na largura toda e painéis abaixo.
   Paisagem/telas largas: tabuleiro limitado pela altura e painéis ao lado, com rolagem própria. */
.chess-screen{position:fixed;inset:0;z-index:41;overflow:auto;color:#f4ecd8;font-family:system-ui,sans-serif;-webkit-overflow-scrolling:touch;
  background:radial-gradient(90% 60% at 50% 40%,rgba(201,162,78,.16),transparent 70%),linear-gradient(180deg,#0b0d24,#161236 55%,#0b0d24)}
.chess-screen.hidden{display:none}
.chess-screen button{font:inherit;color:inherit;cursor:pointer}
.chess-screen button:disabled{cursor:not-allowed;opacity:.45}
.chess-screen :focus-visible{outline:3px solid #ffe08a;outline-offset:2px}
.chess-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}

.chess-app{--gutter:8px;max-width:1120px;margin:0 auto;min-height:100%;box-sizing:border-box;
  padding:calc(6px + env(safe-area-inset-top)) calc(var(--gutter) + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(var(--gutter) + env(safe-area-inset-left));display:flex;flex-direction:column;gap:8px}
.chess-head{display:flex;align-items:center;justify-content:space-between;gap:10px}
.chess-eyebrow{display:block;font-size:10px;letter-spacing:.14em;text-transform:uppercase;color:#c9a24e;font-weight:800}
.chess-head h2{margin:2px 0 0;font:700 19px/1.15 "Cinzel",Georgia,serif;color:#f3e2b0;outline:none}
.chess-close{flex:none;width:40px;height:40px;border-radius:50%;border:1px solid rgba(201,162,78,.6);background:rgba(10,8,28,.7);font-size:22px;line-height:1}

/* Tabuleiro */
.chess-match{display:grid;grid-template-columns:1fr;gap:10px;justify-items:center}
.chess-board-wrap{width:100%;display:flex;justify-content:center}
.chess-board{--size:min(calc(100vw - 2 * var(--gutter) - env(safe-area-inset-left) - env(safe-area-inset-right)),600px);--sq:calc(var(--size) / 8);
  width:var(--size);height:var(--size);display:grid;grid-template-columns:repeat(8,1fr);grid-template-rows:repeat(8,1fr);
  border:3px solid #6e5428;border-radius:8px;overflow:hidden;box-shadow:0 10px 30px rgba(0,0,0,.5),0 0 0 1px rgba(255,224,138,.25);touch-action:manipulation;user-select:none;-webkit-user-select:none}
.chess-sq{position:relative;border:0;padding:0;margin:0;min-width:0;min-height:0;display:block;overflow:visible;-webkit-tap-highlight-color:transparent}
.chess-sq.light{background:#d9c8a2}
.chess-sq.dark{background:#6f8a5e}
.chess-sq.is-last.light{background:#e6d88a}
.chess-sq.is-last.dark{background:#93a456}
.chess-sq.is-last::before{content:"";position:absolute;right:0;top:0;width:0;height:0;border-style:solid;border-width:0 calc(var(--sq) * .2) calc(var(--sq) * .2) 0;border-color:transparent rgba(60,40,10,.55) transparent transparent;z-index:1}
/* Seleção: contorno grosso tracejado (não depende só de cor) */
.chess-sq.is-selected{box-shadow:inset 0 0 0 3px #1b1306,inset 0 0 0 6px #ffe08a}
.chess-sq.is-selected::after{content:"";position:absolute;inset:3px;border:2px dashed #1b1306;border-radius:3px;z-index:3;pointer-events:none}
/* Destino livre: ponto; captura: cantos marcados */
.chess-sq.is-target::after{content:"";position:absolute;left:50%;top:50%;width:28%;height:28%;transform:translate(-50%,-50%);border-radius:50%;background:rgba(20,14,40,.55);box-shadow:0 0 0 2px rgba(255,240,200,.75);z-index:3;pointer-events:none}
.chess-sq.is-capture::after{content:"";position:absolute;inset:0;z-index:3;pointer-events:none;
  background:linear-gradient(135deg,#c0262d 0 22%,transparent 22%) top left,linear-gradient(225deg,#c0262d 0 22%,transparent 22%) top right,linear-gradient(45deg,#c0262d 0 22%,transparent 22%) bottom left,linear-gradient(315deg,#c0262d 0 22%,transparent 22%) bottom right;
  background-size:50% 50%;background-repeat:no-repeat}
.chess-sq.is-check{background:radial-gradient(circle,#ff6a5a 0,#c0262d 55%,transparent 80%),var(--check-base,#d9c8a2)}
.chess-sq.is-check.dark{--check-base:#6f8a5e}
.chess-coord{position:absolute;font:800 calc(var(--sq) * .2)/1 system-ui,sans-serif;z-index:4;pointer-events:none;opacity:.85}
.chess-coord.file{right:3px;bottom:2px}
.chess-coord.rank{left:3px;top:2px}
.chess-sq.light .chess-coord{color:#556e47}
.chess-sq.dark .chess-coord{color:#efe3c4}

/* Peça: retrato da criatura + base com o símbolo da peça e a cor da equipe (nada desenhado sobre o rosto) */
.chess-piece{position:absolute;inset:0;display:block;pointer-events:none;z-index:2}
.chess-piece img{position:absolute;left:8%;right:8%;top:2%;width:84%;height:74%;object-fit:contain;object-position:center bottom;filter:drop-shadow(0 2px 2px rgba(0,0,0,.5))}
.chess-piece.team-b img{transform:scaleX(-1)}
.chess-base{position:absolute;left:50%;bottom:4%;transform:translateX(-50%);min-width:58%;height:26%;border-radius:999px;display:grid;place-items:center;box-sizing:border-box;box-shadow:0 2px 3px rgba(0,0,0,.45)}
.chess-base b{font:900 calc(var(--sq,48px) * .2)/1 system-ui,sans-serif;letter-spacing:0}
.team-w .chess-base{background:linear-gradient(180deg,#fff8e4,#d8c08a);border:2px solid #7a5a1c;color:#2a1c06}
.team-b .chess-base{background:linear-gradient(180deg,#3b2f5c,#120d26);border:2px solid #d4b0ff;color:#f6eaff;border-radius:3px;clip-path:polygon(12% 0,88% 0,100% 50%,88% 100%,12% 100%,0 50%)}

/* Painel lateral */
.chess-side{width:100%;max-width:600px;display:flex;flex-direction:column;gap:8px;min-width:0}
.chess-status{display:flex;align-items:center;gap:8px;padding:9px 12px;border-radius:10px;background:rgba(18,15,40,.8);border:1px solid rgba(201,162,78,.45);font-size:15px}
.chess-turn-dot{flex:none;width:18px;height:18px;border-radius:50%;border:2px solid #7a5a1c}
.chess-status.turn-w .chess-turn-dot{background:#fff8e4}
.chess-status.turn-b .chess-turn-dot{background:#120d26;border-color:#d4b0ff}
.chess-status.turn-none .chess-turn-dot{background:repeating-linear-gradient(45deg,#fff8e4 0 4px,#120d26 4px 8px)}
.chess-status.check{border-color:#ff7a6a;background:rgba(80,14,20,.8)}
.chess-status.over{border-color:#ffe08a;background:rgba(70,52,10,.85)}
.chess-status.thinking b::after{content:"";display:inline-block;width:10px;height:10px;margin-left:8px;border-radius:50%;border:2px solid #f3e2b0;border-right-color:transparent;animation:chess-spin .8s linear infinite;vertical-align:-1px}
@keyframes chess-spin{to{transform:rotate(360deg)}}
@media (prefers-reduced-motion:reduce){.chess-status.thinking b::after{animation:none}}
.chess-info{padding:8px 10px;border-radius:10px;background:rgba(30,26,64,.7);border:1px solid rgba(120,140,255,.3);min-height:54px}
.chess-hint{margin:0;font-size:13px;color:#d8d4f0}
.chess-info-card{display:grid;grid-template-columns:56px 1fr;gap:10px;align-items:start}
.chess-info-art{width:56px;height:56px;border-radius:10px;display:block;overflow:hidden;border:2px solid #7a5a1c;background:radial-gradient(circle at 50% 30%,#4b3f86,#151032)}
.chess-info-art.team-b{border-color:#d4b0ff}
.chess-info-art img{width:100%;height:100%;object-fit:contain;object-position:center bottom}
.chess-info-card strong{display:block;font:700 14px/1.2 "Cinzel",Georgia,serif;color:#f3e2b0}
.chess-info-card small{display:block;font-size:12px;color:#c8c3dd;margin-top:2px}
.chess-info-card p{margin:4px 0 0;font-size:12px;line-height:1.35;color:#e6e1f6}
.chess-controls{display:grid;grid-template-columns:repeat(auto-fit,minmax(118px,1fr));gap:6px}
.chess-controls button,.chess-setup-actions button,.chess-dialog button{min-height:44px;padding:8px 10px;border-radius:9px;border:1px solid #e2c06a;background:linear-gradient(180deg,#7d4fe0,#4a2a9a);font-weight:800;font-size:13px}
.chess-screen button.ghost{background:rgba(10,8,28,.6);border-color:rgba(201,162,78,.55)}
.chess-screen button.primary{background:linear-gradient(180deg,#e2b54e,#9b6c1c);color:#1b1306;border-color:#ffe08a}
.chess-controls button[aria-pressed="true"]{box-shadow:inset 0 0 0 2px #ffe08a}
.chess-history{padding:8px 10px;border-radius:10px;background:rgba(18,15,40,.7);border:1px solid rgba(255,255,255,.1);max-height:170px;overflow:auto}
.chess-history h3{margin:0 0 4px;font:700 13px/1.2 "Cinzel",Georgia,serif;color:#f3e2b0}
.chess-history ol{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:2px 10px;font:13px/1.5 ui-monospace,Consolas,monospace}
.chess-history li{display:grid;grid-template-columns:30px 1fr 1fr;gap:4px}
.chess-history li span{color:#9f98c4}
.chess-history li.empty{display:block;font-family:system-ui,sans-serif;color:#9f98c4}
.chess-notice{margin:0;padding:8px 10px;border-radius:10px;font-size:12px;line-height:1.4;background:rgba(80,50,10,.6);border:1px solid #c9a24e;color:#ffe9b8}

/* Escolha de modalidade */
.chess-setup{width:100%;max-width:640px;margin:0 auto;display:flex;flex-direction:column;gap:12px}
.chess-lead{margin:0;font-size:13px;line-height:1.45;color:#d8d4f0}
.chess-setup fieldset{border:1px solid rgba(201,162,78,.4);border-radius:10px;margin:0;padding:8px 10px 10px}
.chess-setup fieldset[hidden]{display:none}
.chess-setup legend{padding:0 6px;font:700 13px "Cinzel",Georgia,serif;color:#f3e2b0}
.chess-choices{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.chess-choices.three{grid-template-columns:repeat(3,1fr)}
.chess-choice{min-height:56px;padding:8px;border-radius:10px;border:2px solid rgba(201,162,78,.45);background:rgba(20,16,48,.75);display:flex;flex-direction:column;align-items:flex-start;gap:2px;text-align:left}
.chess-choice b{font-size:14px}
.chess-choice small{font-size:11px;color:#c8c3dd}
.chess-choice[aria-pressed="true"]{border-color:#ffe08a;background:linear-gradient(180deg,rgba(125,79,224,.6),rgba(74,42,154,.6));box-shadow:0 0 0 2px rgba(255,224,138,.25)}
.chess-choice[aria-pressed="true"] b::before{content:"✓ ";color:#ffe08a}
.chess-cast{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(3,1fr);gap:6px}
.chess-cast li{--sq:48px;display:grid;grid-template-columns:48px 1fr;gap:6px;align-items:center;padding:4px;border-radius:8px;background:rgba(18,15,40,.6)}
.chess-cast li>.chess-piece{position:relative;display:block;width:48px;height:48px;inset:auto}
.chess-cast li b{display:block;font-size:12px}
.chess-cast li small{display:block;font-size:11px;color:#c8c3dd;line-height:1.2}
.chess-setup-actions{display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px}

/* Diálogos (promoção, regras, resultado) */
.chess-modal{position:fixed;inset:0;z-index:10;display:grid;place-items:center;padding:16px;background:rgba(4,4,14,.66)}
.chess-modal.hidden{display:none}
.chess-dialog{width:min(420px,100%);max-height:calc(100dvh - 32px);overflow:auto;box-sizing:border-box;padding:16px;border-radius:14px;border:2px solid #c9a24e;background:linear-gradient(160deg,#2a2152,#120f28);box-shadow:0 20px 50px rgba(0,0,0,.6);display:flex;flex-direction:column;gap:10px}
.chess-dialog.wide{width:min(620px,100%)}
.chess-dialog h3{outline:none;margin:0;font:700 20px/1.2 "Cinzel",Georgia,serif;color:#f3e2b0}
.chess-dialog h4{margin:4px 0 0;font:700 14px "Cinzel",Georgia,serif;color:#f3e2b0}
.chess-dialog p{margin:0;font-size:13px;line-height:1.45;color:#e6e1f6}
.chess-promo{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.chess-promo button{--sq:56px;display:grid;grid-template-columns:56px 1fr;align-items:center;gap:8px;text-align:left;background:rgba(20,16,48,.8)}
.chess-promo button>.chess-piece{position:relative;display:block;width:56px;height:56px;inset:auto}
.chess-promo b{display:block}
.chess-promo small{display:block;font-size:11px;font-weight:600;color:#c8c3dd}
.chess-dialog-actions{display:grid;gap:8px}
.chess-rules-list{margin:0;padding-left:18px;display:flex;flex-direction:column;gap:5px;font-size:13px;line-height:1.4;color:#e6e1f6}
.chess-rules-list.pieces{list-style:none;padding-left:0}
.chess-rules-list.pieces b{display:block;color:#f3e2b0}

/* Paisagem no celular e telas largas: tabuleiro pela altura, painéis ao lado */
@media (orientation:landscape) and (min-width:640px),(min-width:960px){
  .chess-match{grid-template-columns:auto minmax(240px,1fr);align-items:start;justify-items:stretch}
  .chess-board{--size:min(calc(100vh - 70px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),calc(100vw - 300px),640px)}
  @supports (height:100dvh){.chess-board{--size:min(calc(100dvh - 70px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),calc(100vw - 300px),640px)}}
  .chess-side{max-height:calc(100dvh - 70px);overflow:auto;padding-right:2px}
}
@media (orientation:landscape) and (max-height:500px){
  .chess-app{gap:4px}
  .chess-head h2{font-size:15px}
  .chess-close{width:34px;height:34px;font-size:18px}
  .chess-controls button{min-height:38px;padding:6px 8px;font-size:12px}
  .chess-history{max-height:none}
}
@media (max-width:420px){
  .chess-cast{grid-template-columns:repeat(2,1fr)}
  .chess-setup-actions{grid-template-columns:1fr}
  .chess-choices.three{grid-template-columns:1fr}
}

/* Entrada no menu do Duelo */
.duel-chess-entry{display:grid;grid-template-columns:56px 1fr;gap:8px 12px;padding:12px;border-radius:12px;border:2px solid #c9a24e;background:linear-gradient(160deg,#2d2a18,#151022);box-shadow:inset 0 0 14px rgba(0,0,0,.5)}
.duel-chess-entry .duel-opponent-icon{font-size:32px;color:#f3e2b0}
.duel-chess-entry button{grid-column:1/-1;padding:9px;border-radius:9px;border:1px solid #ffe08a;background:linear-gradient(180deg,#e2b54e,#9b6c1c);color:#1b1306;font-weight:800}
