/* Свободная ячейка VK Mini App — бордовое сукно, золото. Тема единая (тёмная). */
:root {
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;

    --bg-0: #6e1530;
    --bg-1: #250810;
    --felt: radial-gradient(120% 70% at 50% -10%, rgba(220, 60, 100, .24), transparent 60%),
            radial-gradient(90% 60% at 50% 115%, rgba(160, 30, 70, .2), transparent 60%),
            linear-gradient(180deg, var(--bg-0), var(--bg-1) 72%);

    --text: #fff0f2;
    --text-dim: #d79aa8;

    --gold-1: #f6df9c;
    --gold-2: #d4a941;
    --gold-3: #9c7420;

    --panel: rgba(60, 12, 26, .55);
    --panel-border: rgba(240, 150, 175, .26);
    --panel-glow: 0 0 18px rgba(220, 60, 100, .18), inset 0 1px 0 rgba(255,255,255,.05);

    --red: #d23b4a;
    --black: #16233a;
    --accent: #e0577a;

    --card-w: clamp(30px, 10.6vw, 54px);
    --card-h: calc(var(--card-w) * 1.423);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; width: 100%; overflow: hidden; overscroll-behavior: none; }
body {
    font-family: var(--font); color: var(--text); font-size: 15px; line-height: 1.45;
    -webkit-font-smoothing: antialiased; background: var(--felt); background-attachment: fixed;
    touch-action: none;
}
.hidden { display: none !important; }
[hidden] { display: none !important; }
#app { height: 100%; min-height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.screen {
    flex: 1; min-height: 0; display: flex; flex-direction: column;
    padding:
        max(14px, env(safe-area-inset-top))
        max(14px, env(safe-area-inset-right))
        max(14px, env(safe-area-inset-bottom))
        max(14px, env(safe-area-inset-left));
}

/* ---------- Меню ---------- */
#screen-menu {
    align-items: center; justify-content: safe center; gap: 6px;
    overflow-x: hidden; overflow-y: auto; touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}
.brand { text-align: center; margin-bottom: 10px; }
.brand-suits { font-size: 30px; letter-spacing: 6px; margin-bottom: 4px; }
.brand-suits .red { color: var(--red); } .brand-suits .blk { color: var(--gold-1); }
.menu-title {
    font-size: 42px; font-weight: 800; letter-spacing: 1px;
    background: linear-gradient(180deg, var(--gold-1) 20%, var(--gold-2) 62%, var(--gold-3));
    -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 3px 12px rgba(212, 169, 65, .35));
}
.menu-subtitle { font-size: 12px; font-weight: 700; letter-spacing: 2.4px; text-transform: uppercase; color: var(--text-dim); margin: -2px 0 18px; }

.menu-actions { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 10px; }
.mode-card { display: flex; align-items: center; gap: 14px; text-align: left; font-family: var(--font); color: var(--text); cursor: pointer; background: var(--panel); border: 1.5px solid var(--panel-border); border-radius: 16px; padding: 14px 15px; box-shadow: var(--panel-glow); transition: transform .07s ease; position: relative; }
.mode-card:active { transform: scale(.98); }
.mode-card-primary { border-color: rgba(240, 150, 175, .6); box-shadow: 0 0 26px rgba(220, 70, 110, .32), inset 0 1px 0 rgba(255,255,255,.08); background: linear-gradient(165deg, rgba(140, 30, 60, .5), rgba(40, 10, 20, .7)); }
.mode-icon { flex: none; width: 48px; height: 48px; border-radius: 13px; font-size: 24px; background: rgba(30, 6, 14, .6); border: 1px solid var(--panel-border); display: flex; align-items: center; justify-content: center; }
.mode-name { display: block; font-size: 16.5px; font-weight: 800; }
.mode-sub { display: block; font-size: 12.5px; color: var(--text-dim); margin-top: 1px; }

.menu-stats { display: flex; align-items: stretch; gap: 4px; margin-top: 18px; width: 100%; max-width: 400px; background: var(--panel); border: 1.5px solid var(--panel-border); border-radius: 14px; padding: 12px 8px; box-shadow: var(--panel-glow); }
.stat-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat-item b { font-size: 20px; font-weight: 800; color: var(--gold-1); }
.stat-item span { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; text-align: center; }
.stat-sep { width: 1px; background: var(--panel-border); }
.rules-link { margin-top: 18px; background: none; border: none; cursor: pointer; color: var(--text-dim); font-family: var(--font); font-size: 14px; font-weight: 600; text-decoration: underline; }

/* ---------- Шапка игры ---------- */
.game-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.icon-btn { flex: none; width: 38px; height: 38px; border-radius: 12px; cursor: pointer; background: var(--panel); border: 1.5px solid var(--panel-border); color: var(--text); font-size: 18px; display: flex; align-items: center; justify-content: center; font-family: var(--font); }
.icon-btn:active { transform: scale(.94); }
.hud { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; }
.hud-item { display: flex; align-items: center; gap: 4px; font-weight: 700; font-size: 12.5px; color: var(--text); background: var(--panel); border: 1.5px solid var(--panel-border); border-radius: 10px; padding: 6px 9px; }
.hud-ico { font-size: 11px; }

/* ---------- Стол ---------- */
.table-wrap { flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.top-row { display: flex; justify-content: space-between; gap: 6px; }
.freecells, .foundations { display: flex; gap: calc(var(--card-w) * .12); }
.pile { width: var(--card-w); height: var(--card-h); border-radius: 7px; position: relative; }
.pile-freecell, .pile-foundation { border: 1.5px dashed rgba(255,255,255,.22); background: rgba(0,0,0,.14); }
.pile.is-empty.pile-foundation::after { content: attr(data-suit-ico); position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--card-w) * .5); color: rgba(255,255,255,.28); }
.pile.is-empty.pile-foundation[data-suit="H"]::after, .pile.is-empty.pile-foundation[data-suit="D"]::after { color: rgba(255,95,116,.4); }

.tableau-row { flex: 1; display: grid; grid-template-columns: repeat(8, 1fr); gap: calc(var(--card-w) * .1); min-height: 0; overflow-y: auto; overflow-x: hidden; padding-bottom: 12px; }
.pile-tableau { width: 100%; height: var(--card-h); justify-self: center; max-width: var(--card-w); border: 1.5px dashed rgba(255,255,255,.14); border-radius: 7px; }
/* Карты каскада ровно по ширине колонки — не вылезают за край на узких экранах. */
.pile-tableau .card { width: 100%; }

/* ---------- Карты ---------- */
.card { width: var(--card-w); height: var(--card-h); border-radius: calc(var(--card-w) * .13); user-select: none; flex: none; transition: box-shadow .1s; }
.card.face {
    background: linear-gradient(160deg, #ffffff, #eef1f6);
    border: 1px solid rgba(0,0,0,.28);
    box-shadow: 0 2px 5px rgba(0,0,0,.35);
    color: var(--black);
}
.card.face.red { color: var(--red); }
.card.selected { box-shadow: 0 0 0 3px var(--gold-1), 0 4px 10px rgba(0,0,0,.4); }
.card .corner { position: absolute; display: flex; flex-direction: column; align-items: center; line-height: .92; font-weight: 800; }
.card .corner.tl { left: calc(var(--card-w) * .08); top: calc(var(--card-w) * .05); }
.card .corner.br { right: calc(var(--card-w) * .08); bottom: calc(var(--card-w) * .05); transform: rotate(180deg); }
.card .c-rank { font-size: calc(var(--card-w) * .24); }
.card .c-suit { font-size: calc(var(--card-w) * .2); }
.card .center { position: absolute; inset: calc(var(--card-w) * .26) calc(var(--card-w) * .11); }
.card .pip { position: absolute; transform: translate(-50%, -50%); font-size: calc(var(--card-w) * .26); }
.card .pip.flip { transform: translate(-50%, -50%) rotate(180deg); }
.card .ace { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: calc(var(--card-w) * .58); }
.card .court { position: absolute; inset: 0; border: 1.5px solid currentColor; border-radius: 4px; opacity: .92; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.card .court b { font-size: calc(var(--card-w) * .42); font-weight: 800; line-height: 1; }
.card .court i { font-size: calc(var(--card-w) * .3); font-style: normal; }
.card.back { background: repeating-linear-gradient(48deg,#8a1f3d 0 7px,#6e1530 7px 14px); border: 1.5px solid rgba(255,255,255,.42); box-shadow: 0 2px 5px rgba(0,0,0,.3), inset 0 0 0 3px rgba(255,255,255,.1); }
.card.back .back-pattern { position: absolute; inset: 6px; border-radius: 4px; border: 1px solid rgba(255,255,255,.28); background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.12), transparent 60%); }
.drag-ghost .card { box-shadow: 0 10px 26px rgba(0,0,0,.5); }
.hint-flash { animation: hintFlash .9s ease; border-radius: 7px; }
@keyframes hintFlash { 0%, 100% { box-shadow: none; } 40% { box-shadow: 0 0 0 3px var(--gold-1), 0 0 18px rgba(246,223,156,.7); } }

/* ---------- Инструменты ---------- */
.tools { display: flex; gap: 6px; justify-content: center; margin: 8px auto 0; width: 100%; }
.tool { flex: 1; max-width: 100px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 2px; border: 1.5px solid var(--panel-border); border-radius: 12px; background: var(--panel); color: var(--text-dim); font-family: var(--font); font-size: 10.5px; font-weight: 600; cursor: pointer; position: relative; }
.tool:active { transform: scale(.95); }
.tool:disabled { opacity: .4; }
.tool-ico { font-size: 18px; }
.count-badge { position: absolute; top: 3px; right: 5px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 9px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
#sound-row { display: flex; justify-content: center; margin-top: 8px; }

/* ---------- Кнопки ---------- */
.btn { font-family: var(--font); font-weight: 800; font-size: 16px; border: none; border-radius: 14px; padding: 14px 22px; cursor: pointer; color: #063; transition: transform .07s ease; }
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(165deg, #f6df9c, #d4a941); box-shadow: 0 6px 18px rgba(180,140,40,.4), inset 0 1px 0 rgba(255,255,255,.35); color: #3a2a05; }
.btn-secondary { background: var(--panel); border: 1.5px solid var(--panel-border); font-size: 14px; padding: 11px 16px; color: var(--text); }
.btn-ghost { background: none; color: var(--text-dim); font-weight: 700; font-size: 14px; padding: 8px; }

/* ---------- Оверлеи ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); background: rgba(30, 4, 12, .9); backdrop-filter: blur(6px); animation: fade .2s ease; overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.overlay-card { width: 100%; max-width: 360px; background: linear-gradient(180deg, #451226, #200810); border: 1.5px solid var(--panel-border); border-radius: 22px; padding: 26px 22px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.6); display: flex; flex-direction: column; gap: 12px; }
.overlay-emoji { font-size: 60px; }
.overlay-title { font-size: 24px; font-weight: 800; color: var(--gold-1); }
.overlay-time { font-size: 28px; font-weight: 800; color: var(--text); }
.overlay-record { font-size: 14px; font-weight: 800; color: #34c471; }
.share-row { display: flex; gap: 8px; }
.share-row .btn { flex: 1; }
.rules-card { text-align: left; }
.rules-card .overlay-title { text-align: center; }
.rules-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.rules-list li { position: relative; padding-left: 26px; font-size: 14px; }
.rules-list li::before { content: '♠'; position: absolute; left: 0; top: 0; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(40, 8, 18, .95); border: 1.5px solid var(--panel-border); color: var(--text); padding: 11px 18px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: 90%; text-align: center; }

@media (max-height: 700px) { .menu-title { font-size: 36px; } }
@media (max-height: 520px) {
    .screen { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
    .game-header { margin-bottom: 4px; }
    .tools { margin-top: 4px; }
    .tool { padding: 4px 2px; }
}

/* ---------- Доработки качества: скролл каскадов, подсветка целей, тряска, сплэш ---------- */
.tableau-row { touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.pile.drop-target { outline: 2px dashed var(--accent); outline-offset: 2px; box-shadow: 0 0 16px -2px var(--accent), inset 0 0 12px -4px var(--accent); }
.shake { animation: shake .34s cubic-bezier(.36,.07,.19,.97); }
@keyframes shake { 10%,90%{transform:translateX(-2px)} 20%,80%{transform:translateX(3px)} 30%,50%,70%{transform:translateX(-5px)} 40%,60%{transform:translateX(5px)} }
#splash { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; background: var(--felt); background-attachment: fixed; transition: opacity .35s ease; }
#splash.hide { opacity: 0; pointer-events: none; }
.splash-logo { font-size: 42px; letter-spacing: 8px; }
.splash-logo .red { color: var(--red); }
.splash-spin { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.18); border-top-color: var(--gold-1); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.overlay-sub { font-size: 14px; color: var(--text-dim); margin-top: -2px; }

/* ---------- Кросс-промо (другие наши пасьянсы) ---------- */
.cross-promo { width: 100%; max-width: 400px; margin-top: 20px; }
.promo-label { font-size: 11px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-dim); margin-bottom: 8px; text-align: center; }
.promo-row { display: flex; gap: 8px; }
.promo-card { flex: 1; display: flex; align-items: center; gap: 9px; padding: 11px 12px; border: 1.5px solid var(--panel-border); border-radius: 13px; background: var(--panel); box-shadow: var(--panel-glow); color: var(--text); font-family: var(--font); cursor: pointer; text-align: left; transition: transform .07s ease; }
.promo-card:active { transform: scale(.97); }
.promo-ico { flex: none; width: 30px; height: 30px; border-radius: 9px; font-size: 16px; background: rgba(0,0,0,.22); border: 1px solid var(--panel-border); display: flex; align-items: center; justify-content: center; }
.promo-name { font-size: 12.5px; font-weight: 700; line-height: 1.15; }
