/* FLAF.cz — Hra 2048, herní CSS.
 * Glass styl „ala Sčítátko" (projektový kánon), 7. sourozenec
 * Člobrda: tmavé kosmické pozadí, deska = glass panel (čtverec přes container-query jako
 * Mlýn/Dáma), dlaždice cream→gold paleta 1:1 ze zdroje (identita hry). Vše SCOPED pod
 * .g2048-shell (CSS třída nesmí začínat číslicí). POZOR: --cell/--step derivované z --n
 * jsou deklarované NA .board-wrap — JS přepisuje --n inline na témže elementu; na :root
 * by se var(--n) substituoval s výchozí hodnotou a mřížky 5×5/6×6 by se rozbily. */

.g2048-shell {
  --g48-gold: #FFD700;
  --g48-accent: #7FFFD4;
  --g48-accent-hover: #5fffc4;
  --g48-danger: #ff6b81;
  --g48-panel-a: #2a2358;
  --g48-panel-b: #3b2f74;
  --tile-ink: #2A2010;          /* tmavý inkoust dlaždic (kontrast ≥4.5:1 na cream→gold) */
  --slide: 110ms;
  /* glass tokeny převzaté ze Sčítátka (game-core.css) */
  --g48-glass-1: rgba(255, 255, 255, .07);
  --g48-glass-3: rgba(255, 255, 255, .17);
  --g48-glass-edge: rgba(255, 255, 255, .28);
  --g48-glass-inner: rgba(255, 255, 255, .5);
  --g48-shadow-deep: 0 30px 60px -20px rgba(0, 0, 0, .6), inset 0 1px 0 var(--g48-glass-inner), inset 0 -1px 0 rgba(0, 0, 0, .25);

  /* fullscreen shell (jako .mlyn-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) { .g2048-shell { padding: .35rem .5rem .5rem; gap: .35rem; } }

/* ---------- tmavé kosmické pozadí (styl Sčítátka), vždy — nezávislé na light/dark ---------- */
body.game-2048 {
  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;
}
.g2048-shell .g48-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.g2048-shell .g48-blob { position: absolute; border-radius: 50%; filter: blur(52px); opacity: .42; animation: g48Float 22s ease-in-out infinite; }
.g2048-shell .g48-blob--1 { width: 46vw; height: 46vw; background: #d9a514; top: -14vw; left: -10vw; }
.g2048-shell .g48-blob--2 { width: 52vw; height: 52vw; background: #00b4d8; bottom: -16vw; right: -12vw; animation-delay: -7s; }
.g2048-shell .g48-blob--3 { width: 40vw; height: 40vw; background: #6f3fff; top: 40%; right: -12vw; animation-delay: -14s; }
@keyframes g48Float { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(4vw, -5vw) scale(1.1); } }
.g2048-shell .g48-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: g48Twinkle 4s ease-in-out infinite;
}
@keyframes g48Twinkle { 50% { opacity: .28; } }
/* obsah nad pozadím */
.g2048-shell .status, .g2048-shell .hud, .g2048-shell .board-zone, .g2048-shell .under-bar { position: relative; z-index: 1; }
@media (prefers-reduced-motion: reduce) { .g2048-shell .g48-blob, .g2048-shell .g48-stars { animation: none; } }

.g2048-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;
}
.g2048-shell button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.g2048-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ý) ---------- */
.g2048-shell .status {
  flex: 0 0 auto; margin: 0; order: -2;
  font-family: var(--font-heading, sans-serif); font-weight: 800;
  font-size: clamp(1rem, 4.4vw, 1.4rem); letter-spacing: .01em;
  color: #d6d0f5; min-height: 1.3em; text-align: center; line-height: 1.15;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .5);
}
.g2048-shell .status.is-win { color: var(--g48-gold); text-shadow: 0 0 16px currentColor, 0 2px 5px rgba(0, 0, 0, .6); }
.g2048-shell .status.is-over { color: var(--g48-danger); text-shadow: 0 0 16px currentColor, 0 2px 5px rgba(0, 0, 0, .6); }

/* ---------- HUD: skóre boxy ---------- */
.g2048-shell .hud {
  flex: 0 0 auto; order: -1;
  display: flex; gap: .6rem; align-items: stretch; justify-content: center; flex-wrap: wrap;
}
.g2048-shell .score-box {
  position: relative;
  min-width: 5.4rem;
  padding: .3rem .95rem .4rem;
  border-radius: 18px;
  border: 1px solid var(--g48-glass-edge);
  background: linear-gradient(160deg, var(--g48-glass-3), var(--g48-glass-1));
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 6px 18px rgba(0, 0, 0, .3);
  text-align: center; line-height: 1.1;
}
.g2048-shell .score-box .label {
  display: block;
  font-family: var(--font-heading, sans-serif);
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: rgba(255, 255, 255, .75);
  text-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.g2048-shell .score-box .val {
  display: block;
  font-family: var(--font-heading, sans-serif);
  font-size: clamp(1.05rem, 3.4vw, 1.45rem); font-weight: 800;
  color: #fff; font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .45);
}
.g2048-shell .score-box.is-best .val { color: var(--g48-gold); text-shadow: 0 0 10px rgba(255, 215, 0, .55), 0 2px 5px rgba(0, 0, 0, .5); }
/* plovoucí +N nad skórem */
.g2048-shell .gain {
  position: absolute; left: 50%; top: 0.2rem;
  transform: translateX(-50%);
  font-family: var(--font-heading, sans-serif);
  font-weight: 800; font-size: 0.95rem; color: var(--g48-accent);
  text-shadow: 0 0 10px rgba(127, 255, 212, .6);
  pointer-events: none;
  animation: g48GainFloat 700ms ease-out forwards;
}
@keyframes g48GainFloat {
  0% { opacity: 0; transform: translate(-50%, 0); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -1.5rem); }
}

/* ---------- deska (glass panel, čtverec přes container-query) ---------- */
.g2048-shell .board-zone {
  flex: 1 1 auto; min-height: 0; min-width: 0; width: 100%;
  display: flex; align-items: center; justify-content: center;
  container-type: size;   /* deska = největší ČTVEREC, co se vejde */
}
.g2048-shell .board-wrap {
  /* derivované proměnné MUSÍ být tady (JS přepisuje --n inline na tomto elementu) */
  --n: 4;
  --board: min(100cqw, 100cqh);
  --gap: clamp(5px, calc(var(--board) * 0.025), 16px);
  --pad: var(--gap);
  --cell: calc((var(--board) - 2 * var(--pad) - (var(--n) - 1) * var(--gap)) / var(--n));
  --step: calc(var(--cell) + var(--gap));

  position: relative;
  width: var(--board); height: var(--board);
  box-sizing: border-box;
  border-radius: 24px;
  border: 1px solid var(--g48-glass-edge);
  background:
    linear-gradient(160deg, var(--g48-glass-3) 0%, var(--g48-glass-1) 42%, transparent 100%),
    radial-gradient(circle at 50% 38%, rgba(255, 215, 0, .10), transparent 55%),
    linear-gradient(150deg, var(--g48-panel-b), var(--g48-panel-a));
  box-shadow:
    var(--g48-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);
  touch-action: none;   /* řeší dvojklik-zoom a umožní swipe bez scrollu stránky */
  -webkit-user-select: none; user-select: none;
}
/* horní odlesk skla */
.g2048-shell .board-wrap::after {
  content: ''; position: absolute; top: 0; left: 10%; right: 10%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--g48-glass-inner), transparent); pointer-events: none; z-index: 2;
}
.g2048-shell .board-wrap:focus { outline: none; }
.g2048-shell .board-wrap:focus-visible { outline: 3px solid var(--g48-accent); outline-offset: -3px; }

.g2048-shell .grid-bg, .g2048-shell .tiles { position: absolute; inset: var(--pad); }
.g2048-shell .grid-bg {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: var(--gap);
}
.g2048-shell .grid-bg .cell {
  border-radius: 10px;
  background: rgba(248, 250, 252, 0.055);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}

/* ---------- dlaždice ---------- */
.g2048-shell .tiles { pointer-events: none; }
.g2048-shell .tile {
  position: absolute; left: 0; top: 0;
  width: var(--cell); height: var(--cell);
  transform: translate(calc(var(--c) * var(--step)), calc(var(--r) * var(--step)));
  transition: transform var(--slide) ease-out;
  will-change: transform;
}
.g2048-shell .tv {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  font-family: var(--font-heading, sans-serif);
  font-weight: 800;
  color: var(--tile-ink);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.28);
  font-size: calc(var(--cell) * var(--fs, 0.46));
}
.g2048-shell .tile.pop .tv { animation: g48Pop 150ms ease; }
.g2048-shell .tile.appear .tv { animation: g48Appear 160ms ease; }
@keyframes g48Pop {
  0% { transform: scale(1); }
  55% { transform: scale(1.14); }
  100% { transform: scale(1); }
}
@keyframes g48Appear {
  0% { transform: scale(0); opacity: 0; }
  70% { opacity: 1; }
  100% { transform: scale(1); }
}

/* paleta dlaždic (cream → gold) 1:1 ze zdroje — identita hry 2048 */
.g2048-shell .tv[data-v="2"]    { background: linear-gradient(150deg, #EFE7D6, #E5DBC4); }
.g2048-shell .tv[data-v="4"]    { background: linear-gradient(150deg, #F0E1C0, #E7D2A6); }
.g2048-shell .tv[data-v="8"]    { background: linear-gradient(150deg, #F6D69E, #F1C57E); }
.g2048-shell .tv[data-v="16"]   { background: linear-gradient(150deg, #F8C77C, #F4B45E); }
.g2048-shell .tv[data-v="32"]   { background: linear-gradient(150deg, #FBBA5E, #F7A53F); }
.g2048-shell .tv[data-v="64"]   { background: linear-gradient(150deg, #FBAC44, #F59928); }
.g2048-shell .tv[data-v="128"]  { background: linear-gradient(150deg, #F7CB4C, #F0BB1F); }
.g2048-shell .tv[data-v="256"]  { background: linear-gradient(150deg, #F5CE3C, #EEBE12); }
.g2048-shell .tv[data-v="512"]  { background: linear-gradient(150deg, #F3D224, #ECC40A); }
.g2048-shell .tv[data-v="1024"] { background: linear-gradient(150deg, #F1D40D, #E9C800); }
.g2048-shell .tv[data-v="2048"] {
  background: linear-gradient(150deg, #FFE16A, #D4AF37);
  box-shadow: 0 0 18px rgba(255, 215, 0, 0.75), 0 2px 8px rgba(0, 0, 0, 0.35);
}
.g2048-shell .tv[data-v="4096"] { background: linear-gradient(150deg, #7FE3DA, #43C6BA); }
.g2048-shell .tv[data-v="8192"] { background: linear-gradient(150deg, #C2ABFF, #9D7CFF); }
.g2048-shell .tv.super {
  background: linear-gradient(150deg, #FF9FBD, #F86A98);
  box-shadow: 0 0 16px rgba(248, 106, 152, 0.6), 0 2px 8px rgba(0, 0, 0, 0.35);
}

/* ---------- lišta pod deskou: Vrátit tah ---------- */
.g2048-shell .under-bar {
  flex: 0 0 auto;
  display: flex; gap: 1rem; align-items: center; justify-content: center;
  flex-wrap: wrap;
}

/* ---------- tlačítka ---------- */
.g2048-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);
}
.g2048-shell .btn:hover { transform: translateY(-1px); background: rgba(255, 255, 255, .16); }
.g2048-shell .btn:active { transform: translateY(1px); }
.g2048-shell .btn:focus-visible { outline: 3px solid var(--g48-accent); outline-offset: 2px; }
.g2048-shell .btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.g2048-shell .btn[hidden] { display: none; }
.g2048-shell .btn-primary { background: var(--g48-accent); color: #123; border-color: var(--g48-accent); }
.g2048-shell .btn-primary:hover { background: var(--g48-accent-hover); }

/* ---------- dialogy (styl Sčítátka: fullscreen glass, prvky plavou BEZ rámečků/karty) ---------- */
.g2048-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;
}
.g2048-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%);
}
.g2048-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: g48DlgPop .35s cubic-bezier(.34, 1.56, .64, 1);
}
.g2048-shell .dlg > * { width: min(420px, 100%); }
@keyframes g48DlgPop { 0% { transform: scale(.9); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.g2048-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; }
.g2048-shell .dlg fieldset { border: 0; margin: 0; padding: 0; }
.g2048-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) */
.g2048-shell .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: .6rem; }
.g2048-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;
}
.g2048-shell .seg label:hover { background: rgba(255, 255, 255, .14); transform: translateY(-1px); }
.g2048-shell .seg input { position: absolute; opacity: 0; pointer-events: none; }
.g2048-shell .seg label:has(input:checked) { background: var(--g48-accent); color: #123; text-shadow: none; box-shadow: 0 0 18px rgba(127, 255, 212, .5); }
.g2048-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í) */
.g2048-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(--g48-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: g48MenuPulse 2s infinite; transition: transform .12s ease, background .2s ease;
}
.g2048-shell .dlg-cta:hover { background: var(--g48-accent-hover); transform: translateY(-2px); }
.g2048-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 g48MenuPulse {
  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 */
.g2048-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;
}
.g2048-shell .dlg-secondary:hover { background: rgba(255, 255, 255, .12); transform: translateY(-2px); }
.g2048-shell .dlg-secondary:active { transform: translateY(2px); }
/* konec hry */
.g2048-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; }
.g2048-shell .stats-line { color: rgba(255, 255, 255, .8); font-size: .95rem; text-align: center; text-shadow: 0 2px 6px rgba(0, 0, 0, .4); margin: -8px 0 0; }
.g2048-shell .result-emoji { display: block; text-align: center; font-size: 3.2rem; margin-bottom: .2rem; }
.g2048-shell .dlg-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.g2048-shell .dlg-actions .btn { flex: 1 1 auto; }
.g2048-shell .dlg-actions .btn-primary { color: #123; }

/* ---------- konfety ---------- */
.g2048-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) {
  .g2048-shell__game { gap: .3rem; }
  .g2048-shell .status { font-size: clamp(.9rem, 3.6vw, 1.15rem); }
  .g2048-shell .hud { gap: .45rem; }
  .g2048-shell .score-box { min-width: 4.6rem; padding: .2rem .7rem .3rem; }
  .g2048-shell .btn { min-height: 38px; padding: .35rem .8rem; font-size: .85rem; }
}
@media (max-height: 640px) { .g2048-shell__game { gap: .35rem; } }

/* ---------- omezený pohyb: bez smyčkových animací ---------- */
@media (prefers-reduced-motion: reduce) {
  .g2048-shell .dlg { animation: none; }
  .g2048-shell .dlg-cta { animation: none; }
  .g2048-shell .tile { transition-duration: 0.01ms; }
  .g2048-shell .gain { animation-duration: 0.01ms; }
}
