/* ChciHry.cz — Pexeso. Standalone styl; layout čistě CSS (container queries + aspect-ratio + cqmin). */

/* reset, @font-face fallback a sdilene tokeny: viz css/tokens.css (nacist PRED timto souborem) */

body {
    font-family: 'Montserrat', 'Montserrat-fallback', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--surface-dark);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow-x: hidden;
    background-image:
        radial-gradient(circle at 20% 15%, rgba(212, 175, 55, 0.07) 0%, transparent 45%),
        radial-gradient(circle at 85% 80%, rgba(212, 175, 55, 0.05) 0%, transparent 50%);
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

.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;
}

/*herní viewport */
.app {
    box-sizing: border-box;
    height: 100dvh;
    display: grid;
    grid-template-areas: "head" "board";
    grid-template-rows: auto minmax(0, 1fr);
    gap: clamp(0.3rem, 1.2dvh, 0.8rem);
    max-width: 1400px;
    margin: 0 auto;
    padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right))
             0.6rem max(0.5rem, env(safe-area-inset-left));
}

.hd { grid-area: head; text-align: center; min-width: 0; }
.hd h1 {
    font-size: clamp(1.05rem, 4vw, 1.9rem);
    font-weight: 900; letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--primary) 0%, #F5E6D3 55%, var(--primary-dark) 100%);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent; color: transparent;
}
.hd .h1-sub { font-weight: 600; font-size: 0.7em; white-space: nowrap; }

.meta {
    display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
    gap: 0.45rem; margin-top: 0.3rem;
    font-size: 0.85rem; font-weight: 600; color: var(--text-secondary);
}
.chip, .icobtn, .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem;
    border: 1px solid var(--gold-border); border-radius: 9999px;
    color: var(--text-primary); font-weight: 600;
    transition: border-color 0.15s ease, transform 0.15s ease;
    touch-action: manipulation;
}
.chip { padding: 0.25rem 0.7rem; background: rgba(15, 23, 42, 0.8); }
.chip b { color: var(--primary); font-variant-numeric: tabular-nums; }
#timer { font-variant-numeric: tabular-nums; min-width: 3em; }
.icobtn { min-width: 44px; min-height: 36px; padding: 0.25rem 0.6rem; background: rgba(15, 23, 42, 0.8); font-size: 0.95rem; }
.icobtn:hover, .btn:hover { border-color: var(--primary); transform: translateY(-1px); }
.icobtn:focus-visible, .btn:focus-visible, .card:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/*hrací plocha */
.board-area {
    grid-area: board;
    container-type: size;
    display: grid; place-items: center;
    min-height: 0; min-width: 0;
}
.board {
    --cols: 4; --rows: 6;            /* classic portrait default */
    --cap: 9.5rem;                   /* strop hrany karty (~152px) pro 4K */
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    grid-template-rows: repeat(var(--rows), 1fr);
    gap: clamp(0.3rem, 1.4cqmin, 0.9rem);
    aspect-ratio: var(--cols) / var(--rows);
    width: min(100cqw, calc(100cqh * var(--cols) / var(--rows)), calc(var(--cap) * var(--cols)));
}
/* classic: orientaci řídí tvar plochy, ne viewport */
@container (min-aspect-ratio: 1/1) { .board[data-size="classic"] { --cols: 6; --rows: 4; } }
/* small/large = čtverec v obou orientacích (vyšší specificita) */
.board[data-size="small"] { --cols: 4; --rows: 4; }
.board[data-size="large"] { --cols: 6; --rows: 6; }

/*karta */
.card {
    position: relative;
    container-type: size;
    perspective: 1000px;
    border: 0; background: none; padding: 0;
    cursor: pointer;
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
    border-radius: clamp(0.4rem, 2.4cqmin, 1rem);
}
.card:focus-visible { z-index: 3; }
.card__inner {
    position: absolute; inset: 0;
    transform-style: preserve-3d;
    transition: transform 0.45s cubic-bezier(0.4, 0.2, 0.2, 1);
}
.card.is-flipped .card__inner, .card.is-matched .card__inner { transform: rotateY(180deg); }

.card__back, .card__face {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    backface-visibility: hidden; -webkit-backface-visibility: hidden;
    border-radius: inherit;
    overflow: hidden;
}
.card__back {
    background:
        radial-gradient(circle at 50% 36%, rgba(212, 175, 55, 0.22) 0%, transparent 58%),
        linear-gradient(150deg, #3A2A5E 0%, #241640 55%, #190F2C 100%);
    border: 1px solid var(--gold-border);
    box-shadow: inset 0 0 0 1px rgba(212, 175, 55, 0.12), 0 4px 14px rgba(0, 0, 0, 0.45);
}
.card__back::after {
    content: ""; width: 42%; height: 42%;
    border: 2px solid rgba(212, 175, 55, 0.5);
    border-radius: 18%; transform: rotate(45deg);
    box-shadow: inset 0 0 10px rgba(212, 175, 55, 0.22);
}
.card__face {
    transform: rotateY(180deg);
    background: linear-gradient(160deg, #FFFFFF 0%, #F8FAFC 100%);
    border: 1px solid rgba(212, 175, 55, 0.3);
}
.emoji { font-size: min(58cqmin, 140px); line-height: 1; }

/* spárováno */
.card.is-matched { cursor: default; }
.card.is-matched .card__face {
    background: linear-gradient(160deg, #EAF7EA 0%, #F4FBF3 100%);
    border-color: var(--success);
    box-shadow: 0 0 0 2px var(--success), 0 0 16px rgba(92, 184, 92, 0.45);
}

/* událostní efekty */
.card.just-matched .card__inner { animation: pop 0.4s ease-out; }
@keyframes pop {
    0% { transform: rotateY(180deg) scale(1); }
    45% { transform: rotateY(180deg) scale(1.09); }
    100% { transform: rotateY(180deg) scale(1); }
}
.card.shake .card__inner { animation: shake 0.2s ease-in-out; }
@keyframes shake {
    0%, 100% { transform: rotateY(180deg) translateX(0); }
    25% { transform: rotateY(180deg) translateX(-6%); }
    75% { transform: rotateY(180deg) translateX(6%); }
}
.chip.bump, .player.bump { animation: bump 0.28s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 50% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* scoreboard (2–4 hráči) */
#soloChips { display: contents; }
#soloChips[hidden] { display: none; }
.scoreboard { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; margin-top: 0.35rem; }
.scoreboard[hidden] { display: none; }
.player {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.25rem 0.65rem; border: 1px solid var(--gold-border); border-radius: 9999px;
    background: rgba(15, 23, 42, 0.8); font-size: 0.8rem; font-weight: 600; color: var(--text-secondary);
    transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.player .dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--text-muted); flex: none; }
.player .sc { color: var(--primary); font-weight: 800; font-variant-numeric: tabular-nums; min-width: 1ch; text-align: center; }
.player.active { border-color: var(--primary); background: rgba(212, 175, 55, 0.18); color: var(--text-primary); box-shadow: inset 0 0 8px rgba(212, 175, 55, 0.25); transform: scale(1.05); }
.player:nth-child(1) .dot { background: #D4AF37; }
.player:nth-child(2) .dot { background: #5CB85C; }
.player:nth-child(3) .dot { background: #5BC0DE; }
.player:nth-child(4) .dot { background: #D98CB3; }

/* dialog: výběr počtu hráčů */
.players-row { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.8rem; }
.players-row .pl-label { font-size: 0.85rem; font-weight: 700; color: var(--text-secondary); margin-right: 0.1rem; }
.players-row label {
    flex: 1 1 auto; min-width: 2.4rem; text-align: center; padding: 0.45rem 0.2rem;
    border: 1px solid var(--gold-border); border-radius: var(--radius-lg); background: rgba(30, 41, 59, 0.6);
    cursor: pointer; font-weight: 700; transition: border-color 0.15s ease, background 0.15s ease;
}
.players-row input { position: absolute; opacity: 0; pointer-events: none; }
.players-row label:has(input:checked) { border-color: var(--primary); background: rgba(212, 175, 55, 0.16); box-shadow: 0 0 10px rgba(212, 175, 55, 0.2); }
.players-row label:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.players-hint { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.4rem; text-align: center; line-height: 1.4; }

/* výsledek pro více hráčů */
#winSolo[hidden], #winMulti[hidden] { display: none; }
.winner { text-align: center; font-size: 1.15rem; font-weight: 800; color: var(--primary); margin: 0.2rem 0 0.7rem; }
.finalscore { display: flex; flex-direction: column; gap: 0.4rem; }
.fs-row {
    display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
    padding: 0.5rem 0.8rem; border: 1px solid var(--gold-border); border-radius: var(--radius-lg);
    background: rgba(30, 41, 59, 0.5); font-weight: 600; font-size: 0.9rem;
}
.fs-row.win { border-color: var(--primary); background: rgba(212, 175, 55, 0.14); }
.fs-row .fs-sc { color: var(--primary); font-weight: 800; font-variant-numeric: tabular-nums; }
.win-time-multi { text-align: center; color: var(--text-muted); font-size: 0.8rem; margin-top: 0.6rem; }

/*tlačítka / dialogy / toast */
.btn { min-height: 44px; min-width: 44px; padding: 0.5rem 1rem;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.12), rgba(212, 175, 55, 0.05)); font-size: 0.85rem; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: var(--surface-dark); border-color: var(--primary); }
.btn-primary:hover { border-color: #F5E6D3; }

dialog.dlg {
    margin: auto; max-width: min(92vw, 27rem); width: 100%;
    background: linear-gradient(160deg, rgba(15, 23, 42, 0.97), rgba(2, 6, 23, 0.97));
    color: var(--text-primary);
    border: 1px solid rgba(212, 175, 55, 0.35); border-radius: var(--radius-xl);
    padding: 1.3rem;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.7), 0 0 90px rgba(212, 175, 55, 0.12);
}
dialog.dlg::backdrop { background: rgba(2, 6, 23, 0.72); backdrop-filter: blur(4px); }
.dlg h2 { font-size: 1.25rem; font-weight: 800; margin-bottom: 0.9rem; color: var(--primary); text-align: center; }
.dlg .dlg-text { color: var(--text-secondary); font-size: 0.95rem; line-height: 1.5; text-align: center; }
.dlg-actions { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1.1rem; flex-wrap: wrap; }
.dlg-actions .btn { flex: 1 1 auto; }

.sizecards { display: grid; grid-template-columns: 1fr; gap: 0.5rem; }
.sizecards label {
    display: flex; flex-direction: column; gap: 0.15rem; padding: 0.7rem 0.8rem;
    border: 1px solid var(--gold-border); border-radius: var(--radius-lg);
    background: rgba(30, 41, 59, 0.6); cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.sizecards input { position: absolute; opacity: 0; pointer-events: none; }
.sizecards b { font-size: 0.95rem; }
.sizecards small { font-size: 0.7rem; color: var(--text-muted); line-height: 1.35; }
.sizecards label:has(input:checked) {
    border-color: var(--primary); background: rgba(212, 175, 55, 0.14);
    box-shadow: 0 0 12px rgba(212, 175, 55, 0.25);
}
.sizecards label:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

.setrow {
    display: flex; align-items: center; justify-content: space-between; gap: 0.7rem;
    padding: 0.6rem 0; border-bottom: 1px solid rgba(212, 175, 55, 0.12);
    font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.setrow:last-of-type { border-bottom: 0; }
.setrow input[type="checkbox"] { width: 2.6rem; height: 1.4rem; accent-color: var(--primary); cursor: pointer; flex: none; }
.setrow select {
    font: inherit; color: var(--text-primary); background: rgba(30, 41, 59, 0.9);
    border: 1px solid var(--gold-border); border-radius: var(--radius-sm); padding: 0.3rem 0.5rem;
}

.result-emoji { display: block; text-align: center; font-size: 2.6rem; margin-bottom: 0.2rem; }
.stars { text-align: center; font-size: 1.6rem; letter-spacing: 0.15rem; color: var(--primary); margin-bottom: 0.4rem; }
.stars .off { color: var(--text-muted); opacity: 0.5; }
.winstats { margin: 0.6rem 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.winstats div {
    padding: 0.5rem 0.6rem; text-align: center;
    border: 1px solid var(--gold-border); border-radius: var(--radius-lg);
    background: rgba(30, 41, 59, 0.5); font-size: 0.82rem; color: var(--text-secondary);
}
.winstats .span2 { grid-column: 1 / -1; }
.winstats b { display: block; font-size: 1.05rem; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.record { text-align: center; color: var(--primary); font-weight: 800; margin-top: 0.7rem; }
.record[hidden] { display: none; }

.toast {
    position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
    display: flex; gap: 0.6rem; align-items: center;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.97), rgba(2, 6, 23, 0.97));
    border: 1px solid rgba(212, 175, 55, 0.4); border-radius: 9999px;
    padding: 0.55rem 0.6rem 0.55rem 1rem; font-size: 0.85rem; font-weight: 600;
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.6); z-index: 90;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast[hidden] { display: none; }
.toast.hiding { opacity: 0; transform: translateX(-50%) translateY(10px); }
.toast .btn { min-height: 36px; padding: 0.3rem 0.8rem; font-size: 0.78rem; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; }

/*obsah (SEO/GEO) */
.content {
    max-width: 820px; margin: 2.5rem auto 0;
    padding: 0 max(1rem, env(safe-area-inset-right)) 2.5rem max(1rem, env(safe-area-inset-left));
    line-height: 1.65; color: var(--text-secondary);
}
.content .answer-first {
    font-size: 1.02rem; color: var(--text-primary);
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid var(--gold-border); border-left: 4px solid var(--primary);
    border-radius: var(--radius-lg); padding: 1rem 1.2rem;
}
.content h2 { font-size: clamp(1.25rem, 3.4vw, 1.6rem); font-weight: 800; color: var(--text-primary); margin: 2.2rem 0 0.8rem; }
.content h3 { font-size: 1.05rem; font-weight: 700; color: var(--primary); margin: 1.3rem 0 0.45rem; }
.content p { margin-bottom: 0.8rem; }
.content ul, .content ol { margin: 0 0 0.9rem 1.4rem; }
.content li { margin-bottom: 0.35rem; }
.content strong { color: var(--text-primary); }
.content kbd {
    padding: 0.1rem 0.45rem; background: rgba(30, 41, 59, 0.8);
    border: 1px solid var(--gold-border); border-bottom-width: 2px; border-radius: var(--radius-sm);
    font-family: inherit; font-size: 0.85em; font-weight: 700; color: var(--text-primary);
}
.faq-item {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid var(--gold-border); border-radius: var(--radius-lg);
    padding: 0.9rem 1.1rem; margin-bottom: 0.7rem;
}
.faq-item h3 { margin: 0 0 0.4rem; }
.faq-item p { margin: 0; font-size: 0.95rem; }
.more-games { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0.8rem 0; }
.more-games a {
    padding: 0.45rem 1rem; background: rgba(212, 175, 55, 0.1);
    border: 1px solid var(--gold-border); border-radius: 9999px;
    font-size: 0.875rem; font-weight: 600;
    transition: border-color 0.15s ease, transform 0.15s ease;
}
.more-games a:hover { border-color: var(--primary); transform: translateY(-2px); color: var(--primary); }
.more-games .all { flex-basis: 100%; display: flex; justify-content: center; margin-top: 0.6rem; }
.updated { margin-top: 2rem; font-size: 0.8rem; color: var(--text-muted); }

/*responzivita */
/* mobil landscape: deska vlevo, hlavička/ovladače jako boční sloupec */
@media (max-height: 500px) and (orientation: landscape) {
    .app {
        grid-template-areas: "board head";
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-rows: minmax(0, 1fr);
        column-gap: 0.8rem;
    }
    .hd { align-self: center; max-width: 38vw; }
    .hd h1 { font-size: 0.95rem; }
    .hd .h1-sub { display: none; }
    .meta { flex-direction: column; align-items: stretch; }
}

/* tablet/desktop */
@media (min-width: 768px) {
    .hd h1 { margin-bottom: 0.1rem; }
    .meta { font-size: 0.95rem; gap: 0.6rem; }
    .icobtn { min-height: 40px; font-size: 1.05rem; }
}

/* 4K / velmi široké */
@media (min-width: 2560px) {
    .board { --cap: 11rem; }
    .content { max-width: 1100px; font-size: 1.12rem; }
    .meta { font-size: 1.1rem; }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
