/* 기본 스타일 및 폰트 설정 */
:root {
    --bg-color: #eef1f5;
    --container-bg: #ffffff;
    --primary-color: #4a69ff;
    --secondary-color: #ff6b6b;
    --success-color: #2ed573;
    --text-color: #2f3542;
    --border-color: #dcdde1;
    --shadow-color: rgba(47, 53, 66, 0.15);
    --font-main: 'Jua', sans-serif;
    --font-mono: 'Roboto Mono', monospace;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
}

/* 게임 전체 컨테이너 */
.game-container {
    position: relative;
    background: var(--container-bg);
    border-radius: 24px;
    box-shadow: 0 15px 40px var(--shadow-color);
    width: 100%;
    max-width: 550px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 25px;
    border: 1px solid white;
}

/* 헤더 영역 */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: center;
    position: relative;
}

.target-number-display {
    font-family: var(--font-mono);
    font-size: 3.5em;
    color: var(--primary-color);
    line-height: 1;
}

.info-panel {
    display: flex;
    gap: 25px;
}

.info-item h3 {
    font-size: 1.2em;
    margin: 0 0 5px 0;
    color: #7f8fa6;
}

.info-item p {
    font-family: var(--font-mono);
    font-size: 2.5em;
    margin: 0;
    line-height: 1;
}

/* 수식 조합 공간 */
.equation-area {
    display: flex;
    gap: 10px;
    background-color: #f5f6fa;
    border: 2px solid var(--border-color);
    border-radius: 16px;
    padding: 15px;
    min-height: 90px;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.equation-slot {
    width: 64px;
    height: 88px;
    border-radius: 12px;
    border: 2px dashed var(--border-color);
    background-color: rgba(220, 221, 225, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
}

.equation-slot:empty {
    border: 2px dashed var(--primary-color);
    background-color: rgba(74, 105, 255, 0.1);
}

.equation-slot:empty:hover {
    border-color: var(--secondary-color);
    background-color: rgba(255, 107, 107, 0.1);
    transform: scale(1.05);
    cursor: pointer;
}

.equation-slot:not(:empty):hover {
    cursor: pointer;
    transform: scale(1.02);
}

.equation-slot .card {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.equation-slot .card:hover {
    transform: scale(1.05);
}

/* 카드 영역 */
.card-area {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    padding: 15px;
    min-height: 100px;
    position: relative;
}

.card-area:empty::after {
    content: '카드를 선택하고 슬롯에 배치하세요';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #7f8fa6;
    font-size: 1.1em;
    text-align: center;
    pointer-events: none;
}

/* 게임 안내 텍스트 */
.game-instructions {
    text-align: center;
    color: #7f8fa6;
    font-size: 0.9em;
    margin-top: 10px;
    padding: 10px;
    background-color: rgba(127, 143, 166, 0.1);
    border-radius: 8px;
}

.card {
    width: 64px;
    height: 88px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 2.2em;
    font-weight: 700;
    cursor: grab;
    user-select: none;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 10px var(--shadow-color);
}

/* 카드 호버 효과 */
.card:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px var(--shadow-color);
}

.number-card {
    background-color: var(--primary-color);
    color: white;
}

.operator-card {
    background-color: var(--secondary-color);
    color: white;
}

/* 버튼 */
.control-button {
    width: 100%;
    padding: 18px;
    font-family: var(--font-main);
    font-size: 1.5em;
    color: white;
    background-color: var(--success-color);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    box-shadow: 0 4px 15px rgba(46, 213, 115, 0.4);
}

.control-button:hover {
    background-color: #25a25a;
}
.control-button:active {
    transform: scale(0.98);
}

.control-button.auto-submit {
    background-color: #ff6b6b;
    animation: pulse 1.5s infinite;
}

.control-button.auto-submit:hover {
    background-color: #ff5252;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

/* --- 애니메이션 및 피드백 --- */
.equation-area.shake {
    animation: shake-wrong 0.5s ease-in-out;
}

@keyframes shake-wrong {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
    20%, 40%, 60%, 80% { transform: translateX(8px); }
}

.feedback-toast {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translate(-50%, -100px);
    padding: 12px 25px;
    border-radius: 30px;
    color: white;
    font-size: 1.2em;
    opacity: 0;
    transition: transform 0.4s, opacity 0.4s;
    z-index: 10;
}

.feedback-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.feedback-toast.success {
    background-color: var(--success-color);
}

.feedback-toast.error {
    background-color: var(--secondary-color);
}

/* 콤보 디스플레이 */
.combo-display {
    position: absolute;
    top: -10px;
    right: 20px;
    background: linear-gradient(45deg, #ff6b6b, #ffa500);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 1.2em;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
    animation: combo-pulse 0.6s ease-in-out;
    display: none;
}

@keyframes combo-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* 점수 브레이크다운 */
.score-breakdown {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translate(-50%, -100px) scale(0.8);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 20px;
    border-radius: 16px;
    font-family: var(--font-mono);
    font-size: 1.1em;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    min-width: 280px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.score-breakdown.show {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    margin: 6px 0;
    padding: 3px 0;
    align-items: center;
}

.breakdown-item.total {
    border-top: 2px solid var(--success-color);
    margin-top: 12px;
    padding-top: 12px;
    font-size: 1.1em;
    font-weight: bold;
    color: var(--success-color);
}

/* 타이머 깜박임 애니메이션 */
@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.5; }
}

/* 게임 완료 팝업 */
.game-complete-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.game-complete-popup.show {
    display: flex;
    animation: popup-fade-in 0.3s ease-out;
}

@keyframes popup-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.popup-content {
    background: var(--container-bg);
    border-radius: 20px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: popup-slide-in 0.3s ease-out;
}

@keyframes popup-slide-in {
    from { transform: translateY(-50px) scale(0.9); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.popup-header h2 {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.8em;
}

.close-button {
    background: none;
    border: none;
    font-size: 2em;
    color: #7f8fa6;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.close-button:hover {
    background-color: #f1f2f6;
}

.final-score {
    text-align: center;
    margin-bottom: 25px;
}

.final-score h3 {
    margin: 0 0 10px 0;
    color: #7f8fa6;
    font-size: 1.2em;
}

.score-number {
    font-family: var(--font-mono);
    font-size: 3em;
    font-weight: bold;
    color: var(--success-color);
    text-shadow: 0 2px 10px rgba(46, 213, 115, 0.3);
}

.game-stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 25px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 12px;
}

.stat-item {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.9em;
    color: #7f8fa6;
    margin-bottom: 5px;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.5em;
    font-weight: bold;
    color: var(--text-color);
}

.share-section {
    margin-bottom: 25px;
}

.share-section h4 {
    margin: 0 0 15px 0;
    text-align: center;
    color: var(--text-color);
    font-size: 1.1em;
}

.share-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.share-button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-family: var(--font-main);
    font-size: 0.9em;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.share-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.share-button {
    background: var(--primary-color);
    color: white;
}

.popup-footer {
    text-align: center;
}

.play-again-button {
    width: 100%;
    padding: 15px;
    font-family: var(--font-main);
    font-size: 1.2em;
    color: white;
    background: var(--success-color);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    box-shadow: 0 4px 15px rgba(46, 213, 115, 0.4);
}

.play-again-button:hover {
    background-color: #25a25a;
    transform: scale(1.02);
}

.play-again-button:active {
    transform: scale(0.98);
}

/* 게임 광고 관련 스타일 */
.game-ad-container {
    margin: 20px 0;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    border-radius: 12px;
    background: #f8f9fa;
    padding: 10px;
}

.game-ad-container .adsbygoogle {
    border-radius: 8px;
    overflow: hidden;
    margin: 0 auto;
}

.safe-ad-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 300px;
    max-width: calc(100vw - 40px);
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    padding: 10px;
    backdrop-filter: blur(10px);
}

.safe-ad-container .adsbygoogle {
    border-radius: 8px;
    overflow: hidden;
}

/* 게임 중 광고 숨김 */
.game-container.game-active .adsbygoogle {
    display: none !important;
}

/* 반응형 광고 스타일 */
@media (max-width: 768px) {
    .safe-ad-container {
        bottom: 10px;
        right: 10px;
        width: calc(100vw - 20px);
        max-width: 300px;
    }
    
    .game-ad-container {
        margin: 15px 0;
        padding: 8px;
    }
}
