:root {
    /* Palette */
    --c-dark: #1A1A1D;
    --c-yellow: #FDE365;
    --c-bg: #E4E4E4;
    --c-white: #FFFFFF;
    --c-green: #31A38B;
    --c-green-hover: #26806d;
    --c-error: #d9534f;
    --c-gray-light: #f4f4f4;
    --c-gray-border: #ddd;

    /* Spacing & Layout */
    --radius-l: 16px;
    --radius-m: 8px;
    --radius-s: 4px;
    --shadow-hard: 4px 4px 0px var(--c-dark);
    --shadow-cube: 0px 6px 0px #e0c850, 0px 6px 4px rgba(0,0,0,0.2);

    /* Typography */
    --font-head: 'Roboto', sans-serif;
    --font-body: 'DM Sans', sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 10px; /* Reduced padding for mobile */
    font-family: var(--font-body);
    background-color: var(--c-bg);
    color: var(--c-dark);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center; /* Center vertically */
}

.game-wrapper {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* Main Card */
.game-card {
    background: var(--c-white);
    width: 100%;
    padding: 20px 24px; /* Slightly tighter vertical padding */
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-hard);
    border: 2px solid var(--c-dark);
}

/* Header (Inside Card) */
.game-header { 
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    margin-bottom: 12px; /* Tightened from 24px */
    padding-bottom: 12px; /* Tightened from 16px */
    border-bottom: 1px solid #eee;
}

.game-logo {
    max-width: 110px; /* Reduced by ~5% more (was 120px) */
    height: auto;
    display: block;
}

.btn-icon-small {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 24px; /* Slightly smaller for tighter header */
    height: 24px;
    border-radius: 50%;
    background: var(--c-dark);
    color: var(--c-white);
    font-weight: bold;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-head);
    font-size: 14px;
}

.instruction {
    font-size: 14px; /* Slightly smaller to save space */
    color: #666;
    margin: 0 0 12px 0; /* Tightened from 16px */
    font-weight: 500;
    text-align: center;
}

/* Cube Letter Tiles */
.letters-container {
    display: flex;
    justify-content: center;
    gap: 12px; /* Slightly tighter gap */
    margin-bottom: 20px; /* Tightened from 28px */
}

.cube-tile {
    width: 60px; /* Slightly smaller tiles (was 64px) */
    height: 60px;
    background: var(--c-yellow); /* Cube Color */
    color: var(--c-dark);
    font-family: var(--font-head);
    font-size: 30px;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 2px solid var(--c-dark);
    /* 3D Effect */
    box-shadow: 4px 4px 0px var(--c-dark);
    transform: translateY(-2px);
    transition: transform 0.2s;
}

/* Input */
.input-area { margin-bottom: 12px; /* Tightened */ }

#word-input {
    width: 100%;
    padding: 12px;
    font-size: 18px;
    font-family: var(--font-body);
    font-weight: 700;
    text-align: center;
    border: 2px solid var(--c-gray-border);
    border-radius: var(--radius-m);
    outline: none;
    text-transform: uppercase;
    transition: all 0.2s;
}

#word-input:focus {
    border-color: var(--c-dark);
    box-shadow: 0 0 0 2px rgba(0,0,0,0.05);
}

/* Buttons */
.controls {
    display: flex;
    gap: 10px;
    margin-bottom: 16px; /* Tightened */
}

.btn {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--c-dark);
    border-radius: var(--radius-m);
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 14px;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:active { transform: translateY(2px); box-shadow: none !important; }

.btn-primary {
    background: var(--c-green);
    color: var(--c-white);
    box-shadow: 2px 2px 0 var(--c-dark);
}

.btn-primary:hover { background: var(--c-green-hover); }

.btn-secondary {
    background: var(--c-white);
    color: var(--c-dark);
    box-shadow: 2px 2px 0 var(--c-dark);
}

.btn-secondary:hover { background: var(--c-gray-light); }

.btn-icon {
    height: 16px;
    width: auto;
    display: block;
}

/* Message Area */
.message-box {
    min-height: 20px;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 16px;
}
.msg-error { color: var(--c-error); }
.msg-success { color: var(--c-green); }

/* Score Board */
.score-board {
    background: var(--c-gray-light);
    padding: 12px 16px; /* Slightly tighter padding */
    border-radius: var(--radius-m);
    margin-bottom: 16px;
    border: 1px solid var(--c-gray-border);
}

.score-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 13px; /* Slightly smaller text */
    font-weight: 700;
    color: #555;
}

.score-numbers { color: var(--c-dark); }

.progress-track {
    height: 10px;
    background: #ccc;
    border-radius: 5px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--c-green); /* Matching CTA Green */
    transition: width 0.3s cubic-bezier(0.4, 1, 0.7, 1);
}

/* History */
.history-section h3 {
    font-size: 13px;
    text-transform: uppercase;
    color: #888;
    margin: 0 0 8px 0;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.history-list {
    max-height: 160px; /* Increased to allow ~4 items visible at once */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    padding: 6px 10px;
    background: #fcfcfc;
    border-radius: 4px;
    border: 1px solid #eee;
}

.history-item .word { font-weight: 500; text-transform: capitalize; }
.history-item .pts { font-weight: 700; color: var(--c-green); }
.empty-state { color: #aaa; font-style: italic; font-size: 14px; text-align: center; padding: 10px; }

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: var(--c-white);
    padding: 32px;
    border-radius: var(--radius-l);
    max-width: 90%;
    width: 350px;
    text-align: center;
    border: 2px solid var(--c-dark);
    box-shadow: var(--shadow-hard);
    position: relative;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.hidden { display: none; }

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #888;
}

.help-list {
    text-align: left;
    padding-left: 20px;
    color: #444;
    line-height: 1.5;
    font-size: 15px;
}

.modal-score {
    font-size: 24px;
    font-weight: 900;
    color: var(--c-green);
    margin: 16px 0 24px 0;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    justify-content: center;
}

/* Responsive */
@media (max-width: 480px) {
    .cube-tile { width: 52px; height: 52px; font-size: 26px; }
    .game-card { padding: 16px; }
    .btn { padding: 10px; font-size: 13px; }
    /* Slightly reduced history on mobile but still enough for ~3.5-4 items */
    .history-list { max-height: 150px; }
}