:root {
    --cell-size: 64px;
    --gap: 4px;
    --bg-color: #f0f4f8; 
    --card-bg: #ffffff;
    --card-border: #cbd5e1;
    --accent: #ff7e5f;
    --success: #2ecc71;
    --error: #ef4444;
    --hint-color: #f39c12;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(-45deg, #ff7e5f, #feb47b, #ff9a9e);
    background-size: 400% 400%;
    overflow-y: auto; /* Исправлено для скролла */
    animation: seaAnimation 15s ease infinite;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    user-select: none;
}

@keyframes seaAnimation {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

h1 { 
    color: #ffffff; 
    text-shadow: 0 2px 4px rgba(0,0,0,0.3); 
    margin-bottom: 5px; 
}

#settings-panel {
    background: rgba(255, 255, 255, 0.9);
    padding: 10px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    margin-bottom: 15px;
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.cat-panel {
	display: flex;
	flex-direction: column;
    align-items: center;
	background: rgba(255, 255, 255, 0.9);
	padding: 10px 20px;
	border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
	height: max-height;
}

.setting-group { 
    display: flex; 
    align-items: center; 
    gap: 5px; 
    color: #333; 
    font-weight: bold;
}

select, button { 
    padding: 8px 12px; 
    border-radius: 6px; 
    border: 1px solid #cbd5e1; 
    cursor: pointer; 
}

button.primary { 
    background: var(--accent); 
    color: white; 
    border: none; 
    font-weight: bold; 
    transition: 0.3s;
}
button.primary:hover { background: #e66a4b; }

button.hint-btn { 
    background: var(--hint-color); 
    color: white; 
    border: none; 
    font-weight: bold; 
    transition: 0.3s;
}
button.hint-btn:hover { background: #d68910; }

#info-panel {
    display: flex;
	align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 10px;
    font-size: 1rem;
    font-weight: 500;
}

#info-panel span {
    background: orange;
    color: #fff;
    padding: 6px 14px;
    border-radius: 10px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
    font-size: 1.1rem;
    white-space: nowrap;
}

#points {
    background: linear-gradient(135deg, #f9a825, #ff8f00);
    color: #fff;
    font-weight: bold;
    font-size: 1.2rem;
    box-shadow: 0 2px 6px rgba(249, 168, 37, 0.5);
}

#records {
    min-width: 60px;
    text-align: center;
}

/* === НОВЫЙ МАКЕТ === */
#main-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    margin-top: 10px;
    flex-wrap: wrap; /* Адаптивность для мобильных */
}

/* Склад слева */
#warehouse {
    width: 100%;
    min-height: 60px;
    max-height: 80px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 6px;
    align-content: start;
    overflow-y: auto;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.warehouse-card {
    font-size: 1.5rem;
    text-align: center;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    transition: background 0.2s;
    line-height: 1.2;
}

.warehouse-card:hover {
    background: rgba(0,0,0,0.05);
}

#game-container {
    background: var(--card-bg);
    border: 2px solid var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-align: center;
}

.warehouse-card[data-count] {
    font-size: 1.1rem;
}

.warehouse-card[data-count]::after {
    content: attr(data-count);
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--accent);
    background: #fff;
    border-radius: 4px;
    padding: 0 3px;
    line-height: 1;
}

@keyframes popIn {
    from { transform: scale(0) rotate(-10deg); opacity: 0; }
    to { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* Обёртка игры */
#game-wrapper { 
    padding: 0; 
    background: transparent; 
    box-shadow: none; 
}

#game-container {
    position: relative;
    background: rgba(255, 255, 255, 0.85);
    padding: var(--cell-size);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    backdrop-filter: blur(5px);
}

#grid {
    display: grid;
    gap: var(--gap);
}

.card {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc( var(--cell-size) / 2);
    cursor: pointer;
    transition: transform 0.3s ease, border-color 0.15s, opacity 0.3s;
    box-sizing: border-box;
    user-select: none;
    position: relative;
}

.card:hover { 
    transform: scale(1.1); 
    z-index: 2; 
}

.card.selected { 
    border-color: var(--accent); 
    box-shadow: 0 0 0 4px rgba(255, 126, 95, 0.4);
    background-color: #fff0ed;
    transform: scale(1.1);
}

.card.matched { 
    opacity: 0; 
    pointer-events: none; 
    transform: scale(0); 
    border-radius: 50%; 
}

/* === КАРТОЧКИ С ЭМОДЗИ (лёгкий режим) === */
.card.emoji-card {
    flex-direction: column;
    justify-content: center;
    padding: 2px;
    gap: 1px;
    font-size: calc(var(--cell-size) / 3);
}

.card.emoji-card .card-emoji {
    font-size: calc(var(--cell-size) / 2.2);
    line-height: 1.2;
    display: block;
    width: 100%;
    text-align: center;
}

.card.emoji-card .card-symbol {
    font-size: calc(var(--cell-size) / 4.5);
    line-height: 1.1;
    overflow-wrap: anywhere;
    display: block;
    width: 100%;
    text-align: center;
}

/* === КАРТОЧКИ ТОЛЬКО ТЕКСТ (сложный режим) === */
.card.text-only-card {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: calc(var(--cell-size) / 3.5);
    padding: 2px;
}

.card.text-only-card .card-symbol {
    display: block;
    text-align: center;
    overflow-wrap: anywhere;
    width: 90%;
    line-height: 1.2;
}

.card.hint-highlight {
    border-color: var(--hint-color);
    background-color: #fffbeb;
    animation: pulseHint 1s infinite;
    z-index: 5;
}

/* === РУБАШКА КАРТЫ (переворот) === */
#grid {
    perspective: 600px;
}

.card.flipped {
    pointer-events: none;
    border-color: #4a6fa7;
    background: linear-gradient(135deg, #2c3e6b 0%, #1a2544 50%, #2c3e6b 100%);
}

.card.flipped::before {
    content: '';
    position: absolute;
    inset: 8px;
    border: 1.5px solid rgba(255,255,255,0.12);
    border-radius: 4px;
    background: repeating-conic-gradient(rgba(255,255,255,0.06) 0% 25%, transparent 0% 50%) 50% / 10px 10px;
}

.card.flipped::after {
    content: '✦';
    position: absolute;
    font-size: calc(var(--cell-size) / 3);
    color: rgba(255,255,255,0.2);
    z-index: 1;
}

.card.flipped .card-symbol,
.card.flipped .card-emoji {
    opacity: 0 !important;
}

.card.reveal {
    animation: cardReveal 0.4s ease-out;
}

@keyframes cardReveal {
    0% { transform: rotateY(180deg); }
    100% { transform: rotateY(0deg); }
}

@keyframes pulseHint {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.7); }
    50% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(243, 156, 18, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(243, 156, 18, 0); }
}

#lines-svg {
    position: absolute;
    top: 0; left: 0;
    pointer-events: none;
    z-index: 10;
}

.path-line {
    fill: none;
    stroke: var(--success);
    stroke-width: 4;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0px 2px 2px rgba(0,0,0,0.3));
    stroke-dasharray: 3000;
    stroke-dashoffset: 3000;
    animation: drawLine 0.4s forwards, fadeOut 0.3s 0.5s forwards;
}

@keyframes drawLine { to { stroke-dashoffset: 0; } }
@keyframes fadeOut { to { opacity: 0; } }

#message {
    margin-top: 10px;
    font-weight: 600;
    height: 24px;
    color: white;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    text-align: center;
}

/* Кот */
#cat-img {
    max-height: 340px;
    transition: transform 0.3s ease;
    cursor: default;
	transition: filter 0.5s ease; 
}
#cat-img:hover { transform: scale(1.05); }
.is-red { filter: sepia(1) hue-rotate(-50deg) saturate(2); }

/* Вращение кота после победы */
@keyframes catSpinning {
    0% { transform: rotate(0deg) scale(1.3); }
    100% { transform: rotate(360deg) scale(1.3); }
}

.cat-spinning {
    animation: catSpinning 2s linear 5;
}

/* Длительное вращение (10-20 сек) */
.cat-spinning-long {
    animation: catSpinning 2s linear 10;
}


@keyframes shuffleShake {
    0%   { transform: scale(1) rotate(0deg); }
    25%  { transform: scale(0.85) rotate(-6deg); }
    50%  { transform: scale(1.15) rotate(6deg); }
    75%  { transform: scale(0.9) rotate(-3deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.card.shuffling {
    animation: shuffleShake 0.6s ease-in-out;
    pointer-events: none; /* Блокируем клики во время анимации */
    z-index: 20;
}

/* Анимация кота при победе (флип + увеличение) */
@keyframes catWinAnim {
    0%   { transform: scale(1) rotateY(0deg); }
    50%  { transform: scale(1.4) rotateY(180deg); }
    75%  { transform: scale(1.2) rotateY(360deg); }
    100% { transform: scale(1.3) rotateY(360deg); }
}

.cat-win-anim {
    animation: catWinAnim 1s ease-out;
}

/* Стили для конфетти */
.confetti-piece {
    position: fixed;
    top: -10px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    z-index: 9999;
    pointer-events: none;
    animation: confettiFall linear forwards;
}

@keyframes confettiFall {
    to { 
        transform: translateY(105vh) rotate(720deg); 
        opacity: 0; 
    }
}

/* Адаптив для мобильных */
@media (max-width: 768px) {
    #main-layout { flex-direction: column; align-items: center; }
    #warehouse { grid-template-columns: repeat(auto-fill, minmax(35px, 1fr)); font-size: 1.2rem; }
}

@media (max-width: 768px) and (-webkit-min-device-pixel-ratio: 2), (max-width: 768px) {
    .warehouse-card { width: 42px !important; height: 45px !important; font-size: 1.05rem !important; }
}

@media (min-width: 320px) and (max-width: 480px) {
    #warehouse { grid-template-columns: repeat(3, 1fr); }
}

/* Адаптивный размер ячеек для больших полей */
body.large-grid { --cell-size: 50px; --gap: 3px; }
body.xlarge-grid { --cell-size: 42px; --gap: 3px; }

@media (max-width: 900px) {
    body.large-grid { --cell-size: 40px; --gap: 2px; }
    body.xlarge-grid { --cell-size: 34px; --gap: 2px; }
}

/* === КНОПКИ ТЕМ === */
#theme-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.theme-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #cbd5e1;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.3s;
}

.theme-btn:hover {
    background: #fffbeb;
    border-color: var(--accent);
    transform: translateY(-2px);
}

.theme-btn.active-theme {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    font-weight: bold;
}

/* === МОДАЛЬНОЕ ОКНО ВЫБОРА УРОВНЕЙ === */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border-radius: 20px;
    padding: 30px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    position: relative;
    animation: modalPopIn 0.3s ease-out;
}

@keyframes modalPopIn {
    from { transform: scale(0.8) translateY(20px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #666;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

.level-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.level-group {
    width: 100%;
}

.level-toggle {
    padding: 12px 16px;
    border: 2px solid #cbd5e1;
    border-radius: 12px;
    background: white;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    width: 100%;
    text-align: left;
}

.level-toggle:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 126, 95, 0.2);
}

.level-toggle.locked {
    opacity: 0.7;
    cursor: not-allowed;
    border-style: dashed;
    background: #f8f9fa;
}

.level-toggle.locked:hover {
    transform: none;
    box-shadow: none;
}

.level-options {
    margin-top: 8px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.random-btn {
    padding: 8px 12px;
    border: 2px solid #cbd5e1;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.random-btn:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.modal-setting {
    margin-top: 5px;
}

.modal-setting label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #333;
    font-weight: bold;
    cursor: pointer;
}

.modal-emoji-toggle {
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
}

.modal-emoji-toggle label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #333;
    font-weight: bold;
    cursor: pointer;
}

.modal-content #theme-buttons {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e2e8f0;
}

.modal-content #theme-buttons span {
    display: block;
    text-align: center;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #666;
}
