@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;800&family=Pretendard:wght@400;600;800&display=swap');

:root {
    --color-red: #ff4757;
    --color-blue: #1e90ff;
    --color-yellow: #ffa502;
    
    --color-indigo-light: #818cf8;
    --color-indigo: #6366f1;
    --color-indigo-dark: #4f46e5;
    
    --color-text: #1e293b;
    --color-text-light: #64748b;
    
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(255, 255, 255, 0.8);
    --glass-shadow: 0 20px 40px -10px rgba(99, 102, 241, 0.15);
}

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

body {
    /* Premium Animated Gradient Background */
    background: linear-gradient(-45deg, #e0e7ff, #f3e8ff, #fbcfe8, #dbeafe);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    font-family: 'Outfit', 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Shared standard nav */
.std-nav { position: fixed; top: 1.5rem; left: 1.5rem; z-index: 100; }
.std-back-btn {
    display: flex; align-items: center; gap: 0.75rem;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    padding: 0.75rem 1.25rem; border-radius: 9999px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
    text-decoration: none; transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.std-back-btn:hover { box-shadow: 0 20px 30px -10px rgba(99, 102, 241, 0.3); transform: translateY(-3px); background: rgba(255, 255, 255, 0.9); }
.std-icon-box {
    width: 2.2rem; height: 2.2rem; background: linear-gradient(135deg, var(--color-indigo-light), var(--color-indigo)); border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.4); transition: transform 0.4s;
}
.std-back-btn:hover .std-icon-box { transform: rotate(15deg) scale(1.1); }
.std-icon-box img { width: 1.25rem; height: 1.25rem; filter: brightness(0) invert(1); }
.std-text-box { display: flex; flex-direction: column; text-align: left; }
.std-text-sub { font-size: 0.65rem; font-weight: 800; color: var(--color-indigo); text-transform: uppercase; letter-spacing: 0.1em; line-height: 1; margin-bottom: 3px; }
.std-text-main { font-size: 0.95rem; font-weight: 800; color: #1e293b; letter-spacing: -0.02em; line-height: 1; }

.icon-btn {
    display: flex; align-items: center; justify-content: center;
    width: 3.8rem; height: 3.8rem;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-radius: 50%; border: 1px solid var(--glass-border);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
    color: var(--color-indigo); cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.icon-btn:hover { box-shadow: 0 20px 30px -10px rgba(99, 102, 241, 0.3); transform: translateY(-3px) scale(1.05); background: rgba(255, 255, 255, 0.9); color: var(--color-indigo-dark); }
.icon-btn svg { width: 2rem; height: 2rem; }

.hidden { display: none !important; }

.app-container {
    width: 100%;
    max-width: 1100px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    margin-top: 2rem;
}

/* Glass Panels */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--glass-border);
    border-radius: 2rem;
    box-shadow: var(--glass-shadow);
    padding: 2rem;
    transition: transform 0.3s;
}

/* Titles */
.game-title {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--color-indigo-dark), var(--color-indigo-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
    margin-bottom: 0.5rem;
    letter-spacing: -2px;
}
.game-desc {
    text-align: center;
    color: var(--color-text-light);
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.5;
}

/* Turn Indicator */
.turn-indicator {
    display: inline-block;
    padding: 0.75rem 2.5rem;
    border-radius: 9999px;
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
    box-shadow: 0 10px 20px -5px rgba(0,0,0,0.2);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: -0.5px;
}
.turn-p1 { background: linear-gradient(135deg, #f87171, var(--color-red)); box-shadow: 0 10px 20px -5px rgba(239, 68, 68, 0.4); }
.turn-p2 { background: linear-gradient(135deg, #60a5fa, var(--color-blue)); box-shadow: 0 10px 20px -5px rgba(59, 130, 246, 0.4); }

/* Layout */
.board-area {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 3rem;
    width: 100%;
}

/* Inventory Panel */
.player-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 260px;
    padding: 1.5rem;
}
.player-name {
    font-size: 1.35rem;
    font-weight: 800;
    padding: 0.75rem 1.5rem;
    border-radius: 9999px;
    color: white;
    width: 100%;
    text-align: center;
    box-shadow: 0 4px 15px -3px rgba(0,0,0,0.1);
}
.p1-panel .player-name { background: linear-gradient(135deg, #f87171, var(--color-red)); }
.p2-panel .player-name { background: linear-gradient(135deg, #60a5fa, var(--color-blue)); }

.inventory {
    display: grid;
    grid-template-columns: repeat(3, max-content);
    gap: 12px;
    justify-content: center;
    background: rgba(255,255,255,0.4);
    padding: 1.5rem;
    border-radius: 1.5rem;
    width: 100%;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.05);
}
.inventory-item {
    width: 48px;
    height: 48px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.inventory-item:hover:not(.disabled) { transform: translateY(-5px) scale(1.1); box-shadow: 0 10px 20px rgba(0,0,0,0.15); }
.inventory-item.selected { transform: scale(1.15) translateY(-3px); box-shadow: 0 0 0 5px rgba(99, 102, 241, 0.6), 0 10px 20px rgba(0,0,0,0.2); z-index: 10; }
.inventory-item.disabled { opacity: 0.3; cursor: not-allowed; filter: grayscale(80%); }

/* Board */
.board-container {
    background: rgba(255,255,255,0.4);
    padding: 20px;
    border-radius: 2rem;
    box-shadow: inset 0 2px 15px rgba(0,0,0,0.05), 0 15px 30px -10px rgba(0,0,0,0.05);
    border: 1px solid rgba(255,255,255,0.5);
}
.board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
}
.cell {
    width: 85px;
    height: 85px;
    background: rgba(255,255,255,0.7);
    border-radius: 1rem;
    position: relative;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}
.cell:hover { background: #ffffff; box-shadow: 0 5px 15px rgba(0,0,0,0.08); transform: translateY(-2px); }
.cell.highlight-place { background: rgba(224, 231, 255, 0.8); border: 2px dashed var(--color-indigo); }
.cell.highlight-move { background: rgba(220, 252, 231, 0.8); border: 2px dashed #22c55e; }
.cell.locked::after {
    content: '🔒';
    position: absolute;
    font-size: 2.5rem;
    opacity: 0.5;
    z-index: 10;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

/* Piece - Square with thick border */
.piece-wrapper {
    width: 85%;
    height: 85%;
    position: absolute;
    perspective: 1200px;
    cursor: pointer;
    z-index: 5;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.piece-wrapper.selected { z-index: 6; transform: scale(1.15) translateY(-5px); filter: drop-shadow(0 15px 20px rgba(0,0,0,0.2)); }
.piece-wrapper.selected .piece { box-shadow: 0 0 0 5px rgba(99, 102, 241, 0.6); }

.piece {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 12px;
}
.piece.flipped { transform: rotateY(180deg); }

.piece-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 12px;
    border: 8px solid; 
    box-shadow: 0 8px 15px rgba(0,0,0,0.15);
}
.piece-face.front { transform: rotateY(0deg); }
.piece-face.back { transform: rotateY(180deg); }

/* Action Bar */
.action-bar { width: 100%; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.5rem; margin-top: 1rem; }
.action-instruction { font-size: 1.4rem; font-weight: 800; color: var(--color-indigo-dark); letter-spacing: -0.5px; }

.action-controls { display: flex; gap: 1.25rem; align-items: center; justify-content: center; }
.btn {
    padding: 1rem 2rem;
    border: none;
    border-radius: 9999px;
    font-size: 1.15rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 20px -5px rgba(0,0,0,0.15);
    background: white;
    color: var(--color-text);
    font-family: 'Outfit', 'Pretendard', sans-serif;
    letter-spacing: -0.5px;
}
.btn:hover:not(:disabled) { transform: translateY(-4px); box-shadow: 0 12px 25px -5px rgba(0,0,0,0.2); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(50%); transform: none !important; box-shadow: none !important; }

.btn-primary { background: linear-gradient(135deg, var(--color-indigo-light), var(--color-indigo)); color: white; box-shadow: 0 8px 20px -5px rgba(99, 102, 241, 0.4); }
.btn-danger { background: linear-gradient(135deg, #fca5a5, #ef4444); color: white; box-shadow: 0 8px 20px -5px rgba(239, 68, 68, 0.4); }
.btn-success { background: linear-gradient(135deg, #86efac, #10b981); color: white; box-shadow: 0 8px 20px -5px rgba(16, 185, 129, 0.4); }

.side-selector { display: flex; gap: 1.5rem; margin-top: 1rem; }
.side-preview {
    width: 70px; height: 70px;
    border: 8px solid;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 8px 15px rgba(0,0,0,0.1);
}
.side-preview:hover { transform: scale(1.15) translateY(-5px); box-shadow: 0 12px 20px rgba(0,0,0,0.2); }

/* Modals */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    display: flex; justify-content: center; align-items: center; z-index: 1000;
}
.modal-content { 
    text-align: center; 
    padding: 3rem; 
    border-radius: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    background: rgba(255, 255, 255, 0.85);
}

.winner-text { font-size: 4rem; font-weight: 900; margin-bottom: 1rem; letter-spacing: -2px; }
.winner-red { background: linear-gradient(135deg, #f87171, var(--color-red)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.winner-blue { background: linear-gradient(135deg, #60a5fa, var(--color-blue)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.win-highlight { position: relative; z-index: 10; }
.win-highlight::after {
    content: ''; position: absolute; inset: -8px;
    border: 5px solid var(--color-indigo);
    border-radius: 1.25rem;
    animation: pulse 1s infinite alternate;
    pointer-events: none;
    z-index: 20;
}
@keyframes pulse {
    0% { transform: scale(1); opacity: 1; box-shadow: 0 0 20px rgba(99, 102, 241, 0.4); }
    100% { transform: scale(1.05); opacity: 0.6; box-shadow: 0 0 40px rgba(99, 102, 241, 0.8); }
}

/* Help Modal Responsive Layout */
.help-modal-content {
    max-width: 650px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    text-align: left;
    padding: 3rem;
    line-height: 1.7;
}

.help-modal-content::-webkit-scrollbar { width: 10px; }
.help-modal-content::-webkit-scrollbar-track { background: transparent; margin: 1rem 0; }
.help-modal-content::-webkit-scrollbar-thumb { background: rgba(99, 102, 241, 0.2); border-radius: 9999px; }
.help-modal-content::-webkit-scrollbar-thumb:hover { background: rgba(99, 102, 241, 0.5); }

.help-title { font-size: 2.5rem; color: var(--color-indigo-dark); margin-bottom: 2rem; text-align: center; font-weight: 900; letter-spacing: -1px; }
.help-body { font-size: 1.15rem; color: var(--color-text); font-weight: 600; }
.help-desc { margin-bottom: 1.5rem; line-height: 1.6; }
.help-subtitle { font-weight: 800; color: #334155; margin-top: 2rem; margin-bottom: 0.75rem; font-size: 1.35rem; }
.help-subtext { font-size: 1rem; color: #64748b; font-weight: 500; }
.help-list { padding-left: 1.5rem; margin-bottom: 2rem; margin-top: 1rem; }
.help-list li { margin-bottom: 1.25rem; }
.help-warning { color: #b91c1c; font-size: 1.05rem; background: rgba(254, 226, 226, 0.7); padding: 1.25rem; border-radius: 1rem; border: 1px solid rgba(252, 165, 165, 0.5); margin-bottom: 1rem; box-shadow: 0 4px 10px rgba(220, 38, 38, 0.05); }
.help-footer { text-align: center; margin-top: 2.5rem; }
.btn-close-help { padding: 1rem 4rem; font-size: 1.25rem; }

@media (max-width: 950px) {
    .app-container { padding: 1rem; gap: 1rem; }
    .board-area { flex-direction: row; gap: 1rem; width: 100%; justify-content: center; }
    .player-panel { width: auto; padding: 0.5rem; gap: 0.75rem; flex: none; }
    .player-name { font-size: 1rem; padding: 0.5rem 1rem; }
    .inventory { padding: 0.75rem; gap: 6px; min-height: auto; width: auto; margin: 0; }
    .inventory-item { width: 32px; height: 32px; border-width: 5px; border-radius: 6px; }
    .board-container { padding: 10px; border-radius: 1.5rem; }
    .board { gap: 6px; }
    .cell { width: 55px; height: 55px; border-radius: 10px; }
    .cell.locked::after { font-size: 1.8rem; }
    .piece-face { border-width: 6px; border-radius: 8px; }
    .game-title { font-size: 2.5rem; margin-top: 1rem; }
    .game-desc { font-size: 1rem; }
}

@media (max-width: 650px) {
    .app-container { margin-top: 3.5rem; padding: 0.5rem; }
    .board-area { gap: 0.5rem; }
    .player-panel { padding: 0.25rem; gap: 0.5rem; }
    .player-name { font-size: 0.85rem; padding: 0.4rem 0.5rem; }
    .inventory { grid-template-columns: 1fr; padding: 0.5rem; gap: 4px; border-radius: 1rem; }
    .inventory-item { width: 24px; height: 24px; border-width: 4px; border-radius: 4px; }
    .board-container { padding: 8px; border-radius: 1rem; }
    .board { gap: 4px; }
    .cell { width: 42px; height: 42px; border-radius: 8px; }
    .cell.locked::after { font-size: 1.25rem; }
    .piece-face { border-width: 4px; border-radius: 6px; }
    
    .std-nav { top: 0.75rem; left: 0.75rem; }
    .help-nav { top: 0.75rem; right: 0.75rem; }
    .game-title { font-size: 2rem; margin-top: 1rem; }
    
    .action-instruction { font-size: 1.1rem; }
    .btn { padding: 0.75rem 1.25rem; font-size: 1rem; }
    .side-preview { width: 50px; height: 50px; border-width: 5px; }
    
    .help-modal-content { padding: 2rem 1.5rem; }
    .help-title { font-size: 1.8rem; margin-bottom: 1rem; }
    .help-body { font-size: 0.95rem; }
    .help-subtitle { font-size: 1.1rem; }
    .help-subtext { font-size: 0.85rem; }
}
