* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --container-max-width: 1780px;
    --base-padding: 30px;
    --base-gap: 10px;
    --btn-padding-y: 10px;
    --btn-padding-x: 15px;
    --font-size-large: 2rem;
    --font-size-medium: 1.1rem;
    --font-size-small: 0.9rem;
    --grid-cell-size: 80px;
    --grid-gap: 5px;
    --piece-cell-size: 40px;
    --game-info-min-width: 200px;
    --center-info-gap: 20px;
    --puzzle-area-min-width: 300px;
    --puzzle-area-h3-margin: 15px;
    --puzzle-area-h3-font-size: 1.2rem;
    --body-padding: 20px;
    --game-board-gap: 20px;
    --puzzle-pieces-gap: 15px;
    --puzzle-area-gap: 20px;
    --piece-grid-gap: 2px;
    --popup-stats-gap: 15px;
    --popup-buttons-gap: 10px;
}

body {
    font-family: 'Arial', sans-serif;
    background: 
        radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(120, 219, 255, 0.3) 0%, transparent 50%),
        linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%;
    min-height: 100vh;
    padding: var(--body-padding);
    position: relative;
    overflow-x: auto;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 10% 20%, rgba(255, 255, 255, 0.1) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 20%),
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.05) 0%, transparent 30%);
    pointer-events: none;
    z-index: -1;
}

.mobile-landscape-notice {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.notice-content {
    text-align: center;
    color: white;
    padding: 20px;
}

.rotate-icon {
    font-size: 3rem;
    margin-bottom: 15px;
    animation: rotate 2s ease-in-out infinite;
}

.notice-content p {
    font-size: 1.2rem;
    font-weight: bold;
    margin: 0;
}

@keyframes rotate {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(90deg); }
    75% { transform: rotate(90deg); }
}

@media (max-width: 768px) and (orientation: portrait) {
    .mobile-landscape-notice {
        display: flex;
    }
    
    .container {
        display: none;
    }
}

@media (max-width: 768px) {
    .piece-cell {
        touch-action: none;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    .grid-cell {
        touch-action: none;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    .puzzle-piece {
        touch-action: none;
    }
    
    .back-btn, .btn, .popup-btn {
        touch-action: manipulation;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    .drag-preview {
        pointer-events: none;
        z-index: 1000;
        opacity: 0.8;
        transform: scale(1.1);
        transition: transform 0.1s ease;
    }
    
    .drag-preview.mobile {
        transition: left 0.05s ease, top 0.05s ease;
    }
    
    .piece-cell:active {
        transform: scale(0.95);
        transition: transform 0.1s;
    }
    
    .grid-cell:active {
        transform: scale(0.95);
        transition: transform 0.1s;
    }
    
    .puzzle-piece.dragging {
        opacity: 0.3;
        transform: scale(0.95);
        transition: all 0.2s ease;
    }
    
    .grid-cell.occupied {
        cursor: grab;
        transition: all 0.2s ease;
    }
    
    .grid-cell.occupied:active {
        cursor: grabbing;
        transform: scale(0.95);
    }
}

.back-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: var(--btn-padding-y) var(--btn-padding-x);
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: all 0.3s ease;
    font-size: var(--btn-font-size);
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.back-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.back-btn:active {
    transform: translateY(0);
}

.btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    padding: var(--btn-padding-y) var(--btn-padding-x);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: var(--btn-font-size);
    font-weight: bold;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn:active {
    transform: translateY(0);
}

.container {
    max-width: var(--container-max-width);
    width: 95%;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 25px;
    padding: var(--base-padding);
    box-shadow: 
        0 25px 50px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    position: relative;
    overflow: hidden;
}

.container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5), transparent);
}

.top-buttons {
    position: relative;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.left-buttons {
    display: flex;
    gap: var(--btn-gap, 20px);
}

.right-buttons {
    display: flex;
    gap: var(--btn-gap, 20px);
}

.fullscreen-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-weight: 600;
    transition: all 0.3s ease;
}

.fullscreen-btn:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.fullscreen-btn:active {
    transform: translateY(0);
}

.fullscreen-icon {
    font-size: 1.2em;
}

.fullscreen-text {
    font-size: 0.9em;
}

/* 전체화면 모드일 때 버튼 스타일 변경 */
.fullscreen-btn.fullscreen-active {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.fullscreen-btn.fullscreen-active .fullscreen-icon {
    transform: rotate(180deg);
}

/* 모바일에서 전체화면 버튼 숨기기 (모바일에서는 자동 전체화면) */
@media (max-width: 768px) {
    .fullscreen-btn {
        display: none;
    }
}

h1 {
    text-align: center;
    background: linear-gradient(45deg, #667eea, #764ba2, #f093fb);
    background-size: 300% 300%;
    animation: gradientShift 3s ease infinite;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0 0 20px 0;
    font-size: var(--font-size-large);
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    letter-spacing: 2px;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.game-info {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 15px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: fit-content;
    min-width: var(--game-info-min-width);
}

.center-info {
    text-align: center;
    display: flex;
    gap: var(--center-info-gap);
}

.center-info div {
    font-size: var(--font-size-medium);
    font-weight: bold;
    color: #333;
}

#stage {
    color: #4CAF50;
}

#timer {
    color: #2196F3;
}

#timer.warning {
    color: #FF9800;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.game-content {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--base-gap);
    flex-wrap: wrap;
}

.game-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 0 0 auto;
    order: 2;
    gap: var(--game-board-gap);
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, var(--grid-cell-size));
    grid-template-rows: repeat(4, var(--grid-cell-size));
    gap: var(--grid-gap);
    background: #333;
    padding: 10px;
    border-radius: 10px;
}

.grid-cell {
    width: var(--grid-cell-size);
    height: var(--grid-cell-size);
    background: #f0f0f0;
    border: 2px solid #ddd;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-small);
    font-weight: bold;
    color: #666;
    transition: all 0.3s;
    position: relative;
}

.grid-cell.occupied {
    background: #4CAF50;
    border-color: #45a049;
    color: white;
    cursor: grab;
}

.grid-cell.occupied:hover {
    transform: scale(1.05);
}

.grid-cell.occupied:active {
    transform: translateY(0);
}

.grid-cell.drop-zone {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.2);
}

.grid-cell.invalid-drop {
    border-color: #f44336;
    background: rgba(244, 67, 54, 0.2);
}

.puzzle-area-left {
    text-align: center;
    flex: 1;
    width: var(--puzzle-area-min-width);
    order: 1;
}

.puzzle-area-right {
    text-align: center;
    flex: 1;
    width: var(--puzzle-area-min-width);
    order: 3;
}

.puzzle-area h3 {
    margin-bottom: var(--puzzle-area-h3-margin);
    color: #333;
    font-size: var(--puzzle-area-h3-font-size);
}

.puzzle-pieces {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: var(--puzzle-pieces-gap);
    justify-items: center;
    align-items: center;
    max-width: 100%;
}

@media (min-width: 1200px) {
    .puzzle-pieces {
        gap: var(--puzzle-area-gap);
    }
}

.puzzle-piece {
    position: relative;
    cursor: default;
    padding: 5px;
    background: transparent;
    border: none;
    transition: all 0.3s;
    margin: 8px;
    display: inline-block;
}

.piece-cell:hover, .piece-label:hover {
    transform: scale(1.05);
    transition: transform 0.2s;
}

.piece-cell[draggable="true"]:hover {
    cursor: grab;
}

.piece-label[draggable="true"]:hover {
    cursor: grab;
}

.puzzle-piece.dragging {
    opacity: 0.3;
    transform: scale(0.95);
    cursor: grabbing;
    z-index: 1000;
}

.puzzle-piece.placed {
    opacity: 0.5;
    transform: scale(0.8);
    cursor: not-allowed;
    pointer-events: none;
    filter: grayscale(0.3);
    transition: all 0.3s ease;
}

.puzzle-piece.placed .piece-cell,
.puzzle-piece.placed .piece-label {
    pointer-events: none;
    cursor: not-allowed;
}

.piece-grid {
    display: grid;
    gap: var(--piece-grid-gap);
}

.piece-cell {
    width: var(--piece-cell-size);
    height: var(--piece-cell-size);
    background: #2196F3;
    border: 2px solid #1976D2;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-small);
    font-weight: bold;
    color: white;
    pointer-events: auto;
    box-sizing: border-box;
}

.piece-label {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    pointer-events: auto;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
}

.drag-preview {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.8;
}

.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.popup-container {
    background: white;
    border-radius: 15px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.popup-content h2 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.5rem;
}

.popup-content p {
    color: #666;
    margin-bottom: 20px;
    line-height: 1.5;
}

.popup-stats {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    gap: var(--popup-stats-gap);
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 8px;
    min-width: 100px;
}

.stat-label {
    font-size: 0.9rem;
    color: #666;
    font-weight: 500;
}

.stat-item span:last-child {
    font-size: 1.2rem;
    font-weight: bold;
    color: #333;
}

.popup-buttons {
    display: flex;
    gap: var(--popup-buttons-gap);
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

.popup-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
    min-width: 120px;
}

.popup-btn.primary {
    background: #4CAF50;
    color: white;
    border: none;
}

.popup-btn.primary:hover {
    background: #45a049;
}

.popup-btn.secondary {
    background: white;
    color: #666;
    border: 1px solid #ddd;
}

.popup-btn.secondary:hover {
    background: #f5f5f5;
}

.success-action {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
    pointer-events: auto;
}

.success-content {
    background: #4CAF50;
    color: white;
    padding: 20px 30px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    animation: successFadeIn 0.5s ease, successFadeOut 0.5s ease 1.5s forwards;
}

.success-icon {
    font-size: 2rem;
    margin-bottom: 10px;
    animation: bounce 0.6s ease 0.3s;
}

.success-text {
    font-size: 1.2rem;
    font-weight: bold;
}

@keyframes successFadeIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes successFadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
} 