:root {
    --bg-color: #0d0a06;
    --text-color: #3d2b1f;
    --header-bg: rgba(244, 236, 216, 0.07);
    --header-border: rgba(212, 168, 75, 0.25);
    --header-text: #f4ecd8;
    --score-bg: rgba(244, 236, 216, 0.05);
    --score-border: rgba(212, 168, 75, 0.2);
    --score-label: #d4a84b;
    --score-value: #ffd700;
    --dot-bg: rgba(212, 168, 75, 0.12);
    --dot-border: rgba(212, 168, 75, 0.25);
    --popup-bg: #f5ecd6;
    --popup-text: #4a3020;
    --popup-subtitle: #8d6e63;
    --popup-clue-bg: rgba(141, 110, 99, 0.1);
    --popup-border: #c89a50;
}

body.dark-mode {
    --bg-color: #18191a;
    --text-color: #e4e6eb;
    --header-bg: rgba(255, 255, 255, 0.05);
    --header-border: rgba(255, 215, 0, 0.15);
    --header-text: #e4e6eb;
    --score-bg: rgba(255, 255, 255, 0.03);
    --score-border: rgba(255, 215, 0, 0.1);
    --score-label: #a0a0a0;
    --score-value: #ffd700;
    --dot-bg: rgba(255, 255, 255, 0.05);
    --dot-border: rgba(255, 215, 0, 0.1);
    --popup-bg: #242526;
    --popup-text: #e4e6eb;
    --popup-subtitle: #a0a0a0;
    --popup-clue-bg: rgba(255, 255, 255, 0.05);
    --popup-border: #ffd700;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: 'Malgun Gothic', 'Apple SD Gothic Neo', 'Nanum Gothic', sans-serif;
    color: var(--text-color);
    padding: 16px 12px 32px;
    transition: background-color 0.3s, color 0.3s;
}

/* ── Header ── */
.page-header {
    width: 100%;
    max-width: 580px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding: 12px 18px;
    background: var(--header-bg);
    border-radius: 10px;
    border: 1px solid var(--header-border);
    position: relative;
}

.back-link {
    color: #d4a84b;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: bold;
    white-space: nowrap;
}

.back-link:hover { color: #f0c870; }

.page-header h1 {
    color: var(--header-text);
    font-size: 1.25rem;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
    flex: 1;
    text-align: center;
}

.treasure-count {
    color: #ffd700;
    font-weight: bold;
    font-size: 0.9rem;
    white-space: nowrap;
}

/* ── Score Bar ── */
.score-bar {
    width: 100%;
    max-width: 580px;
    display: flex;
    justify-content: space-around;
    padding: 12px 16px;
    background: var(--score-bg);
    border-radius: 8px;
    border: 1px solid var(--score-border);
    margin-bottom: 12px;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.score-label {
    font-size: 0.68rem;
    color: var(--score-label);
}

.score-value {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--score-value);
}

/* ── Progress Dots ── */
.progress-dots {
    width: 100%;
    max-width: 580px;
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    padding: 0 2px;
}

.progress-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--dot-bg);
    border: 1.5px solid var(--dot-border);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s ease;
    cursor: default;
    color: var(--text-color);
}

.progress-dot.found {
    background: rgba(255, 215, 0, 0.2);
    border-color: #ffd700;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
    transform: scale(1.1);
}

/* ── Map Container ── */
.map-container {
    width: 100%;
    max-width: 580px;
}

#korea-map {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 10px 50px rgba(0, 0, 0, 0.9));
    border-radius: 8px;
}

/* ── SVG Treasure Markers ── */
.treasure-marker {
    cursor: pointer;
}

.treasure-marker .marker-circle {
    transition: filter 0.2s;
}

.treasure-marker:hover .marker-circle {
    filter: brightness(1.4) url(#glow);
}

.treasure-marker:hover .marker-label {
    font-size: 8.5px;
}

/* ── Popup ── */
.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
    padding: 16px;
}

.popup-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.popup {
    background: var(--popup-bg);
    background-image:
        radial-gradient(ellipse at top left, rgba(212, 163, 115, 0.15) 0%, transparent 55%),
        radial-gradient(ellipse at bottom right, rgba(141, 110, 99, 0.15) 0%, transparent 55%);
    border-radius: 14px;
    padding: 30px 26px 24px;
    max-width: 400px;
    width: 100%;
    box-shadow:
        0 24px 70px rgba(0, 0, 0, 0.85),
        inset 0 0 40px rgba(141, 110, 99, 0.08);
    border: 2.5px solid var(--popup-border);
    transform: scale(0.85) translateY(24px);
    transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.popup-overlay.active .popup {
    transform: scale(1) translateY(0);
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.popup-location-name {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--popup-text);
}

.popup-subtitle {
    font-size: 0.8rem;
    color: var(--popup-subtitle);
    margin-top: 2px;
}

.discovered-badge {
    background: rgba(46, 125, 50, 0.15);
    border: 1px solid #4caf50;
    color: #388e3c;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: bold;
    white-space: nowrap;
}

.popup-clue {
    background: var(--popup-clue-bg);
    border-left: 4px solid var(--popup-border);
    padding: 13px 15px;
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: var(--popup-text);
    line-height: 1.75;
    margin-bottom: 20px;
    font-size: 0.92rem;
    position: relative;
}

.popup-clue::before {
    content: '💬 단서: ';
    font-style: normal;
    font-weight: 700;
    color: var(--popup-subtitle);
}

/* ── Treasure Reveal ── */
.treasure-reveal {
    text-align: center;
    padding: 18px 16px;
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.12), rgba(255, 165, 0, 0.08));
    border-radius: 10px;
    border: 2px solid #ffd700;
    margin-bottom: 18px;
    animation: reveal-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes reveal-pop {
    0% { opacity: 0; transform: scale(0.5); }
    100% { opacity: 1; transform: scale(1); }
}

.reveal-emoji {
    font-size: 3rem;
    display: block;
    margin-bottom: 8px;
    animation: float-emoji 2s ease-in-out infinite;
}

@keyframes float-emoji {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.reveal-name {
    font-size: 1.05rem;
    font-weight: 800;
    color: #ffd700;
    margin-bottom: 4px;
}

.reveal-points {
    color: #e67e22;
    font-size: 0.9rem;
    font-weight: bold;
}

/* ── Buttons ── */
.popup-btn {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 9px;
    font-size: 0.95rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, #c89a50, #a07020);
    color: white;
    box-shadow: 0 4px 12px rgba(160, 112, 32, 0.4);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #d4a860, #b08030);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(160, 112, 32, 0.5);
}

.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: none;
    border: 2px solid var(--popup-border);
    color: var(--popup-subtitle);
    margin-top: 10px;
}

.btn-secondary:hover {
    background: rgba(200, 154, 80, 0.1);
    color: var(--popup-text);
}

/* ── Victory Screen ── */
.victory-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    padding: 20px;
}

.victory-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.victory-box {
    background: var(--popup-bg);
    background-image: radial-gradient(ellipse at top, rgba(255, 215, 0, 0.15) 0%, transparent 60%);
    border-radius: 20px;
    padding: 44px 36px 36px;
    text-align: center;
    max-width: 420px;
    width: 100%;
    border: 3px solid #ffd700;
    box-shadow:
        0 0 80px rgba(255, 215, 0, 0.3),
        0 30px 80px rgba(0, 0, 0, 0.8);
    animation: victory-appear 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes victory-appear {
    from { transform: scale(0.6) rotate(-5deg); opacity: 0; }
    to { transform: scale(1) rotate(0); opacity: 1; }
}

.victory-crown {
    font-size: 3.5rem;
    margin-bottom: 14px;
    animation: crown-spin 1.5s ease;
}

@keyframes crown-spin {
    0% { transform: rotateY(0); }
    50% { transform: rotateY(180deg) scale(1.2); }
    100% { transform: rotateY(360deg); }
}

.victory-box h2 {
    font-size: 1.8rem;
    color: var(--popup-text);
    margin-bottom: 12px;
}

.victory-box p {
    font-size: 0.9rem;
    color: var(--popup-subtitle);
    margin-bottom: 22px;
    line-height: 1.7;
}

.victory-treasures {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-bottom: 22px;
}

.victory-treasure-item {
    font-size: 2rem;
    animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes pop-in {
    from { transform: scale(0) rotate(-30deg); opacity: 0; }
    to { transform: scale(1) rotate(0); opacity: 1; }
}

.victory-score {
    font-size: 1.6rem;
    font-weight: 900;
    color: #a07020;
    margin-bottom: 24px;
}

.victory-score span {
    color: #e67e22;
    font-size: 2rem;
}

/* ── Utility ── */
.hidden {
    display: none !important;
}

#theme-toggle {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--header-text);
    padding: 5px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

#theme-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ── Responsive ── */
@media (max-width: 500px) {
    .page-header h1 { font-size: 1rem; }
    .page-header { padding: 10px 12px; }
    .popup { padding: 24px 18px 20px; }
    .popup-location-name { font-size: 1.2rem; }
    .victory-box { padding: 32px 22px 28px; }
    .victory-box h2 { font-size: 1.4rem; }
}
