@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css');

:root {
    --bg-gradient: linear-gradient(160deg, #fff8f0 0%, #f0f7ff 45%, #fdf2ff 100%);
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --accent: #f472b6;
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --warning-title: #d97706;
    --warning-text: #92400e;
    --border: #e2e8f0;
    --shadow: 0 8px 32px rgba(99, 102, 241, 0.1);
    --shadow-soft: 0 4px 16px rgba(15, 23, 42, 0.06);
    --radius: 16px;
    --radius-sm: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text);
    padding: max(20px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    display: block;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    overflow-x: hidden;
}

.page-layout {
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
}

.page-main {
    width: 100%;
    max-width: 560px;
}

.container {
    background: var(--surface);
    padding: clamp(22px, 5vw, 36px) clamp(16px, 5vw, 36px);
    border-radius: clamp(18px, 4vw, 24px);
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.8);
}

h1 {
    margin: 0 0 6px;
    background: linear-gradient(135deg, #6366f1, #f472b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: clamp(1.45rem, 5vw, 1.9rem);
    letter-spacing: -0.5px;
    line-height: 1.3;
}

p.subtitle {
    color: var(--text-muted);
    font-size: 0.92rem;
    margin: 0 0 22px;
    line-height: 1.5;
}

input[type="file"] {
    width: 100%;
    padding: 14px;
    margin-top: 4px;
    border-radius: var(--radius-sm);
    border: 2px dashed #c7d2fe;
    background: var(--primary-light);
    color: var(--text);
    font-size: 0.95rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

input[type="file"]:hover {
    border-color: var(--primary);
    background: #e0e7ff;
}

.warning-box {
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    padding: 16px;
    border-radius: var(--radius-sm);
    margin: 20px 0;
    text-align: left;
}

.warning-box-bottom {
    margin-top: 28px;
    margin-bottom: 4px;
}

.warning-box p.title {
    color: var(--warning-title);
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0 0 8px;
}

.warning-box p.desc {
    color: var(--warning-text);
    font-size: 0.85rem;
    margin: 0;
    line-height: 1.55;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: left;
    margin-bottom: 20px;
    cursor: pointer;
    line-height: 1.45;
}

.checkbox-label input {
    margin-top: 3px;
    margin-right: 10px;
    cursor: pointer;
    transform: scale(1.15);
    accent-color: var(--primary);
}

button {
    width: 100%;
    padding: 16px;
    min-height: 48px;
    border-radius: var(--radius-sm);
    border: none;
    font-weight: 700;
    cursor: pointer;
    font-size: 1rem;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
    box-sizing: border-box;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-soft);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #818cf8);
    color: #fff;
    margin-bottom: 12px;
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #4f46e5, #6366f1);
}

.btn-primary:disabled {
    background: #e2e8f0;
    color: #94a3b8;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-webshare {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    margin-bottom: 12px;
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.28);
}

.share-sub-row {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.btn-sub {
    flex: 1;
    background: var(--surface-soft);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 13px 6px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn-sub:hover { background: #eef2ff; }

.btn-copy {
    background: var(--surface-soft);
    color: var(--text);
    border: 1px solid var(--border);
    margin-bottom: 12px;
}

.btn-kakao {
    background-color: #fee500;
    color: #191919;
    margin-bottom: 12px;
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #34d399) !important;
    color: #fff;
}

.success-msg {
    color: var(--success);
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 20px;
    background: var(--success-light);
    padding: 12px;
    border-radius: var(--radius-sm);
}

.notice-title {
    color: #d97706;
    font-weight: 700;
    font-size: 1.05rem;
    margin: 0 0 10px;
}

.notice-text {
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-muted);
    margin: 0 0 20px;
}

.notice-text strong {
    color: var(--primary);
}

.ad-wrap {
    margin: 0 auto 8px;
    max-width: 100%;
}

.ad-wrap-top {
    margin-bottom: 2px;
}

.ad-coupang {
    display: block;
    overflow: hidden;
    border-radius: var(--radius-sm);
    line-height: 0;
    text-decoration: none;
    touch-action: manipulation;
}

.ad-coupang-img {
    width: 100%;
    height: auto;
    display: block;
    border: none;
}

.ad-label {
    display: block;
    font-size: 0.62rem;
    color: #94a3b8;
    text-align: right;
    margin: 3px 2px 8px;
}

.btn-start-connected {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    margin-bottom: 20px;
    margin-top: 0;
}

#timer-display {
    font-size: clamp(2rem, 8vw, 2.4rem);
    font-weight: 800;
    color: var(--accent);
    margin: 8px 0;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

#timer-display.timer-success {
    color: var(--success);
}

#timer-display.timer-failed {
    color: #94a3b8;
}

#game-instruction {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0 0 12px;
}

#puzzle-board {
    display: grid;
    gap: 2px;
    width: 100%;
    aspect-ratio: 1/1;
    max-width: min(460px, 100%);
    margin: 0 auto;
    background: #fff;
    border: 3px solid #e0e7ff;
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-soft);
    touch-action: manipulation;
}

.puzzle-piece {
    width: 100%;
    height: 100%;
    cursor: pointer;
    box-sizing: border-box;
    transition: transform 0.1s;
    touch-action: manipulation;
    -webkit-touch-callout: none;
}

.puzzle-piece.selected {
    transform: scale(0.92);
    border: 3px solid var(--primary);
    border-radius: 8px;
    z-index: 10;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.puzzle-piece:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: -3px;
}

#loading {
    display: none;
    margin: 20px 0;
    color: var(--primary);
    font-weight: 700;
}

.ad-gameover-wrap {
    max-width: 460px;
    margin: 0 auto;
}

.gameover-msg {
    margin: 0 0 12px;
    color: #ef4444;
    font-size: 1rem;
    font-weight: 700;
}

.error-title {
    color: #ef4444;
    margin: 0 0 8px;
}

.error-desc {
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
}

#make-mine-zone {
    display: none;
    margin-top: 25px;
    padding: 22px 18px 20px;
    border-radius: var(--radius-sm);
    background: linear-gradient(160deg, #f5f3ff 0%, #e0e7ff 100%);
    border: 1px solid #c7d2fe;
}

.result-headline {
    font-size: 1.6rem;
    font-weight: 800;
    margin: 0 0 8px;
    letter-spacing: -0.02em;
}

.result-headline.result-win { color: #6d28d9; }
.result-headline.result-lose { color: #4f46e5; }

.result-taunt {
    font-size: 0.95rem;
    color: #4c1d95;
    line-height: 1.55;
    margin: 0 0 18px;
}

#make-mine-zone .btn-primary {
    font-size: 1.05rem;
    padding: 16px;
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.28);
}

.views-badge {
    display: none;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #15803d;
    font-size: 0.85rem;
    font-weight: 700;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin: 0 0 14px;
}

.option-hint {
    font-weight: 500;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.custom-views-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

#custom-views {
    width: 90px;
    padding: 11px 12px;
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
}

#custom-views:focus {
    outline: none;
    border-color: #6366f1;
}

.custom-views-suffix {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.adfit-wrap {
    display: flex;
    justify-content: center;
    margin: 18px 0 10px;
    min-height: 100px;
}

.lang-switch {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin-bottom: 6px;
}

.lang-switch button {
    width: auto;
    min-height: 0;
    flex: 0 0 auto;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 6px 11px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.lang-switch button:hover {
    background: #eef2ff;
}

.lang-switch button.active {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
}

.btn-save-image {
    background: #fff;
    color: #4f46e5;
    border: 2px solid #c7d2fe;
    margin-bottom: 10px;
    width: 100%;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-size: 0.98rem;
    font-weight: 800;
    cursor: pointer;
}

.btn-save-image:hover { background: #eef2ff; }

.btn-brag {
    background: linear-gradient(135deg, #f59e0b, #fbbf24);
    color: #fff;
    margin-bottom: 10px;
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(245, 158, 11, 0.3);
}

.challenge-badge {
    display: none;
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #b45309;
    font-size: 0.92rem;
    font-weight: 700;
    padding: 13px 14px;
    border-radius: var(--radius-sm);
    margin: 0 0 14px;
    line-height: 1.5;
}

.record-badge {
    display: none;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    color: #4338ca;
    font-size: 0.9rem;
    font-weight: 700;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin: 0 0 16px;
}

#share-buttons {
    display: none;
    margin-top: 20px;
}

.option-group {
    margin: 18px 0 20px;
    text-align: left;
}

.option-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 10px;
}

.option-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

#max-views-options {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

#max-views-options .option-btn {
    padding-left: 4px;
    padding-right: 4px;
}

#max-views-options .option-desc {
    font-size: 0.68rem;
}

.option-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 6px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.option-btn input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.option-btn.selected,
.option-btn:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: translateY(-1px);
}

.option-title {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text);
}

.option-desc {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: center;
    line-height: 1.3;
}

.puzzle-info {
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 600;
    margin: 0 0 12px;
}

.time-extend-zone {
    display: none;
    margin: 14px auto 0;
    max-width: 460px;
    padding: 12px;
    background: linear-gradient(135deg, #fff7ed, #fef3c7);
    border: 1px solid #fcd34d;
    border-radius: var(--radius-sm);
    animation: extendPop 0.35s ease;
}

@keyframes extendPop {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.extend-hint {
    margin: 0 0 10px;
    font-size: 0.82rem;
    font-weight: 700;
    color: #b45309;
}

.extend-sub {
    margin: 6px 2px 0;
    font-size: 0.68rem;
    color: #94a3b8;
    text-align: center;
}

.extend-row {
    display: flex;
    gap: 6px;
    align-items: stretch;
}

.btn-extend {
    flex: 1;
    padding: 10px 6px;
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.2;
    background: linear-gradient(135deg, #6366f1, #818cf8);
    color: #fff;
    border: none;
    border-radius: 10px;
    min-height: 52px;
    font-weight: 800;
    touch-action: manipulation;
}

.btn-extend span {
    font-size: 0.72rem;
    font-weight: 600;
}

.ad-extend-link {
    margin-top: 10px;
    border: 1px solid var(--border);
}

#timer-display.timer-urgent {
    color: #ef4444;
    animation: timerBlink 0.8s ease-in-out infinite;
}

@keyframes timerBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.65; }
}

.site-domain {
    margin: 4px auto 0;
    color: #94a3b8;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-align: center;
}

.affiliate-disclosure {
    margin: 8px auto 0;
    max-width: 520px;
    color: #64748b;
    font-size: 0.68rem;
    line-height: 1.45;
    text-align: center;
}

/* ── 모바일 ── */
@media (max-width: 767px) {
    body {
        padding-left: max(8px, env(safe-area-inset-left));
        padding-right: max(8px, env(safe-area-inset-right));
    }

    .container {
        border-radius: 18px;
    }

    .option-btn {
        padding: 14px 4px;
        min-height: 64px;
    }

    .option-desc {
        font-size: 0.68rem;
    }

    .ad-top-banner,
    .ad-coupang {
        min-height: auto;
    }

    .btn-extend {
        min-height: 52px;
    }

    .ad-gameover-wrap {
        max-width: 100%;
    }
}

/* ── 데스크톱 ── */
@media (min-width: 768px) {
    body {
        padding-top: 40px;
        padding-bottom: 40px;
    }

    .container {
        border-radius: 28px;
    }

    #game-instruction {
        font-size: 0.92rem;
        margin-bottom: 16px;
    }
}

/* ── 초소형 화면 ── */
@media (max-width: 360px) {
    .extend-hint {
        font-size: 0.75rem;
    }

    .btn-extend { font-size: 0.85rem; }
}
