@import url('../_pool/style.css');

:root {
  --bg0: #0a0e16;
  --panel: rgba(22, 30, 48, 0.9);
  --go: #22c97c;
  --gold: #ffc83d;
  --light: #e7edf2;
  --dark: #7192b4;
}

body {
  background: radial-gradient(ellipse 90% 70% at 50% 30%, #1a2840 0%, var(--bg0) 70%);
}

#bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background: radial-gradient(circle at 20% 80%, rgba(114, 146, 180, 0.25), transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(34, 201, 124, 0.12), transparent 45%);
}

#play { position: fixed; inset: 0; display: flex; flex-direction: column; }

#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
  flex: none;
}
#status { flex: 1; text-align: center; font-weight: 800; font-size: 14px; color: var(--gold); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-right { display: flex; gap: 6px; }
.icon-btn {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.1); background: rgba(16,22,34,0.88);
  box-shadow: 0 3px 0 rgba(0,0,0,0.4); color: inherit;
}
.icon-btn:active { transform: translateY(2px); }
.icon-btn.sound .off { display: none; }
.icon-btn.sound.muted .on { display: none; }
.icon-btn.sound.muted .off { display: inline; }

#stage {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: 1fr minmax(0, min(92vh, 100vw - 24px)) 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "m m m" ". b . " "mv mv mv";
  gap: 6px;
  padding: 0 max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  align-content: center;
}
#card-top { grid-area: m; justify-self: center; width: min(100%, 520px); }
/* The board is always square: it takes the smaller side of its grid cell. */
#board-wrap { grid-area: b; container-type: size; width: 100%; height: 100%; min-width: 0; min-height: 0; display: grid; place-items: center; }
#board { --bs: calc(min(100cqw, 100cqh) - 2 * clamp(6px, 1.5vmin, 14px) - 4px); width: var(--bs); height: var(--bs); touch-action: none; }
#card-bot { grid-area: mv; justify-self: center; width: min(100%, 520px); }
#moves { grid-column: 1 / -1; font-size: 12px; color: var(--muted); text-align: center; max-height: 2.6em; overflow: hidden; padding: 0 8px; }
#actions { grid-column: 1 / -1; text-align: center; }

.pcard {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 999px;
  background: var(--panel); border: 2px solid rgba(255,255,255,0.08);
}
.pcard.turn { border-color: rgba(255, 200, 61, 0.8); box-shadow: 0 0 20px rgba(255, 200, 61, 0.25); }
.pcard .av {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 900; background: linear-gradient(135deg, #f4efe4, #c9a86c); color: #3a2e22; flex: none;
}
.pcard .who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pcard .name { font-weight: 900; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .caps { display: flex; gap: 2px; min-height: 14px; }
.pcard .caps i { width: 14px; height: 14px; display: block; background-size: contain; background-repeat: no-repeat; opacity: 0.85; }
.pcard .clock { font-weight: 900; font-variant-numeric: tabular-nums; color: var(--gold); min-width: 48px; text-align: right; }
.pcard .think { display: flex; gap: 4px; }
.pcard .think i { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); animation: bounce 0.9s ease-in-out infinite; }
.pcard .think i:nth-child(2) { animation-delay: 0.15s; }
.pcard .think i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 50% { transform: translateY(-4px); opacity: 0.5; } }

.board {
  --fw: clamp(6px, 1.5vmin, 14px);
  position: relative; border-radius: 4px; overflow: hidden;
  box-shadow: 0 0 0 var(--fw) var(--frame, #2a2f3e), 0 0 0 calc(var(--fw) + 1.5px) rgba(255,255,255,0.18), 0 18px 44px calc(var(--fw) * 0.5) rgba(0,0,0,0.6);
  outline: none;
}
.board.wood .squares::after { content: ''; position: absolute; inset: 0; background: var(--grain) 0 0 / 100% 100%; mix-blend-mode: overlay; opacity: 0.75; pointer-events: none; }
.board .squares::before { content: ''; position: absolute; inset: 0; z-index: 1; pointer-events: none; box-shadow: inset 0 0 calc(var(--fw) * 1.2) rgba(0,0,0,0.45); }
.board .sq { position: relative; }
.board .pc { filter: drop-shadow(0 2px 1.5px rgba(0,0,0,0.35)); }
.board .squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.board .sq.l { background: var(--light); }
.board .sq.d { background: var(--dark); }
.board .sq i { position: absolute; font-size: clamp(8px, 1.5vmin, 13px); font-weight: 800; font-style: normal; opacity: 0.45; pointer-events: none; }
.board .sq .fl { right: 3px; bottom: 2px; }
.board .sq .rk { left: 3px; top: 2px; }
.board .marks, .board .pieces, .board .promo { position: absolute; inset: 0; pointer-events: none; }
.board .promo { pointer-events: auto; }
.board .mk { position: absolute; width: 12.5%; height: 12.5%; left: 0; top: 0; transform-origin: top left; }
.board .mk.dot::after { content: ''; position: absolute; left: 50%; top: 50%; width: 28%; height: 28%; margin: -14% 0 0 -14%; border-radius: 50%; background: rgba(0,0,0,0.28); }
.board .mk.ring::after { content: ''; position: absolute; inset: 8%; border-radius: 50%; border: 4px solid rgba(0,0,0,0.32); }
.board .mk.sel { box-shadow: inset 0 0 0 4px rgba(255, 200, 61, 0.85); }
.board .mk.last { box-shadow: inset 0 0 0 4px rgba(155, 199, 0, 0.75); }
.board .mk.check { box-shadow: inset 0 0 0 5px rgba(255, 80, 60, 0.9); }
.board .mk.check.mated { animation: flash 0.6s ease-in-out 3; }
.board .mk.hover::after { background: rgba(34, 201, 124, 0.45); }
.board .mk.kb::before { content: ''; position: absolute; inset: 2px; border: 2px solid var(--go); border-radius: 4px; opacity: 0.8; }
@keyframes flash { 50% { box-shadow: inset 0 0 0 8px rgba(255, 40, 40, 1); } }
.board .pc {
  position: absolute; width: 12.5%; height: 12.5%; left: 0; top: 0;
  background-size: 88% 88%; background-position: center; background-repeat: no-repeat;
  transform-origin: top left; transition: transform 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.05);
  will-change: transform;
}
.board .pc.moving { transition-duration: 0.22s; }
.board .pc.drag { transition: none; z-index: 5; filter: drop-shadow(0 10px 10px rgba(0,0,0,0.5)); }
.board .pc.gone { opacity: 0; transform: scale(0.4) !important; transition: opacity 0.28s, transform 0.28s; }
.board .pc.appear, .board .pc.pop { animation: poppc 0.28s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes poppc { from { transform: scale(0.5); opacity: 0; } }
.board .promo .opt {
  position: absolute; width: 12.5%; height: 12.5%; border: 0; border-radius: 8px;
  background-size: 85%; background-position: center; background-repeat: no-repeat;
  background-color: rgba(8, 12, 20, 0.75); box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  cursor: pointer;
}

.logo-piece { width: 56px; height: 56px; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.5)); }
.record { color: var(--muted); font-weight: 800; font-size: 13px; }

.seg { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.seg button {
  flex: 1; min-width: 90px; padding: 12px; border-radius: 16px; border: 2px solid var(--line);
  background: var(--panel); font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.seg button.on { border-color: var(--go); box-shadow: 0 0 16px rgba(34, 201, 124, 0.25); }
.seg button img { width: 28px; height: 28px; }
.seg .dice { font-size: 22px; color: var(--gold); }

.levels-col .big-btn { justify-content: space-between; text-align: left; }
.lv { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.lv small { font-size: 12px; font-weight: 700; opacity: 0.85; }
.stars { color: var(--gold); font-size: 14px; letter-spacing: 1px; }
.stars i { opacity: 0.35; font-style: normal; }

.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.shopcard { padding: 10px; border-radius: 16px; background: var(--panel); border: 2px solid var(--line); text-align: center; }
.shopcard.on { border-color: var(--go); }
.shopcard .prev { position: relative; height: 64px; border-radius: 10px; margin-bottom: 8px; overflow: hidden; }
.shopcard .prev.wood::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(8deg, rgba(60,30,10,0.12) 0 2px, transparent 2px 7px); mix-blend-mode: multiply; }
.shopcard .btn { width: 100%; margin-top: 8px; }

#s-wait .spinner img { width: 74px; height: 74px; animation: bob 2s ease-in-out infinite; }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
.win-banner {
  position: fixed; left: 50%; top: 42%; z-index: 40; transform: translate(-50%, -50%);
  pointer-events: none; white-space: nowrap; font-size: clamp(36px, 8vw, 88px); font-weight: 900;
  color: #fff3a8; filter: drop-shadow(0 4px 0 #8a4a00) drop-shadow(0 10px 30px rgba(0,0,0,0.6));
  animation: banner 1.6s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
@keyframes banner {
  0% { transform: translate(-50%, -50%) scale(0.2); opacity: 0; }
  18% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
  82% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.96); }
}
.trophy.win::after { content: '♔'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 44px; color: #fff6c4; }
#s-result.won .rtitle { font-size: 38px; color: var(--gold); }

@media (max-width: 500px) and (orientation: portrait) {
  #stage {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto auto;
    grid-template-areas: "m" "b" "mv" "mv2" "act";
  }
  #card-bot { grid-area: mv2; }
  #moves { grid-area: mv; }
  #actions { grid-area: act; }
}
@media (orientation: landscape) and (max-height: 520px) {
  #stage {
    grid-template-columns: minmax(120px, 1fr) minmax(0, calc(100vh - 52px)) minmax(120px, 1fr);
    grid-template-rows: 1fr;
    grid-template-areas: "m b mv";
    align-items: center;
  }
  #moves, #actions { display: none; }
  #card-top, #card-bot { width: 100%; max-width: 180px; }

}
/* Messages sit at the bottom so they never cover the top rank. */
#toast { top: auto !important; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 20; }
#play.behind { pointer-events: none; filter: blur(1.5px) brightness(0.55); }
#play.behind #topbar, #play.behind .pcard, #play.behind #moves, #play.behind #actions { visibility: hidden; }
#menu { z-index: 2; }

/* Wide screens: the player cards sit beside the board instead of above and
   below it, so the board gets the full height. Opponent top-left, you
   bottom-right, the move list on the right. */
@media (min-aspect-ratio: 5/4) and (min-height: 521px) {
  #stage {
    grid-template-columns: minmax(170px, 1fr) minmax(0, calc(100vh - 64px)) minmax(170px, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "m b ." "act b moves" ". b mv";
    gap: 10px 18px;
    align-content: stretch;
  }
  #card-top { grid-area: m; justify-self: end; align-self: start; width: min(100%, 280px); margin-top: 14px; }
  #card-bot { grid-area: mv; justify-self: start; align-self: end; width: min(100%, 280px); margin-bottom: 14px; }
  #moves { grid-area: moves; grid-column: auto; align-self: end; justify-self: start; text-align: left; max-width: 280px; max-height: 40vh; overflow-y: auto; padding: 0; line-height: 1.6; font-size: 13px; }
  #actions { grid-area: act; grid-column: auto; align-self: start; justify-self: end; }
}
