:root {
    /* Ties cell size strongly to screen height (7.5vh) to prevent scrolling on mobile */
    --cell-size: clamp(38px, min(14vw, 7.5vh), 70px);
    --gap: clamp(2px, 0.5vmin, 4px);
    --highlight: #e65b27;
    --success: #27ae60;
    --bg-color: #1a1a1a;
    --text-color: white;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Open Sans', 'Segoe UI', Tahoma, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 0;
    margin: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* --- HEADER SECTION (COMPACT) --- */
#score-container {
    font-size: clamp(20px, 3.5vh, 36px);
    font-weight: 800; 
    color: var(--highlight);
    margin-top: 15px;
    margin-bottom: 2px;
    cursor: pointer;
    transition: transform 0.1s;
}
#score-container:active { transform: scale(0.95); }

#stats-bar {
    display: flex;
    gap: 20px;
    margin-bottom: 2px;
    font-size: clamp(12px, 2vh, 18px);
    color: #aaa;
    font-weight: 600;
}
.stat-box span { color: white; }
.low-moves { color: #e74c3c !important; }

/* --- START SCREEN SPECIFIC --- */
#start-logo {
    width: 100%;
    max-width: 320px;
    margin-bottom: 30px;
}
.start-content {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* --- GAME GRID LAYOUT --- */
.game-layout { display: flex; align-items: center; gap: var(--gap); }
.col-arrows-container { display: flex; justify-content: center; width: 100%; }
.col-arrows-row, .side-arrows { display: grid; gap: var(--gap); }
.col-arrows-row { grid-template-columns: repeat(5, var(--cell-size)); }
.side-arrows { grid-template-rows: repeat(5, var(--cell-size)); }

.grid-container { display: grid; grid-template-rows: repeat(5, var(--cell-size)); gap: var(--gap); overflow: hidden; padding: 0; }
.grid-container.intro-mode { overflow: visible; }
.grid-row { display: flex; gap: var(--gap); height: var(--cell-size); transition: transform 0.2s ease-in-out; }

/* --- CELLS & ARROWS --- */
.grid-cell { 
    position: relative; 
    width: var(--cell-size); 
    height: var(--cell-size); 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    font-size: calc(var(--cell-size) * 0.55); 
    font-weight: 800; 
    line-height: 1; 
    background: transparent; 
    border-radius: 6px; 
    border: 2px solid transparent; 
    box-sizing: border-box; 
    transition: all 0.1s; 
    cursor: pointer; 
    z-index: 1; 
}
.grid-cell.empty-cell { border: none !important; background: transparent !important; cursor: default !important; box-shadow: none !important; }
.grid-cell > * { pointer-events: none; }

.letter-value { 
    position: absolute; 
    top: 6%; right: 8%; 
    font-size: 0.35em; font-weight: 600; 
    color: #999; line-height: 1; 
}

.grid-cell.selected { background-color: rgba(230, 91, 39, 0.3) !important; border: 2px solid var(--highlight); color: var(--highlight); }
.grid-cell.selected .letter-value { color: var(--highlight); }
.grid-cell.auto-highlight { border: 1px solid #2ecc71; box-shadow: inset 0 0 10px rgba(46, 204, 113, 0.4); }
.grid-cell.auto-highlight-thick { border: 1.5px solid rgba(39, 174, 96, 0.5); box-shadow: inset 0 0 6px rgba(39, 174, 96, 0.2); }

.arrow { 
    width: var(--cell-size); height: var(--cell-size); 
    font-size: var(--cell-size); background: transparent; 
    border: none; cursor: pointer; padding: 0; 
    display: flex; justify-content: center; align-items: center; 
    color: #333; transition: color 0.2s; 
    -webkit-tap-highlight-color: transparent; 
}
.arrow:hover { color: var(--highlight); }
.arrow.disabled { opacity: 0.2; cursor: default; pointer-events: none; }

.caret { display: inline-block; width: 0.25em; height: 0.25em; border-style: solid; border-color: currentColor; border-width: 0.05em 0.05em 0 0; border-radius: 1px; transition: transform 0.2s; margin-bottom: 0.05em; }
.caret-up { transform: rotate(-45deg); margin-top: 0.1em; }
.caret-right { transform: rotate(45deg); margin-left: -0.1em; }
.caret-down { transform: rotate(135deg); margin-bottom: 0.1em; }
.caret-left { transform: rotate(-135deg); margin-right: -0.1em; }

.spacer { width: var(--cell-size); }

/* --- CONTROLS & PREVIEW (COMPACT) --- */
#word-preview-container {
    margin-top: 2px;
    margin-bottom: 2px;
    height: clamp(24px, 4vh, 32px);
    font-size: clamp(18px, 3.5vh, 32px);
    font-weight: 700; color: white; 
    text-align: center; display: flex; align-items: center; justify-content: center;
}
.preview-score { color: #888; font-size: 0.8em; margin-left: 10px; }

.controls {
    margin-top: 5px;
    display: flex; gap: 10px;
    padding-bottom: 5px;
}
.main-btn {
    padding: 10px 15px;
    font-size: clamp(14px, 2.5vh, 18px);
    font-weight: 700; border-radius: 8px; border: none; cursor: pointer;
}
#submit-btn { background: #27ae60; color: white; }
#clear-btn { background: #c0392b; color: white; }

.footer-menu {
    display: flex; flex-wrap: wrap; gap: 15px; justify-content: center;
    margin-top: 5px; padding-bottom: 10px;
}
.footer-link {
    background: none; border: none; color: #888; cursor: pointer;
    font-size: clamp(11px, 1.5vh, 14px);
    font-weight: 600; text-transform: uppercase; font-family: inherit; transition: color 0.2s;
}
.footer-link:hover { color: var(--highlight); }

/* --- MODALS --- */
.hidden { display: none !important; }
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 100; display: flex; justify-content: center; align-items: center; }
.modal-content { background: #222; padding: 30px; border-radius: 12px; text-align: center; border: 2px solid var(--highlight); width: 85%; max-width: 450px; position: relative; box-sizing: border-box; }
.modal-content.text-left { text-align: left; }
.modal-content h2 { margin-top: 0; color: var(--highlight); font-size: 28px; font-weight: 800; margin-bottom: 15px; text-transform: uppercase; }
.modal-content p { color: #aaa; font-size: 18px; margin-bottom: 5px; }

/* Close X Button */
.close-x {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 32px;
    color: #666;
    cursor: pointer;
    font-weight: 700;
    line-height: 1;
    transition: color 0.2s;
}
.close-x:hover { color: var(--highlight); }

/* Game Over Score */
#final-score-display { font-size: 64px; font-weight: 800; color: white; margin-bottom: 30px; }

/* Initials Input */
.initials-container { display: flex; justify-content: center; gap: 15px; margin: 20px 0; }
.initial-box-group { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.initial-box { width: 50px; height: 60px; background: #111; border: 2px solid #444; color: white; font-size: 32px; font-weight: 700; display: flex; justify-content: center; align-items: center; border-radius: 4px; }
.arrow-btn { background: none; border: none; color: var(--highlight); font-size: 18px; cursor: pointer; padding: 5px; transition: transform 0.1s; }
.arrow-btn:active { transform: scale(0.9); }

/* History List */
.history-content { max-height: 80vh; display: flex; flex-direction: column; }
#history-list { flex: 1; overflow-y: auto; margin-top: 10px; border-top: 1px solid #444; border-bottom: 1px solid #444; text-align: left; max-height: 300px; }
.history-item { display: flex; justify-content: space-between; padding: 12px 10px; border-bottom: 1px solid #333; font-size: 20px; color: white; }
.history-points { color: var(--success); font-weight: 700; }

/* --- HALL OF FAME TABS --- */
.score-tabs {
    display: flex; justify-content: center; gap: 5px; 
    margin-bottom: 15px; flex-wrap: wrap;
}
.tab-btn {
    background: transparent;
    border: 1px solid #444;
    color: #888;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    transition: all 0.2s;
}
.tab-btn:hover { border-color: var(--highlight); color: white; }
.tab-btn.active {
    background: var(--highlight);
    color: white;
    border-color: var(--highlight);
}

/* Hall of Fame List */
.high-score-header {
    display: grid;
    grid-template-columns: 0.5fr 1fr 1fr 1fr;
    font-weight: 700; color: #888;
    border-bottom: 2px solid #444;
    padding-bottom: 10px; margin-bottom: 10px;
    font-size: 14px;
}
.high-score-row {
    display: grid;
    grid-template-columns: 0.5fr 1fr 1fr 1fr;
    padding: 8px 0;
    border-bottom: 1px solid #333;
    color: white; font-size: 16px;
}
.high-score-row:last-child { border-bottom: none; }
.high-score-rank { color: var(--highlight); font-weight: bold; }
.word-col { font-family: monospace; letter-spacing: 1px; color: var(--success); }

/* --- FOOTER & COPYRIGHT --- */
.footer-menu {
    display: flex; flex-wrap: wrap; gap: 15px; justify-content: center;
    margin-top: 10px; padding-bottom: 0px;
}
.footer-link {
    background: none; border: none; color: #888; cursor: pointer;
    font-size: clamp(11px, 1.5vh, 14px);
    font-weight: 600; text-transform: uppercase; font-family: inherit; transition: color 0.2s;
}
.footer-link:hover { color: var(--highlight); }

.copyright {
    width: 100%;
    text-align: center;
    color: #555;
    font-size: 11px;
    margin-top: 1px;
    letter-spacing: 0.5px;
}

/* --- ANIMATIONS --- */
.slide-left { transform: translateX(calc(-1 * (var(--cell-size) + var(--gap)))); }
.slide-right { transform: translateX(calc(var(--cell-size) + var(--gap))); }
.slide-up { transform: translateY(calc(-1 * (var(--cell-size) + var(--gap)))); transition: transform 0.2s ease-in-out; }
.slide-down { transform: translateY(calc(var(--cell-size) + var(--gap))); transition: transform 0.2s ease-in-out; }

@keyframes dropIn { 
    0% { transform: translateY(-100vh); opacity: 0; } 
    60% { transform: translateY(10px); opacity: 1; } 
    100% { transform: translateY(0); opacity: 1; } 
}
.drop-in { animation: dropIn 0.8s cubic-bezier(0.25, 1, 0.5, 1) backwards; }