@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css');

/* --- 🎨 초고퀄리티 테마 4종 --- */
body.theme-glass { 
    --bg-page: #f8fafc; 
    --bg-img: radial-gradient(at 0% 0%, #e0e7ff 0px, transparent 50%), radial-gradient(at 100% 100%, #fae8ff 0px, transparent 50%);
    --bg-surface: rgba(255, 255, 255, 0.7); 
    --text-main: #0f172a; --text-muted: #64748b; 
    --border: rgba(15, 23, 42, 0.15); 
    --accent: #3b82f6; --accent-hover: #2563eb;
    --board-border: #94A3B8; 
}
body.theme-cyber { 
    --bg-page: #0f172a; 
    --bg-img: radial-gradient(at 50% 100%, #1e1b4b 0px, transparent 70%), radial-gradient(at 100% 0%, #064e3b 0px, transparent 50%);
    --bg-surface: rgba(15, 23, 42, 0.8); 
    --text-main: #f8fafc; --text-muted: #94a3b8; 
    --border: rgba(167, 243, 208, 0.3); 
    --accent: #10b981; --accent-hover: #059669;
    --board-border: #10B981;
}
body.theme-arcade { 
    --bg-page: #1e1b4b; 
    --bg-img: linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
    background-size: 30px 30px; 
    --bg-surface: rgba(30, 27, 75, 0.9); 
    --text-main: #e0e7ff; --text-muted: #818cf8; 
    --border: rgba(99, 102, 241, 0.4); 
    --accent: #8b5cf6; --accent-hover: #7c3aed;
    --board-border: #8b5cf6;
}
body.theme-synth { 
    --bg-page: #2e1065; 
    --bg-img: linear-gradient(180deg, #2e1065 0%, #701a75 50%, #db2777 100%);
    --bg-surface: rgba(0, 0, 0, 0.4); 
    --text-main: #fdf2f8; --text-muted: #fbcfe8; 
    --border: rgba(244, 114, 182, 0.3); 
    --accent: #ec4899; --accent-hover: #db2777;
    --board-border: #ec4899;
}

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
body { font-family: 'Pretendard', sans-serif; background-color: var(--bg-page); background-image: var(--bg-img); background-attachment: fixed; color: var(--text-main); overflow: hidden; transition: 0.4s ease; }
.hidden { display: none !important; }
@media (max-width: 600px) { .pc-only { display: none; } }

select, option, button, input { font-family: 'Pretendard', sans-serif !important; }
body.theme-glass .logo-for-dark { display: none; }
body.theme-cyber .logo-for-light, body.theme-arcade .logo-for-light, body.theme-synth .logo-for-light { display: none; }

.global-dropzone { position: fixed; top: 0; left: 0; width: 100vw; height: 100dvh; background: rgba(59, 130, 246, 0.85); z-index: 9999; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(8px); }
.drop-message { font-size: 2rem; font-weight: 800; color: white; border: 4px dashed white; padding: 40px; border-radius: 24px; }

/* 💡 화면 중앙 정렬을 해제하고 상단으로 끌어올림 (애드센스 공간 확보 및 시각적 안정감) */
.screen-center { 
    display: flex; align-items: flex-start; justify-content: center; 
    height: 100dvh; padding: 12vh 20px 20px 20px; 
    overflow-y: auto; 
}

/* 🌟 업로드 화면 (구도 완벽 통일) */
.setup-container { 
    text-align: center; width: 100%; max-width: 480px; margin: 0 auto; 
}

.setup-logo-link { 
    display: inline-block; margin-bottom: 16px; transition: transform 0.2s; 
}
.setup-logo-link:hover { transform: scale(1.02); }

.setup-logo { 
    height: 44px; width: auto; object-fit: contain; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.05)); 
}

@media (max-width: 768px) {
    .screen-center { padding-top: 10vh; }
    .setup-logo { height: 36px; }
    .setup-logo-link { margin-bottom: 12px; }
}

.game-title { 
    font-size: 2.5rem; font-weight: 900; margin-bottom: 8px; 
    letter-spacing: -0.02em; display: flex; align-items: center; justify-content: center; gap: 10px;
    background: linear-gradient(135deg, var(--text-main), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
}
.title-icon { width: 36px; height: 36px; color: var(--accent); }

.game-desc { font-size: 1.15rem; color: var(--text-muted); margin-bottom: 30px; font-weight: 600; letter-spacing: -0.01em;}

/* 💡 애드센스 슬롯 공간 확보 (추후 스크립트 추가 시 min-height 조절) */
.adsense-slot { width: 100%; min-height: 0; display: flex; justify-content: center; align-items: center; }
.setup-adsense { margin-top: 15px; min-height: 50px; } 
.result-adsense { margin-bottom: 15px; min-height: 50px; }

.upload-box { border: 2px dashed var(--border); border-radius: 24px; padding: 40px 20px; background: var(--bg-surface); cursor: pointer; transition: 0.3s; backdrop-filter: blur(10px); }
.upload-box:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: 0 15px 30px rgba(0,0,0,0.1); }
.upload-icon { width: 48px; height: 48px; color: var(--accent); margin-bottom: 15px; }

/* 💡 가로형(16:9) 샘플 이미지를 위한 CSS 반응형 처리 */
.sample-section { margin-top: 24px; animation: fadeIn 0.5s ease-out; }
.sample-title { font-size: 0.9rem; font-weight: 700; color: var(--text-muted); margin-bottom: 12px; }
.sample-grid { display: flex; justify-content: center; gap: 8px; width: 100%; }
.sample-img { 
    flex: 1; 
    max-width: 110px; 
    aspect-ratio: 16 / 9; 
    border-radius: 8px; 
    object-fit: cover; 
    cursor: pointer; 
    border: 2px solid transparent; 
    transition: 0.2s; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.1); 
}
.sample-img:hover { transform: translateY(-3px) scale(1.05); border-color: var(--accent); box-shadow: 0 8px 15px rgba(0,0,0,0.2); z-index: 2; }

.tip-box { margin-top: 24px; font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; font-weight: 600; background: var(--bg-surface); padding: 16px; border-radius: 12px; border: 1px solid var(--border);}
.prep-link-wrapper { margin-top: 8px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.link-badge { display: inline-flex; align-items: center; gap: 4px; background: var(--accent); color: white; padding: 4px 12px; border-radius: 20px; font-weight: 700; text-decoration: none; transition: 0.2s; font-size: 0.8rem; box-shadow: 0 4px 10px rgba(0,0,0,0.1);}
.link-badge:hover { background: var(--text-main); transform: translateY(-1px); }

/* 토글 스위치 */
.toggle-group { display: flex; justify-content: space-between; align-items: center; padding-top: 10px; border-top: 1px solid var(--border); }
.toggle-text { font-size: 0.95rem; font-weight: 600; color: var(--text-main); }
.toggle-text small { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; display: block; margin-top: 4px;}
.toggle-switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border); transition: .3s; border-radius: 28px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px; background-color: white; transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(22px); }

.settings-box { margin-top: 24px; background: var(--bg-surface); padding: 24px; border-radius: 20px; border: 1px solid var(--border); backdrop-filter: blur(10px); text-align: left; animation: fadeIn 0.4s ease-out;}
.setting-group { margin-bottom: 20px; }
.setting-label { display: block; font-weight: 800; font-size: 0.95rem; margin-bottom: 8px; color: var(--text-main);}
.modern-select { width: 100%; padding: 14px; border-radius: 12px; background: var(--bg-page); color: var(--text-main); border: 2px solid var(--border); font-size: 1rem; font-weight: 800; outline: none; cursor: pointer; transition: 0.2s;}
.modern-select:focus { border-color: var(--accent); }

.btn-primary { width: 100%; background: var(--text-main); color: var(--bg-page); border: none; padding: 16px; border-radius: 14px; font-weight: 900; font-size: 1.1rem; cursor: pointer; transition: 0.2s; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
.btn-primary:hover { background: var(--accent); color: #fff; transform: translateY(-2px); box-shadow: 0 10px 20px rgba(0,0,0,0.2); }
.btn-secondary { width: 100%; background: #10B981; color: white; border: none; padding: 16px; border-radius: 14px; font-weight: 800; font-size: 1.1rem; cursor: pointer; transition: 0.2s; }
.btn-secondary:hover { background: #059669; }
.btn-outline { width: 100%; background: transparent; color: var(--text-main); border: 2px solid var(--border); padding: 16px; border-radius: 14px; font-weight: 800; font-size: 1rem; cursor: pointer; transition: 0.2s; }
.btn-outline:hover { background: var(--border); }

/* 🌟 헤더 */
.game-header { position: fixed; top: 0; left: 0; width: 100%; padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; background: var(--bg-surface); backdrop-filter: blur(20px); border-bottom: 1px solid var(--border); z-index: 200; }
.header-left { display: flex; align-items: center; gap: 20px; }
.game-stats { display: flex; gap: 16px; }
.stat-box { display: flex; flex-direction: column; }
.stat-label { font-size: 0.7rem; font-weight: 900; color: var(--text-muted); letter-spacing: 0.05em; }
.stat-value { font-size: 1.3rem; font-weight: 900; color: var(--text-main); line-height: 1; font-variant-numeric: tabular-nums; }
.header-right { display: flex; align-items: center; gap: 8px; }

.btn-icon, .btn-action { display: flex; align-items: center; justify-content: center; gap: 6px; height: 44px; border-radius: 12px; font-weight: 800; font-size: 0.95rem; background: transparent; color: var(--text-main); border: 2px solid var(--border); cursor: pointer; transition: all 0.2s ease; text-decoration: none; }
.btn-icon { width: 44px; padding: 0; }
.btn-action { padding: 0 16px; }
.btn-icon:hover, .btn-action:hover { border-color: var(--accent); color: var(--accent); }
.btn-action.active { background: var(--accent) !important; border-color: var(--accent) !important; color: white !important; box-shadow: 0 0 15px var(--accent); transform: scale(0.95); } 

.hint-btn-wrapper { position: relative; display: flex; align-items: center; }
.hint-tooltip { position: absolute; top: calc(100% + 12px); right: 0; background: var(--text-main); color: var(--bg-page); padding: 10px 16px; border-radius: 8px; font-size: 0.85rem; font-weight: 500; white-space: nowrap; opacity: 0; visibility: hidden; transition: 0.2s; transform: translateY(-5px); z-index: 101; box-shadow: 0 10px 20px rgba(0,0,0,0.1); }
.hint-tooltip::after { content: ""; position: absolute; bottom: 100%; right: 24px; border-width: 6px; border-style: solid; border-color: transparent transparent var(--text-main) transparent; }
.hint-btn-wrapper:hover .hint-tooltip { opacity: 1; visibility: visible; transform: translateY(0); }

.theme-container { position: relative; }
.theme-palette { position: absolute; top: 55px; right: 0; background: var(--bg-surface); backdrop-filter: blur(20px); padding: 12px; border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.15); border: 1px solid var(--border); display: flex; gap: 8px; z-index: 50; }
.theme-swatch { width: 32px; height: 32px; border-radius: 50%; cursor: pointer; border: 2px solid rgba(255,255,255,0.5); transition: 0.2s; box-shadow: 0 4px 6px rgba(0,0,0,0.2); }
.theme-swatch:hover { transform: scale(1.15); }
.theme-swatch.active { outline: 3px solid var(--text-main); outline-offset: 2px; }

/* 🌟 직쏘 캔버스 (풀스크린) */
#puzzleCanvas {
    position: absolute; top: 0; left: 0; width: 100vw; height: 100dvh;
    z-index: 10; cursor: default; display: block;
}

.rotation-guide {
    position: fixed; top: 80px; left: 50%; transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.8); color: white; padding: 8px 20px;
    border-radius: 20px; font-size: 0.9rem; font-weight: 700;
    backdrop-filter: blur(4px); z-index: 50; pointer-events: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15); transition: opacity 0.5s ease;
}
body.theme-glass .rotation-guide { background: rgba(255, 255, 255, 0.9); color: var(--text-main); border: 1px solid var(--border); }

/* 🌟 하단 툴바 */
.jigsaw-toolbar {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 8px; z-index: 100;
    background: var(--bg-surface); padding: 8px 16px; border-radius: 16px;
    border: 1px solid var(--border); backdrop-filter: blur(20px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.btn-tool {
    display: flex; align-items: center; gap: 6px;
    background: transparent; color: var(--text-main); border: none;
    font-weight: 800; font-size: 0.85rem; cursor: pointer;
    padding: 8px 12px; border-radius: 10px; transition: 0.2s;
}
.btn-tool svg { width: 18px; height: 18px; }
.btn-tool:hover { background: var(--border); }
.btn-tool.active { background: var(--accent); color: white; box-shadow: 0 4px 10px rgba(0,0,0,0.2); }

/* 🌟 모달 */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100dvh; background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(12px); display: flex; align-items: center; justify-content: center; z-index: 1000; animation: fadeIn 0.3s; padding: 20px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content { background: var(--bg-surface); padding: 30px 24px; border-radius: 24px; width: 100%; max-width: 380px; text-align: center; box-shadow: 0 25px 50px rgba(0,0,0,0.3); border: 1px solid var(--border); backdrop-filter: blur(20px); }
.modal-title { font-size: 1.8rem; font-weight: 900; margin-bottom: 20px; color: var(--text-main); letter-spacing: -0.05em; }
.modal-buttons.vertical { display: flex; flex-direction: column; gap: 10px; }

.result-header { margin-bottom: 12px; }
.badge { display: inline-block; background: var(--accent); color: white; font-size: 0.75rem; font-weight: 900; padding: 4px 10px; border-radius: 12px; letter-spacing: 0.05em; margin-bottom: 6px;}
.result-title { font-size: 1.8rem; font-weight: 900; line-height: 1; color: var(--text-main); margin-bottom: 16px;}

.preview-container { 
    margin: 0 auto 20px auto; width: 100%; max-width: 240px; 
    border-radius: 12px; overflow: hidden; 
    box-shadow: 0 10px 20px rgba(0,0,0,0.15); border: 1px solid var(--border); 
    background: transparent;
}
#artifactPreview { width: 100%; height: auto; display: block; object-fit: contain; }

.action-row { display: flex; gap: 8px; margin-bottom: 8px; }
.btn-save, .btn-share { flex: 1; padding: 14px 10px; border-radius: 50px; font-weight: 900; font-size: 1rem; border: none; cursor: pointer; transition: 0.2s; color: white; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 15px rgba(0,0,0,0.15); }
.btn-save { background: #10B981; }
.btn-save:hover { background: #059669; transform: translateY(-2px); }
.btn-share { background: linear-gradient(135deg, #ec4899, #8b5cf6); } 
.btn-share:hover { filter: brightness(1.1); transform: translateY(-2px); }