:root {
    --primary: #86efac;
    --primary-dark: #166534;
    --secondary: #facc15;
    --accent: #fb7185;
    --danger: #ef4444;
    --success: #16a34a;
    --surface: rgba(251, 255, 252, 0.9);
    --surface-strong: #ffffff;
    --surface-soft: rgba(244, 255, 245, 0.72);
    --border-soft: rgba(255, 255, 255, 0.5);
    --text-main: #10261a;
    --text-muted: #4b6354;
    --text-soft: #6d8476;
    --bg-gradient: radial-gradient(circle at top left, rgba(74, 222, 128, 0.38), transparent 30%), linear-gradient(145deg, #0b2f1b 0%, #126936 52%, #1f9d4c 100%);
    --shadow-lg: 0 28px 80px rgba(4, 26, 14, 0.32);
    --shadow-md: 0 16px 34px rgba(16, 38, 26, 0.12);
    --shadow-sm: 0 10px 24px rgba(16, 38, 26, 0.08);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    min-height: 100%;
}

body {
    font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
    background: var(--bg-gradient);
    background-attachment: fixed;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center; /* 중앙 배치 */
    min-height: 100vh;
    padding: 16px;
    color: var(--text-main);
    overflow-x: hidden;
}

body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 999px;
    filter: blur(80px);
    pointer-events: none;
    z-index: 0;
}

body::before {
    width: 280px;
    height: 280px;
    top: -80px;
    left: -60px;
    background: rgba(250, 204, 21, 0.2);
}

body::after {
    width: 340px;
    height: 340px;
    right: -90px;
    bottom: -110px;
    background: rgba(134, 239, 172, 0.2);
}

.container {
    width: min(100%, 1120px);
    padding: 24px 32px 32px; /* 하단 패딩 소폭 조절 */
    border-radius: 44px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(247, 255, 249, 0.94) 100%);
    border: 1px solid var(--border-soft);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    position: relative;
    z-index: 1;
    text-align: left;
    margin: auto; /* 중앙 정렬 유지 */
}

.container::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top right, rgba(134, 239, 172, 0.3), transparent 35%), radial-gradient(circle at bottom left, rgba(250, 204, 21, 0.18), transparent 30%);
    pointer-events: none;
    border-radius: inherit;
}

.back-btn {
    position: absolute;
    top: 24px;
    right: 32px;
    z-index: 3;
    height: 40px;
    padding: 0 18px;
    border-radius: 12px;
    background: rgba(16, 38, 26, 0.9);
    color: #f8fff8;
    font-size: 0.88rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-4px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.back-btn.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.back-btn:hover {
    background: #000;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.15);
}

.header-area {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 28px;
    margin-bottom: 32px;
    padding: 16px 0 0; /* 상단 패딩 축소 */
    cursor: pointer;
}

.brand-mark {
    flex: 0 0 110px;
    width: 110px;
    height: 110px;
    border-radius: 32px;
    background: linear-gradient(145deg, #facc15 0%, #86efac 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.6), 0 20px 40px rgba(22, 101, 52, 0.15);
    animation: floating 3s ease-in-out infinite;
}

@keyframes floating {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.main-title {
    margin: 0;
    font-size: 2.8rem;
    line-height: 1;
    font-weight: 900;
    letter-spacing: -0.06em;
    color: var(--text-main);
}

.brand-subtitle,
.section-description {
    margin: 10px 0 0;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.6;
    max-width: 600px;
}

.brand-kicker,
.section-kicker {
    margin: 0 0 8px;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: #059669;
}

.view {
    display: none;
    position: relative;
    z-index: 1;
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.view.active {
    display: block;
}

#home-view.active,
#level-view.active {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 40px;
    align-items: start;
}

.section-title,
.selected-category,
.result-title {
    margin: 0;
    font-size: 2rem;
    line-height: 1.2;
    font-weight: 900;
    color: var(--text-main);
}

.grid-layout {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

@media (min-width: 1200px) {
    .grid-layout { grid-template-columns: repeat(3, 1fr); }
}

button {
    cursor: pointer;
    border: 0;
    outline: none;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-select {
    min-height: 150px;
    padding: 22px;
    border-radius: 28px;
    background: #ffffff;
    border: 1px solid rgba(22, 101, 52, 0.08);
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
    text-align: left;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.btn-select:hover {
    transform: translateY(-6px);
    box-shadow: 0 20px 40px rgba(16, 38, 26, 0.1);
    border-color: rgba(22, 163, 74, 0.3);
}

.select-emoji {
    width: 50px;
    height: 50px;
    border-radius: 18px;
    background: rgba(22, 163, 74, 0.1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    transition: transform 0.3s ease;
}

.btn-select:hover .select-emoji {
    transform: scale(1.1) rotate(-5deg);
}

.select-title {
    display: block;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-main);
}

.select-meta {
    display: block;
    font-size: 0.85rem;
    color: var(--text-soft);
    font-weight: 600;
}

.level-column {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.btn-bar {
    width: 100%;
    padding: 18px 22px;
    border-radius: 24px;
    background: #ffffff;
    border: 1px solid rgba(22, 101, 52, 0.08);
    display: flex;
    align-items: center;
    gap: 16px;
    text-align: left;
}

.btn-bar:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 25px rgba(16, 38, 26, 0.08);
}

.level-badge {
    flex: 0 0 54px;
    width: 54px;
    height: 54px;
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 900;
    background: rgba(16, 38, 26, 0.05);
    transition: all 0.3s ease;
}

.btn-bar:hover .level-badge {
    transform: scale(1.05);
}

.level-all,
.retry-btn {
    background: linear-gradient(135deg, #064e3b 0%, #10b981 100%);
    color: #ffffff;
    border: 0;
}

.level-all .level-badge {
    background: rgba(255,255,255,0.2);
    color: #ffffff;
}

.study-view.active {
    display: block;
}

.study-layout {
    display: grid;
    grid-template-columns: 460px 1fr;
    gap: 48px;
    align-items: center;
}

.study-side-panel {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.card {
    width: 100%;
    max-width: 420px;
    height: 340px;
    perspective: 1500px;
    margin: 0 auto;
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.75s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.card.flipped .card-inner { transform: rotateY(180deg); }

.card-front,
.card-back {
    position: absolute;
    inset: 0;
    border-radius: 32px;
    padding: 24px;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(22, 101, 52, 0.1);
}

.card-front { background: linear-gradient(160deg, #ffffff 0%, #f2fff3 100%); }
.card-back {
    transform: rotateY(180deg);
    background: linear-gradient(160deg, #ffffff 0%, #ecfff0 70%, #dcfce7 100%);
}

.word-text,
.answer-word {
    font-size: 2.8rem;
    font-weight: 900;
    line-height: 1.1;
    color: var(--text-main);
}

.card-hint {
    margin-top: 32px;
    font-size: 0.9rem;
    color: var(--text-soft);
    font-weight: 700;
}

.meaning-text {
    margin-top: 12px;
    font-size: 1.7rem;
    font-weight: 900;
    color: #b91c1c;
}

.example-box {
    width: 100%;
    margin-top: 16px;
    padding: 16px;
    border-radius: 20px;
    background: rgba(255,255,255,0.85);
    border: 1px solid rgba(22, 101, 52, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
}

.example-line {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

.example-translation {
    font-size: 0.95rem;
    color: var(--text-soft);
    font-weight: 600;
}

.tts-icon,
.example-audio {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    background: rgba(20, 83, 45, 0.08);
    color: #166534;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
}

.tts-icon:hover,
.example-audio:hover {
    transform: scale(1.1);
    background: rgba(20, 83, 45, 0.12);
}

.action-group {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.action-group button {
    min-height: 60px;
    border-radius: 20px;
    font-size: 1.1rem;
    font-weight: 900;
    color: white;
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}

.btn-wrong { background: linear-gradient(135deg, #fb7185 0%, #ef4444 100%); }
.btn-correct { background: linear-gradient(135deg, #22c55e 0%, #15803d 100%); }

.btn-wrong:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 15px 30px rgba(239, 68, 68, 0.3);
}

.btn-correct:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 15px 30px rgba(21, 128, 61, 0.3);
}

.btn-wrong:active,
.btn-correct:active {
    transform: scale(0.96);
}

.stats-bar {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.stat-pill {
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 0.95rem;
    font-weight: 800;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.85);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: visible !important; /* 이모지가 밖으로 나갈 수 있게 허용 */
}

.stat-emoji {
    position: absolute;
    font-size: 2rem; /* 크기 확대 */
    pointer-events: none;
    z-index: 100; /* 최상단 배치 */
    left: 50%;
    top: -10px;
    transform: translateX(-50%);
    animation: floatUp 1s ease-out forwards;
    opacity: 0;
}

@keyframes floatUp {
    0% { transform: translateX(-50%) translateY(0) scale(0.5); opacity: 0; }
    20% { opacity: 1; }
    100% { transform: translateX(-50%) translateY(-60px) scale(1.5); opacity: 0; }
}

.stat-pill strong { font-size: 1.15rem; }

.result-view.active {
    display: block;
    min-height: auto; /* 불필요한 공백 제거 */
}

.result-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 40px;
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

.result-score-wrap {
    padding: 32px;
    border-radius: 36px;
    background: #ffffff;
    box-shadow: var(--shadow-md);
    text-align: center;
    order: -1; /* 점수를 위로 배치하고 싶다면 사용, 여기서는 시각적 강조를 위해 위로 올림 */
}

#result-score {
    font-size: 6rem;
    line-height: 1;
    font-weight: 900;
    background: linear-gradient(180deg, #16a34a 0%, #14532d 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.result-text {
    margin: 12px auto 28px;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1.6;
    font-weight: 700;
    max-width: 400px;
}

.result-copy-panel .section-head {
    margin-bottom: 24px;
}

.section-description {
    margin: 10px auto 0;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.6;
    max-width: 600px;
}
.retry-btn {
    min-height: 68px;
    font-size: 1.15rem;
    justify-content: center;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(25px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
    .container { padding: 24px 28px 32px; }
    #home-view.active, #level-view.active, .study-layout, .result-layout {
        grid-template-columns: 1fr;
        gap: 32px;
    }
    .header-area { flex-direction: column; text-align: center; gap: 20px; padding-top: 32px; }
    .brand-copy { text-align: center; }
    .brand-subtitle, .section-description { margin-left: auto; margin-right: auto; }
    .back-btn { top: 20px; right: 24px; }
}

@media (max-width: 480px) {
    body { padding: 0 10px; }
    .container { padding: 16px 20px 24px; border-radius: 36px; }
    .brand-mark { width: 90px; height: 90px; font-size: 2.8rem; }
    .main-title { font-size: 2.2rem; }
    .grid-layout { grid-template-columns: 1fr; }
    .card { height: 320px; }
    #result-score { font-size: 4.8rem; }
}
