/* ============================================
   CSS Variables & Reset
   ============================================ */
:root {
    --bg-dark: #0a0a0f;
    --bg-card: #14141f;
    --bg-card-hover: #1a1a2e;
    --accent: #ff6b6b;
    --accent-glow: rgba(255, 107, 107, 0.3);
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;
    --border: #2a2a3a;
    --gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-body);
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
}

/* ============================================
   Screen Base
   ============================================ */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.screen.active {
    display: flex;
}

/* ============================================
   화면 1: 인트로
   ============================================ */
#screen-intro {
    justify-content: center;
    align-items: center;
    background: var(--bg-dark);
    position: relative;
}

.intro-container {
    text-align: center;
    padding: 2rem;
    z-index: 1;
}

.intro-decoration {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
}

.circle {
    position: absolute;
    border-radius: 50%;
    opacity: 0.15;
}

.circle-1 {
    width: 400px;
    height: 400px;
    background: var(--gradient-1);
    top: -100px;
    right: -100px;
    animation: float 8s ease-in-out infinite;
}

.circle-2 {
    width: 300px;
    height: 300px;
    background: var(--gradient-2);
    bottom: -50px;
    left: -80px;
    animation: float 6s ease-in-out infinite reverse;
}

.circle-3 {
    width: 200px;
    height: 200px;
    background: var(--accent);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: pulse 4s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-30px) rotate(10deg); }
}

@keyframes pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.1; }
    50% { transform: translate(-50%, -50%) scale(1.2); opacity: 0.2; }
}

.intro-title {
    font-family: var(--font-display);
    font-size: 3.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.1;
    margin-bottom: 1rem;
}

.intro-title span {
    background: var(--gradient-2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.intro-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 2.5rem;
    font-family: var(--font-body);
    font-size: 1.1rem;
    font-weight: 500;
    color: white;
    background: var(--gradient-1);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
}

.btn-primary:active {
    transform: scale(0.96);
}

.intro-count {
    margin-top: 2rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ============================================
   화면 2: 문장 선택
   ============================================ */
#screen-list {
    background: var(--bg-dark);
    padding: 0;
}

.list-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem 1.25rem;
    padding-top: max(1.5rem, env(safe-area-inset-top));
    background: var(--bg-dark);
    position: relative;
    z-index: 10;
}

.list-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Pull-to-refresh 인디케이터 */
.pull-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 0;
    overflow: hidden;
    transition: height 0.2s ease-out;
    color: var(--text-secondary);
}

.pull-indicator.pulling {
    transition: none;
}

.pull-indicator .pull-arrow {
    transition: transform 0.2s;
}

.pull-indicator.ready .pull-arrow {
    transform: rotate(180deg);
}

.pull-indicator .pull-spinner {
    display: none;
}

.pull-indicator.refreshing .pull-arrow {
    display: none;
}

.pull-indicator.refreshing .pull-spinner {
    display: block;
    animation: spin 1s linear infinite;
}

.pull-indicator.refreshing .pull-text {
    display: none;
}

.pull-text {
    font-size: 0.85rem;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.sentence-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 1.25rem 2rem;
    -webkit-overflow-scrolling: touch;
}

.sentence-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.sentence-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--gradient-1);
    opacity: 0;
    transition: opacity 0.2s;
}

.sentence-card:active {
    transform: scale(0.98);
    background: var(--bg-card-hover);
}

.sentence-card:active::before {
    opacity: 1;
}

.sentence-card .word-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: rgba(255, 107, 107, 0.15);
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 20px;
    margin-bottom: 0.75rem;
}

.sentence-card .sentence-text {
    font-size: 1rem;
    color: var(--text-primary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.sentence-card .sentence-text .highlight {
    color: var(--accent);
    font-weight: 600;
}

/* ============================================
   화면 3: 학습 화면
   ============================================ */
#screen-study {
    background: var(--bg-dark);
    position: relative;
    overflow: hidden;
    overscroll-behavior: none;
}

.btn-back {
    position: absolute;
    top: max(1rem, env(safe-area-inset-top));
    left: 1rem;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(20, 20, 31, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    cursor: pointer;
    z-index: 100;
    transition: all 0.2s;
}

.btn-back:active {
    transform: scale(0.92);
    background: var(--bg-card-hover);
}

.study-container {
    position: relative;
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    -webkit-overflow-scrolling: auto;
    overscroll-behavior: none;
}

.study-card {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    padding-top: calc(50px + max(0.75rem, env(safe-area-inset-top)));
    padding-bottom: 60px;
    background: var(--bg-dark);
    transition: transform 0.3s ease-out;
    overflow: hidden;
    overscroll-behavior: none;
    will-change: transform;
}

.study-card.prev {
    transform: translateY(-100%);
}

.study-card.current {
    transform: translateY(0);
}

.study-card.next {
    transform: translateY(100%);
}

.illustration-wrapper {
    flex: 0 0 auto;
    max-height: 40vh;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 0.75rem;
    border-radius: 16px;
    overflow: hidden;
    background: var(--bg-card);
}

.illustration-wrapper img {
    width: 100%;
    height: 100%;
    max-height: 40vh;
    object-fit: contain;
    border-radius: 16px;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}

.illustration-wrapper img:active {
    transform: scale(0.98);
    opacity: 0.8;
}

.study-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
}

.study-sentence {
    font-size: 1.25rem;
    font-weight: 500;
    line-height: 1.5;
    margin-bottom: 0.5rem;
    cursor: pointer;
    padding: 0.75rem;
    border-radius: 12px;
    transition: background 0.2s;
}

.study-sentence:active {
    background: var(--bg-card);
}

.study-sentence .highlight {
    color: var(--accent);
    font-weight: 700;
    text-decoration: underline;
    text-decoration-color: rgba(255, 107, 107, 0.4);
    text-underline-offset: 4px;
}

.study-sentence-meaning {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.word-card {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    margin: 0 auto;
    max-width: 280px;
    width: 100%;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.word-card:active {
    transform: scale(0.98);
    background: var(--bg-card-hover);
}

.study-word {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--accent);
}

.study-meaning {
    font-size: 1rem;
    color: var(--text-secondary);
}

/* 오디오 인디케이터 */
.audio-indicator {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: rgba(20, 20, 31, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 50px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 50;
}

.audio-indicator.active {
    opacity: 1;
    visibility: visible;
}

.audio-wave {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 20px;
}

.audio-wave span {
    width: 3px;
    height: 8px;
    background: var(--accent);
    border-radius: 2px;
    animation: wave 0.8s ease-in-out infinite;
}

.audio-wave span:nth-child(2) { animation-delay: 0.1s; }
.audio-wave span:nth-child(3) { animation-delay: 0.2s; }
.audio-wave span:nth-child(4) { animation-delay: 0.3s; }
.audio-wave span:nth-child(5) { animation-delay: 0.4s; }

@keyframes wave {
    0%, 100% { height: 8px; }
    50% { height: 20px; }
}

#voice-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* 스와이프 힌트 */
.swipe-hint {
    position: fixed;
    bottom: max(1rem, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: var(--text-muted);
    animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-5px); }
}

/* ============================================
   유틸리티 & 애니메이션
   ============================================ */
.fade-in {
    animation: fadeIn 0.4s ease-out;
}

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

/* 스크롤바 스타일링 */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* Safe area padding for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
    .swipe-hint {
        bottom: calc(1rem + env(safe-area-inset-bottom));
    }
}

/* ============================================
   스피킹 기능 스타일
   ============================================ */

/* 마이크 버튼 */
.btn-speak {
    position: fixed;
    bottom: max(80px, calc(60px + env(safe-area-inset-bottom)));
    right: 1.5rem;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-1);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 90;
}

.btn-speak:active {
    transform: scale(0.92);
}

.btn-speak.recording {
    background: var(--accent);
    box-shadow: 0 4px 20px rgba(255, 107, 107, 0.5);
    animation: pulse-recording 1.5s ease-in-out infinite;
}

@keyframes pulse-recording {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.7); }
    50% { box-shadow: 0 0 0 15px rgba(255, 107, 107, 0); }
}

/* 녹음 상태 인디케이터 */
.recording-indicator {
    position: fixed;
    bottom: 160px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: rgba(255, 107, 107, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 50px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 95;
}

.recording-indicator.active {
    opacity: 1;
    visibility: visible;
}

.recording-wave {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 20px;
}

.recording-wave span {
    width: 3px;
    height: 8px;
    background: white;
    border-radius: 2px;
    animation: recording-wave 0.6s ease-in-out infinite;
}

.recording-wave span:nth-child(2) { animation-delay: 0.1s; }
.recording-wave span:nth-child(3) { animation-delay: 0.2s; }
.recording-wave span:nth-child(4) { animation-delay: 0.3s; }
.recording-wave span:nth-child(5) { animation-delay: 0.4s; }

@keyframes recording-wave {
    0%, 100% { height: 8px; }
    50% { height: 20px; }
}

.recording-text {
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
}

.btn-stop-recording {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-stop-recording:active {
    background: rgba(255, 255, 255, 0.3);
}

/* 스피킹 결과 오버레이 */
.speaking-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 150;
}

.speaking-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* 스피킹 결과 패널 */
.speaking-result-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 75vh;
    background: var(--bg-card);
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
    z-index: 200;
    overflow-y: auto;
}

.speaking-result-panel.active {
    transform: translateY(0);
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.result-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.btn-close-result {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.btn-close-result:active {
    background: var(--bg-card-hover);
}

.result-content {
    text-align: center;
}

/* 점수 원형 표시 */
.score-circle {
    width: 110px;
    height: 110px;
    margin: 0 auto 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--gradient-1);
    border-radius: 50%;
    color: white;
}

.score-circle.excellent {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.score-circle.good {
    background: var(--gradient-1);
}

.score-circle.try-again {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.score-value {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
}

.score-label {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* 인식된 문장 / 원본 문장 */
.user-speech, .original-sentence {
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--bg-dark);
    border-radius: 12px;
    text-align: left;
}

.user-speech label, .original-sentence label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.user-speech p, .original-sentence p {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.user-speech .correct {
    color: #10b981;
    font-weight: 600;
}

.user-speech .incorrect {
    color: var(--accent);
    text-decoration: line-through;
}

.original-sentence .highlight {
    color: var(--accent);
    font-weight: 600;
}

/* 피드백 배지 */
.feedback-area {
    margin: 1.25rem 0;
}

.feedback-badge {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    border-radius: 20px;
    font-size: 0.95rem;
    font-weight: 500;
}

.feedback-badge.excellent {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.feedback-badge.good {
    background: rgba(102, 126, 234, 0.15);
    color: #667eea;
}

.feedback-badge.try-again {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

/* 다시 말하기 버튼 */
.btn-retry-speak {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    margin-top: 0.5rem;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 500;
    color: white;
    background: var(--gradient-1);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-retry-speak:active {
    transform: scale(0.98);
}
