@import url('https://fonts.googleapis.com/css2?family=Jua&family=Noto+Sans+KR:wght@400;700;900&display=swap');

:root {
    --bg: #0a0a0f;
    --glass: rgba(255,255,255,0.07);
    --glass-border: rgba(255,255,255,0.12);
    --glass-hover: rgba(255,255,255,0.11);
    --blur: 20px;
    --primary: #7b8cff;
    --primary-glow: rgba(123,140,255,0.4);
    --accent: #ff6b9d;
    --accent2: #ffd166;
    --success: #06ffa5;
    --danger: #ff4d6d;
    --text: #f0f0f5;
    --subtext: rgba(240,240,245,0.55);
    --radius: 20px;
    --radius-sm: 12px;
}

* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }

body {
    font-family: 'Jua', 'Noto Sans KR', sans-serif;
    background: var(--bg);
    background-image:
        radial-gradient(ellipse 80% 50% at 20% 0%, rgba(123,140,255,0.15) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(255,107,157,0.12) 0%, transparent 60%),
        radial-gradient(ellipse 40% 60% at 50% 50%, rgba(6,255,165,0.04) 0%, transparent 70%);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 0 80px;
    overflow-x: hidden;
    touch-action: manipulation;
}

/* ===== CONTAINER ===== */
.container {
    width: 95%;
    max-width: 480px;
    min-height: 480px; /* 문제와 입력창 전환 시 덜컹거림 방지를 위한 고정 높이 */
    display: flex;
    flex-direction: column;
    background: var(--glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--glass-border);
    border-radius: 28px;
    padding: 20px 16px 18px;
    position: relative;
    box-shadow:
        0 8px 40px rgba(0,0,0,0.5),
        inset 0 1px 0 rgba(255,255,255,0.1);
}

/* ===== LANGUAGE TOGGLE ===== */
.language-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
}

.lang-btn {
    display: inline-block;
    background: rgba(123,140,255,0.15);
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 0.75rem;
    text-decoration: none;
    font-family: 'Jua', sans-serif;
    letter-spacing: 0.05em;
    transition: all 0.2s;
}
.lang-btn:hover { background: rgba(123,140,255,0.3); }

/* ===== SCREENS ===== */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    flex: 1; /* 컨테이너의 고정 높이에 맞춰 내부 요소를 꽉 채움 */
    animation: fadeIn 0.35s ease;
}
.screen.active { display: flex; }

@keyframes fadeIn {
    from { opacity:0; transform: translateY(12px); }
    to { opacity:1; transform: translateY(0); }
}

/* ===== START SCREEN ===== */
.brain-icon {
    font-size: 4rem;
    margin-bottom: 8px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%,100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.title {
    font-size: 2.1rem;
    font-weight: 900;
    background: linear-gradient(135deg, #fff 0%, var(--primary) 60%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
    text-align: center;
}

.subtitle {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 12px;
    opacity: 0.9;
}

.description {
    font-size: 0.95rem;
    color: var(--subtext);
    text-align: center;
    margin-bottom: 20px;
    line-height: 1.6;
}
.description strong { color: var(--text); }

.game-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
}

.game-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    backdrop-filter: blur(10px);
    transition: border-color 0.2s;
}
.game-item:hover { border-color: var(--primary); }

.game-num {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.game-info { display: flex; flex-direction: column; gap: 2px; }
.game-name { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.game-desc { font-size: 0.78rem; color: var(--subtext); }

.time-estimate {
    margin-top: 10px;
    font-size: 0.82rem;
    color: var(--subtext);
}

/* ===== BUTTONS ===== */
.btn {
    font-family: 'Jua', sans-serif;
    border: none;
    border-radius: var(--radius-sm);
    padding: 14px 0;
    width: 100%;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.02em;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #9b6ee8 100%);
    color: #fff;
    box-shadow: 0 4px 20px var(--primary-glow);
}
.btn-primary:hover { box-shadow: 0 6px 28px var(--primary-glow); }

.btn-secondary {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--text);
    backdrop-filter: blur(10px);
    font-size: 0.9rem;
    padding: 10px 0;
    margin-top: 8px;
}

.btn-copy {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--text);
    font-size: 0.9rem;
}
.btn-kakao {
    background: #fee500;
    color: #000;
    font-size: 0.9rem;
}

.pulse {
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%,100% { box-shadow: 0 4px 20px var(--primary-glow); }
    50% { box-shadow: 0 4px 35px rgba(123,140,255,0.7), 0 0 0 6px rgba(123,140,255,0.1); }
}

/* ===== TRANSITION SCREEN ===== */
.transition-num {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 900;
    color: #fff;
    margin-bottom: 12px;
    box-shadow: 0 4px 20px var(--primary-glow);
}

.transition-icon { font-size: 3rem; margin-bottom: 10px; }
.transition-title {
    font-size: 1.6rem;
    font-weight: 900;
    margin-bottom: 10px;
    text-align: center;
}
.transition-desc {
    font-size: 0.95rem;
    color: var(--subtext);
    text-align: center;
    line-height: 1.7;
    margin-bottom: 20px;
}

.progress-steps {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 24px;
}

.step {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    color: var(--subtext);
    transition: all 0.3s;
}
.step.done {
    background: var(--success);
    border-color: var(--success);
    color: #000;
}
.step.active {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-color: transparent;
    color: #fff;
    box-shadow: 0 2px 12px var(--primary-glow);
}
.step-line {
    flex: 1;
    height: 2px;
    background: rgba(255,255,255,0.1);
    border-radius: 1px;
    max-width: 40px;
}

/* ===== GAME HEADER ===== */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 4px;
}

.game-badge {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
}

.level-badge {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--subtext);
    margin-right: 52px;
}

.game-instruction {
    font-size: 0.95rem;
    color: var(--subtext);
    margin-bottom: 10px;
    text-align: center;
    line-height: 1.4;
}
.game-instruction strong { color: var(--text); }

/* ===== GAME 1: CHIMP GRID ===== */
.chimp-grid {
    display: grid;
    gap: 6px;
    width: 100%;
    margin: 0 auto 10px;
}

.chimp-cell {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    background: var(--glass);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 900;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    position: relative;
    overflow: hidden;
}

.chimp-cell.has-num {
    background: linear-gradient(135deg, rgba(123,140,255,0.25), rgba(155,110,232,0.2));
    border-color: var(--primary);
    color: var(--text);
    box-shadow: 0 2px 10px rgba(123,140,255,0.2);
}

.chimp-cell.hidden {
    background: linear-gradient(135deg, rgba(255,255,255,0.06), rgba(255,255,255,0.04));
    border-color: rgba(255,255,255,0.15);
    cursor: pointer;
}

.chimp-cell.hidden::after {
    content: '?';
    color: rgba(255,255,255,0.2);
    font-size: 1.2rem;
}

.chimp-cell.correct {
    background: linear-gradient(135deg, rgba(6,255,165,0.3), rgba(0,200,100,0.2));
    border-color: var(--success);
    animation: pop 0.2s ease;
}

.chimp-cell.wrong {
    background: linear-gradient(135deg, rgba(255,77,109,0.3), rgba(200,0,50,0.2));
    border-color: var(--danger);
    animation: shake 0.3s ease;
}

@keyframes pop {
    0% { transform: scale(0.9); }
    60% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

@keyframes shake {
    0%,100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.score-display {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 0.82rem;
    color: var(--subtext);
    padding: 5px 4px;
}
.score-display strong { color: var(--text); }

/* ===== GAME 2: REVERSE DIGITS ===== */
.number-display {
    width: 100%;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    min-height: 80px;
    flex: 1; /* 표시될 때 넉넉하게 자리 차지 */
}

.number-show {
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: 0.2em;
    background: linear-gradient(135deg, var(--primary), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-family: 'Noto Sans KR', monospace;
    transition: opacity 0.15s ease;
}

.number-input-area { width: 100%; flex: 1; display: flex; flex-direction: column; justify-content: center;}
.input-prompt {
    text-align: center;
    font-size: 0.85rem;
    color: var(--subtext);
    margin-bottom: 8px;
}

.digit-buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    margin-bottom: 8px;
}

.digit-btn {
    width: 100%;
    height: clamp(44px, 10vw, 60px);
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1.2rem;
    font-weight: 900;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    font-family: 'Jua', sans-serif;
}
.digit-btn:active {
    background: rgba(123,140,255,0.25);
    border-color: var(--primary);
    transform: scale(0.94);
}

.user-input-display {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 8px;
    text-align: center;
    font-size: 1.5rem;
    letter-spacing: 0.15em;
    font-weight: 900;
    min-height: 46px;
    color: var(--accent2);
    margin-bottom: 4px;
}

/* ===== GAME 3: SHOPPING LIST ===== */
.memo-timer-bar {
    width: 100%;
    height: 5px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    margin-bottom: 16px;
    overflow: hidden;
}

.timer-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 3px;
    width: 100%;
    transition: width linear;
}

.shopping-list {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    justify-content: center;
    width: 100%;
    margin-bottom: 10px;
}

.shop-item {
    background: linear-gradient(135deg, rgba(123,140,255,0.2), rgba(255,107,157,0.15));
    border: 1px solid rgba(123,140,255,0.3);
    border-radius: 50px;
    padding: 6px 14px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.answer-hint {
    font-size: 0.85rem;
    color: var(--subtext);
    margin-bottom: 8px;
    text-align: center;
}

.shopping-choices {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
    margin-bottom: 10px;
    max-height: 55vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 2px;
}

.choice-btn {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 12px 6px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Jua', sans-serif;
    text-align: center;
    white-space: normal;
    word-break: keep-all;
    overflow: visible;
}

.choice-btn.selected {
    background: linear-gradient(135deg, rgba(123,140,255,0.3), rgba(155,110,232,0.25));
    border-color: var(--primary);
    color: var(--text);
    box-shadow: 0 0 12px rgba(123,140,255,0.3);
}

.choice-btn:active { transform: scale(0.96); }

/* ===== GAME 4: SIMON ===== */
.simon-board {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 280px;
    margin: 0 auto 12px;
}

.simon-btn {
    aspect-ratio: 1;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.15s;
    border: 3px solid rgba(255,255,255,0.1);
    box-shadow: inset 0 4px 12px rgba(0,0,0,0.4);
}

.simon-btn[data-idx="0"] { background: radial-gradient(circle at 35% 35%, #ff6b9d, #c0394d); }
.simon-btn[data-idx="1"] { background: radial-gradient(circle at 35% 35%, #7b8cff, #4455cc); }
.simon-btn[data-idx="2"] { background: radial-gradient(circle at 35% 35%, #ffd166, #c08800); }
.simon-btn[data-idx="3"] { background: radial-gradient(circle at 35% 35%, #06ffa5, #009960); }

.simon-btn.lit {
    filter: brightness(1.8) saturate(1.3);
    transform: scale(1.04);
    box-shadow: 0 0 25px currentColor;
}

.simon-btn.wrong {
    animation: shake 0.3s ease;
    filter: brightness(0.4);
}

.simon-progress {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
    min-height: 24px;
}

.simon-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    transition: background 0.3s;
}
.simon-dot.done { background: var(--success); box-shadow: 0 0 6px var(--success); }
.simon-dot.active { background: var(--primary); box-shadow: 0 0 6px var(--primary); }

/* ===== RESULT SCREEN ===== */
.result-emoji {
    font-size: 4.5rem;
    margin-bottom: 8px;
    animation: pop 0.5s ease;
}

.result-has-img {
    font-size: 0;
    width: 140px;
    height: 140px;
    border-radius: 24px;
    overflow: hidden;
    border: 2px solid var(--glass-border);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    margin-bottom: 8px;
    flex-shrink: 0;
}

.result-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.result-rank-badge {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #000;
    padding: 5px 18px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.result-title {
    font-size: 1.6rem;
    font-weight: 900;
    text-align: center;
    margin-bottom: 12px;
    line-height: 1.3;
}

.brain-age-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 16px 32px;
    margin-bottom: 14px;
    gap: 4px;
}

.brain-age-label {
    font-size: 0.8rem;
    color: var(--subtext);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.brain-age-value {
    font-size: 3rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
}

.result-desc {
    font-size: 0.95rem;
    color: var(--subtext);
    text-align: center;
    line-height: 1.7;
    margin-bottom: 18px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
}

.score-breakdown {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: 100%;
    margin-bottom: 18px;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 10px 4px;
}

.score-icon { font-size: 1.2rem; }
.score-name { font-size: 0.68rem; color: var(--subtext); }
.score-val { font-size: 0.9rem; font-weight: 700; color: var(--primary); }

.share-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    margin-bottom: 10px;
}

/* ===== PROMO SECTION ===== */
.promo-section { width: 100%; margin-top: 24px; }
.promo-title {
    font-size: 0.95rem;
    color: var(--subtext);
    margin-bottom: 12px;
    text-align: center;
}

.more-tests {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    padding-right: 4px;
}

.more-tests::-webkit-scrollbar { width: 4px; }
.more-tests::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 2px; }
.more-tests::-webkit-scrollbar-track { background: rgba(255,255,255,0.04); }

.promo-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    text-decoration: none;
    color: var(--text);
    transition: all 0.2s;
}

.promo-card:hover {
    background: var(--glass-hover);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.promo-icon { font-size: 1.3rem; flex-shrink: 0; }
.promo-text {
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 115px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30,30,40,0.95);
    backdrop-filter: blur(10px);
    color: #fff;
    padding: 10px 22px;
    border-radius: 20px;
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    z-index: 10000;
    border: 1px solid var(--glass-border);
    transition: opacity 0.3s;
    white-space: nowrap;
}
.toast.show { opacity: 1; }

/* ===== FIXED AD ===== */
.ad-fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100px;
    background: #f1f1f1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* ===== FEEDBACK OVERLAY ===== */
.feedback-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 8000;
    pointer-events: none;
    animation: feedbackAnim 0.8s ease forwards;
}

.feedback-text {
    font-size: 3rem;
    font-weight: 900;
    text-shadow: 0 0 20px currentColor;
}

@keyframes feedbackAnim {
    0% { opacity: 0; transform: scale(0.5); }
    40% { opacity: 1; transform: scale(1.1); }
    70% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.2); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 380px) {
    .container { padding: 16px 12px 16px; min-height: 450px; }
    .title { font-size: 1.8rem; }
    .digit-buttons { gap: 5px; }
    .score-breakdown { grid-template-columns: repeat(2, 1fr); }
    .chimp-grid { gap: 5px; }
    .digit-btn { height: clamp(40px, 10vw, 54px); }
}

@media (max-height: 700px) {
    .container { padding: 14px 14px 14px; min-height: 430px; }
    .brain-icon { font-size: 3rem; }
    .game-header { margin-bottom: 6px; }
    .game-instruction { margin-bottom: 8px; font-size: 0.88rem; }
    .number-display { padding: 10px 16px; min-height: 64px; margin-bottom: 8px; }
    .digit-btn { height: clamp(40px, 9vw, 54px); }
    .digit-buttons { gap: 5px; margin-bottom: 6px; }
    .user-input-display { min-height: 40px; padding: 6px; font-size: 1.3rem; margin-bottom: 3px; }
    .simon-board { max-width: 240px; gap: 8px; }
    .score-display { padding: 3px 4px; }
    .memo-timer-bar { margin-bottom: 10px; }
    .shopping-list { gap: 5px; margin-bottom: 8px; }
    .shop-item { padding: 5px 11px; font-size: 0.82rem; }
    .shopping-choices { gap: 6px; }
    .choice-btn { padding: 10px 4px; font-size: 0.95rem; }
}

@media (max-height: 580px) {
    .container { padding: 10px 12px 10px; min-height: 380px; }
    .digit-btn { height: 40px; }
    .number-display { min-height: 54px; padding: 8px 12px; }
    .simon-board { max-width: 210px; }
}