/* Base Layout & Typography */
body { font-family: 'Poppins', sans-serif; background-color: #f1f5f9; color: #334155; margin: 0; padding: 15px; transition: background-color 0.4s ease, color 0.4s ease; }
.hidden { display: none !important; }

/* Top Bar */
.top-bar { display: flex; justify-content: space-between; align-items: center; max-width: 1100px; margin: 0 auto 10px auto; }
.top-bar button { background: #ffffff; border: none; box-shadow: 0 2px 10px rgba(0,0,0,0.05); color: #475569; padding: 8px 16px; border-radius: 30px; cursor: pointer; font-size: 14px; font-weight: 600; transition: all 0.2s; }
.top-bar button:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); color: #0f172a; }

/* --- SIDE-BY-SIDE LAYOUT --- */
.layout-wrapper { display: flex; gap: 30px; max-width: 1100px; margin: 0 auto; align-items: flex-start; justify-content: center;}

/* Sidebar (Left) */
.sidebar { width: 320px; flex-shrink: 0; background: #ffffff; padding: 20px; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.06); box-sizing: border-box;}
.main-content { display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 600px;}

/* Headers & Score */
.header-container { text-align: center; margin-bottom: 20px; }
h1 { font-size: 32px; margin: 0 0 5px 0; font-weight: 700; color: #0f172a; letter-spacing: -1px; line-height: 1.1;}
.score-board { font-size: 16px; font-weight: 600; color: #3b82f6; background: #eff6ff; padding: 8px 15px; border-radius: 12px; display: inline-block; margin-top: 10px; }
.quick-tip { font-size: 12px; color: #64748b; background: #f8fafc; padding: 10px; border-radius: 8px; margin: 15px 0 0 0; text-align: center; line-height: 1.4; border: 1px solid #e2e8f0; }

/* Controls */
.controls { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.sidebar-divider { border: none; border-top: 1px solid #e2e8f0; margin: 10px 0; }
.control-label { font-size: 12px; font-weight: 700; color: #64748b; text-transform: uppercase; margin-bottom: -5px; margin-top: 5px; }

select, button.action-btn, button.danger-btn { padding: 12px; font-size: 14px; cursor: pointer; border-radius: 12px; width: 100%; font-family: 'Poppins', sans-serif; outline: none; border: none; font-weight: 600; transition: all 0.2s; box-sizing: border-box;}
select { border: 1px solid #cbd5e1; background: #f8fafc; color: #334155; }
button.action-btn { background-color: #3b82f6; color: white; box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3); }
button.action-btn:hover { background-color: #2563eb; transform: translateY(-2px); }
button.danger-btn.outline { background-color: transparent; border: 2px solid #ef4444; color: #ef4444; }
button.danger-btn.outline:hover { background-color: #fef2f2; }

/* History Panel */
#history-panel { background: #f8fafc; padding: 12px; border-radius: 12px; font-size: 12px; border: 1px solid #e2e8f0; }
#history-list { list-style: none; padding: 0; margin: 8px 0 0 0; color: #475569; }
#history-list li { padding: 6px 0; border-bottom: 1px dashed #cbd5e1; }
#history-list li:last-child { border-bottom: none; padding-bottom: 0; }

/* --- MAIN GAME AREA --- */
.board-container { display: flex; flex-direction: column; background: #ffffff; padding: 25px; border-radius: 20px; box-shadow: 0 10px 40px rgba(0,0,0,0.08); margin-top: 5px; width: 100%; box-sizing: border-box;}

/* Header / Reference Image */
.game-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.reference-container { display: flex; flex-direction: column; align-items: flex-start; }
.reference-container p { margin: 0 0 5px 0; font-size: 13px; font-weight: 700; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.5px;}
#reference-img { width: 120px; height: 120px; border-radius: 8px; object-fit: cover; border: 3px solid #e2e8f0; box-shadow: 0 4px 10px rgba(0,0,0,0.1);}
.stats-box { background: #f8fafc; padding: 10px 20px; border-radius: 10px; border: 1px solid #e2e8f0; text-align: center; font-size: 12px; font-weight: 600; color: #64748b; }
#move-counter { display: block; font-size: 28px; font-weight: 700; color: #3b82f6; line-height: 1.1; margin-top: 5px;}

/* PUZZLE GRID */
.grid-wrapper { position: relative; margin-bottom: 25px; align-self: center;}
#drop-grid { display: grid; gap: 0; background-color: #cbd5e1; border: 4px solid #cbd5e1; border-radius: 8px; overflow: hidden; box-shadow: inset 0 4px 10px rgba(0,0,0,0.1); width: 300px; height: 300px;}
.grid-cell { background-color: #f8fafc; width: 100%; height: 100%; cursor: pointer; transition: background-color 0.2s; box-sizing: border-box; border: 1px dashed #cbd5e1; display: flex; justify-content: center; align-items: center;}
.grid-cell:hover { background-color: #e2e8f0; }

/* TILE TRAY */
.tray-container { background: #f1f5f9; padding: 15px; border-radius: 12px; border: 1px solid #e2e8f0;}
.tray-header { font-size: 13px; font-weight: 700; color: #64748b; margin-bottom: 10px; text-transform: uppercase; }
#tile-tray { display: flex; flex-wrap: wrap; gap: 5px; min-height: 80px; align-content: flex-start;}

/* Individual Tiles */
.puzzle-tile { background-repeat: no-repeat; cursor: pointer; transition: transform 0.1s, box-shadow 0.1s; }
#drop-grid .puzzle-tile { border-radius: 0; box-shadow: none; }
#tile-tray .puzzle-tile { border-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.15); }
.puzzle-tile:hover { filter: brightness(1.1); }
.puzzle-tile.selected { transform: scale(0.92); box-shadow: 0 0 0 3px #3b82f6 inset; z-index: 10; }

/* Overlays */
.board-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(255, 255, 255, 0.9); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 20; backdrop-filter: blur(4px); }
.win-text { font-size: 36px; font-weight: 700; color: #10b981; }
.win-subtext { font-size: 18px; color: #475569; margin-top: 10px; font-weight: 600;}

/* Tutorial Modal */
#tutorial-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.7); display: flex; justify-content: center; align-items: center; z-index: 1000; backdrop-filter: blur(3px); }
.tutorial-content { background: #fff; padding: 30px; border-radius: 20px; max-width: 450px; width: 90%; position: relative; box-shadow: 0 20px 50px rgba(0,0,0,0.2); }
.close-btn { position: absolute; top: 15px; right: 20px; cursor: pointer; font-size: 24px; font-weight: bold; color: #64748b; }

/* Responsive */
@media (max-width: 850px) {
    .layout-wrapper { flex-direction: column; align-items: center; gap: 20px;}
    .sidebar { width: 100%; max-width: 450px; }
}

/* --- DARK MODE --- */
body.dark-mode { background-color: #0f172a; color: #f8fafc; }
body.dark-mode .top-bar button { background: #1e293b; color: #cbd5e1; box-shadow: 0 2px 10px rgba(0,0,0,0.2); }
body.dark-mode .top-bar button:hover { background: #334155; color: #fff; }
body.dark-mode .sidebar, body.dark-mode .board-container, body.dark-mode .tutorial-content { background-color: #1e293b; color: #f8fafc; box-shadow: 0 10px 30px rgba(0,0,0,0.3); border: 1px solid #334155; }
body.dark-mode h1, body.dark-mode .win-subtext { color: #f8fafc; }
body.dark-mode select { background: #0f172a; color: #f8fafc; border-color: #334155;}
body.dark-mode .score-board { background: #0f172a; color: #60a5fa; }
body.dark-mode .quick-tip, body.dark-mode .sidebar-divider { border-color: #334155; }
body.dark-mode .control-label { color: #94a3b8; }
body.dark-mode .quick-tip { background: #0f172a; color: #94a3b8; }
body.dark-mode #history-panel, body.dark-mode .stats-box { background: #0f172a; border-color: #334155; }
body.dark-mode #history-list li { border-color: #334155; color: #94a3b8; }
body.dark-mode button.danger-btn.outline { border-color: #ef4444; color: #ef4444; }
body.dark-mode button.danger-btn.outline:hover { background-color: rgba(239, 68, 68, 0.1); }
body.dark-mode .reference-container p, body.dark-mode .stats-box { color: #94a3b8; }
body.dark-mode #drop-grid { background-color: #1e293b; border-color: #334155; }
body.dark-mode .grid-cell { background-color: #0f172a; border-color: #334155; }
body.dark-mode .grid-cell:hover { background-color: #1e293b; }
body.dark-mode .tray-container { background: #0f172a; border-color: #334155; }
body.dark-mode .tray-header { color: #94a3b8; }
body.dark-mode .board-overlay { background-color: rgba(15, 23, 42, 0.85); }