/* ChciHry.cz — Gonu (čtyřpolové, 네밭고누). Standalone styl (model B).
 * Sdílené tokeny + reset + @font-face: css/tokens.css (načíst PRED tímto souborem).
 * Zde jen herně specifické tokeny a layout/komponenty. Animace pouze transform/opacity, jen událostní. */

:root {
    --line: rgba(212, 175, 55, 0.55);
    --node: rgba(212, 175, 55, 0.35);
    --board: min(100vw - 1rem, 60svh);
    --pt: 17%;          /* velikost průsečíku vůči desce */
    /* dvě armády — zlatá (brand) vs modrá (kontrast, colorblind-safe) */
    --gold-1: #FFFDF4; --gold-2: #F0E2C4; --gold-3: #C6AE82;
    --blue-1: #BFE6FB; --blue-2: #5BB6E6; --blue-3: #2D7DB0;
}

html { height: 100%; }

body {
    font-family: 'Montserrat', 'Montserrat-fallback', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--surface-dark);
    color: var(--text-primary);
    min-height: 100svh;
    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(91, 182, 230, 0.06) 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); }
svg { display: block; }

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

/* ---------- layout ---------- */
.shell {
    container-type: inline-size;
    container-name: app;
    padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right))
             0.5rem max(0.5rem, env(safe-area-inset-left));
}
.app {
    display: grid;
    grid-template-areas: "head" "board" "panel";
    justify-items: center;
    gap: clamp(0.4rem, 1.2dvh, 1rem);
    max-width: 1400px;
    margin: 0 auto;
}

.hd { grid-area: head; text-align: center; min-width: 0; }
.hd h1 {
    font-size: clamp(1.15rem, 4.4vw, 2rem);
    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.72em; white-space: nowrap; }

.status {
    margin-top: 0.2rem;
    font-size: clamp(0.85rem, 2.6vw, 1.05rem);
    font-weight: 600;
    color: var(--text-secondary);
    min-height: 1.4em;
}
.status.is-capture { color: var(--danger); }
.status.is-thinking { color: var(--primary); }
.status.is-over { color: var(--primary); }

/* ---------- deska ---------- */
.board-zone { grid-area: board; min-width: 0; }
.board-wrap {
    width: var(--board);
    aspect-ratio: 1;
    padding: 2.5%;
    border: 3px solid var(--primary-dark);
    outline: 1px solid rgba(212, 175, 55, 0.45);
    border-radius: var(--radius-md);
    background:
        radial-gradient(circle at 30% 25%, rgba(40, 30, 12, 0.35), transparent 60%),
        linear-gradient(150deg, #20283a 0%, #161d2c 60%, #0d1420 100%);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55), 0 0 60px rgba(212, 175, 55, 0.08);
    touch-action: manipulation;
    -webkit-user-select: none; user-select: none;
}
.board {
    position: relative;
    width: 100%; height: 100%;
}
.board-lines {
    position: absolute; inset: 0; width: 100%; height: 100%;
    pointer-events: none;
}
.board-lines line {
    fill: none; stroke: var(--line); stroke-width: 1.3;
    stroke-linejoin: round; stroke-linecap: round;
}

/* ---------- průsečíky a kameny ---------- */
.point {
    position: absolute;
    width: var(--pt); height: var(--pt);
    transform: translate(-50%, -50%);
    display: grid; place-items: center;
    border-radius: 50%;
    padding: 0;
}
/* uzel (značka volného průsečíku) */
.point::before {
    content: ''; position: absolute;
    width: 30%; height: 30%;
    border-radius: 50%;
    background: var(--node);
    transition: opacity 0.15s ease, transform 0.15s ease;
}
.point.p1::before, .point.p2::before { opacity: 0; }

.point:focus { outline: none; }
.point:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 0;
    z-index: 4;
}

.stone {
    position: relative;
    width: 88%; height: 88%;
    border-radius: 50%;
    opacity: 0;
    transform: scale(0.4);
    transition: opacity 0.18s ease-out, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.5));
    pointer-events: none;
}
.point.p1 .stone, .point.p2 .stone { opacity: 1; transform: scale(1); }
.point.p1 .stone {
    background: radial-gradient(circle at 38% 30%, var(--gold-1) 0%, var(--gold-2) 55%, var(--gold-3) 100%);
    box-shadow: inset 0 -3px 6px rgba(120, 95, 50, 0.45), inset 0 2px 5px rgba(255, 255, 255, 0.7);
}
.point.p2 .stone {
    background: radial-gradient(circle at 38% 30%, var(--blue-1) 0%, var(--blue-2) 55%, var(--blue-3) 100%);
    box-shadow: inset 0 -3px 6px rgba(12, 50, 80, 0.5), inset 0 2px 5px rgba(255, 255, 255, 0.55);
}

/* legální cíl obyčejného posunu (zlatá tečka) — jen prázdné body */
.point.dst::after {
    content: ''; position: absolute;
    width: 32%; height: 32%;
    border-radius: 50%;
    background: rgba(212, 175, 55, 0.85);
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.7);
    animation: dstIn 0.18s ease-out;
}
@keyframes dstIn { from { transform: scale(0.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* soupeřův kámen, na který lze přeskočit (braní) — červený prstenec */
.point.capt { z-index: 3; cursor: pointer; }
.point.capt .stone {
    box-shadow: 0 0 0 3px var(--danger), 0 0 14px rgba(217, 83, 79, 0.7);
    animation: captPulse 1s ease-in-out infinite;
}
@keyframes captPulse { 0%, 100% { filter: drop-shadow(0 3px 4px rgba(0,0,0,0.5)) brightness(1); } 50% { filter: drop-shadow(0 3px 4px rgba(0,0,0,0.5)) brightness(1.3); } }

/* kámen, kterým lze brát, když není jiný tah (typicky plná deska na startu) — jemný zlatý prstenec */
.point.movable .stone {
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.75), 0 0 12px rgba(212, 175, 55, 0.5);
    animation: movablePulse 1.3s ease-in-out infinite;
}
@keyframes movablePulse { 0%, 100% { filter: drop-shadow(0 3px 4px rgba(0,0,0,0.5)) brightness(1); } 50% { filter: drop-shadow(0 3px 4px rgba(0,0,0,0.5)) brightness(1.18); } }

/* nelegální klepnutí — krátké zatřesení kamenem (viditelná zpětná vazba) */
.point.nogo .stone { animation: nogoShake 0.4s ease; }
@keyframes nogoShake { 0%, 100% { transform: scale(1); } 20% { transform: scale(1) translateX(-12%); } 50% { transform: scale(1) translateX(12%); } 80% { transform: scale(1) translateX(-6%); } }

/* vybraný kámen — zlatý prstenec + levitace */
.point.sel { z-index: 3; }
.point.sel .stone {
    box-shadow: 0 0 0 3px var(--primary), 0 0 16px rgba(212, 175, 55, 0.7);
    animation: selFloat 1.4s ease-in-out infinite;
}
@keyframes selFloat { 0%, 100% { transform: scale(1.04) translateY(0); } 50% { transform: scale(1.04) translateY(-7%); } }

/* poslední tah */
.point.last::before { opacity: 1; background: rgba(212, 175, 55, 0.6); transform: scale(1.6); }
.point.placed .stone { animation: placePop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes placePop { 0% { transform: scale(0.55); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* ---------- panel ---------- */
.panel {
    grid-area: panel;
    display: flex; flex-direction: column; align-items: center;
    gap: 0.6rem;
    width: 100%;
    max-width: calc(var(--board) + 1.2rem);
}
.counts {
    display: flex; gap: 1rem; align-items: center;
    font-weight: 700; font-size: 1rem; color: var(--text-secondary);
}
.cnt { display: inline-flex; align-items: center; gap: 0.4rem; }
.cnt.active { color: var(--primary); }
.cdot { width: 1rem; height: 1rem; border-radius: 50%; display: inline-block; }
.cdot.p1 { background: radial-gradient(circle at 38% 30%, var(--gold-1), var(--gold-3)); box-shadow: inset 0 -1px 2px rgba(120,95,50,0.5); }
.cdot.p2 { background: radial-gradient(circle at 38% 30%, var(--blue-1), var(--blue-3)); box-shadow: inset 0 -1px 2px rgba(12,50,80,0.5); }

.btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.45rem; width: 100%; }
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; min-width: 44px;
    padding: 0.5rem 0.7rem;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.12), rgba(212, 175, 55, 0.05));
    border: 1px solid var(--gold-border);
    border-radius: 9999px;
    color: var(--text-primary);
    font-size: 0.8rem; font-weight: 600; letter-spacing: 0.02em;
    transition: border-color 0.15s ease, transform 0.15s ease;
    text-align: center;
}
.btn:hover { border-color: var(--primary); transform: translateY(-1px); }
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn[aria-pressed="true"] { border-color: var(--primary); background: rgba(212, 175, 55, 0.16); }
.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; }
.btn[hidden] { display: none; }

/* ---------- dialogy ---------- */
dialog.dlg {
    margin: auto;
    max-width: min(92vw, 26rem); 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 fieldset { border: 0; margin-bottom: 0.9rem; }
.dlg legend { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); margin-bottom: 0.4rem; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0.4rem; }
.seg label {
    display: flex; align-items: center; justify-content: center;
    min-height: 44px; padding: 0.45rem 0.5rem;
    border: 1px solid var(--gold-border); border-radius: var(--radius-lg);
    background: rgba(30, 41, 59, 0.6);
    font-size: 0.85rem; font-weight: 600; text-align: center; cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: var(--primary); }
.seg 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); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.dlg-actions { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1.1rem; flex-wrap: wrap; }
.dlg-actions .btn { flex: 1 1 auto; }
.dlg .stats-line { text-align: center; margin-top: 0.7rem; color: var(--text-secondary); font-size: 0.9rem; }
.dlg .result-emoji { display: block; text-align: center; font-size: 2.6rem; margin-bottom: 0.4rem; }

/* ---------- toast ---------- */
.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; opacity: 1;
    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; }

/* ---------- obsahová sekce (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); }
.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); }

/* ========== ANIMOVANÝ NÁVOD (mini-ukázky) ========== */
.tutorial { margin-top: 1.2rem; }
.demos { display: grid; gap: 1.4rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .demos { grid-template-columns: 1fr 1fr; } }

.demo {
    margin: 0;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid var(--gold-border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.1rem 1.1rem;
    display: flex; flex-direction: column; gap: 0.7rem;
}
.demo-title { font-size: 1.02rem; font-weight: 700; color: var(--primary); margin: 0; }

/* mini-deska: čtvercová plocha s absolutně pozicovanými kameny */
.demo-board {
    position: relative;
    width: min(100%, 260px);
    aspect-ratio: 1;
    align-self: center;
    margin: 0.2rem 0;
    border: 2px solid var(--primary-dark);
    border-radius: var(--radius-sm);
    background: linear-gradient(150deg, #20283a 0%, #161d2c 60%, #0d1420 100%);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}
.demo-board svg.demo-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.demo-board svg.demo-lines line { stroke: var(--line); stroke-width: 1.3; stroke-linecap: round; }
.demo-stone {
    position: absolute;
    width: 17%; height: 17%;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    left: 0; top: 0;
    transition: left 0.55s cubic-bezier(0.4, 0, 0.2, 1), top 0.55s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease, box-shadow 0.3s ease;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
}
.demo-stone.p1 { background: radial-gradient(circle at 38% 30%, var(--gold-1), var(--gold-2) 55%, var(--gold-3)); box-shadow: inset 0 -2px 4px rgba(120,95,50,0.45), inset 0 1px 3px rgba(255,255,255,0.7); }
.demo-stone.p2 { background: radial-gradient(circle at 38% 30%, var(--blue-1), var(--blue-2) 55%, var(--blue-3)); box-shadow: inset 0 -2px 4px rgba(12,50,80,0.5), inset 0 1px 3px rgba(255,255,255,0.55); }
.demo-stone.captured { opacity: 0; transform: translate(-50%, -50%) scale(0.2); }
.demo-stone.active { box-shadow: 0 0 0 3px var(--primary), 0 0 12px rgba(212,175,55,0.7); z-index: 2; }
.demo-stone.target-capt { box-shadow: 0 0 0 3px var(--danger), 0 0 12px rgba(217,83,79,0.7); }
/* ukazatel cíle */
.demo-ghost {
    position: absolute; width: 13%; height: 13%; border-radius: 50%;
    transform: translate(-50%, -50%); left: 0; top: 0;
    background: rgba(212, 175, 55, 0.85); box-shadow: 0 0 8px rgba(212,175,55,0.7);
    opacity: 0; transition: opacity 0.3s ease;
}
.demo-ghost.show { opacity: 1; }
.demo-board.bad-diag::after,
.demo-board.bad-enemy::after { content: ''; }

.demo-caption {
    min-height: 2.6em;
    font-size: 0.92rem; font-weight: 600; color: var(--text-primary);
    background: rgba(2, 6, 23, 0.55);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.7rem;
}
.demo-controls { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.demo-controls .btn { min-height: 40px; font-size: 0.78rem; padding: 0.4rem 0.9rem; }
.demo-steps { margin: 0.2rem 0 0 1.2rem; font-size: 0.9rem; color: var(--text-secondary); }
.demo-steps li { margin-bottom: 0.25rem; }
.demo-steps li.is-current { color: var(--primary); font-weight: 700; }

/* statická poznámka „co nelze" */
.demo--rules .demo-board { background: linear-gradient(150deg, #2a1d20 0%, #1c1418 60%, #140d10 100%); }
.no-list { list-style: none; margin-left: 0; }
.no-list li { display: flex; align-items: flex-start; gap: 0.5rem; }
.no-list .x { color: var(--danger); font-weight: 800; }

/* ---------- responzivita ---------- */
@media (min-width: 768px) {
    :root { --board: min(72svh, 560px); }
    .btns { grid-template-columns: repeat(3, minmax(8rem, 1fr)); }
}

/* desktop: panel vpravo od desky */
@container app (min-width: 1024px) {
    .app {
        grid-template-areas: "head head" "board panel";
        grid-template-columns: auto minmax(220px, 280px);
        align-items: start; justify-content: center; justify-items: stretch;
        column-gap: 1.5rem;
    }
    .hd { justify-self: center; }
    .panel { max-width: none; position: sticky; top: 1rem; }
    .btns { grid-template-columns: 1fr; }
    .counts { font-size: 1.15rem; justify-content: center; padding: 0.6rem 0; flex-direction: column; gap: 0.4rem; }
}
@media (min-width: 1024px) {
    :root { --board: min(72svh, calc(100vw - 360px), 620px); }
}

/* mobil landscape: deska vlevo, ovládání vpravo */
@media (max-height: 500px) and (orientation: landscape) {
    :root { --board: min(92svh - 1rem, calc(100vw - 250px)); }
    .app {
        grid-template-areas: "board head" "board panel";
        grid-template-columns: auto 1fr;
        grid-template-rows: auto 1fr;
        column-gap: 1rem; align-items: start;
    }
    .hd h1 { font-size: 1rem; }
    .hd .h1-sub { display: block; font-size: 0.7rem; }
    .panel { max-width: 320px; justify-self: center; }
    .btns { grid-template-columns: repeat(2, 1fr); gap: 0.35rem; }
    .btn { min-height: 40px; font-size: 0.72rem; }
}

/* widescreen / 4K */
@media (min-width: 2560px) {
    :root { --board: min(72svh, 820px); }
    .content { max-width: 1000px; font-size: 1.1rem; }
}

/* výkon: na malých displejích vypnout smyčkové animace (levitace/pulz) */
@media (max-width: 768px) {
    .point.sel .stone { animation: none; }
    .point.capt .stone { animation: none; }
    .point.movable .stone { animation: none; }
}

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