:root {
    /* 파스텔톤 색상 팔레트 변수 */
    --primary-color: #ffb3ba;
    --secondary-color: #baffc9;
    --accent-color: #ffdfba;
    --bg-color: #fcfcfc;
    --text-color: #555;
    --btn-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --border-color: #eaeaea;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Jua', sans-serif; /* 귀여운 폰트 */
    user-select: none; /* 텍스트 선택 방지 */
}

html, body {
    overflow: hidden;
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    position: fixed; /* Prevents scroll elasticity / bounce on mobile devices */
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    width: 100vw;
    overflow: hidden; /* 스크롤 방지 */
    position: relative; /* 배경 애니메이션 기준점 */
}

/* Background Animations */
.bg-animations {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    overflow: hidden;
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}
.cloud {
    position: absolute;
    font-size: 5rem;
    opacity: 0.6;
    animation: floatCloud 20s linear infinite;
}
.cloud1 { top: 10%; animation-duration: 25s; }
.cloud2 { top: 30%; animation-duration: 18s; animation-delay: -5s; font-size: 4rem; }
@keyframes floatCloud {
    from { transform: translateX(-100%); }
    to { transform: translateX(100vw); }
}
.balloon {
    position: absolute;
    bottom: -10%; left: 20%;
    font-size: 3rem;
    animation: floatUp 15s ease-in infinite;
}
@keyframes floatUp {
    from { transform: translateY(0) rotate(0deg); opacity: 1; }
    to { transform: translateY(-120vh) rotate(20deg); opacity: 0; }
}

#app {
    width: 100%;
    max-width: 600px; /* PC에서는 중앙 고정 */
    height: 100%;
    max-height: 100vh;
    position: relative;
    background-color: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent layout shifting */
}

/* 화면 전환 처리 */
.screen {
    display: none;
    flex-direction: column;
    height: 100%;
    width: 100%;
    padding: 20px;
}
.screen.active {
    display: flex;
}

/* 공통 버튼 스타일 */
.btn {
    border: none;
    border-radius: 20px;
    padding: 15px 20px;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: var(--btn-shadow);
    transition: transform 0.1s;
}
.btn:active {
    transform: scale(0.95);
}
.btn-primary {
    background-color: var(--primary-color);
    color: white;
    font-weight: bold;
}
.btn-secondary {
    background-color: var(--secondary-color);
    color: var(--text-color);
}
.btn-large {
    font-size: 1.5rem;
    padding: 20px 40px;
    border-radius: 30px;
}
.btn-icon {
    background-color: white;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
}

/* Start Screen (v2) */
#start-screen {
    justify-content: flex-start;
    align-items: center;
    padding-top: 40px;
}
.main-title-area {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}
.logo {
    font-size: 3.5rem;
    color: #ff6b6b;
    text-shadow: 3px 3px 0px #ffeaa7;
}
.mascot {
    font-size: 4rem;
    animation: bounce 2s infinite alternate;
}
.today-recommend {
    background: rgba(255,255,255,0.8);
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 30px;
    width: 90%;
    text-align: center;
    border: 3px dashed #ff9ff3;
}
.today-recommend h3 {
    margin-bottom: 10px;
    color: #5f27cd;
}
.recommend-card {
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}
.main-menu {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    align-items: center;
}
.menu-row {
    display: flex;
    gap: 15px;
}

/* Header & Top Bar (v2) */
.top-bar {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 50;
    pointer-events: none;
}
.top-bar.hidden { display: none; }
.level-info {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.9);
    padding: 5px 15px;
    border-radius: 20px;
    border: 2px solid #ccc;
    pointer-events: auto;
}
.level-badge {
    font-weight: bold;
    color: #54a0ff;
}
.exp-bar-container {
    width: 100px;
    height: 10px;
    background: #eee;
    border-radius: 5px;
    overflow: hidden;
}
.exp-bar-fill {
    height: 100%;
    background: #1dd1a1;
    transition: width 0.3s;
}
.star-info {
    background: rgba(255,255,255,0.9);
    padding: 5px 15px;
    border-radius: 20px;
    border: 2px solid #ccc;
    font-weight: bold;
    font-size: 1.2rem;
    pointer-events: auto;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    margin-top: 40px; /* 탑바 공간 확보 */
}
header h2 {
    font-size: 1.8rem;
    color: var(--primary-color);
}
.tools-top {
    display: flex;
    gap: 10px;
}

/* Grid Layout for Categories & Designs */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 15px;
    overflow-y: auto;
    padding-bottom: 20px;
    flex: 1;
    min-height: 0;
}
.card {
    background-color: white;
    border: 3px solid var(--accent-color);
    border-radius: 15px;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
}
.card:active {
    transform: scale(0.95);
}
.card img, .card svg {
    width: 100%;
    height: 80px;
    object-fit: contain;
    margin-bottom: 10px;
}
.card .title {
    font-size: 1.2rem;
    font-weight: bold;
}
.card-progress-bar {
    width: 100%;
    height: 8px;
    background: #eee;
    border-radius: 4px;
    margin-top: 5px;
    overflow: hidden;
}
.card-progress-fill {
    height: 100%;
    background: #ff9f43;
}
.card .progress-text {
    font-size: 0.8rem;
    color: #888;
    margin-top: 3px;
}
.silhouette svg path, .silhouette svg circle, .silhouette svg rect, .silhouette svg polygon {
    fill: #ccc !important;
    stroke: none !important;
}

/* Coloring Screen Layout */
#coloring-screen {
    padding: 0;
}
.coloring-layout {
    display: flex;
    width: 100%;
    height: 100%;
    background-color: #333; /* 어두운 배경 (캔버스 돋보이게) */
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    border-radius: 0 20px 20px 0;
    margin-right: 15px; /* 툴바와의 간격 */
    overflow: hidden;
}
.btn-back-absolute {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 10;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.canvas-container {
    width: 90%;
    height: 90%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.canvas-container svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
/* SVG 영역에 커서 모양 변경 */
.canvas-container svg path {
    cursor: pointer;
    transition: fill 0.1s, filter 0.1s;
}
.canvas-container svg path:hover {
    filter: brightness(0.9);
}

/* Vertical Toolbar */
.vertical-toolbar {
    width: 90px;
    background-color: #fce8a6; /* 나무 느낌의 연노랑 */
    border-radius: 20px 0 0 20px;
    padding: 15px 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    box-shadow: -5px 0 15px rgba(0,0,0,0.2);
}
.toolbar-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
    width: 100%;
}
.flex-grow {
    flex: 1;
    justify-content: center;
}

/* Tool Buttons */
.tool-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 4px solid #fff;
    background-color: #eee;
    font-size: 1.8rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    transition: transform 0.1s, border-color 0.2s;
    user-select: none;
}
.tool-btn:active {
    transform: scale(0.9);
}
.tool-btn.active {
    border-color: #ff6b6b;
    background-color: #ffeaa7;
}
.btn-green {
    background-color: #7bed9f;
    color: white;
}
.btn-blue {
    background-color: #70a1ff;
    color: white;
}

/* Current Color Indicator */
.current-color-indicator {
    width: 70px;
    height: 70px;
    border: 5px solid white;
    background-color: #ff6b6b;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

/* Palette Popover */
.palette-popover {
    position: absolute;
    right: 20px; /* 캔버스 우측 (툴바 옆) */
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(255, 255, 255, 0.95);
    border: 4px solid #a4b0be;
    border-radius: 20px;
    padding: 20px;
    width: 320px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 20;
    transition: opacity 0.2s, transform 0.2s;
}
.palette-popover.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%) scale(0.9);
}
.palette-header {
    text-align: center;
    font-size: 1.5rem;
    font-weight: bold;
    color: #333;
    margin-bottom: 15px;
    background-color: #dfe4ea;
    padding: 5px;
    border-radius: 10px;
}
.palette-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    justify-items: center;
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 5px;
}
.color-btn {
    width: 50px;
    height: 50px;
    border-radius: 12px; /* 둥근 사각형으로 변경 */
    border: 3px solid #ced6e0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s;
}
.color-btn:active {
    transform: scale(0.9);
}
.color-btn.selected {
    border-color: #2f3542;
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

/* Sticker Popover (v2) */
.sticker-popover {
    position: absolute;
    right: 120px;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(255, 255, 255, 0.95);
    border: 4px solid #a4b0be;
    border-radius: 20px;
    padding: 15px;
    width: 250px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 30;
}
.sticker-popover.hidden {
    display: none;
}
.sticker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 10px;
    background: #dfe4ea;
    padding: 5px 10px;
    border-radius: 10px;
}
.sticker-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-height: 200px;
    overflow-y: auto;
}
.sticker-item {
    font-size: 2.5rem;
    text-align: center;
    cursor: pointer;
    transition: transform 0.1s;
}
.sticker-item:active { transform: scale(1.2); }

/* Draggable Sticker on Canvas */
.placed-sticker {
    position: absolute;
    font-size: 3rem;
    user-select: none;
    touch-action: none; /* 드래그를 위해 기본 터치 액션 방지 */
    filter: drop-shadow(0 2px 5px rgba(0,0,0,0.3));
}
.placed-sticker.selected {
    border: 2px dashed #ff6b6b;
    padding: 5px;
}
.sticker-delete-btn {
    position: absolute;
    top: -15px;
    right: -15px;
    background: red;
    color: white;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    font-size: 1rem;
    text-align: center;
    line-height: 25px;
    cursor: pointer;
    display: none;
}
.placed-sticker.selected .sticker-delete-btn {
    display: block;
}

/* Completion Screen */
#completion-screen {
    justify-content: center;
    align-items: center;
}
.bounce {
    animation: bounce 1s infinite alternate;
}
@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-10px); }
}
.completed-image-container {
    width: 80%;
    height: 300px;
    background-color: #eee;
    border-radius: 15px;
    margin: 20px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 4px solid var(--secondary-color);
}
.completed-image-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
.stars {
    font-size: 2rem;
    color: gold;
    margin-bottom: 20px;
}

/* Modal */
.modal {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
    z-index: 100;
}
.modal.active {
    display: flex;
}
.modal-content {
    background-color: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    width: 80%;
}
.settings-options {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.settings-options label {
    display: flex;
    justify-content: space-between;
    font-size: 1.2rem;
}

/* Ads Placeholder */
.ad-placeholder {
    display: none; /* 모바일에서는 일단 숨김, PC에서만 보이게 하려면 미디어쿼리 사용 */
}

/* Desktop layout additions */
@media (min-width: 800px) {
    body {
        gap: 20px;
    }
    .ad-placeholder {
        display: flex;
        width: 160px;
        height: 600px;
        background-color: #eaeaea;
        color: #999;
        justify-content: center;
        align-items: center;
        border: 2px dashed #ccc;
        position: absolute;
    }
    .ad-area-left {
        left: -180px;
    }
    .ad-area-right {
        right: -180px;
    }
}

/* =============================================
   자유그림 화면 (freedraw-screen)
   ============================================= */
.freedraw-layout {
    display: flex;
    flex-direction: row;
    gap: 8px;
    width: 100%;
    height: calc(100% - 56px); /* header 높이 제외 */
    padding: 8px;
    overflow: hidden;
}

.freedraw-canvas-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f0f0f0;
    border-radius: 16px;
    border: 3px solid #ddd;
    overflow: hidden;
    min-width: 0;
}

#freedraw-canvas {
    border-radius: 12px;
    cursor: crosshair;
    touch-action: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    max-width: 100%;
    max-height: 100%;
    background: #ffffff;
}

.freedraw-toolbar {
    width: 130px;
    min-width: 120px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px;
}

.freedraw-toolbar::-webkit-scrollbar { width: 4px; }
.freedraw-toolbar::-webkit-scrollbar-track { background: transparent; }
.freedraw-toolbar::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

.fd-section {
    background: rgba(255,255,255,0.8);
    border-radius: 12px;
    padding: 8px;
    border: 1.5px solid #eee;
}

.fd-section-label {
    font-size: 0.7rem;
    color: #888;
    margin-bottom: 5px;
    font-weight: 700;
}

.fd-tools {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.fd-tool-btn {
    background: #f8f8f8;
    border: 2px solid #ddd;
    border-radius: 10px;
    padding: 5px 4px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}

.fd-tool-btn:hover {
    background: #fff0f5;
    border-color: #ffb3c6;
    transform: scale(1.08);
}

.fd-tool-btn.active {
    background: #ffe0eb;
    border-color: #ff6b95;
    box-shadow: 0 0 0 2px #ffb3c6;
}

.fd-shape-btn.active {
    background: #e0f0ff;
    border-color: #4dabf7;
    box-shadow: 0 0 0 2px #a5d8ff;
}

.fd-slider {
    width: 100%;
    margin-top: 2px;
    accent-color: #ff6b95;
}

.fd-palette {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 3px;
}

.fd-color-btn {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s;
}

.fd-color-btn:hover {
    transform: scale(1.2);
    z-index: 1;
}

.fd-section-palette {
    flex: 1;
}

.fd-action-btn {
    width: 100%;
    margin-top: 4px;
    padding: 7px 4px;
    font-size: 0.72rem;
    border-radius: 10px;
}

/* 모바일에서 자유그림 레이아웃 조정 */
@media (max-width: 480px) {
    .freedraw-layout {
        flex-direction: column;
    }
    .freedraw-toolbar {
        width: 100%;
        min-width: unset;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        height: 160px;
        padding: 4px 0;
    }
    .fd-section {
        min-width: 100px;
        flex-shrink: 0;
    }
    .fd-section-palette {
        min-width: 180px;
    }
    .fd-palette {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* =============================================
   업적 화면 및 알림 스타일 (Achievements & Toasts)
   ============================================= */
.achievements-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    flex: 1;
    padding-bottom: 30px;
}

.ach-header {
    background: linear-gradient(135deg, #fff9db 0%, #fff3bf 100%);
    border: 3px solid #fcc419;
    border-radius: 20px;
    padding: 15px;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.ach-summary {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ach-count {
    font-size: 2.2rem;
    color: #f03e3e;
    font-weight: bold;
    text-shadow: 1px 1px 0px #ffe3e3;
}

.ach-count-of {
    font-size: 1.2rem;
    color: #868e96;
}

.ach-label-text {
    font-size: 1rem;
    color: #495057;
    font-weight: bold;
}

.ach-progress-bar {
    width: 100%;
    height: 16px;
    background: #e9ecef;
    border-radius: 10px;
    margin: 10px 0;
    overflow: hidden;
    border: 2px solid #dee2e6;
}

.ach-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff8787, #ffd43b, #66d9e8);
    border-radius: 10px;
    transition: width 0.5s ease-out;
}

.ach-pct-label {
    font-size: 0.9rem;
    color: #495057;
    font-weight: bold;
}

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

.ach-group-label {
    font-size: 1.3rem;
    color: #343a40;
    border-bottom: 3px dashed #dee2e6;
    padding-bottom: 5px;
    margin-top: 10px;
}

.ach-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
}

.ach-card {
    background: #ffffff;
    border-radius: 18px;
    padding: 12px;
    text-align: center;
    position: relative;
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    border: 3px solid #dee2e6;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

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

.ach-card.ach-unlocked {
    background: #fff;
    transform: scale(1);
}

.ach-card.ach-unlocked.ach-tier-bronze { border-color: #ffd8a8; background: #fff9db; }
.ach-card.ach-unlocked.ach-tier-silver { border-color: #e7f5ff; background: #e7f5ff; }
.ach-card.ach-unlocked.ach-tier-gold { border-color: #fff3bf; background: #fffbeb; }
.ach-card.ach-unlocked.ach-tier-rainbow { border-color: #f3d9fa; background: #fdf2ff; }

.ach-card.ach-locked {
    background: #f8f9fa;
    border-color: #e9ecef;
    opacity: 0.85;
}

.ach-icon {
    font-size: 2.2rem;
    margin-bottom: 8px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.ach-card.ach-locked .ach-icon {
    filter: grayscale(1) opacity(0.5);
}

.ach-title {
    font-size: 0.95rem;
    font-weight: bold;
    color: #212529;
    margin-bottom: 4px;
}

.ach-card.ach-locked .ach-title {
    color: #868e96;
}

.ach-desc {
    font-size: 0.72rem;
    color: #495057;
    line-height: 1.2;
}

.ach-card.ach-locked .ach-desc {
    color: #adb5bd;
}

.ach-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #37b24d;
    color: white;
    font-size: 0.65rem;
    font-weight: bold;
    padding: 3px 8px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transform: rotate(5deg);
}

/* 반짝 클릭 효과 애니메이션 */
@keyframes achPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.15) rotate(3deg); }
    100% { transform: scale(1); }
}
.ach-pop {
    animation: achPop 0.4s ease-out;
}

/* 🏅 요술 토스트 알림 스타일 */
.ach-toast {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 360px;
    background: #ffffff;
    border-radius: 20px;
    padding: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: top 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 4px solid #dee2e6;
}

.ach-toast.show {
    top: 20px;
}

.ach-toast.ach-tier-bronze { border-color: #ffa94d; background: #fff9db; }
.ach-toast.ach-tier-silver { border-color: #339af0; background: #e7f5ff; }
.ach-toast.ach-tier-gold { border-color: #fcc419; background: #fffbeb; }
.ach-toast.ach-tier-rainbow { border-color: #da77f2; background: #fdf2ff; }

.ach-toast-icon {
    font-size: 2.8rem;
    animation: bounce 0.8s infinite alternate;
}

.ach-toast-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ach-toast-label {
    font-size: 0.72rem;
    color: #e03131;
    font-weight: bold;
    background: #ffe3e3;
    padding: 2px 8px;
    border-radius: 10px;
    width: fit-content;
}

.ach-toast-title {
    font-size: 1.1rem;
    font-weight: bold;
    color: #212529;
}

.ach-toast-desc {
    font-size: 0.8rem;
    color: #495057;
}
