:root {
    --bg: #08150f;
    --panel: rgba(18, 46, 33, 0.94);
    --panel-2: rgba(10, 31, 22, 0.9);
    --line: rgba(255, 255, 255, 0.11);
    --text: #f4f8f5;
    --muted: #a9bdb1;
    --gold: #f4c45d;
    --green: #45d483;
    --green-dark: #14894d;
    --red: #ff6b72;
    --card-w: 67px;
    --card-h: 96px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: radial-gradient(circle at 50% -10%, #1c5a3c 0, #0b2418 42%, var(--bg) 78%);
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body { min-height: 100vh; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.felt-noise {
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: .12;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E");
}

.app-shell {
    position: relative;
    width: min(100%, 760px);
    margin: 0 auto;
    padding: 18px 14px 30px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(24px, 7vw, 38px); line-height: 1; }
h2 { margin-bottom: 10px; font-size: 24px; }
h3 { margin-bottom: 12px; }

.eyebrow {
    margin-bottom: 4px;
    color: var(--gold);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .14em;
}

.balance-chip {
    flex: 0 0 auto;
    display: grid;
    gap: 2px;
    min-width: 104px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(0, 0, 0, .24);
    text-align: right;
}
.balance-chip span { color: var(--muted); font-size: 11px; }
.balance-chip strong { color: var(--gold); }

.panel {
    margin-bottom: 14px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: linear-gradient(145deg, rgba(24, 58, 42, .96), rgba(9, 29, 20, .96));
    box-shadow: 0 18px 50px rgba(0, 0, 0, .25);
}
.centered { text-align: center; }
.hidden { display: none !important; }

.notice {
    margin-bottom: 12px;
    padding: 12px 14px;
    border: 1px solid rgba(255, 107, 114, .45);
    border-radius: 14px;
    background: rgba(110, 24, 35, .88);
    color: #fff;
    font-size: 14px;
}
.notice.success { border-color: rgba(69, 212, 131, .45); background: rgba(21, 92, 54, .9); }

.loader {
    width: 40px;
    height: 40px;
    margin: 4px auto 14px;
    border: 4px solid rgba(255, 255, 255, .14);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hero-card { overflow: hidden; }
.hero-card p, .rules-panel li, #waitingView p { color: var(--muted); line-height: 1.5; }
.hero-cards { display: flex; justify-content: center; height: 88px; margin: 0 0 14px; }
.mini-card {
    display: grid;
    place-items: center;
    width: 58px;
    height: 82px;
    margin: 0 -7px;
    border-radius: 10px;
    background: #fff;
    color: #171c19;
    font: 800 20px Georgia, serif;
    box-shadow: 0 10px 20px rgba(0, 0, 0, .28);
}
.mini-card:first-child { transform: rotate(-12deg) translateY(6px); }
.mini-card:last-child { transform: rotate(12deg) translateY(6px); }
.red { color: #cf2839 !important; }

.field-label { display: block; margin: 18px 0 8px; color: var(--muted); font-size: 13px; }
.bet-row { display: grid; grid-template-columns: 48px 1fr 48px; gap: 8px; }
.bet-row input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(0, 0, 0, .25);
    color: var(--text);
    text-align: center;
    font-size: 21px;
    font-weight: 800;
    outline: none;
}
.step-btn, .quick-bets button {
    border: 1px solid var(--line);
    border-radius: 13px;
    background: rgba(255, 255, 255, .06);
    color: var(--text);
}
.step-btn { font-size: 24px; }
.quick-bets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin: 10px 0 16px; }
.quick-bets button { padding: 8px 2px; font-size: 12px; }

.primary-btn, .secondary-btn, .ghost-btn, .action-btn {
    width: 100%;
    border: 0;
    border-radius: 15px;
    padding: 14px 16px;
    font-weight: 800;
    cursor: pointer;
}
.primary-btn { background: linear-gradient(135deg, #f4cf70, #dc9e2d); color: #241800; }
.secondary-btn { background: linear-gradient(135deg, #55dc92, #19985a); color: #061c11; }
.ghost-btn { margin-top: 9px; border: 1px solid var(--line); background: transparent; color: var(--text); }
button:disabled { opacity: .5; cursor: not-allowed; }

.rules-panel ul { margin: 0; padding-left: 20px; }
.rules-panel li + li { margin-top: 7px; }

.invite-versus { display: flex; align-items: center; gap: 12px; margin: 18px 0; }
.avatar { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--gold); color: #211600; font-weight: 900; }
.invite-versus p { margin: 3px 0 0; color: var(--muted); }
.price-card, .room-code {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 14px 0;
    padding: 13px 15px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(0, 0, 0, .2);
}
.price-card span, .room-code span { color: var(--muted); }
.price-card strong, .room-code strong { color: var(--gold); font-size: 19px; }
.waiting-icon { font-size: 48px; margin-bottom: 8px; }
.danger-link { width: 100%; margin-top: 12px; border: 0; background: transparent; color: var(--red); padding: 10px; }

.game-view { display: grid; gap: 10px; }
.status-strip {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 13px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(0, 0, 0, .25);
    font-size: 13px;
}
.status-strip strong { color: var(--gold); }

.opponent-zone, .player-zone {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(5, 20, 13, .52);
}
.player-line { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.player-line p { margin-bottom: 2px; }
.role-badge { padding: 5px 9px; border-radius: 999px; background: rgba(244, 196, 93, .14); color: var(--gold); font-size: 11px; }

.opponent-hand, .player-hand { display: flex; justify-content: center; min-height: var(--card-h); padding: 4px 0; overflow-x: auto; overflow-y: visible; }
.opponent-hand .card, .player-hand .card { flex: 0 0 var(--card-w); margin-left: -24px; }
.opponent-hand .card:first-child, .player-hand .card:first-child { margin-left: 0; }
.player-hand .card { cursor: pointer; transition: transform .16s ease, box-shadow .16s ease, opacity .16s; }
.player-hand .card.playable:hover, .player-hand .card.playable:active { transform: translateY(-10px); }
.player-hand .card:not(.playable) { opacity: .62; }

.card {
    position: relative;
    width: var(--card-w);
    height: var(--card-h);
    border: 1px solid rgba(0, 0, 0, .18);
    border-radius: 10px;
    background: linear-gradient(145deg, #fff, #e8ece9);
    color: #101713;
    box-shadow: 0 7px 16px rgba(0, 0, 0, .28);
    font-family: Georgia, serif;
    user-select: none;
}
.card .rank { position: absolute; left: 6px; top: 5px; font-size: 16px; font-weight: 800; line-height: .95; }
.card .suit { position: absolute; inset: 0; display: grid; place-items: center; font-size: 32px; }
.card-back {
    background:
        linear-gradient(45deg, transparent 42%, rgba(255,255,255,.16) 43% 57%, transparent 58%),
        linear-gradient(-45deg, transparent 42%, rgba(255,255,255,.12) 43% 57%, transparent 58%),
        #922e3e;
    background-size: 16px 16px;
    border: 3px solid #f2dfb6;
}
.compact { width: 50px; height: 72px; }
.trump-card { transform: rotate(90deg); margin-left: 8px; }

.table-zone {
    min-height: 218px;
    padding: 12px;
    border: 2px solid rgba(244, 196, 93, .22);
    border-radius: 26px;
    background: radial-gradient(circle, rgba(27, 106, 68, .8), rgba(11, 53, 34, .9));
}
.deck-area { display: flex; align-items: center; gap: 8px; min-height: 75px; }
.deck-meta { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.deck-meta strong { color: var(--gold); font-size: 18px; }
.table-cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 13px 20px; padding: 8px 0 4px; min-height: 116px; }
.attack-pair { position: relative; width: 92px; height: 114px; }
.attack-pair .card { position: absolute; left: 0; top: 0; }
.attack-pair .defense-card { left: 28px; top: 19px; }
.attack-pair.targetable .card:first-child { outline: 3px solid var(--gold); cursor: pointer; }
.attack-pair.selected .card:first-child { box-shadow: 0 0 0 4px var(--green), 0 7px 16px rgba(0,0,0,.28); }
.empty-table { margin: auto; color: rgba(255,255,255,.45); }

.action-hint { min-height: 38px; padding: 10px 13px; border-radius: 13px; background: rgba(0,0,0,.22); color: var(--muted); text-align: center; font-size: 13px; }
.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.action-btn { padding: 11px 6px; color: white; }
.action-btn.warning { background: #a96e1d; }
.action-btn.success { background: #188752; }
.action-btn.danger { background: #7e2832; }

.result-icon { font-size: 60px; margin-bottom: 8px; }
#resultText { color: var(--muted); line-height: 1.5; }

@media (min-width: 600px) {
    :root { --card-w: 82px; --card-h: 116px; }
    .app-shell { padding-top: 28px; }
    .panel { padding: 26px; }
    .card .rank { font-size: 19px; }
    .card .suit { font-size: 40px; }
}


/* Победная анимация */
.victory-overlay {
    position: fixed;
    z-index: 70;
    inset: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 22px;
    background:
        radial-gradient(circle at center, rgba(244, 196, 93, .24), transparent 34%),
        rgba(3, 13, 8, .86);
    backdrop-filter: blur(11px);
    cursor: pointer;
    animation: victory-overlay-in .28s ease-out both;
}

.victory-overlay.is-hiding {
    animation: victory-overlay-out .26s ease-in both;
}

.victory-rays {
    position: absolute;
    width: min(132vw, 850px);
    aspect-ratio: 1;
    border-radius: 50%;
    opacity: .36;
    background:
        repeating-conic-gradient(
            from 0deg,
            rgba(244, 196, 93, .3) 0deg 8deg,
            transparent 8deg 18deg
        );
    animation: victory-rays-spin 14s linear infinite;
}

.victory-particles {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.victory-card {
    position: relative;
    z-index: 2;
    width: min(100%, 400px);
    padding: 27px 22px 23px;
    border: 1px solid rgba(244, 196, 93, .5);
    border-radius: 28px;
    background:
        linear-gradient(145deg, rgba(28, 76, 52, .98), rgba(6, 29, 18, .98));
    box-shadow:
        0 0 0 5px rgba(244, 196, 93, .08),
        0 32px 110px rgba(0, 0, 0, .68),
        inset 0 1px 0 rgba(255, 255, 255, .14);
    text-align: center;
    animation: victory-card-pop .68s cubic-bezier(.18,.89,.32,1.28) both;
}

.victory-card::after {
    content: "";
    position: absolute;
    inset: -3px;
    z-index: -1;
    border-radius: inherit;
    background: linear-gradient(
        125deg,
        transparent 16%,
        rgba(255, 242, 181, .52) 43%,
        transparent 68%
    );
    filter: blur(11px);
    animation: victory-shimmer 2.3s ease-in-out infinite;
}

.victory-crown {
    display: grid;
    place-items: center;
    width: 92px;
    height: 92px;
    margin: 0 auto 12px;
    border: 2px solid rgba(255, 239, 169, .72);
    border-radius: 50%;
    background:
        radial-gradient(circle at 35% 22%, #fff7bd, #e8ac2f 52%, #7e5107);
    box-shadow:
        0 0 40px rgba(244, 196, 93, .48),
        inset 0 2px 5px rgba(255, 255, 255, .42);
    color: #fff5c4;
    font-family: Georgia, serif;
    font-size: 55px;
    text-shadow: 0 3px 0 #8b5d0d;
    animation: victory-crown-bounce 1.25s ease-in-out infinite;
}

.victory-kicker {
    margin: 0 0 5px;
    color: var(--gold);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .2em;
}

.victory-title {
    margin: 0;
    color: #fff2af;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(44px, 14vw, 72px);
    line-height: .95;
    text-shadow:
        0 3px 0 #835508,
        0 0 24px rgba(244, 196, 93, .55);
    animation: victory-title-pulse 1.45s ease-in-out infinite;
}

.victory-subtitle {
    margin: 14px 0 0;
    color: #dfffee;
    font-size: 15px;
    font-weight: 700;
}

.victory-bank {
    display: grid;
    gap: 3px;
    margin-top: 16px;
    padding: 12px 15px;
    border: 1px solid rgba(244, 196, 93, .28);
    border-radius: 15px;
    background: rgba(244, 196, 93, .08);
}

.victory-bank span {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.victory-bank strong {
    color: var(--gold);
    font-size: 24px;
}

.victory-dismiss {
    display: block;
    margin-top: 16px;
    color: rgba(255, 255, 255, .54);
    font-size: 11px;
}

.victory-confetti {
    position: absolute;
    top: -24px;
    width: 10px;
    height: 16px;
    border-radius: 2px;
    box-shadow: 0 0 7px currentColor;
    animation:
        victory-confetti-fall
        var(--victory-duration)
        var(--victory-delay)
        linear
        infinite;
}

.victory-flying-card {
    position: absolute;
    bottom: -78px;
    display: grid;
    align-content: center;
    justify-items: center;
    width: 48px;
    height: 68px;
    border: 2px solid rgba(244, 196, 93, .72);
    border-radius: 9px;
    background: linear-gradient(145deg, #fff, #e6ebe8);
    color: #131a16;
    box-shadow: 0 13px 32px rgba(0, 0, 0, .45);
    font-family: Georgia, serif;
    animation:
        victory-card-rise
        var(--card-duration)
        var(--card-delay)
        cubic-bezier(.2,.74,.2,1)
        infinite;
}

.victory-flying-card b {
    font-size: 18px;
    line-height: 1;
}

.victory-flying-card small {
    margin-top: 3px;
    font-size: 20px;
    line-height: 1;
}

@keyframes victory-overlay-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes victory-overlay-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes victory-rays-spin {
    to { transform: rotate(360deg); }
}

@keyframes victory-card-pop {
    0% {
        opacity: 0;
        transform: translateY(42px) scale(.58) rotate(-5deg);
    }
    72% {
        opacity: 1;
        transform: translateY(-8px) scale(1.045) rotate(1deg);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1) rotate(0);
    }
}

@keyframes victory-crown-bounce {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-10px) rotate(5deg) scale(1.06); }
}

@keyframes victory-title-pulse {
    0%, 100% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.035); filter: brightness(1.23); }
}

@keyframes victory-shimmer {
    0%, 100% { transform: translateX(-12%); opacity: .28; }
    50% { transform: translateX(12%); opacity: .7; }
}

@keyframes victory-confetti-fall {
    from {
        transform: translate3d(0, -8vh, 0) rotate(0deg);
        opacity: 0;
    }
    8% { opacity: 1; }
    to {
        transform:
            translate3d(var(--victory-drift), 112vh, 0)
            rotate(var(--victory-spin));
        opacity: .94;
    }
}

@keyframes victory-card-rise {
    0% {
        transform:
            translate3d(0, 0, 0)
            rotate(var(--card-rotate))
            scale(.7);
        opacity: 0;
    }
    12% { opacity: 1; }
    100% {
        transform:
            translate3d(var(--card-drift), -116vh, 0)
            rotate(calc(var(--card-rotate) + 450deg))
            scale(1.05);
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .victory-rays,
    .victory-confetti,
    .victory-flying-card,
    .victory-card,
    .victory-crown,
    .victory-title {
        animation: none !important;
    }

    .victory-confetti,
    .victory-flying-card {
        display: none;
    }
}
