* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: #ffffff;
    line-height: 1.6;
    background-color: black;
    background-image: url('../background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    overflow: hidden;
    width: 100%;
    height: 100vh;
    margin: 0;
    padding: 0;
}

.hidden {
    display: none !important;
}

/* Login Page */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: black;
    background-image: url('../background.png');
    background-size: cover;
    background-position: top;
    background-repeat: no-repeat;
}

.login-container {
    background: #3d4d3d;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

.login-container h1 {
    text-align: center;
    color: #e0e0e0;
    margin-bottom: 0.5rem;
}

.subtitle {
    text-align: center;
    color: #b0b0b0;
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.auth-forms {
    margin-top: 2rem;
}

.form-section h2 {
    margin-bottom: 1rem;
    color: #d0d0d0;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #b0b0b0;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: #4a7c2c;
}

.btn-primary, .btn-secondary {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary {
    background-color: #4a7c2c;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: #3d6724;
}

.btn-primary:disabled {
    background-color: #999;
    color: #666;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-secondary {
    background-color: #e0e0e0;
    color: #333;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #d0d0d0;
}

.btn-secondary:disabled {
    background-color: #999;
    color: #666;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Full width buttons in forms */
.auth-container .btn-primary {
    width: 100%;
    margin-bottom: 1rem;
}

.button-group .btn-primary,
.button-group .btn-secondary {
    width: 100%;
}

.form-switch {
    text-align: center;
    margin-top: 1rem;
    color: #b0b0b0;
}

.form-switch a {
    color: #4a7c2c;
    text-decoration: none;
}

.form-switch a:hover {
    text-decoration: underline;
}

.error-message {
    background-color: #fee;
    color: #c33;
    padding: 0.75rem;
    border-radius: 5px;
    margin-top: 1rem;
    border: 1px solid #fcc;
}

/* Main App */
.app-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.app-header {
    color: white;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.app-header h1 {
    font-size: 1.3rem;
    margin: 0;
}

.header-info {
    position: absolute;
    right: 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-info .btn-secondary {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    padding: 0.5rem 1rem;
}

.header-info .btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.main-content {
    flex: 1;
    padding: 0.5rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

/* Games List */
.games-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.games-list {
    display: grid;
    gap: 1rem;
}

.games-list-organized {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.games-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.section-header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #4a7c2c;
}

.section-header {
    font-size: 1.2rem;
    font-weight: 600;
    color: #ffffff;
    margin: 0;
}

.clear-all-btn {
    background-color: #c94a4a;
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background-color 0.2s;
}

.clear-all-btn:hover {
    background-color: #b33939;
}

.games-section-list {
    display: grid;
    gap: 0.75rem;
}

.empty-message {
    color: #999;
    font-style: italic;
    margin: 0.5rem 0;
}

.game-card {
    background: #3d4d3d;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.game-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.game-card-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.game-card-left {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.game-card-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: #e0e0e0;
}

.game-card-timestamp {
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.25rem;
}

.game-card-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.game-card-score {
    font-weight: 600;
    font-size: 1.1rem;
    color: #b0b0b0;
}

.delete-game-btn {
    background: none;
    border: none;
    color: #c94a4a;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, transform 0.2s;
}

.delete-game-btn:hover {
    color: #b33939;
    transform: scale(1.2);
}

.winner-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
}

.winner-badge.you-won {
    background-color: #4a7c2c;
    color: white;
}

.winner-badge.opponent-won {
    background-color: #c94a4a;
    color: white;
}

.winner-badge.tie {
    background-color: #999;
    color: white;
}

.loading {
    text-align: center;
    color: #666;
    padding: 2rem;
}

/* New Game */
.new-game-container {
    background: #3d4d3d;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    max-width: 500px;
    margin: 0 auto;
}

.new-game-container h2 {
    margin-bottom: 1.5rem;
    color: #e0e0e0;
}

.opponent-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #5a6a5a;
}

.opponent-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.opponent-section h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: #e0e0e0;
}

.username-search {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    box-sizing: border-box;
}

.username-search:focus {
    outline: none;
    border-color: #4a7c2c;
}

.bot-select,
.recent-opponent-select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    box-sizing: border-box;
}

.bot-description {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    color: #b0b0b0;
    font-size: 0.9rem;
    font-style: italic;
    display: none;
}

.bot-description.visible {
    display: block;
}

.head-to-head-record {
    margin-top: 1rem;
    padding: 0.75rem;
    background-color: rgba(74, 124, 44, 0.15);
    border-radius: 5px;
    color: #e0e0e0;
    font-size: 0.9rem;
    display: none;
}

.head-to-head-record.visible {
    display: block;
}

.head-to-head-record strong {
    color: #4a7c2c;
}

.button-group {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.button-group button {
    flex: 1;
}

/* Game View */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    background: #3d4d3d;
    padding: 0.5rem;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.game-header-left {
    display: flex;
    gap: 0.5rem;
}

.btn-resign {
    background-color: #d32f2f;
    color: white;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-resign:hover {
    background-color: #c62828;
}

.btn-resign:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.game-info {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.score, .tiles-remaining {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score .label, .tiles-remaining .label {
    font-size: 0.7rem;
    color: #b0b0b0;
}

.score span:last-child, .tiles-remaining span:last-child {
    font-size: 1.1rem;
    font-weight: 600;
    color: #6fbc4f;
}

.turn-indicator {
    margin-bottom: 0.5rem;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
}

.turn-indicator.your-turn {
    color: #4caf50;
}

.turn-indicator.opponent-turn {
    color: #ff9800;
}

.game-board-container {
    display: flex;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.game-controls {
    background: #3d4d3d;
    padding: 0.75rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tile-rack {
    margin-bottom: 0.25rem;
}

.rack-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.rack-label {
    font-weight: 600;
    color: #b0b0b0;
    margin: 0;
}

.btn-shuffle {
    background: none;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

.btn-shuffle:hover:not(:disabled) {
    background-color: #f0f0f0;
    border-color: #4a7c2c;
}

.btn-shuffle:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: #ccc;
}

.rack-tiles {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    min-height: 70px;
    flex-wrap: wrap;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.move-preview {
    display: none;
}

.move-preview.valid {
    display: none;
}

.move-preview.invalid {
    display: none;
}

.preview-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preview-words {
    font-weight: 600;
    font-size: 1.1rem;
    color: #333;
}

.preview-score {
    font-size: 1.3rem;
    font-weight: bold;
    color: #4a7c2c;
}

.preview-status {
    display: none;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-areas:
        "play play play"
        "swap shuffle clear";
    gap: 0.5rem;
    max-width: 600px;
    margin: 0 auto;
}

.action-buttons button {
    min-width: 0;
}

#playMoveBtn {
    grid-area: play;
}

#clearBtn {
    grid-area: clear;
}

#shuffleBtn {
    grid-area: shuffle;
}

#swapBtn {
    grid-area: swap;
}

.game-status {
    display: none;
}

.game-status.success {
    display: none;
}

.game-status.error {
    display: none;
}

.game-status.info {
    display: none;
}

/* Wildcard Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: #3d4d3d;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
}

.modal-content h3 {
    margin-bottom: 1.5rem;
    text-align: center;
    color: #e0e0e0;
}

.letter-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.5rem;
}

.letter-option {
    aspect-ratio: 1;
    background: linear-gradient(145deg, #f9e5a9, #e6d193);
    border: 2px solid #b8935e;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.letter-option:hover {
    background: linear-gradient(145deg, #ffd700, #daa520);
    transform: scale(1.05);
}

/* Confirmation Modal */
.confirm-modal {
    max-width: 400px;
}

.confirm-modal p {
    text-align: center;
    color: #b0b0b0;
    margin-bottom: 1.5rem;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn-danger {
    background-color: #c94a4a;
    color: white;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background-color 0.2s;
}

.btn-danger:hover {
    background-color: #b33939;
}

/* Responsive */
@media (max-width: 768px) {
    .app-header {
        padding: 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }

    .app-header h1 {
        font-size: 1.5rem;
    }

    .header-info {
        position: static;
        right: auto;
    }

    .main-content {
        padding: 0.5rem;
    }

    .game-info {
        gap: 0.25rem;
    }

    .button-group {
        flex-direction: column;
    }

    /* Hide app header when in game view on mobile */
    .app-container:has(#gameView.active) .app-header {
        display: none;
    }

    /* Shrink game header to half size on mobile */
    .game-header {
        padding: 0.25rem;
        margin-bottom: 0.25rem;
    }

    .game-header-left {
        gap: 0.25rem;
    }

    .game-header-left button {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }

    .btn-resign {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }

    .score .label, .tiles-remaining .label {
        font-size: 0.5rem;
    }

    .score span:last-child, .tiles-remaining span:last-child {
        font-size: 0.8rem;
    }
}
