/* ============================================
   ТЕМА 1: PLAYFUL
   ============================================ */
.ihg-pary-wrapper.ihg-theme-playful {
    --bg-gradient-start: #f0f4fc; --bg-gradient-end: #e0f2ec;
    --header-bg: #2b2f2d; --header-text-start: #4f8aff; --header-text-end: #20b2aa;
    --toast-bg: #313131; --toast-text: #fff;
    --btn-gradient-start: #4c5fc5; --btn-gradient-end: #2c9782;
    --btn-shadow: #2a4185; --btn-glow: rgba(44,151,130,0.3);
    --card-bg: #4b5563; --card-bg-shadow: #374151;
    --card-face-bg: #f0f4fc; --card-face-shadow: #c5d0e8;
    --card-matched-bg: #f4b24e; --card-matched-shadow: #d9911e;
    --card-matched-glow: rgba(244,178,78,0.35);
    --card-radius: 14px; --card-front-color: #9ca3af;
    --scoreline-bg: #2b2f2d; --scoreline-text: #e5e7eb;
}

/* ============================================
   ТЕМА 2: MIDNIGHT
   ============================================ */
.ihg-pary-wrapper.ihg-theme-midnight {
    --bg-gradient-start: #212121; --bg-gradient-end: #212121;
    --header-bg: #2d2d2d; --header-text-start: #4f8aff; --header-text-end: #20b2aa;
    --toast-bg: #333; --toast-text: #fff;
    --btn-gradient-start: #4c5fc5; --btn-gradient-end: #2c9782;
    --btn-shadow: transparent; --btn-glow: transparent;
    --card-bg: #3a3a3c; --card-bg-shadow: transparent;
    --card-face-bg: #2d2d2f; --card-face-shadow: transparent;
    --card-matched-bg: #f3a600; --card-matched-shadow: transparent;
    --card-matched-glow: rgba(243,166,0,0.25);
    --card-radius: 12px; --card-front-color: #5a5a5c;
    --scoreline-bg: #2d2d2d; --scoreline-text: #fff;
    box-shadow: none; border: 1px solid #333;
}

/* ============================================
   ТЕМА 3: SUNSET
   ============================================ */
.ihg-pary-wrapper.ihg-theme-sunset {
    --bg-gradient-start: #ffecd2; --bg-gradient-end: #fcb69f;
    --header-bg: #ffffff; --header-text-start: #ff7e5f; --header-text-end: #feb47b;
    --toast-bg: #ff7e5f; --toast-text: #fff;
    --btn-gradient-start: #ff7e5f; --btn-gradient-end: #feb47b;
    --btn-shadow: #e06c50; --btn-glow: rgba(255,126,95,0.3);
    --card-bg: #ffcdb2; --card-bg-shadow: #e5b098;
    --card-face-bg: #fff8f4; --card-face-shadow: #ffe0d2;
    --card-matched-bg: #ff7e5f; --card-matched-shadow: #e06c50;
    --card-matched-glow: rgba(255,126,95,0.3);
    --card-radius: 16px; --card-front-color: #ffb49a;
    --scoreline-bg: #fff; --scoreline-text: #ff7e5f;
}

/* ============================================
   ОБЁРТКА
   ============================================ */
.ihg-pary-wrapper {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 100%;
    max-width: 480px;
    min-height: 600px; /* ИСПРАВЛЕНИЕ: минимальная высота, чтобы не схлопывался */
    margin: 0 auto;
    box-sizing: border-box;
    padding: 40px 20px 32px;
    background: linear-gradient(180deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    border-radius: 28px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.07);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    position: relative;
    overflow: hidden;
}

.ihg-pary-wrapper .ihg-board-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

/* ============================================
   ОВЕРЛЕИ
   ============================================ */
.ihg-pary-wrapper .ihg-auth-overlay {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 500;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    box-sizing: border-box;
}
.ihg-pary-wrapper .ihg-auth-overlay.ihg-visible {
    display: flex;
}

.ihg-pary-wrapper .ihg-auth-box {
    background: #2b2f2d;
    padding: 28px 24px;
    border-radius: 20px;
    width: 88%;
    max-width: 300px;
    text-align: center;
    box-sizing: border-box;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    font-family: inherit;
}
.ihg-pary-wrapper .ihg-auth-box h2 {
    color: #fff;
    margin: 0 0 22px;
    font-size: 22px;
    font-weight: 800;
}

.ihg-pary-wrapper .ihg-auth-box input {
    display: block;
    width: 100%;
    padding: 14px 16px;
    margin-bottom: 12px;
    border-radius: 12px;
    border: 2px solid #3a3f3c;
    background: #1e2120;
    color: #fff;
    box-sizing: border-box;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.2s;
}
.ihg-pary-wrapper .ihg-auth-box input:focus {
    border-color: #20b2aa;
    outline: none;
}

.ihg-pary-wrapper .ihg-auth-btn {
    display: block;
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    margin-bottom: 10px;
    color: #fff;
    transition: transform 0.1s;
    font-family: inherit;
    box-sizing: border-box;
    text-align: center;
}
.ihg-pary-wrapper .ihg-auth-btn:last-child { margin-bottom: 0; }
.ihg-pary-wrapper .ihg-auth-btn:active { transform: scale(0.96); }

.ihg-pary-wrapper .ihg-btn-primary {
    background: linear-gradient(90deg, #4c5fc5, #2c9782);
    box-shadow: 0 4px 15px rgba(44,151,130,0.3);
}
.ihg-pary-wrapper .ihg-btn-secondary {
    background: #4b5563;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.ihg-pary-wrapper .ihg-btn-link {
    background: transparent;
    color: #9ca3af;
    box-shadow: none;
    font-size: 14px;
    padding: 10px 16px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    font-family: inherit;
    width: 100%;
    border-radius: 10px;
    display: block;
    box-sizing: border-box;
    text-align: center;
    margin-bottom: 0;
}
.ihg-pary-wrapper .ihg-btn-link:hover { color: #fff; }

.ihg-pary-wrapper #ihg-auth-buttons {
    display: flex;
    gap: 10px;
}
.ihg-pary-wrapper #ihg-auth-buttons .ihg-auth-btn {
    flex: 1;
    margin-bottom: 0;
}

/* ── Лидерборд ── */
.ihg-pary-wrapper .ihg-leaderboard-box { text-align: left; max-height: 70vh; overflow-y: auto; }
.ihg-pary-wrapper .ihg-leaderboard-box h3 { color: #fff; margin: 0 0 14px; text-align: center; font-size: 20px; font-weight: 800; }
.ihg-pary-wrapper .ihg-leaderboard-box ol { padding-left: 20px; color: #fff; margin: 0 0 18px; font-size: 15px; }
.ihg-pary-wrapper .ihg-leaderboard-box li { padding: 8px 0; border-bottom: 1px solid #3a3f3c; display: flex; justify-content: space-between; gap: 10px; }
.ihg-pary-wrapper .ihg-leaderboard-box li:last-child { border-bottom: none; }
.ihg-pary-wrapper .ihg-leaderboard-box li span:last-child { font-variant-numeric: tabular-nums; font-weight: bold; opacity: 0.8; }
.ihg-pary-wrapper .ihg-leaderboard-box li.ihg-current-player { color: #f4b24e; font-weight: 800; }
.ihg-pary-wrapper .ihg-leaderboard-box li.ihg-current-player span:last-child { opacity: 1; }

/* ── Заголовок / таймер ── */
.ihg-pary-wrapper .ihg-header-pill {
    background: var(--header-bg);
    padding: 14px 32px;
    border-radius: 24px;
    margin-bottom: 14px;
    box-shadow: 0 6px 12px rgba(0,0,0,0.1);
    flex-shrink: 0;
}
.ihg-pary-wrapper .ihg-gradient-text {
    display: block;
    text-align: center;
    font-size: 22px;
    font-weight: 800;
    background: linear-gradient(90deg, var(--header-text-start), var(--header-text-end));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.5px;
    transition: font-size 0.3s;
    white-space: nowrap;
}
.ihg-pary-wrapper .ihg-timer-active {
    font-variant-numeric: tabular-nums;
    font-size: 26px;
    animation: paryTimerPulse 1s infinite alternate ease-in-out;
}
@keyframes paryTimerPulse {
    0%   { transform: scale(1);    filter: drop-shadow(0 0 2px rgba(255,255,255,0.2)); }
    100% { transform: scale(1.05); filter: drop-shadow(0 0 8px #20b2aa); }
}

/* ── Счётчик пар ── */
.ihg-pary-scoreline {
    background: var(--scoreline-bg);
    color: var(--scoreline-text);
    padding: 9px 22px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 14px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.08);
    flex-shrink: 0;
}
.ihg-pary-scoreline strong {
    font-size: 18px;
    font-variant-numeric: tabular-nums;
}

/* ── Toast ── */
.ihg-pary-wrapper .ihg-toast {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -30%);
    background: var(--toast-bg);
    color: var(--toast-text);
    padding: 18px 24px;
    border-radius: 16px;
    font-weight: 700;
    font-size: 16px;
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
    z-index: 9999;
    box-shadow: 0 15px 35px rgba(0,0,0,0.3);
    text-align: center;
    line-height: 1.6;
    max-width: 85%;
    width: max-content;
    box-sizing: border-box;
}
.ihg-pary-wrapper .ihg-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%);
}
.ihg-pary-wrapper .ihg-toast-btns {
    display: flex;
    gap: 10px;
    margin-top: 14px;
    justify-content: center;
    pointer-events: auto;
}
.ihg-pary-wrapper .ihg-toast-btn {
    padding: 8px 18px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    color: #fff;
    transition: transform 0.1s;
    font-family: inherit;
}
.ihg-pary-wrapper .ihg-toast-btn:active { transform: scale(0.95); }

/* ============================================
   ИГРОВОЕ ПОЛЕ И СЕТКА
   ============================================ */
.ihg-pary-grid {
    display: grid;
    gap: 10px;
    width: 100%;
    margin-bottom: 16px;
    flex-shrink: 0;
}
.grid-easy   { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }
.grid-normal { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(5, 1fr); }
.grid-hard   { grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(5, 1fr); }

/* ── Карта ── */
.ihg-pary-card {
    aspect-ratio: 1;
    perspective: 800px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.ihg-pary-card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.42s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: var(--card-radius);
}
.ihg-pary-card.is-flipped .ihg-pary-card-inner,
.ihg-pary-card.is-matched .ihg-pary-card-inner {
    transform: rotateY(180deg);
}
.ihg-pary-card-front {
    position: absolute; inset: 0;
    backface-visibility: hidden; -webkit-backface-visibility: hidden;
    background: var(--card-bg);
    border-radius: var(--card-radius);
    box-shadow: 0 5px 0 var(--card-bg-shadow);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.6rem; color: var(--card-front-color);
}
.ihg-pary-card-back {
    position: absolute; inset: 0;
    backface-visibility: hidden; -webkit-backface-visibility: hidden;
    transform: rotateY(180deg);
    background: var(--card-face-bg);
    border-radius: var(--card-radius);
    box-shadow: 0 5px 0 var(--card-face-shadow);
    display: flex; align-items: center; justify-content: center;
    font-size: clamp(1.4rem, 4.5vw, 2.2rem); line-height: 1;
}
.ihg-pary-card.is-matched .ihg-pary-card-back {
    background: var(--card-matched-bg);
    box-shadow: 0 5px 0 var(--card-matched-shadow), 0 0 16px var(--card-matched-glow);
}

/* ── Часы (ИСПРАВЛЕНО) ── */
.ihg-center-glass-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.04);
    border-radius: var(--card-radius);
    box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.05);
}
.ihg-pary-wrapper.ihg-theme-midnight .ihg-center-glass-wrapper {
    background: rgba(255, 255, 255, 0.04);
}
.ihg-center-glass {
    display: inline-block;
    font-size: 2.5rem;
    animation: flipHourglass 10s infinite ease-in-out;
}
@keyframes flipHourglass {
    0%, 45% { transform: rotate(0deg) scale(1); }
    50%     { transform: rotate(180deg) scale(1.2); filter: drop-shadow(0 5px 5px rgba(0,0,0,0.3)); }
    55%, 95%{ transform: rotate(180deg) scale(1); }
    100%    { transform: rotate(360deg) scale(1); }
}

/* Анимации карт */
.ihg-pary-card.wrong-shake { animation: paryWrongShake 0.4s ease; }
@keyframes paryWrongShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}
.ihg-pary-card.card-appear { animation: paryCardAppear 0.35s ease both; }
@keyframes paryCardAppear {
    from { opacity: 0; transform: scale(0.75); }
    to   { opacity: 1; transform: scale(1); }
}
.ihg-pary-card.dance { animation: paryCardDance 0.55s ease-in-out; }
@keyframes paryCardDance {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    30%  { transform: translateY(-12px) rotate(-4deg); }
    70%  { transform: translateY(-8px) rotate(4deg); }
}

/* ── Кнопка «Играть ещё» ── */
.ihg-pary-wrapper .ihg-submit-btn {
    width: 100%; padding: 16px; border: none; border-radius: 16px;
    background: linear-gradient(90deg, var(--btn-gradient-start), var(--btn-gradient-end));
    color: #fff; font-size: 17px; font-weight: 700; cursor: pointer;
    box-shadow: 0 6px 0 var(--btn-shadow), 0 10px 20px var(--btn-glow);
    transition: transform 0.1s, box-shadow 0.1s;
    font-family: inherit; flex-shrink: 0;
}
.ihg-pary-wrapper .ihg-submit-btn:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 var(--btn-shadow), 0 4px 10px var(--btn-glow);
}

/* ── Fullscreen ── */
.ihg-pary-wrapper .ihg-fullscreen-btn {
    position: absolute; top: 10px; right: 10px;
    width: 40px; height: 40px;
    border: none !important; background: transparent !important;
    cursor: pointer; display: none;
    align-items: center; justify-content: center;
    z-index: 100; padding: 0; outline: none;
}
.ihg-pary-wrapper .ihg-fullscreen-btn i { font-size: 24px; opacity: 0.55; transition: opacity 0.2s, transform 0.2s; }
.ihg-pary-wrapper .ihg-fullscreen-btn:active i { opacity: 1; transform: scale(0.9); }
.ihg-pary-wrapper.ihg-theme-midnight .ihg-fullscreen-btn i { color: #fff; }
.ihg-pary-wrapper.ihg-theme-sunset  .ihg-fullscreen-btn i { color: #ff7e5f; }
.ihg-pary-wrapper.ihg-theme-playful .ihg-fullscreen-btn i { color: #2b2f2d; }

/* ── Адаптивность ── */
@media (max-width: 768px) {
    .ihg-pary-wrapper .ihg-fullscreen-btn { display: flex; }
}
@media (max-width: 480px) {
    .ihg-pary-wrapper { padding: 28px 14px 22px; border-radius: 20px; }
    .ihg-pary-grid { gap: 8px; }
    .ihg-pary-card-front { font-size: 1.3rem; }
    .ihg-pary-card-back  { font-size: clamp(1.1rem, 5vw, 1.7rem); }
}
@media (max-width: 360px) {
    .ihg-pary-wrapper { padding: 18px 8px 16px; }
    .ihg-pary-grid { gap: 6px; }
}

/* ── Полноэкранный режим ── */
.ihg-pary-wrapper.ihg-is-fullscreen {
    position: fixed !important; inset: 0 !important;
    width: 100vw !important; height: 100dvh !important;
    max-width: 100% !important; border-radius: 0 !important;
    z-index: 999999 !important; margin: 0 !important;
    padding: 20px 14px 30px !important;
    box-sizing: border-box !important;
    overflow-y: auto; justify-content: center;
}
.ihg-pary-wrapper.ihg-is-fullscreen .ihg-pary-grid { max-width: 400px; }