/* FLAF.cz — Šachy, herní CSS.
 * Glass styl „ala Sčítátko" (projektový kánon), 8. sourozenec
 * Člobrda (vzor Dáma): tmavé kosmické pozadí, deska = glass panel (čtverec přes
 * container-query, .board-inner kvůli glass paddingu), pole klasická dřevěná (identita
 * šachů), figury SVG s literálními barvami (defs v markupu stránky — žádné :root proměnné),
 * zvýraznění tahů zlatě, král v šachu červený prstenec. Vše SCOPED pod .sachy-shell. */

.sachy-shell {
  --sx-gold: #FFD700;
  --sx-accent: #7FFFD4;
  --sx-accent-hover: #5fffc4;
  --sx-danger: #ff6b81;
  --sx-panel-a: #2a2358;
  --sx-panel-b: #3b2f74;
  /* pole šachovnice (klasické dřevo — identita hry) */
  --sx-cell-light-1: #E8D5B5; --sx-cell-light-2: #F0DDC0;
  --sx-cell-dark-1: #8B6B47;  --sx-cell-dark-2: #9D7A55;
  /* glass tokeny převzaté ze Sčítátka (game-core.css) */
  --sx-glass-1: rgba(255, 255, 255, .07);
  --sx-glass-3: rgba(255, 255, 255, .17);
  --sx-glass-edge: rgba(255, 255, 255, .28);
  --sx-glass-inner: rgba(255, 255, 255, .5);
  --sx-shadow-deep: 0 30px 60px -20px rgba(0, 0, 0, .6), inset 0 1px 0 var(--sx-glass-inner), inset 0 -1px 0 rgba(0, 0, 0, .25);

  /* fullscreen shell (jako .dama-shell) — self-contained */
  position: relative; z-index: 0;
  flex: 1 1 auto; min-height: 0; width: 100%;
  display: flex; flex-direction: column; align-items: center;
  padding: .5rem .75rem; padding-bottom: max(.75rem, env(safe-area-inset-bottom));
  gap: .5rem;
  font-family: var(--font-body, sans-serif);
}
@media (max-height: 640px) { .sachy-shell { padding: .35rem .5rem .5rem; gap: .35rem; } }

/* ---------- tmavé kosmické pozadí (styl Sčítátka), vždy — nezávislé na light/dark ---------- */
body.game-sachy {
  background:
    radial-gradient(at 15% 10%, #3a2a78 0, transparent 55%),
    radial-gradient(at 85% 15%, #1e4d9c 0, transparent 55%),
    radial-gradient(at 75% 90%, #5b2a9c 0, transparent 55%),
    radial-gradient(at 10% 85%, #2a6db5 0, transparent 55%),
    #0e0d2b;
}
.sachy-shell .sx-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.sachy-shell .sx-blob { position: absolute; border-radius: 50%; filter: blur(52px); opacity: .42; animation: sxFloat 22s ease-in-out infinite; }
.sachy-shell .sx-blob--1 { width: 46vw; height: 46vw; background: #a9744f; top: -14vw; left: -10vw; }
.sachy-shell .sx-blob--2 { width: 52vw; height: 52vw; background: #00b4d8; bottom: -16vw; right: -12vw; animation-delay: -7s; }
.sachy-shell .sx-blob--3 { width: 40vw; height: 40vw; background: #6f3fff; top: 40%; right: -12vw; animation-delay: -14s; }
@keyframes sxFloat { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(4vw, -5vw) scale(1.1); } }
.sachy-shell .sx-stars {
  position: absolute; inset: 0; opacity: .55;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff, transparent),
    radial-gradient(1px 1px at 32% 68%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 56% 34%, #fff, transparent),
    radial-gradient(1px 1px at 82% 78%, #fff, transparent),
    radial-gradient(1px 1px at 91% 24%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 22% 48%, #fff, transparent),
    radial-gradient(1px 1px at 66% 60%, #fff, transparent),
    radial-gradient(1px 1px at 46% 88%, #fff, transparent);
  animation: sxTwinkle 4s ease-in-out infinite;
}
@keyframes sxTwinkle { 50% { opacity: .28; } }
/* obsah nad pozadím */
.sachy-shell .status, .sachy-shell .board-zone, .sachy-shell .under-bar { position: relative; z-index: 1; }
@media (prefers-reduced-motion: reduce) { .sachy-shell .sx-blob, .sachy-shell .sx-stars { animation: none; } }

.sachy-shell__game {
  display: flex; flex-direction: column; align-items: center;
  gap: .5rem; width: 100%; min-height: 0; flex: 1 1 auto;
  -webkit-user-select: none; user-select: none;
}
.sachy-shell button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.sachy-shell svg { display: block; }
.sachy-shell .sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- status (velký barevný „na tahu") ---------- */
.sachy-shell .status {
  flex: 0 0 auto; margin: 0; order: -1;
  font-family: var(--font-heading, sans-serif); font-weight: 800;
  font-size: clamp(1.1rem, 5vw, 1.6rem); letter-spacing: .01em;
  color: #d6d0f5; min-height: 1.4em; text-align: center; line-height: 1.15;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .5);
}
.sachy-shell .status.thinking { color: var(--sx-accent); }
.sachy-shell .status.capture { color: var(--sx-danger); text-shadow: 0 0 16px currentColor, 0 2px 5px rgba(0, 0, 0, .6); }
.sachy-shell .status.over { color: var(--sx-gold); }
.sachy-shell .status.turn { text-shadow: 0 0 16px currentColor, 0 2px 5px rgba(0, 0, 0, .6); }
.sachy-shell .status.turn.w { color: #FFF0B8; }
.sachy-shell .status.turn.b { color: #9BF0E2; }

/* ---------- deska (glass panel, čtverec přes container-query, board-inner kvůli paddingu) ---------- */
.sachy-shell .board-zone {
  flex: 1 1 auto; min-height: 0; width: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  container-type: size;   /* deska = největší ČTVEREC, co se vejde */
}
.sachy-shell .board-wrap {
  width: min(100cqw, 100cqh); height: min(100cqw, 100cqh); aspect-ratio: 1;
  padding: 3.5%; border-radius: 24px;
  border: 1px solid var(--sx-glass-edge);
  background:
    linear-gradient(160deg, var(--sx-glass-3) 0%, var(--sx-glass-1) 42%, transparent 100%),
    radial-gradient(circle at 50% 38%, rgba(255, 215, 0, .10), transparent 55%),
    linear-gradient(150deg, var(--sx-panel-b), var(--sx-panel-a));
  box-shadow:
    var(--sx-shadow-deep),
    0 0 48px rgba(255, 215, 0, .12),
    inset 0 0 0 1px rgba(255, 215, 0, .14);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  position: relative; overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
/* horní odlesk skla */
.sachy-shell .board-wrap::before {
  content: ''; position: absolute; top: 0; left: 10%; right: 10%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--sx-glass-inner), transparent); pointer-events: none; z-index: 2;
}
.sachy-shell .board-inner { position: relative; width: 100%; height: 100%; }
.sachy-shell .board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%; height: 100%;
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .45);
  /* none ⊃ manipulation: řeší dvojklik-zoom A umožní drag&drop bez rušení scrollem */
  touch-action: none;
}
/* ARIA řádky (role="row") se layoutu neúčastní — gridem jsou přímo buňky */
.sachy-shell .brow { display: contents; }

/* obě barvy polí jsou hrací */
.sachy-shell .cell { position: relative; background: linear-gradient(135deg, var(--sx-cell-light-1), var(--sx-cell-light-2)); }
.sachy-shell .cell.dark { background: linear-gradient(135deg, var(--sx-cell-dark-1), var(--sx-cell-dark-2)); }

.sachy-shell .cell:focus { outline: none; }
.sachy-shell .cell:focus-visible {
  outline: 3px solid var(--sx-accent);
  outline-offset: -3px;
  z-index: 3;
}
@media (hover: hover) {
  .sachy-shell .cell:hover { box-shadow: inset 0 0 0 100px rgba(255, 215, 0, 0.07); }
}

/* poslední tah — jemný zlatý nádech (u rošády pole krále) */
.sachy-shell .cell.last::before {
  content: ''; position: absolute; inset: 0;
  background: rgba(255, 215, 0, 0.28);
}
/* vybraná figura — zvýrazněné pole */
.sachy-shell .cell.sel::before {
  content: ''; position: absolute; inset: 0;
  background: rgba(255, 215, 0, 0.4);
  box-shadow: inset 0 0 0 3px var(--sx-gold);
}
/* legální tichý cíl — tečka */
.sachy-shell .cell.dst::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 26%; height: 26%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 215, 0, 0.85);
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
}
/* cíl braní — zlatý prstenec */
.sachy-shell .cell.cap-dst::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 62%; height: 62%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: transparent;
  border: 3px solid var(--sx-gold);
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.7), inset 0 0 6px rgba(255, 215, 0, 0.4);
}
/* pole krále v šachu — statický červený prstenec + glow (žádná nekonečná animace).
   Bez z-index: prstenec je na buňce (#board) POD vrstvou figur (#pieces), aby král nezmizel. */
.sachy-shell .cell.check {
  box-shadow: inset 0 0 0 3px var(--sx-danger), inset 0 0 16px rgba(255, 107, 129, 0.5);
}

/* ---------- figury ---------- */
.sachy-shell .pieces { position: absolute; inset: 0; pointer-events: none; }

.sachy-shell .piece {
  position: absolute; left: 0; top: 0;
  width: 12.5%; height: 12.5%;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s ease-out, opacity 0.25s ease-out;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.5));
}
.sachy-shell .piece > svg { width: 88%; height: 88%; }

.sachy-shell .piece.selected { z-index: 4; }
/* jemná levitace — animuje se vnitřní SVG, ne kontejner */
.sachy-shell .piece.selected > svg { animation: sxSelFloat 1.4s ease-in-out infinite; }
.sachy-shell .piece.dragging { transition: none; z-index: 6; filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.55)); }
.sachy-shell .piece.returning { z-index: 5; }
.sachy-shell .piece.dying { opacity: 0; z-index: 1; } /* scale řídí JS v inline transformu */
.sachy-shell .piece.crowned > svg { animation: sxCrownShine 0.6s ease-out; }

@keyframes sxSelFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-9%); }
}
@keyframes sxCrownShine {
  0% { filter: brightness(1); }
  35% { filter: brightness(2.1) drop-shadow(0 0 14px rgba(255, 215, 0, 0.95)); }
  100% { filter: brightness(1); }
}

/* ---------- lišta pod deskou: sebrané figury + Vrátit tah ---------- */
.sachy-shell .under-bar {
  flex: 0 0 auto;
  display: flex; gap: .8rem; align-items: center; justify-content: center;
  flex-wrap: wrap;
  width: 100%; max-width: 560px;
}
.sachy-shell .captured { display: flex; flex-direction: column; gap: 0.25rem; flex: 1 1 200px; min-width: 0; }
.sachy-shell .cap-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
  min-height: 24px; padding: 0.15rem 0.5rem;
  background: linear-gradient(160deg, var(--sx-glass-3), var(--sx-glass-1));
  border: 1px solid var(--sx-glass-edge);
  border-radius: 9999px;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.sachy-shell .cap-row .mini { width: 20px; height: 20px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5)); }
.sachy-shell .cap-row .adv {
  margin-left: auto; font-family: var(--font-heading, sans-serif); font-weight: 800;
  color: var(--sx-gold); font-size: 0.85rem;
  text-shadow: 0 0 8px rgba(255, 215, 0, .5);
}

/* ---------- tlačítka ---------- */
.sachy-shell .btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: .5rem 1.1rem;
  font-family: var(--font-heading, sans-serif); font-weight: 700; font-size: .95rem;
  border: 2px solid rgba(255, 255, 255, .3); border-radius: 9999px;
  background: rgba(255, 255, 255, .1); color: #fff;
  cursor: pointer; transition: transform .12s ease, background .2s ease, border-color .2s ease;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.sachy-shell .btn:hover { transform: translateY(-1px); background: rgba(255, 255, 255, .16); }
.sachy-shell .btn:active { transform: translateY(1px); }
.sachy-shell .btn:focus-visible { outline: 3px solid var(--sx-accent); outline-offset: 2px; }
.sachy-shell .btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.sachy-shell .btn-primary { background: var(--sx-accent); color: #123; border-color: var(--sx-accent); }
.sachy-shell .btn-primary:hover { background: var(--sx-accent-hover); }

/* ---------- dialogy (styl Sčítátka: fullscreen glass, prvky plavou BEZ rámečků/karty) ---------- */
.sachy-shell .dlg {
  margin: 0; padding: 0; max-width: none; max-height: none; width: 100%; height: 100%;
  background: none; border: 0; color: #fff; overflow-y: auto;
}
.sachy-shell .dlg::backdrop {
  background:
    radial-gradient(at 20% 20%, rgba(107, 91, 149, .75) 0, transparent 55%),
    radial-gradient(at 80% 80%, rgba(72, 61, 139, .75) 0, transparent 55%),
    rgba(14, 13, 43, .82);
  backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
}
.sachy-shell .dlg[open] {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  padding: calc(64px + env(safe-area-inset-top, 0px)) 22px calc(28px + env(safe-area-inset-bottom, 0px));
  animation: sxDlgPop .35s cubic-bezier(.34, 1.56, .64, 1);
}
.sachy-shell .dlg > * { width: min(420px, 100%); }
@keyframes sxDlgPop { 0% { transform: scale(.9); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.sachy-shell .dlg h2 { font-family: var(--font-display, sans-serif); font-size: 1.7rem; color: #fff; text-align: center; text-shadow: 0 2px 10px rgba(0, 0, 0, .5); margin: 0; }
.sachy-shell .dlg fieldset { border: 0; margin: 0; padding: 0; }
.sachy-shell .dlg legend { display: block; width: 100%; text-align: center; font-family: var(--font-heading, sans-serif); font-weight: 700; font-size: 1.15rem; color: #fff; text-shadow: 0 2px 6px rgba(0, 0, 0, .45); margin-bottom: .7rem; padding: 0; }
/* segment voleb — měkká glass tlačítka bez tvrdého rámečku (styl Sčítátka) */
.sachy-shell .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: .6rem; }
.sachy-shell .seg label {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 56px; padding: .5rem .4rem; border-radius: 18px; cursor: pointer;
  background: rgba(255, 255, 255, .08); border: 0;
  font-family: var(--font-heading, sans-serif); font-weight: 800; font-size: 1rem; color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .4); transition: background .15s ease, transform .12s ease, box-shadow .15s ease;
}
.sachy-shell .seg label:hover { background: rgba(255, 255, 255, .14); transform: translateY(-1px); }
.sachy-shell .seg input { position: absolute; opacity: 0; pointer-events: none; }
.sachy-shell .seg label:has(input:checked) { background: var(--sx-accent); color: #123; text-shadow: none; box-shadow: 0 0 18px rgba(127, 255, 212, .5); }
.sachy-shell .seg label:has(input:focus-visible) { outline: 3px solid #fff; outline-offset: 2px; }

/* velké CTA HRÁT (styl Sčítátka menu-cta, pulsující) */
.sachy-shell .dlg-cta {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 18px 32px; min-height: 60px; width: min(420px, 100%);
  font-family: var(--font-heading, sans-serif); font-weight: 800; font-size: 1.5rem; letter-spacing: .04em;
  color: #123; background: var(--sx-accent); border: 0; border-radius: 9999px; cursor: pointer;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .18), 0 10px 28px rgba(127, 255, 212, .35);
  animation: sxMenuPulse 2s infinite; transition: transform .12s ease, background .2s ease;
}
.sachy-shell .dlg-cta:hover { background: var(--sx-accent-hover); transform: translateY(-2px); }
.sachy-shell .dlg-cta:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, .2), 0 4px 16px rgba(127, 255, 212, .3); }
@keyframes sxMenuPulse {
  0%, 100% { box-shadow: 0 6px 0 rgba(0, 0, 0, .18), 0 0 0 0 rgba(127, 255, 212, .7), 0 10px 28px rgba(127, 255, 212, .35); }
  50% { box-shadow: 0 6px 0 rgba(0, 0, 0, .18), 0 0 0 18px rgba(127, 255, 212, 0), 0 10px 28px rgba(127, 255, 212, .35); }
}
/* sekundární tlačítko (NOVÁ HRA v menu rozehrané hry) — styl Sčítátka menu-secondary */
.sachy-shell .dlg-secondary {
  display: inline-flex; align-items: center; justify-content: center;
  width: min(420px, 100%); padding: 14px 28px; min-height: 52px;
  font-family: var(--font-heading, sans-serif); font-weight: 700; font-size: 1.15rem; letter-spacing: .04em;
  color: #fff; background: transparent; border: 3px solid rgba(255, 255, 255, .85); border-radius: 9999px; cursor: pointer;
  transition: transform .12s ease, background .2s ease;
}
.sachy-shell .dlg-secondary:hover { background: rgba(255, 255, 255, .12); transform: translateY(-2px); }
.sachy-shell .dlg-secondary:active { transform: translateY(2px); }
/* konec hry */
.sachy-shell .dlg-text { color: rgba(255, 255, 255, .9); font-size: 1.05rem; line-height: 1.5; text-align: center; text-shadow: 0 2px 6px rgba(0, 0, 0, .4); margin: 0; }
.sachy-shell .result-emoji { display: block; text-align: center; font-size: 3.2rem; margin-bottom: .2rem; }
.sachy-shell .dlg-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.sachy-shell .dlg-actions .btn { flex: 1 1 auto; }
.sachy-shell .dlg-actions .btn-primary { color: #123; }

/* dialog proměny pěšce (glass) */
.sachy-shell .promo-pieces { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }
.sachy-shell .promo-piece {
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1; padding: 0.5rem;
  border: 0; border-radius: 18px;
  background: rgba(255, 255, 255, .08);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.sachy-shell .promo-piece svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5)); }
.sachy-shell .promo-piece:hover { background: rgba(255, 255, 255, .16); transform: translateY(-2px); box-shadow: 0 0 18px rgba(127, 255, 212, .35); }
.sachy-shell .promo-piece:focus-visible { outline: 3px solid var(--sx-accent); outline-offset: 2px; }

/* ---------- konfety ---------- */
.sachy-shell .confetti, .confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; }

/* ---------- landscape: kompaktnější svislý rytmus ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .sachy-shell__game { gap: .3rem; }
  .sachy-shell .status { font-size: clamp(1rem, 4vw, 1.3rem); }
  .sachy-shell .under-bar { gap: .5rem; }
  .sachy-shell .btn { min-height: 38px; padding: .35rem .8rem; font-size: .85rem; }
  .sachy-shell .cap-row { min-height: 20px; }
  .sachy-shell .cap-row .mini { width: 16px; height: 16px; }
}
@media (max-height: 640px) { .sachy-shell__game { gap: .35rem; } }

/* výkon: na malých displejích vypnout smyčkové animace (levitace) */
@media (max-width: 768px) {
  .sachy-shell .piece.selected > svg { animation: none; }
}

/* ---------- omezený pohyb: bez smyčkových animací ---------- */
@media (prefers-reduced-motion: reduce) {
  .sachy-shell .dlg { animation: none; }
  .sachy-shell .dlg-cta { animation: none; }
  .sachy-shell .piece.selected > svg { animation: none; }
  .sachy-shell .piece, .sachy-shell * { transition-duration: 0.01ms; }
}
