/* リセットとベース設定 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Rajdhani', sans-serif;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%);
    color: #00ffff;
    min-height: 100vh;
    overflow-x: hidden;
    user-select: none;
}

/* サイバーパンク背景 */
.cyberpunk-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 50%, rgba(120, 0, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 0, 150, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 80%, rgba(0, 255, 255, 0.1) 0%, transparent 50%);
    z-index: -1;
    animation: bgPulse 4s ease-in-out infinite alternate;
}

@keyframes bgPulse {
    0% { opacity: 0.8; }
    100% { opacity: 1; }
}

/* コンテナとレイアウト */
.container {
    min-height: 100vh;
    padding: 20px;
    max-width: 1600px;
    margin: 0 auto;
}

.game-header {
    text-align: center;
    margin-bottom: 30px;
    background: rgba(0, 0, 0, 0.8);
    padding: 20px;
    border-radius: 20px;
    border: 2px solid #00ffff;
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.3);
    backdrop-filter: blur(10px);
}

.game-title {
    font-family: 'Orbitron', monospace;
    font-size: clamp(1.8rem, 4vw, 3rem);
    font-weight: 900;
    background: linear-gradient(45deg, #00ffff, #ff00ff, #ffff00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 20px rgba(0, 255, 255, 0.5);
    margin-bottom: 10px;
    animation: titleGlow 3s ease-in-out infinite alternate;
}

@keyframes titleGlow {
    0% { filter: drop-shadow(0 0 10px rgba(0, 255, 255, 0.5)); }
    100% { filter: drop-shadow(0 0 20px rgba(255, 0, 255, 0.7)); }
}

.game-subtitle {
    font-size: 1.2rem;
    color: #00aaff;
    text-shadow: 0 0 10px rgba(0, 170, 255, 0.5);
}

/* ゲームレイアウト */
.game-layout {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    gap: 25px;
    min-height: calc(100vh - 200px);
}

/* コントロールパネル */
.controls-panel {
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid #00ffff;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.3);
    backdrop-filter: blur(10px);
    height: fit-content;
}

.controls-panel h3 {
    font-family: 'Orbitron', monospace;
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: #00ffff;
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

.stage-info {
    margin-bottom: 25px;
    text-align: center;
}

.stage-display {
    font-family: 'Orbitron', monospace;
    font-size: 1.5rem;
    font-weight: bold;
    color: #ffff00;
    text-shadow: 0 0 15px rgba(255, 255, 0, 0.8);
    margin-bottom: 10px;
    padding: 10px;
    background: rgba(255, 255, 0, 0.1);
    border: 2px solid #ffff00;
    border-radius: 8px;
    animation: stagePulse 2s ease-in-out infinite alternate;
}

@keyframes stagePulse {
    0% { box-shadow: 0 0 15px rgba(255, 255, 0, 0.5); }
    100% { box-shadow: 0 0 25px rgba(255, 255, 0, 0.8); }
}

.timer-display {
    font-family: 'Orbitron', monospace;
    font-size: 1.2rem;
    font-weight: bold;
    color: #ff00ff;
    text-shadow: 0 0 10px rgba(255, 0, 255, 0.5);
    padding: 8px 12px;
    background: rgba(255, 0, 255, 0.1);
    border: 1px solid #ff00ff;
    border-radius: 5px;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.timer-display.warning {
    color: #ff4444;
    border-color: #ff4444;
    background: rgba(255, 68, 68, 0.2);
    animation: timerWarning 1s ease-in-out infinite alternate;
}

@keyframes timerWarning {
    0% { box-shadow: 0 0 10px rgba(255, 68, 68, 0.5); }
    100% { box-shadow: 0 0 20px rgba(255, 68, 68, 0.9); }
}

/* フルスクリーン対応 */
:fullscreen {
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%);
}

:fullscreen .container {
    max-width: 100%;
    height: 100vh;
    padding: 10px;
}

:fullscreen .game-layout {
    height: calc(100vh - 120px);
    max-width: 100%;
}

:fullscreen .puzzle-frame {
    width: min(450px, 40vw);
    height: min(450px, 40vw);
}

:fullscreen .puzzle-slot {
    width: min(140px, 12vw);
    height: min(140px, 12vw);
}

:fullscreen .puzzle-piece {
    width: min(130px, 11vw) !important;
    height: min(130px, 11vw) !important;
    background-size: min(390px, 33vw) min(390px, 33vw) !important;
}

:fullscreen .puzzle-frame {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
}

:fullscreen .pieces-area {
    width: min(450px, 40vw);
    height: min(300px, 27vw);
}

:fullscreen .reference-image img {
    width: min(300px, 25vw);
    height: min(300px, 25vw);
}

.progress-section {
    margin-bottom: 25px;
}

.progress-bar {
    width: 100%;
    height: 12px;
    background: rgba(0, 255, 255, 0.2);
    border-radius: 6px;
    overflow: hidden;
    margin: 10px 0;
    box-shadow: inset 0 0 10px rgba(0, 255, 255, 0.3);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #00ffff, #ff00ff);
    width: 0%;
    transition: width 0.5s ease;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.6);
}

.progress-text {
    font-size: 0.9rem;
    text-align: center;
    color: #00aaff;
}

.control-buttons {
    margin-bottom: 25px;
}

.control-btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    background: linear-gradient(45deg, rgba(0, 255, 255, 0.2), rgba(255, 0, 255, 0.2));
    border: 2px solid #00ffff;
    border-radius: 8px;
    color: #00ffff;
    font-family: 'Rajdhani', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-btn:hover {
    background: linear-gradient(45deg, rgba(0, 255, 255, 0.4), rgba(255, 0, 255, 0.4));
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.5);
    transform: translateY(-2px);
}

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

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.selected-piece-info {
    background: rgba(255, 255, 0, 0.1);
    border: 1px solid #ffff00;
    border-radius: 8px;
    padding: 15px;
}

#selectedPieceDisplay {
    color: #ffff00;
    font-weight: 600;
    text-align: center;
    padding: 10px;
    background: rgba(255, 255, 0, 0.1);
    border-radius: 5px;
    margin-top: 10px;
}

/* ゲームエリア */
.game-area {
    display: flex;
    flex-direction: column;
    gap: 30px;
    align-items: center;
}

.section-title {
    font-family: 'Orbitron', monospace;
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: #00ffff;
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
    text-align: center;
}

/* パズルフレーム */
.puzzle-frame-container {
    background: rgba(0, 0, 0, 0.8);
    border: 3px solid #00ffff;
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 0 40px rgba(0, 255, 255, 0.4);
}

.puzzle-frame {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 5px;
    width: 375px;
    height: 375px;
    margin: 0 auto;
}

.puzzle-slot {
    width: 120px;
    height: 120px;
    border: 2px dashed #00ffff;
    border-radius: 8px;
    background: rgba(0, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s ease;
    padding: 5px;
    box-sizing: border-box;
}



.puzzle-slot.drop-zone {
    border-color: #00ff00;
    background: rgba(0, 255, 0, 0.2);
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.4);
    transform: scale(1.05);
}

.puzzle-slot.occupied {
    border-color: #00ff00;
    background: rgba(0, 255, 0, 0.1);
}

.puzzle-slot .puzzle-piece {
    position: static !important;
    left: auto !important;
    top: auto !important;
    width: 110px !important;
    height: 110px !important;
    margin: 0 !important;
    border-radius: 6px !important;
}

.puzzle-slot.correct {
    border-color: #00ff00;
    box-shadow: 0 0 25px rgba(0, 255, 0, 0.6);
    animation: correctPulse 2s ease-in-out infinite;
}

@keyframes correctPulse {
    0%, 100% { box-shadow: 0 0 25px rgba(0, 255, 0, 0.6); }
    50% { box-shadow: 0 0 35px rgba(0, 255, 0, 0.8); }
}

/* ピース置き場 */
.pieces-area-container {
    background: rgba(0, 0, 0, 0.8);
    border: 3px solid #ff00ff;
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 0 40px rgba(255, 0, 255, 0.4);
}

.pieces-area {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    width: 360px;
    height: 240px;
    margin: 0 auto;
}

.puzzle-piece {
    width: 110px;
    height: 110px;
    background-size: 330px 330px;
    border: 2px solid #ff00ff;
    border-radius: 8px;
    cursor: grab;
    position: relative;
    transition: none;
    box-shadow: 0 0 15px rgba(255, 0, 255, 0.4);
    user-select: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
}



.puzzle-piece:hover {
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(255, 0, 255, 0.6);
    z-index: 10;
}

.puzzle-piece.selected {
    border-color: #ffff00;
    box-shadow: 0 0 30px rgba(255, 255, 0, 0.8);
    transform: scale(1.1);
    z-index: 15;
}

.puzzle-piece.dragging {
    cursor: grabbing;
    transform: scale(1.1);
    z-index: 20;
    opacity: 0.9;
    box-shadow: 0 0 35px rgba(255, 255, 0, 0.9);
    pointer-events: none;
    transition: none;
}

.puzzle-piece.placed {
    opacity: 0.3;
    pointer-events: none;
}

/* 右側パネル */
.reference-panel {
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid #ffff00;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 0 30px rgba(255, 255, 0, 0.3);
    backdrop-filter: blur(10px);
    height: fit-content;
}

.reference-image {
    margin-bottom: 25px;
    text-align: center;
}

.reference-image img {
    width: 250px;
    height: 250px;
    border: 3px solid #ffff00;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(255, 255, 0, 0.4);
    object-fit: cover;
}

.instructions h4 {
    font-family: 'Orbitron', monospace;
    font-size: 1rem;
    margin-bottom: 15px;
    color: #ffff00;
    text-shadow: 0 0 10px rgba(255, 255, 0, 0.5);
}

.instruction-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 0, 0.1);
    border: 1px solid rgba(255, 255, 0, 0.3);
    border-radius: 5px;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.instruction-item:hover {
    background: rgba(255, 255, 0, 0.2);
    transform: translateX(5px);
}

.instruction-item i {
    color: #ffff00;
    width: 16px;
}

/* ステージ時間表示 */
.stage-times {
    margin-bottom: 20px;
}

.stage-times h4 {
    font-family: 'Orbitron', monospace;
    font-size: 1rem;
    margin-bottom: 10px;
    color: #ffff00;
    text-shadow: 0 0 10px rgba(255, 255, 0, 0.5);
}

.time-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.time-item {
    font-size: 0.9rem;
    color: #00aaff;
    padding: 4px 8px;
    background: rgba(0, 170, 255, 0.1);
    border: 1px solid rgba(0, 170, 255, 0.3);
    border-radius: 4px;
    transition: all 0.3s ease;
}

.time-item:hover {
    background: rgba(0, 170, 255, 0.2);
}

/* 完成モーダル */
.victory-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    animation: modalFadeIn 0.5s ease-out;
}

.victory-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.9), rgba(0, 20, 40, 0.9));
    border: 3px solid #00ffff;
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 0 50px rgba(0, 255, 255, 0.5);
    backdrop-filter: blur(15px);
    max-width: 500px;
    width: 90%;
}

.victory-effects {
    position: relative;
    margin-bottom: 30px;
}

.victory-icon {
    font-size: 4rem;
    color: #ffff00;
    animation: victoryBounce 1s ease-in-out infinite alternate;
}

@keyframes victoryBounce {
    0% { transform: scale(1) rotate(-5deg); }
    100% { transform: scale(1.2) rotate(5deg); }
}

.victory-title {
    font-family: 'Orbitron', monospace;
    font-size: 2rem;
    font-weight: 900;
    background: linear-gradient(45deg, #00ffff, #ff00ff, #ffff00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 20px;
    animation: titleGlow 2s ease-in-out infinite alternate;
}

.victory-message {
    font-size: 1.2rem;
    color: #00ffff;
    margin-bottom: 30px;
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

.victory-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 30px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 15px;
    background: rgba(0, 255, 255, 0.1);
    border: 1px solid #00ffff;
    border-radius: 10px;
}

.stat-item i {
    font-size: 1.5rem;
    color: #00ffff;
}

.victory-btn {
    padding: 15px 30px;
    margin: 5px;
    background: linear-gradient(45deg, #00ffff, #ff00ff);
    border: none;
    border-radius: 10px;
    color: #000;
    font-family: 'Orbitron', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-shadow: none;
}

.victory-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0, 255, 255, 0.4);
}

.victory-btn.secondary {
    background: linear-gradient(45deg, #666, #999);
}

.victory-btn.secondary:hover {
    box-shadow: 0 10px 25px rgba(153, 153, 153, 0.4);
}

/* ゲームオーバーモーダル */
.gameover-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    animation: modalFadeIn 0.5s ease-out;
}

.gameover-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, rgba(20, 0, 0, 0.9), rgba(40, 0, 20, 0.9));
    border: 3px solid #ff4444;
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 0 50px rgba(255, 68, 68, 0.5);
    backdrop-filter: blur(15px);
    max-width: 500px;
    width: 90%;
}

.gameover-icon {
    font-size: 4rem;
    color: #ff4444;
    animation: gameoverShake 1s ease-in-out infinite alternate;
}

@keyframes gameoverShake {
    0% { transform: rotate(-3deg); }
    100% { transform: rotate(3deg); }
}

.gameover-title {
    font-family: 'Orbitron', monospace;
    font-size: 2rem;
    font-weight: 900;
    color: #ff4444;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(255, 68, 68, 0.8);
}

.gameover-message {
    font-size: 1.2rem;
    color: #ff6666;
    margin-bottom: 30px;
    text-shadow: 0 0 10px rgba(255, 102, 102, 0.5);
}

.gameover-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 30px;
}

.gameover-btn {
    padding: 15px 30px;
    background: linear-gradient(45deg, #ff4444, #ff6666);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-family: 'Orbitron', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
}

.gameover-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(255, 68, 68, 0.4);
}

/* レスポンシブデザイン */
@media (max-width: 1200px) {
    .game-layout {
        grid-template-columns: 250px 1fr 280px;
        gap: 20px;
    }
    
    .puzzle-frame {
        width: 300px;
        height: 300px;
    }
    
    .puzzle-slot {
        width: 96px;
        height: 96px;
    }
    
    .pieces-area {
        width: 300px;
        height: 200px;
    }
    
    .puzzle-piece {
        width: 90px;
        height: 90px;
        background-size: 270px 270px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .game-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .controls-panel,
    .reference-panel {
        order: 2;
    }
    
    .game-area {
        order: 1;
    }
    
    .puzzle-frame {
        width: 240px;
        height: 240px;
    }
    
    .puzzle-slot {
        width: 76px;
        height: 76px;
    }
    
    .pieces-area {
        width: 240px;
        height: 160px;
    }
    
    .puzzle-piece {
        width: 70px;
        height: 70px;
        background-size: 210px 210px;
    }
    
    .reference-image img {
        width: 200px;
        height: 200px;
    }
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: translate(-50%, -60%); }
    to { opacity: 1; transform: translate(-50%, -50%); }
}