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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: #333;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.header-info {
    display: flex;
    justify-content: center;
    gap: 40px;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.stat .label {
    font-size: 0.9em;
    opacity: 0.9;
}

.stat .value {
    font-size: 1.8em;
    font-weight: bold;
}

main {
    padding: 30px;
}

.game-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    justify-content: center;
}

.btn {
    padding: 12px 30px;
    font-size: 1em;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-danger {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.game-section {
    margin-bottom: 40px;
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
}

h3 {
    color: #667eea;
    margin-bottom: 12px;
    font-size: 1.1em;
}

.tiles-display {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 25px;
    min-height: 100px;
    align-content: flex-start;
}

.tile {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    border: 2px solid #ddd;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.5em;
    color: #333;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    position: relative;
    cursor: default;
}

.tile.open {
    background: linear-gradient(135deg, #fff9c4 0%, #ffe082 100%);
    border-color: #f9a825;
}

.tile-points {
    position: absolute;
    bottom: 2px;
    right: 3px;
    font-size: 0.65em;
    color: #666;
    font-weight: normal;
}

.input-container {
    background: white;
    padding: 20px;
    border-radius: 8px;
    border: 2px solid #e0e0e0;
    margin-bottom: 20px;
}

#wordInput {
    width: 100%;
    padding: 12px 15px;
    font-size: 1.1em;
    border: 2px solid #ddd;
    border-radius: 6px;
    transition: border-color 0.3s ease;
    margin-bottom: 10px;
}

#wordInput:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#hintBtn {
    width: 100%;
    padding: 10px 15px;
    font-size: 0.95em;
    background: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

#hintBtn:hover {
    background: #e8e8e8;
    border-color: #999;
}

.message {
    margin-top: 12px;
    margin-bottom: 12px;
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 0.95em;
    min-height: 20px;
}

.message.success {
    background: #c8e6c9;
    color: #2e7d32;
    border-left: 4px solid #2e7d32;
}

.message.error {
    background: #ef5350;
    color: white;
    border-left: 4px solid #b71c1c;
}

.hint-display {
    background: #fff3cd;
    border: 2px solid #ffc107;
    color: #856404;
    padding: 12px 15px;
    border-radius: 6px;
    margin-bottom: 10px;
    text-align: center;
    font-weight: 600;
}

.flash-optimal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px 40px;
    border-radius: 12px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
    z-index: 999;
    text-align: center;
    animation: slideIn 0.3s ease, slideOut 0.3s ease 2.7s forwards;
}

.flash-optimal h3 {
    color: #667eea;
    margin-bottom: 10px;
}

.flash-optimal .optimal-word {
    font-size: 2em;
    font-weight: bold;
    color: #333;
    margin: 15px 0;
    letter-spacing: 2px;
}

.flash-optimal .optimal-score {
    font-size: 1.2em;
    color: #666;
}

.flash-star {
    background: linear-gradient(135deg, #fffde7 0%, #fff8e1 100%);
    border: 3px solid #ffc107;
    box-shadow: 0 10px 50px rgba(255, 193, 7, 0.5);
}

.flash-star h3 {
    color: #f57f17;
    font-size: 1.4em;
}

.flash-star .optimal-word {
    color: #e65100;
}

.flash-star .optimal-score {
    color: #f57f17;
    font-weight: 600;
}

.flash-context {
    margin-top: 10px;
    font-size: 0.85em;
    color: #888;
}

.flash-tile {
    display: inline-block;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    border: 1px solid #ccc;
    border-radius: 3px;
    text-align: center;
    line-height: 24px;
    font-weight: bold;
    font-size: 0.9em;
    margin: 0 2px;
}

.flash-tile.blank {
    background: linear-gradient(135deg, #fff9c4 0%, #ffe082 100%);
    border-color: #f9a825;
}

.flash-star .flash-tile {
    border-color: #f9a825;
}

.star-burst {
    font-size: 3em;
    animation: starPop 0.4s ease;
    display: block;
    margin-bottom: 5px;
}

@keyframes starPop {
    0%   { transform: scale(0) rotate(-20deg); }
    60%  { transform: scale(1.3) rotate(10deg); }
    100% { transform: scale(1) rotate(0deg); }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -60%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
    to {
        opacity: 0;
        transform: translate(-50%, -60%);
    }
}

.words-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
}

.words-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.word-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: white;
    border-left: 4px solid #667eea;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.word-text {
    font-weight: 600;
    font-size: 1.1em;
    color: #333;
    letter-spacing: 2px;
}

.word-score {
    background: #667eea;
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 0.9em;
}

.empty {
    text-align: center;
    color: #999;
    padding: 20px;
    font-style: italic;
}

/* Game Over Overlay */
.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.game-over-dialog {
    background: white;
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 60px rgba(0, 0, 0, 0.3);
    max-width: 400px;
}

.game-over-dialog h2 {
    color: #667eea;
    font-size: 2em;
    margin-bottom: 20px;
}

.game-over-dialog p {
    color: #666;
    margin-bottom: 15px;
    font-size: 1.1em;
}

.game-over-dialog span {
    font-weight: bold;
    color: #333;
}

.game-over-dialog button {
    margin-top: 20px;
    padding: 12px 30px;
    font-size: 1em;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.2s, box-shadow 0.2s;
}

.game-over-dialog button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

/* How to Play button */
.how-to-play-btn {
    font-size: 0.45em;
    padding: 5px 12px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    vertical-align: middle;
    margin-left: 12px;
    transition: background 0.2s;
    letter-spacing: normal;
}

.how-to-play-btn:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 35px 40px;
    max-width: 560px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    font-size: 1.8em;
    color: #aaa;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.modal-close:hover {
    color: #333;
}

.modal-content h2 {
    color: #667eea;
    font-size: 1.6em;
    margin-bottom: 20px;
}

.modal-section {
    margin-bottom: 22px;
}

.modal-section h3 {
    color: #444;
    font-size: 1em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 4px;
}

.modal-section ul {
    padding-left: 18px;
    color: #555;
    line-height: 1.7;
}

.tile-values {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tv-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95em;
}

.tv-pts {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.85em;
    flex-shrink: 0;
}

.tv-letters {
    color: #555;
    font-weight: 500;
    letter-spacing: 0.05em;
}

@media (max-width: 600px) {
    .header-info {
        gap: 20px;
    }

    header h1 {
        font-size: 1.8em;
    }

    .tile {
        width: 45px;
        height: 45px;
        font-size: 1.2em;
    }

    .tiles-display {
        gap: 8px;
    }

    .word-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .word-score {
        align-self: flex-end;
    }

    .game-controls {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }
}

/* Leaderboard */
.leaderboard-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
}

.leaderboard-table {
    background: white;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.leaderboard-row {
    display: flex;
    padding: 12px 15px;
    border-bottom: 1px solid #e0e0e0;
    align-items: center;
}

.leaderboard-row.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: bold;
    border-bottom: none;
}

.leaderboard-row:last-child {
    border-bottom: none;
}

.leaderboard-row:hover {
    background: #f5f5f5;
}

.leaderboard-row.header:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.leaderboard-row .col {
    flex: 1;
    text-align: center;
}

.leaderboard-row .col.rank {
    flex: 0 0 50px;
    font-weight: bold;
    color: #667eea;
}

.leaderboard-row .col.score {
    flex: 0 0 100px;
    font-weight: 600;
}

.leaderboard-row .col.time {
    flex: 0 0 100px;
}

.leaderboard-row .col.words {
    flex: 0 0 80px;
}

.leaderboard-row .col.deficit {
    flex: 0 0 90px;
    color: #e74c3c;
    font-weight: 600;
}

.leaderboard-row .col.stars {
    flex: 0 0 80px;
    color: #f39c12;
    font-weight: 600;
}
