/* ChciHry.cz — Sudoku Master. Standalone styl; animace jen transform/opacity. */

/* reset, @font-face fallback a sdilene tokeny: viz css/tokens.css (nacist PRED timto souborem) */
:root {
    --line: rgba(212, 175, 55, 0.15); --line-box: rgba(212, 175, 55, 0.45);
    --board: min(100vw - 1rem, 52dvh);
}

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

/* ---------- 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.35rem, 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.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);
}
.meta .chip { gap: 0.3rem; padding: 0.25rem 0.7rem; background: rgba(15, 23, 42, 0.8); }
#timer { font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: center; }
.btn, .icobtn, .meta .chip {
    display: inline-flex; align-items: center; justify-content: center;
    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;
}
.icobtn { min-width: 44px; min-height: 36px; padding: 0.25rem 0.6rem; background: rgba(15, 23, 42, 0.8); font-size: 0.9rem; }
.btn:hover, .icobtn:hover, .abtn:hover, .np button:hover { border-color: var(--primary); transform: translateY(-1px); }
.icobtn:focus-visible, .btn:focus-visible, .cell:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ---------- mřížka ---------- */
.board-zone { grid-area: board; position: relative; }

.board-wrap {
    width: var(--board);
    aspect-ratio: 1;
    container-type: inline-size;
    position: relative;
    border: 2px solid var(--line-box);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: rgba(15, 23, 42, 0.92);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55), 0 0 60px rgba(212, 175, 55, 0.08);
    touch-action: manipulation;
}

.grid { display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); width: 100%; height: 100%; }
.grid.hidden-board { visibility: hidden; }
.grow { display: contents; }

.cell {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
    background: transparent;
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.grow .cell:nth-child(3n) { border-right: 2px solid var(--line-box); }
.grow .cell:nth-child(9) { border-right: 0; }
.grow:nth-child(3n) .cell { border-bottom: 2px solid var(--line-box); }
.grow:nth-child(9) .cell { border-bottom: 0; }

.cell:focus-visible { outline-offset: -3px; z-index: 3; }

.cell.hl { background: rgba(212, 175, 55, 0.07); }
.cell.same { background: rgba(212, 175, 55, 0.22); }
.cell.conflict, .cell.err { background: rgba(217, 83, 79, 0.25); }
.cell.sel { background: rgba(212, 175, 55, 0.14); box-shadow: inset 0 0 0 2px var(--primary); z-index: 2; }

.cell .v {
    font-size: 7.2cqi;
    font-weight: 600;
    color: var(--primary);
    line-height: 1;
}
.cell.given .v { color: var(--text-primary); font-weight: 700; }
.cell.conflict .v, .cell.err .v { color: #FF8A85; }

.cell .n {
    position: absolute; inset: 4%;
    display: grid;
    grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
    pointer-events: none;
}
.cell .n span {
    display: flex; align-items: center; justify-content: center;
    font-size: 2.7cqi; font-weight: 600; line-height: 1;
    color: #94A3B8;
    visibility: hidden;
}
.cell .n span.on { visibility: visible; }
.cell.same .n span.on.nsame { color: var(--primary); font-weight: 700; }

/* animace */
.cell.pop .v { animation: pop 0.12s ease-out; }
@keyframes pop { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }
.cell.shake { animation: shake 0.2s ease-in-out; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6%); } 75% { transform: translateX(6%); } }
.cell.wave::after {
    content: ''; position: absolute; inset: 0;
    background: rgba(212, 175, 55, 0.45);
    opacity: 0;
    animation: wave 0.4s ease-out;
    animation-delay: inherit;
}
@keyframes wave { 0% { opacity: 0; } 35% { opacity: 1; } 100% { opacity: 0; } }

.boardov {
    position: absolute; inset: 0; z-index: 5;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.8rem;
    background: rgba(2, 6, 23, 0.88); backdrop-filter: blur(6px);
    border-radius: var(--radius-sm); text-align: center;
}
.boardov[hidden] { display: none; }
.boardov .big { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.spinner {
    width: 42px; height: 42px; border-radius: 50%;
    border: 4px solid var(--gold-border); border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- panel ---------- */
.panel {
    grid-area: panel;
    display: flex; flex-direction: column;
    gap: clamp(0.35rem, 1.1dvh, 0.7rem);
    width: 100%;
    max-width: var(--board);
}

.actions { display: flex; gap: 0.4rem; justify-content: center; }
.abtn {
    flex: 1 1 0; position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.1rem;
    min-height: 48px; padding: 0.3rem 0.2rem;
    border: 1px solid var(--gold-border); border-radius: var(--radius-lg);
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.10), rgba(212, 175, 55, 0.04));
    font-size: 1.05rem;
    transition: border-color 0.15s ease, transform 0.15s ease;
    touch-action: manipulation;
}
.abtn small { font-size: 0.58rem; font-weight: 600; color: var(--text-secondary); letter-spacing: 0.02em; }
.abtn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.abtn[aria-pressed="true"] {
    border-color: var(--primary);
    background: rgba(212, 175, 55, 0.22);
    box-shadow: inset 0 0 8px rgba(212, 175, 55, 0.25);
}
.abtn .badge {
    position: absolute; top: 2px; right: 6px;
    font-size: 0.6rem; font-weight: 700; color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.np {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.4rem;
}
.np button {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 48px; min-width: 48px;
    border: 1px solid var(--gold-border); border-radius: var(--radius-lg);
    background: rgba(30, 41, 59, 0.75);
    font-size: 1.25rem; font-weight: 700; line-height: 1;
    color: var(--text-primary);
    transition: border-color 0.15s ease, transform 0.15s ease, opacity 0.2s ease;
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.np button .cnt { font-size: 0.62rem; font-weight: 600; color: var(--text-muted); margin-top: 0.1rem; }
.np button.done { opacity: 0.32; }
.np button.grab { border-color: var(--primary); background: rgba(212, 175, 55, 0.2); }

/* ---------- 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; }

.diffcards { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.diffcards label {
    display: flex; flex-direction: column; gap: 0.15rem; padding: 0.6rem 0.7rem;
    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;
}
.diffcards input { position: absolute; opacity: 0; pointer-events: none; }
.diffcards b { font-size: 0.92rem; }
.diffcards small { font-size: 0.68rem; color: var(--text-muted); line-height: 1.35; }
.diffcards 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);
}
.diffcards label:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

.dailybtn {
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
    width: 100%; margin-top: 0.6rem; min-height: 48px;
    border: 1px solid var(--gold-border); border-radius: var(--radius-lg);
    background: rgba(30, 41, 59, 0.6); font-size: 0.92rem; font-weight: 700;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.dailybtn:hover { border-color: var(--primary); background: rgba(212, 175, 55, 0.14); }
.dailybtn small { font-weight: 600; color: var(--text-muted); }

.setrow {
    display: flex; align-items: center; justify-content: space-between; gap: 0.7rem;
    padding: 0.55rem 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 { width: 2.6rem; height: 1.4rem; accent-color: var(--primary); cursor: pointer; flex: none; }

.result-emoji { display: block; text-align: center; font-size: 2.6rem; margin-bottom: 0.4rem; }
.winstats { margin: 0.8rem 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.85rem; color: var(--text-secondary);
}
.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 ---------- */
.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 ---------- */
/* ≤345 px: kompakt bez scrollu */
@media (max-width: 345px) and (max-height: 600px) { :root { --board: min(100vw - 1rem, 47dvh); } }
@container app (max-width: 330px) {
    .hd .h1-sub { display: none; }
    .app { gap: 0.3rem; }
    .abtn { min-height: 42px; font-size: 0.95rem; }
    .abtn small { display: none; }
}

/* širší mobil: numpad 9×1 */
@container app (min-width: 470px) {
    .np { grid-template-columns: repeat(9, 1fr); }
    .np button { min-height: 52px; }
}

#statsBox { display: none; }
#statsBox b { color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* tablet/desktop */
@container app (min-width: 768px) {
    .app {
        grid-template-areas: "head head" "board panel";
        grid-template-columns: auto minmax(230px, 300px);
        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; }
    .np { grid-template-columns: repeat(3, 1fr); }
    .np button { min-height: 56px; font-size: 1.4rem; }
    .actions { flex-wrap: wrap; }
    .abtn { flex: 1 1 30%; }
    #statsBox {
        display: block;
        padding: 0.7rem 0.9rem;
        border: 1px solid var(--gold-border); border-radius: var(--radius-lg);
        background: rgba(15, 23, 42, 0.8);
        font-size: 0.8rem; color: var(--text-secondary); line-height: 1.6;
    }
}
@media (min-width: 768px) { :root { --board: min(70dvh, 640px); } }

/* mobil landscape */
@media (max-height: 500px) and (orientation: landscape) {
    :root { --board: min(92dvh - 0.8rem, 58vw); }
    .app {
        grid-template-areas: "board head" "board panel";
        grid-template-columns: auto 1fr;
        grid-template-rows: auto 1fr;
        column-gap: 0.9rem;
        align-items: start;
    }
    .hd h1 { font-size: 1rem; }
    .hd .h1-sub { display: none; }
    .panel { max-width: 340px; justify-self: center; align-self: center; }
    .np { grid-template-columns: repeat(3, 1fr); gap: 0.3rem; }
    .np button { min-height: 44px; font-size: 1.05rem; }
    .np button .cnt { display: none; }
    .actions { gap: 0.3rem; }
    .abtn { min-height: 42px; }
    .abtn small { display: none; }
}

/* 4K */
@media (min-width: 2560px) {
    :root { --board: min(75dvh, 1000px); }
    .content { max-width: 1000px; font-size: 1.1rem; }
}
@container app (min-width: 2000px) {
    .app { grid-template-columns: auto minmax(280px, 380px); column-gap: 2.2rem; }
    .np button { min-height: 72px; font-size: 1.8rem; }
    .meta { font-size: 1.05rem; }
}

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