/* ==========================================================================
   Starry Night Jigsaw Puzzle - Main Stylesheet
   '별이 빛나는 밤' 어린이 직소 퍼즐 웹 게임 스타일시트
   ========================================================================== */

:root {
    --bg-dark: #070d1e;
    --bg-card: rgba(17, 28, 58, 0.88);
    --border-color: rgba(212, 175, 55, 0.35);
    --gold: #ffd166;
    --gold-glow: rgba(255, 209, 102, 0.45);
    --accent-blue: #38bdf8;
    --accent-green: #34d399;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-main: 0 10px 30px -5px rgba(0, 0, 0, 0.5);
    --font-main: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", sans-serif;
}

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

body {
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(circle at 15% 25%, rgba(30, 58, 138, 0.4) 0%, transparent 45%),
        radial-gradient(circle at 85% 75%, rgba(212, 175, 55, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 50% 10%, rgba(56, 189, 248, 0.12) 0%, transparent 40%);
    background-attachment: fixed;
    color: var(--text-main);
    font-family: var(--font-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    user-select: none;
    touch-action: manipulation;
}

/* --------------------------------------------------------------------------
   Navigation Bar & Header
   -------------------------------------------------------------------------- */
header.app-header {
    background: rgba(10, 19, 44, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.brand-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    font-size: 28px;
    filter: drop-shadow(0 0 8px var(--gold));
    animation: pulseStar 3s ease-in-out infinite;
}

@keyframes pulseStar {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 6px var(--gold)); }
    50% { transform: scale(1.15); filter: drop-shadow(0 0 14px #fff275); }
}

.brand-title {
    font-size: 20px;
    font-weight: 800;
    color: #ffffff;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.header-links {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.nav-link-btn {
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.nav-link-btn:hover {
    background: rgba(255, 209, 102, 0.2);
    border-color: var(--gold);
    color: var(--gold);
    transform: translateY(-1px);
}

.nav-link-btn.highlight {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #ffffff;
    border: none;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}

.nav-link-btn.highlight:hover {
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.6);
}

/* --------------------------------------------------------------------------
   Main Game Layout
   -------------------------------------------------------------------------- */
main.game-main {
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* HUD / Control Toolbar */
.control-toolbar {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    box-shadow: var(--shadow-main);
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.select-control {
    background: #1e293b;
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
}

.select-control:focus {
    border-color: var(--gold);
}

.btn-tool {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.18);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.btn-tool:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: var(--gold);
}

.btn-tool.active {
    background: rgba(255, 209, 102, 0.22);
    border-color: var(--gold);
    color: var(--gold);
}

.btn-tool.primary-action {
    background: linear-gradient(135deg, #eab308, #ca8a04);
    border-color: #facc15;
    color: #0f172a;
    font-weight: 700;
    box-shadow: 0 0 12px rgba(234, 179, 8, 0.35);
}

.btn-tool.primary-action:hover {
    box-shadow: 0 0 20px rgba(250, 204, 21, 0.6);
    transform: translateY(-1px);
}

.btn-tool.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Stat Badges */
.stat-badge {
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.stat-label {
    color: var(--text-muted);
    font-size: 12px;
}

.stat-val {
    color: var(--gold);
    font-weight: 700;
    font-family: monospace;
    font-size: 15px;
}

.chance-container {
    display: inline-flex;
    gap: 3px;
    font-size: 16px;
}

.chance-star.used {
    filter: grayscale(1) opacity(0.3);
}

/* --------------------------------------------------------------------------
   Puzzle Stage Area (Board + Tray)
   -------------------------------------------------------------------------- */
.puzzle-stage-container {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) 340px;
    gap: 20px;
    align-items: start;
}

@media (max-width: 960px) {
    .puzzle-stage-container {
        grid-template-columns: 1fr;
    }
}

/* Puzzle Board Section */
.puzzle-board-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: var(--shadow-main);
}

.board-wrapper {
    position: relative;
    border-radius: var(--radius-sm);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    background: #0c152c;
    border: 3px solid rgba(212, 175, 55, 0.4);
    touch-action: none;
}

.puzzle-board {
    position: relative;
    width: 600px;
    height: 400px;
    background: transparent;
    cursor: pointer;
}

.puzzle-board.completed {
    border-color: #ffd700;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.7);
    animation: goldGlow 2s ease-in-out infinite alternate;
}

@keyframes goldGlow {
    from { box-shadow: 0 0 20px rgba(255, 215, 0, 0.4); }
    to { box-shadow: 0 0 35px rgba(255, 215, 0, 0.8); }
}

.ghost-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

/* Puzzle Piece Elements */
.puzzle-piece {
    position: absolute;
    cursor: grab;
    user-select: none;
    touch-action: none;
    z-index: 10;
    transition: transform 0.15s ease, filter 0.15s ease;
}

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

.puzzle-piece.dragging {
    cursor: grabbing;
    z-index: 1000 !important;
    filter: drop-shadow(0 15px 25px rgba(0, 0, 0, 0.65));
    transform: scale(1.05);
}

.puzzle-piece.selected {
    z-index: 200;
    filter: drop-shadow(0 0 12px var(--gold));
    animation: floatSelect 1.5s ease-in-out infinite alternate;
}

@keyframes floatSelect {
    0% { transform: translateY(0) scale(1.03); }
    100% { transform: translateY(-6px) scale(1.07); }
}

.puzzle-piece.snapped {
    cursor: default;
    pointer-events: none;
    z-index: 5 !important;
    transition: left 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28), top 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.puzzle-piece.flying-hint {
    transition: all 0.35s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 999 !important;
    filter: drop-shadow(0 0 20px #ffd700);
}

.puzzle-piece.wobble {
    animation: wobbleShake 0.4s ease;
}

@keyframes wobbleShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px) rotate(-3deg); }
    40%, 80% { transform: translateX(8px) rotate(3deg); }
}

/* --------------------------------------------------------------------------
   Piece Tray Section
   -------------------------------------------------------------------------- */
.piece-tray-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: var(--shadow-main);
    max-height: 520px;
}

.tray-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
}

.tray-title {
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 6px;
}

.piece-tray {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 10px;
    overflow-y: auto;
    max-height: 440px;
    padding: 8px 4px;
    min-height: 180px;
    background: rgba(10, 19, 44, 0.6);
    border-radius: var(--radius-sm);
    border: 1px inset rgba(255, 255, 255, 0.05);
}

/* Scrollbar styling */
.piece-tray::-webkit-scrollbar {
    width: 6px;
}
.piece-tray::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.4);
    border-radius: 4px;
}

.tray-slot {
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    overflow: visible;
    position: relative;
}

/* --------------------------------------------------------------------------
   Toast Notifications
   -------------------------------------------------------------------------- */
.toast-msg {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(50px);
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--gold);
    color: #ffffff;
    padding: 10px 22px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    z-index: 99999;
}

.toast-msg.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* --------------------------------------------------------------------------
   Victory Modal
   -------------------------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(5, 10, 25, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
    padding: 20px;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: linear-gradient(145deg, #0f1f45, #081126);
    border: 2px solid var(--gold);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 500px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 30px rgba(255, 209, 102, 0.25);
    transform: scale(0.9);
    transition: transform 0.35s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.victory-icon {
    font-size: 54px;
    margin-bottom: 12px;
    animation: victoryBounce 1s ease-in-out infinite alternate;
}

@keyframes victoryBounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-10px); }
}

.victory-title {
    font-size: 26px;
    font-weight: 800;
    color: var(--gold);
    margin-bottom: 8px;
}

.victory-stars {
    font-size: 32px;
    color: var(--gold);
    margin-bottom: 16px;
    letter-spacing: 4px;
}

.victory-subtitle {
    font-size: 15px;
    color: #cbd5e1;
    margin-bottom: 24px;
    line-height: 1.5;
}

.victory-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
    background: rgba(0, 0, 0, 0.25);
    padding: 14px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-item-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.stat-item-value {
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-modal {
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.btn-modal.primary {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4);
}

.btn-modal.primary:hover {
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.6);
    transform: translateY(-1px);
}

.btn-modal.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-modal.secondary:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
footer.app-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(5, 10, 25, 0.6);
    padding: 16px 24px;
    margin-top: auto;
}

.footer-inner {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.footer-inner a {
    color: var(--gold);
    text-decoration: none;
}

.footer-inner a:hover {
    text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Mobile Media Queries
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    header.app-header {
        padding: 10px 14px;
    }
    .brand-title {
        font-size: 17px;
    }
    .control-toolbar {
        padding: 10px;
    }
    .btn-tool {
        padding: 6px 10px;
        font-size: 13px;
    }
    .piece-tray {
        grid-template-columns: repeat(auto-fill, minmax(65px, 1fr));
        max-height: 280px;
    }
    .tray-slot {
        min-height: 65px;
    }
}
