/* === CSS Reset & Base === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Apple SD Gothic Neo', 'Noto Sans KR', -apple-system, sans-serif;
    background: #1a1a2e;
    color: #fff;
    touch-action: manipulation;
}

/* === Landscape Enforcement === */
#rotate-prompt {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #1a1a2e;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

#rotate-prompt .rotate-icon {
    font-size: 80px;
    animation: rotate-hint 2s ease-in-out infinite;
}

#rotate-prompt p {
    font-size: 28px;
    font-weight: 700;
}

@media (orientation: portrait) {
    #rotate-prompt {
        display: flex;
    }
    #game-container {
        display: none !important;
    }
}

@keyframes rotate-hint {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(90deg); }
    75% { transform: rotate(90deg); }
}

/* === Game Container === */
#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

/* === Screens === */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    padding: 20px;
    padding-top: env(safe-area-inset-top, 20px);
    padding-bottom: env(safe-area-inset-bottom, 20px);
    padding-left: env(safe-area-inset-left, 20px);
    padding-right: env(safe-area-inset-right, 20px);
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
}

/* === Screen Headers === */
.screen-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 8px 0;
    position: relative;
}

.screen-header h2 {
    font-size: 36px;
    font-weight: 800;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.screen-header .btn-back {
    position: absolute;
    left: 0;
}

.screen-header .btn-sticker-book {
    position: absolute;
    right: 0;
}

/* === Typography === */
h1 { font-size: 52px; font-weight: 900; }
h2 { font-size: 36px; font-weight: 800; }

.letter-display {
    font-size: 120px;
    font-weight: 900;
    line-height: 1.1;
    text-align: center;
    font-family: 'SF Pro Rounded', 'Apple SD Gothic Neo', sans-serif;
}

.letter-display.huge {
    font-size: 160px;
}

.letter-label {
    font-size: 28px;
    font-weight: 600;
    opacity: 0.85;
    text-align: center;
}

/* === Buttons === */
.btn {
    border: none;
    border-radius: 20px;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    font-family: inherit;
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    position: relative;
    overflow: hidden;
}

.btn:active {
    transform: scale(0.95);
}

.btn-large {
    min-width: 240px;
    min-height: 100px;
    font-size: 36px;
    padding: 20px 48px;
    border-radius: 24px;
}

.btn-medium {
    min-width: 160px;
    min-height: 80px;
    font-size: 28px;
    padding: 16px 32px;
}

.btn-small {
    min-width: 60px;
    min-height: 60px;
    font-size: 28px;
    padding: 12px 16px;
    border-radius: 16px;
}

.btn-primary {
    background: linear-gradient(180deg, #2ed573, #20bf6b);
    box-shadow: 0 6px 0 #18a058, 0 8px 20px rgba(0,0,0,0.3);
}

.btn-primary:active {
    box-shadow: 0 2px 0 #18a058, 0 4px 10px rgba(0,0,0,0.3);
    transform: translateY(4px) scale(0.98);
}

.btn-secondary {
    background: linear-gradient(180deg, #74b9ff, #0984e3);
    box-shadow: 0 4px 0 #0652DD, 0 6px 16px rgba(0,0,0,0.3);
}

.btn-secondary:active {
    box-shadow: 0 2px 0 #0652DD, 0 3px 8px rgba(0,0,0,0.3);
    transform: translateY(2px) scale(0.98);
}

.btn-back {
    background: rgba(255,255,255,0.15);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.btn-sticker-book {
    background: rgba(255,255,255,0.15);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* === Answer Buttons (Letter choices) === */
.answer-btn {
    min-width: 120px;
    min-height: 100px;
    font-size: 52px;
    font-weight: 900;
    border: 4px solid rgba(255,255,255,0.3);
    border-radius: 24px;
    background: rgba(255,255,255,0.15);
    box-shadow: 0 6px 0 rgba(0,0,0,0.2), 0 8px 20px rgba(0,0,0,0.15);
    color: #fff;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-family: 'SF Pro Rounded', 'Apple SD Gothic Neo', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

.answer-btn:active {
    transform: scale(0.95) translateY(3px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.2), 0 4px 10px rgba(0,0,0,0.15);
}

.answer-btn .answer-label {
    font-size: 18px;
    font-weight: 600;
    opacity: 0.8;
}

.answer-btn.correct {
    background: rgba(46, 213, 115, 0.6);
    border-color: #2ed573;
    animation: correct-bounce 0.5s ease;
}

.answer-btn.wrong {
    background: rgba(255, 107, 107, 0.3);
    border-color: rgba(255, 107, 107, 0.5);
    animation: wrong-wobble 0.5s ease;
}

/* === Answer Grid === */
.answers-grid {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    max-width: 800px;
}

/* === Splash Screen === */
.splash-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.splash-title {
    text-align: center;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.4);
    background: linear-gradient(135deg, #ffd32a, #ff6b6b, #a29bfe, #6ab04c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.splash-characters {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: center;
    font-size: 64px;
}

.splash-char {
    animation: float 3s ease-in-out infinite;
    font-weight: 900;
    font-family: 'SF Pro Rounded', sans-serif;
}

.splash-char:nth-child(2) { animation-delay: 0.3s; color: #ff6b6b; }
.splash-char:nth-child(3) { animation-delay: 0.6s; color: #ffd32a; }
.splash-char:nth-child(4) { animation-delay: 0.9s; color: #6ab04c; }
.splash-char:nth-child(5) { animation-delay: 1.2s; color: #74b9ff; }

/* === World Grid === */
.world-grid {
    display: flex;
    gap: 16px;
    justify-content: center;
    align-items: stretch;
    flex-wrap: wrap;
    width: 100%;
    max-width: 1000px;
    padding: 16px 0;
}

.world-card {
    width: 170px;
    min-height: 160px;
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    cursor: pointer;
    border: 4px solid rgba(255,255,255,0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
    color: #fff;
}

.world-card:active {
    transform: scale(0.95);
}

.world-card.locked {
    opacity: 0.4;
    filter: grayscale(0.5);
    pointer-events: none;
}

.world-card .world-icon {
    font-size: 56px;
}

.world-card .world-name {
    font-size: 20px;
    font-weight: 800;
    text-align: center;
}

.world-card .world-skill {
    font-size: 14px;
    opacity: 0.8;
    text-align: center;
}

.world-card .world-progress {
    font-size: 13px;
    opacity: 0.7;
}

/* === Level Grid === */
.level-grid {
    display: flex;
    gap: 16px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    max-width: 700px;
    padding: 24px 0;
}

.level-btn {
    width: 100px;
    height: 100px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    border: 3px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-family: inherit;
    font-size: 32px;
    font-weight: 900;
    transition: transform 0.15s ease;
}

.level-btn:active {
    transform: scale(0.93);
}

.level-btn.locked {
    opacity: 0.3;
    pointer-events: none;
}

.level-btn.boss {
    border-color: #ffd32a;
    background: rgba(255,211,42,0.2);
}

.level-btn .level-stars {
    font-size: 14px;
    letter-spacing: 2px;
}

/* === Gameplay === */
.gameplay-header {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 0;
}

.progress-bar {
    flex: 1;
    height: 16px;
    background: rgba(255,255,255,0.15);
    border-radius: 8px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #ffd32a, #ff6b6b);
    border-radius: 8px;
    transition: width 0.4s ease;
    width: 0%;
}

.question-count {
    font-size: 22px;
    font-weight: 700;
    min-width: 60px;
    text-align: center;
}

.gameplay-area {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
}

.question-prompt {
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

/* === Letter intro card === */
.letter-intro-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 32px 48px;
    border-radius: 32px;
    background: rgba(255,255,255,0.1);
    border: 4px solid rgba(255,255,255,0.2);
    cursor: pointer;
    transition: transform 0.2s;
}

.letter-intro-card:active {
    transform: scale(0.97);
}

.letter-intro-card .letter-big {
    font-size: 140px;
    font-weight: 900;
    line-height: 1;
    font-family: 'SF Pro Rounded', sans-serif;
}

.letter-intro-card .letter-emoji {
    font-size: 64px;
}

.letter-intro-card .letter-word {
    font-size: 28px;
    font-weight: 700;
    opacity: 0.9;
}

/* === Word display with emoji === */
.word-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.word-emoji {
    font-size: 80px;
    animation: float 3s ease-in-out infinite;
}

.word-text {
    font-size: 36px;
    font-weight: 800;
    letter-spacing: 2px;
}

.word-text .highlight {
    color: #ffd32a;
    text-decoration: underline;
    text-decoration-thickness: 4px;
}

/* === Match pairs === */
.match-container {
    display: flex;
    gap: 40px;
    align-items: flex-start;
    justify-content: center;
}

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

.match-item {
    min-width: 120px;
    min-height: 80px;
    border-radius: 16px;
    border: 3px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    font-weight: 800;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.15s;
    font-family: 'SF Pro Rounded', 'Apple SD Gothic Neo', sans-serif;
    color: #fff;
}

.match-item:active {
    transform: scale(0.95);
}

.match-item.selected {
    border-color: #ffd32a;
    background: rgba(255,211,42,0.2);
}

.match-item.matched {
    border-color: #2ed573;
    background: rgba(46,213,115,0.2);
    pointer-events: none;
    opacity: 0.6;
}

.match-item.wrong {
    border-color: #ff6b6b;
    background: rgba(255,107,107,0.15);
    animation: wrong-wobble 0.5s ease;
}

/* === Sequence display === */
.sequence-display {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
}

.sequence-item {
    width: 80px;
    height: 80px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    font-weight: 900;
    background: rgba(255,255,255,0.1);
    border: 3px solid rgba(255,255,255,0.2);
    font-family: 'SF Pro Rounded', sans-serif;
}

.sequence-item.blank {
    border: 4px dashed #ffd32a;
    background: rgba(255,211,42,0.1);
    font-size: 32px;
    color: #ffd32a;
}

/* === Sound button (play letter sound) === */
.sound-btn {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.15);
    font-size: 56px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, background 0.15s;
    animation: pulse-glow 2s ease-in-out infinite;
}

.sound-btn:active {
    transform: scale(0.9);
    background: rgba(255,255,255,0.25);
}

/* === Results Screen === */
.results-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.results-content h2 {
    font-size: 44px;
}

.stars-display {
    font-size: 64px;
    display: flex;
    gap: 16px;
}

.stars-display .star {
    opacity: 0.3;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.stars-display .star.earned {
    opacity: 1;
    animation: star-pop 0.5s ease backwards;
}

.sticker-reveal {
    font-size: 80px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sticker-reveal .sticker-new {
    animation: sticker-appear 0.8s ease;
}

.results-buttons {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
}

/* === Sticker Book === */
.sticker-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    max-width: 900px;
    padding: 16px;
    overflow-y: auto;
    max-height: calc(100vh - 120px);
}

.sticker-slot {
    width: 90px;
    height: 90px;
    border-radius: 16px;
    border: 3px dashed rgba(255,255,255,0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    background: rgba(255,255,255,0.05);
    gap: 2px;
}

.sticker-slot .sticker-label {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.7;
}

.sticker-slot.earned {
    border-style: solid;
    border-color: rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.1);
}

.sticker-slot.empty {
    opacity: 0.3;
}

.sticker-slot.empty::after {
    content: '?';
    font-size: 32px;
    opacity: 0.5;
}

/* === Confetti Canvas === */
#confetti-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

/* === Hint display === */
.hint-text {
    font-size: 24px;
    color: #ffd32a;
    font-weight: 600;
    animation: fade-in 0.5s ease;
    text-align: center;
}

/* === Correct answer floating emoji === */
.correct-floater {
    position: fixed;
    font-size: 80px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    animation: floater-fly 1.5s ease-out forwards;
    pointer-events: none;
    z-index: 50;
}

@keyframes floater-fly {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 1;
    }
    50% {
        transform: translate(-50%, -120%) scale(1.5);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -200%) scale(1);
        opacity: 0;
    }
}

/* === Streak badge === */
.streak-badge {
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 28px;
    font-weight: 900;
    color: #ffd32a;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    animation: streak-pop 2s ease-out forwards;
    pointer-events: none;
    z-index: 50;
    white-space: nowrap;
}

@keyframes streak-pop {
    0% {
        transform: translateX(-50%) scale(0);
        opacity: 0;
    }
    20% {
        transform: translateX(-50%) scale(1.3);
        opacity: 1;
    }
    80% {
        transform: translateX(-50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateX(-50%) scale(0.8);
        opacity: 0;
    }
}
