/* 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: 1200px; 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: 1200px; margin: 0 auto; align-items: flex-start; justify-content: center;}

/* Sidebar (Left) */
.sidebar { width: 300px; 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: 800px;}

/* Headers & Score */
.header-container { text-align: center; margin-bottom: 20px; }
h1 { font-size: 28px; 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; margin-bottom: 20px; }
.sidebar-divider { border: none; border-top: 1px solid #e2e8f0; margin: 12px 0; }
.control-label { font-size: 12px; font-weight: 700; color: #64748b; text-transform: uppercase; margin-bottom: 5px; }

/* Grid layout for buttons */
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }

select, button.action-btn, button.hint-btn, button.warning-btn, button.danger-btn { padding: 12px; font-size: 13px; 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;}
.btn-grid button { padding: 8px 5px; font-size: 12px; } /* Smaller buttons for the grid */

select { border: 1px solid #cbd5e1; background: #f8fafc; color: #334155; margin-bottom: 8px; }
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.warning-btn { background-color: #64748b; color: white; }
button.warning-btn:hover { background-color: #475569; transform: translateY(-1px); }
button.hint-btn { background-color: #f59e0b; color: white; box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3); }
button.hint-btn:hover { background-color: #d97706; transform: translateY(-1px); }
button.danger-btn { background-color: #ef4444; color: white; }
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;}

/* Active Clue Bar */
.active-clue-bar { background: #eff6ff; border: 2px solid #bfdbfe; padding: 15px 20px; border-radius: 12px; width: 100%; box-sizing: border-box; display: flex; align-items: center; gap: 15px; margin-bottom: 25px; min-height: 60px;}
.clue-badge { background: #3b82f6; color: white; font-size: 11px; font-weight: 700; padding: 5px 10px; border-radius: 6px; letter-spacing: 0.5px; flex-shrink: 0;}
#active-clue-text { font-size: 16px; font-weight: 600; color: #1e3a8a; line-height: 1.3;}

/* Crossword Layout (Grid + Clue Lists side by side) */
.crossword-layout { display: flex; gap: 25px; width: 100%; margin-bottom: 25px; align-items: flex-start;}

/* CROSSWORD GRID */
.grid-wrapper { position: relative; flex-shrink: 0;}
#crossword-grid { display: grid; gap: 1px; background-color: #334155; border: 3px solid #334155; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.1); width: 350px; height: 350px; }

.cw-cell { background-color: #ffffff; position: relative; display: flex; justify-content: center; align-items: center; font-size: 20px; font-weight: 700; color: #0f172a; text-transform: uppercase; cursor: pointer; user-select: none; transition: background-color 0.1s;}
.cw-cell.black { background-color: #0f172a; cursor: default; }
.cw-cell .cell-num { position: absolute; top: 2px; left: 3px; font-size: 9px; font-weight: 600; color: #475569; line-height: 1;}

/* Highlighting Logic */
.cw-cell.word-highlight { background-color: #dbeafe; }
.cw-cell.active-highlight { background-color: #fef08a; }
.cw-cell.error { background-color: #fca5a5; color: #991b1b; animation: shake 0.3s;}
@keyframes shake { 0%, 100% { transform: translateX(0); } 25%, 75% { transform: translateX(-3px); } 50% { transform: translateX(3px); } }

/* CLUE LISTS */
.clue-lists { display: flex; flex-direction: column; gap: 15px; flex-grow: 1; height: 350px; overflow-y: auto; padding-right: 10px;}
.clue-lists::-webkit-scrollbar { width: 6px; }
.clue-lists::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
.clue-section h3 { margin: 0 0 10px 0; font-size: 15px; font-weight: 700; color: #334155; border-bottom: 2px solid #e2e8f0; padding-bottom: 5px;}
.clue-section ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 5px;}
.clue-section li { font-size: 13px; color: #475569; padding: 6px 10px; border-radius: 6px; cursor: pointer; transition: background 0.2s;}
.clue-section li:hover { background: #f1f5f9; }
.clue-section li.highlighted-clue { background: #3b82f6; color: white; font-weight: 600; }
.clue-section li strong { margin-right: 5px; }

/* Keyboard */
#keyboard { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 550px;}
.keyboard-row { display: flex; justify-content: center; gap: 6px; }
.key { background-color: #e2e8f0; border: none; border-radius: 6px; padding: 15px 10px; font-size: 14px; font-weight: 700; cursor: pointer; text-transform: uppercase; flex: 1; max-width: 45px; display: flex; justify-content: center; align-items: center; transition: all 0.2s; color: #334155; font-family: 'Poppins', sans-serif;}
.key.large { max-width: 65px; font-size: 12px; }
.key:active { transform: scale(0.95); background-color: #cbd5e1; }

/* Overlays */
.board-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(255, 255, 255, 0.95); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 20; backdrop-filter: blur(4px); }
.win-text { font-size: 32px; font-weight: 700; color: #10b981; }
.win-subtext { font-size: 16px; color: #475569; margin-top: 5px; font-weight: 600;}
.bonus-text { font-size: 14px; color: #f59e0b; margin-top: 10px; font-weight: 700; background: #fffbeb; padding: 5px 10px; border-radius: 8px;}

/* 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: 900px) {
    .layout-wrapper { flex-direction: column; align-items: center; gap: 20px;}
    .sidebar { width: 100%; max-width: 450px; }
    .crossword-layout { flex-direction: column; align-items: center; }
    .clue-lists { height: auto; width: 100%; max-height: 250px; }
    #crossword-grid { width: 320px; height: 320px; }
}

/* --- 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, body.dark-mode .clue-section h3 { color: #f8fafc; }
body.dark-mode .score-board { background: #0f172a; color: #60a5fa; }
body.dark-mode select { background: #0f172a; color: #f8fafc; border-color: #334155; }
body.dark-mode .quick-tip, body.dark-mode .sidebar-divider, body.dark-mode .clue-section h3 { border-color: #334155; }
body.dark-mode .control-label { color: #94a3b8; }
body.dark-mode .quick-tip { background: #0f172a; color: #94a3b8; }
body.dark-mode #history-panel { 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 .active-clue-bar { background: #0f172a; border-color: #334155; }
body.dark-mode #active-clue-text { color: #60a5fa; }
body.dark-mode .clue-section li { color: #94a3b8; }
body.dark-mode .clue-section li:hover { background: #334155; }
body.dark-mode .clue-section li.highlighted-clue { background: #3b82f6; color: white;}

body.dark-mode #crossword-grid { background-color: #0f172a; border-color: #0f172a;}
body.dark-mode .cw-cell { background-color: #1e293b; color: #f8fafc; }
body.dark-mode .cw-cell.black { background-color: #0f172a; border-color: #0f172a; }
body.dark-mode .cw-cell .cell-num { color: #94a3b8; }
body.dark-mode .cw-cell.word-highlight { background-color: #334155; }
body.dark-mode .cw-cell.active-highlight { background-color: #2563eb; color: #fff;}
body.dark-mode .cw-cell.error { background-color: #991b1b; color: #fca5a5; }

body.dark-mode .key { background-color: #334155; color: #f8fafc; }
body.dark-mode .key:hover { background-color: #475569; }
body.dark-mode .board-overlay { background-color: rgba(15, 23, 42, 0.95); }
body.dark-mode .bonus-text { background: #451a03; color: #fde68a;}