* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: none;
}

html, body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    background: #1a1a2e;
}

/* ─── 로딩 ─── */
#loading-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 60px; height: 60px;
    border: 5px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loading-overlay p { color: white; font-size: 20px; margin-top: 20px; }

/* ─── 유료회원 화면 ─── */
#premium-required {
    width: 100vw; height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-content { text-align: center; color: white; }
.login-content h1 { font-size: 48px; margin-bottom: 20px; }
.login-content p  { font-size: 20px; margin-bottom: 40px; opacity: 0.9; }

.login-btn {
    display: inline-block;
    background: linear-gradient(135deg, #ffd700 0%, #ffaa00 100%);
    color: #333;
    text-decoration: none;
    padding: 20px 60px;
    font-size: 24px;
    font-weight: 800;
    border-radius: 50px;
    transition: all 0.3s;
    box-shadow: 0 15px 40px rgba(255,215,0,0.4);
}
.login-btn:hover { transform: translateY(-5px); }

/* ═══════════════════════════════════════════
   설정 화면 (인트로)
═══════════════════════════════════════════ */
#intro-screen {
    width: 100vw; height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    overflow-y: auto;
}

#intro-screen::before {
    content: '';
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 5c-2 0-3.5 1.5-3.5 3.5v3c0 1-0.5 2-1.5 2.5-1 0.5-2 0.3-2.8-0.5l-2-2c-1.4-1.4-3.6-1.4-5 0s-1.4 3.6 0 5l2 2c0.8 0.8 1 1.8 0.5 2.8-0.5 1-1.5 1.5-2.5 1.5h-3c-2 0-3.5 1.5-3.5 3.5s1.5 3.5 3.5 3.5h3c1 0 2 0.5 2.5 1.5 0.5 1 0.3 2-0.5 2.8l-2 2c-1.4 1.4-1.4 3.6 0 5s3.6 1.4 5 0l2-2c0.8-0.8 1.8-1 2.8-0.5 1 0.5 1.5 1.5 1.5 2.5v3c0 2 1.5 3.5 3.5 3.5s3.5-1.5 3.5-3.5v-3c0-1 0.5-2 1.5-2.5 1-0.5 2-0.3 2.8 0.5l2 2c1.4 1.4 3.6 1.4 5 0s1.4-3.6 0-5l-2-2c-0.8-0.8-1-1.8-0.5-2.8 0.5-1 1.5-1.5 2.5-1.5h3c2 0 3.5-1.5 3.5-3.5s-1.5-3.5-3.5-3.5h-3c-1 0-2-0.5-2.5-1.5-0.5-1-0.3-2 0.5-2.8l2-2c1.4-1.4 1.4-3.6 0-5s-3.6-1.4-5 0l-2 2c-0.8 0.8-1.8 1-2.8 0.5-1-0.5-1.5-1.5-1.5-2.5v-3c0-2-1.5-3.5-3.5-3.5z' fill='rgba(255,255,255,0.03)'/%3E%3C/svg%3E");
    animation: float 60s linear infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes float {
    0%   { transform: translate(0, 0); }
    100% { transform: translate(60px, 60px); }
}

.intro-content {
    position: relative;
    z-index: 1;
    text-align: center;
    width: 90%;
    max-width: 1100px;
    padding: 30px 20px 40px;
}

.title {
    font-size: clamp(36px, 5.5vw, 72px);
    font-weight: 900;
    color: white;
    text-shadow: 0 10px 30px rgba(0,0,0,0.3);
    margin-bottom: 8px;
}

.subtitle {
    font-size: clamp(14px, 1.8vw, 22px);
    color: rgba(255,255,255,0.85);
    margin-bottom: 22px;
}

/* ── 안내 박스 ── */
.guide-box {
    background: rgba(255,255,255,0.12);
    backdrop-filter: blur(16px);
    border-radius: 18px;
    padding: 18px 24px;
    margin: 0 auto 26px;
    max-width: 780px;
    border: 1.5px solid rgba(255,255,255,0.2);
    text-align: left;
}

.guide-box-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #ffd700;
    margin-bottom: 12px;
}

.guide-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.guide-step {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.88rem;
    color: rgba(255,255,255,0.9);
    line-height: 1.5;
}

.guide-step strong { color: #ffd700; font-weight: 700; }

.guide-step-num {
    background: #ffd700;
    color: #333;
    width: 22px; height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 800;
    flex-shrink: 0;
    margin-top: 2px;
}

/* ── 세팅 컨테이너 ── */
.settings-container {
    display: flex;
    gap: 24px;
    justify-content: center;
    align-items: flex-start;
    margin-bottom: 26px;
    flex-wrap: wrap;
}

.setting-box {
    background: rgba(255,255,255,0.13);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 22px 28px;
    border: 2px solid rgba(255,255,255,0.18);
    min-width: 280px;
    flex: 1;
    max-width: 420px;
}

.setting-title {
    font-size: clamp(15px, 1.4vw, 19px);
    color: white;
    margin-bottom: 16px;
    font-weight: 700;
}

/* ── 이미지 업로드 영역 ── */
.upload-area {
    width: 100%;
    height: 175px;
    border: 2.5px dashed rgba(255,255,255,0.38);
    border-radius: 14px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.25s, background 0.25s;
    background: rgba(255,255,255,0.05);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: rgba(255,215,0,0.85);
    background: rgba(255,215,0,0.06);
}

.upload-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 9px;
    text-align: center;
    padding: 16px;
    pointer-events: none;
    user-select: none;
}

.upload-icon-circle {
    width: 52px; height: 52px;
    border: 2px dashed rgba(255,255,255,0.5);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    color: rgba(255,255,255,0.65);
    line-height: 1;
    font-weight: 200;
}

.upload-main-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: rgba(255,255,255,0.82);
}

.upload-sub-label {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.45);
}

.upload-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.upload-change-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.52);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    color: white;
    font-size: 1rem;
    font-weight: 700;
    pointer-events: none;
}

.upload-area.has-image:hover .upload-change-overlay { opacity: 1; }

.upload-hint-text {
    font-size: 0.78rem;
    color: rgba(255,255,255,0.48);
    margin-top: 8px;
    text-align: center;
    min-height: 16px;
    transition: color 0.3s;
}

.upload-hint-text.ready {
    color: #a5f3a5;
    font-weight: 600;
}

/* ── 조각 수 선택기 ── */
.piece-counter {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 16px;
}

.counter-btn {
    width: 50px; height: 50px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.22);
    color: white;
    font-size: 28px;
    cursor: pointer;
    transition: all 0.25s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.counter-btn:hover { background: rgba(255,255,255,0.38); transform: scale(1.1); }

.piece-count {
    font-size: clamp(38px, 4.5vw, 56px);
    font-weight: 800;
    color: white;
    min-width: 90px;
    text-align: center;
}

.piece-info {
    font-size: 13px;
    color: rgba(255,255,255,0.65);
    margin-top: 4px;
    text-align: center;
}

.piece-guide {
    display: flex;
    flex-direction: column;
    gap: 5px;
    text-align: left;
}

.piece-guide-row {
    font-size: 0.78rem;
    color: rgba(255,255,255,0.6);
    line-height: 1.5;
}

/* ── 시작 버튼 ── */
.start-btn-container { display: flex; justify-content: center; width: 100%; }

.start-btn {
    background: linear-gradient(135deg, #ffd700 0%, #ffaa00 100%);
    color: #333;
    border: none;
    padding: 18px 80px;
    font-size: clamp(18px, 2.2vw, 28px);
    font-weight: 800;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 12px 35px rgba(255,215,0,0.4);
}

.start-btn:hover:not(:disabled) { transform: translateY(-4px); box-shadow: 0 18px 45px rgba(255,215,0,0.5); }
.start-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.start-hint-text {
    font-size: 0.88rem;
    color: rgba(255,255,255,0.5);
    margin-top: 10px;
    min-height: 18px;
    transition: color 0.3s;
}

.start-hint-text.ready {
    color: #a5f3a5;
    font-weight: 600;
}

.multitouch-info { margin-top: 16px; color: rgba(255,255,255,0.4); font-size: 11px; }

/* ═══════════════════════════════════════════
   게임 화면 (원본과 동일)
═══════════════════════════════════════════ */
#game-screen {
    width: 100vw; height: 100vh;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    position: relative;
    overflow: hidden;
}

#preview-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#preview-image {
    max-width: 80vw;
    max-height: 65vh;
    border-radius: 20px;
    box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}

#countdown {
    font-size: clamp(60px, 10vw, 100px);
    font-weight: 900;
    color: #ffd700;
    margin-top: 30px;
    text-shadow: 0 0 50px rgba(255,215,0,0.5);
}

.preview-text {
    font-size: clamp(20px, 3vw, 32px);
    color: white;
    margin-bottom: 20px;
}

#puzzle-frame {
    position: absolute;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

#hint-image { position: absolute; object-fit: fill; }

#puzzle-drop-zone {
    position: absolute;
    background: rgba(0,0,0,0.75);
    border-radius: 3px;
}

.puzzle-piece {
    position: absolute;
    cursor: grab;
    z-index: 10;
    filter: drop-shadow(3px 3px 5px rgba(0,0,0,0.4));
}

.puzzle-piece:active { cursor: grabbing; }

.puzzle-piece.dragging {
    z-index: 100;
    filter: drop-shadow(10px 15px 20px rgba(0,0,0,0.6));
}

.puzzle-piece.placed {
    cursor: default;
    z-index: 5;
    filter: none;
}

#controls {
    position: fixed;
    top: 20px; right: 20px;
    display: flex;
    gap: 10px;
    z-index: 500;
}

.control-btn {
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255,255,255,0.2);
    color: white;
    padding: 12px 25px;
    font-size: clamp(13px, 1.4vw, 17px);
    font-weight: 600;
    border-radius: 40px;
    cursor: pointer;
    transition: all 0.3s;
}

.control-btn:hover { background: rgba(255,255,255,0.25); transform: translateY(-3px); }
.control-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#complete-message {
    display: none;
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 48px 72px;
    border-radius: 30px;
    text-align: center;
    z-index: 2000;
    animation: popIn 0.5s ease;
}

@keyframes popIn {
    0%   { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

#complete-message h2 { font-size: clamp(38px, 5.5vw, 58px); color: #ffd700; margin-bottom: 14px; }
#complete-message p  { font-size: clamp(17px, 1.9vw, 23px); color: white; margin-bottom: 12px; }
#elapsed-time        { font-size: 17px; color: rgba(255,255,255,0.75); }

#image-popup {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.9);
    z-index: 1500;
    align-items: center;
    justify-content: center;
}

#image-popup img { max-width: 90vw; max-height: 90vh; border-radius: 20px; }

#image-popup .close-btn {
    position: absolute;
    top: 20px; right: 30px;
    font-size: 40px;
    color: white;
    cursor: pointer;
}

#progress-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255,255,255,0.1);
    border-radius: 25px;
    padding: 12px 30px;
    display: flex;
    align-items: center;
    gap: 15px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255,255,255,0.1);
    z-index: 500;
}

#progress-bar .label { color: rgba(255,255,255,0.8); font-size: clamp(13px, 1.1vw, 15px); }

#progress-bar .bar {
    width: clamp(140px, 18vw, 240px);
    height: 10px;
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    overflow: hidden;
}

#progress-bar .fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    border-radius: 10px;
    transition: width 0.3s ease;
}

#progress-bar .count {
    color: #ffd700;
    font-size: clamp(13px, 1.1vw, 17px);
    font-weight: 700;
    min-width: 55px;
}

/* ─── 반응형 ─── */
@media (max-width: 768px) {
    .settings-container { flex-direction: column; align-items: center; }
    .setting-box { width: 100%; min-width: auto; max-width: 100%; }
    #controls { flex-wrap: wrap; justify-content: flex-end; }
    .guide-box { text-align: left; }
}

@media (max-width: 480px) {
    .title { font-size: 32px; }
    .upload-area { height: 140px; }
    #complete-message { padding: 36px 28px; }
}
