/* === 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; }

.number-display {
    font-size: 96px;
    font-weight: 900;
    line-height: 1.1;
    text-align: center;
}

.number-display.huge {
    font-size: 120px;
}

.number-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 === */
.answer-btn {
    min-width: 120px;
    min-height: 100px;
    font-size: 48px;
    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: inherit;
    -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: 20px;
    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);
}

.splash-character {
    font-size: 100px;
    animation: float 3s ease-in-out infinite;
}

/* === 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: 48px;
}

.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);
}

/* === Object display for counting === */
.objects-display {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    align-items: center;
    max-width: 500px;
    min-height: 80px;
}

.objects-display .obj-item {
    font-size: 48px;
    animation: pop-in 0.3s ease backwards;
}

/* Object placer area */
.placer-area {
    width: 400px;
    height: 200px;
    border: 4px dashed rgba(255,255,255,0.3);
    border-radius: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: center;
    padding: 16px;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.placer-area.active {
    border-color: rgba(255,255,255,0.6);
}

.placer-area .placed-obj {
    font-size: 48px;
    animation: pop-in 0.3s ease;
}

.placer-count {
    font-size: 28px;
    font-weight: 700;
}

.placer-controls {
    display: flex;
    gap: 16px;
    align-items: center;
}

/* Visual compare */
.compare-container {
    display: flex;
    gap: 40px;
    align-items: center;
    justify-content: center;
}

.compare-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px;
    border-radius: 24px;
    border: 4px solid rgba(255,255,255,0.2);
    cursor: pointer;
    min-width: 180px;
    min-height: 150px;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.compare-group:active {
    transform: scale(0.97);
}

.compare-group.correct {
    border-color: #2ed573;
    background: rgba(46,213,115,0.2);
}

.compare-group.wrong {
    border-color: #ff6b6b;
    background: rgba(255,107,107,0.15);
}

.compare-vs {
    font-size: 36px;
    font-weight: 900;
    opacity: 0.5;
}

/* 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: 36px;
    font-weight: 800;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.15s;
    font-family: inherit;
    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;
}

/* 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);
}

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

/* === 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;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    background: rgba(255,255,255,0.05);
}

.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;
}
