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

:root {
    --green: #6aaa64;
    --yellow: #c9b458;
    --gray: #787c7e;
    --dark-gray: #3a3a3c;
    --light-gray: #d3d6da;
    --white: #ffffff;
    --black: #121213;
    --key-bg: #d3d6da;
    --key-text: #000000;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--white);
    color: var(--black);
    touch-action: manipulation;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.screen {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* Login Screen */
#login-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    text-align: center;
    padding: 2rem;
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    max-width: 90%;
    width: 320px;
}

.login-container h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 0.2rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.login-container p {
    color: var(--gray);
    margin-bottom: 1.5rem;
}

.g_id_signin {
    display: flex;
    justify-content: center;
}

/* Game Screen */
#game-screen {
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--light-gray);
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: 0.15rem;
    text-transform: uppercase;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--black);
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    opacity: 0.7;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#user-name {
    font-size: 0.75rem;
    color: var(--gray);
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 1rem;
    overflow: hidden;
}

/* Game Board */
#game-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.row {
    display: flex;
    gap: 5px;
}

.tile {
    width: 58px;
    height: 58px;
    border: 2px solid var(--light-gray);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: 700;
    text-transform: uppercase;
    user-select: none;
    transition: transform 0.1s;
}

.tile.filled {
    border-color: var(--dark-gray);
    animation: pop 0.1s ease-in-out;
}

.tile.correct {
    background-color: var(--green);
    border-color: var(--green);
    color: var(--white);
}

.tile.present {
    background-color: var(--yellow);
    border-color: var(--yellow);
    color: var(--white);
}

.tile.absent {
    background-color: var(--gray);
    border-color: var(--gray);
    color: var(--white);
}

.tile.flip {
    animation: flip 0.5s ease forwards;
}

@keyframes pop {
    50% {
        transform: scale(1.1);
    }
}

@keyframes flip {
    0% {
        transform: rotateX(0);
    }
    50% {
        transform: rotateX(90deg);
    }
    100% {
        transform: rotateX(0);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

.row.shake {
    animation: shake 0.5s ease;
}

/* Keyboard */
#keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    max-width: 500px;
}

.keyboard-row {
    display: flex;
    gap: 6px;
    width: 100%;
    justify-content: center;
}

.key {
    height: 58px;
    min-width: 32px;
    padding: 0 0.5rem;
    border: none;
    border-radius: 4px;
    background-color: var(--key-bg);
    color: var(--key-text);
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    max-width: 43px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.key.wide {
    min-width: 60px;
    max-width: 65px;
    font-size: 0.75rem;
}

.key:active {
    opacity: 0.8;
}

.key.correct {
    background-color: var(--green);
    color: var(--white);
}

.key.present {
    background-color: var(--yellow);
    color: var(--white);
}

.key.absent {
    background-color: var(--dark-gray);
    color: var(--white);
}

/* Message Toast */
#message {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--black);
    color: var(--white);
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    font-weight: 700;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Stats Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-content {
    background-color: var(--white);
    border-radius: 8px;
    padding: 1.5rem;
    max-width: 400px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.close-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray);
}

.modal-content h2 {
    text-align: center;
    text-transform: uppercase;
    font-size: 1rem;
    letter-spacing: 0.1rem;
    margin-bottom: 1rem;
}

.modal-content h3 {
    text-align: center;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.1rem;
    margin: 1.5rem 0 0.75rem;
}

.stats-grid {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 50px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.65rem;
    text-align: center;
}

#guess-distribution {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.distribution-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.distribution-row span:first-child {
    width: 1rem;
    text-align: right;
    font-weight: 700;
}

.distribution-bar {
    min-width: 1.5rem;
    padding: 0.25rem 0.5rem;
    background-color: var(--gray);
    color: var(--white);
    font-weight: 700;
    font-size: 0.85rem;
    text-align: right;
}

.distribution-bar.highlight {
    background-color: var(--green);
}

.primary-btn {
    width: 100%;
    padding: 1rem;
    margin-top: 1.5rem;
    background-color: var(--green);
    color: var(--white);
    border: none;
    border-radius: 4px;
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
}

.primary-btn:hover {
    opacity: 0.9;
}

/* Mobile Responsive */
@media (max-width: 400px) {
    .tile {
        width: 52px;
        height: 52px;
        font-size: 1.75rem;
    }

    .key {
        height: 50px;
        font-size: 0.8rem;
    }

    header h1 {
        font-size: 1.4rem;
    }
}

@media (max-width: 350px) {
    .tile {
        width: 46px;
        height: 46px;
        font-size: 1.5rem;
    }

    .row {
        gap: 4px;
    }

    .key {
        height: 45px;
        padding: 0 0.25rem;
    }

    .keyboard-row {
        gap: 4px;
    }
}

@media (max-height: 650px) {
    .tile {
        width: 50px;
        height: 50px;
        font-size: 1.6rem;
    }

    .key {
        height: 48px;
    }

    main {
        padding: 0.5rem;
    }

    #game-board {
        gap: 4px;
    }
}

/* Prevent pull-to-refresh on mobile */
body {
    overscroll-behavior-y: contain;
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    main {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* Dashboard Styles */
.dashboard-content {
    max-width: 500px;
    padding: 1rem;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--light-gray);
    margin-bottom: 1rem;
    gap: 0;
}

.tab {
    flex: 1;
    padding: 0.75rem 0.5rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray);
    cursor: pointer;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--black);
}

.tab.active {
    color: var(--black);
    border-bottom-color: var(--green);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Stats Section */
.stats-section {
    margin-top: 1.5rem;
}

.stats-section h3 {
    margin-bottom: 0.75rem;
}

/* Performance Stats */
.performance-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.perf-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background-color: #f5f5f5;
    border-radius: 4px;
}

.perf-label {
    font-size: 0.75rem;
    color: var(--gray);
}

.perf-value {
    font-weight: 700;
    font-size: 0.9rem;
}

/* Leaderboard */
.leaderboard-filters {
    margin-bottom: 1rem;
}

.leaderboard-filters select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--light-gray);
    border-radius: 4px;
    font-size: 0.9rem;
    background-color: var(--white);
    cursor: pointer;
}

.leaderboard-list {
    max-height: 400px;
    overflow-y: auto;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid #f0f0f0;
    gap: 0.75rem;
}

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

.leaderboard-item.current-user {
    background-color: #e8f5e9;
}

.leaderboard-rank {
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    border-radius: 50%;
    background-color: var(--light-gray);
}

.leaderboard-rank.gold {
    background-color: #ffd700;
    color: #000;
}

.leaderboard-rank.silver {
    background-color: #c0c0c0;
    color: #000;
}

.leaderboard-rank.bronze {
    background-color: #cd7f32;
    color: #fff;
}

.leaderboard-info {
    flex: 1;
    min-width: 0;
}

.leaderboard-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-details {
    font-size: 0.75rem;
    color: var(--gray);
}

.leaderboard-stat {
    text-align: right;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--green);
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--gray);
}

/* Head to Head */
.h2h-selector {
    margin-bottom: 1.5rem;
}

.h2h-selector label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--gray);
}

.h2h-selector select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--light-gray);
    border-radius: 4px;
    font-size: 0.9rem;
    background-color: var(--white);
    cursor: pointer;
}

.h2h-placeholder {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray);
}

.h2h-comparison {
    animation: fadeIn 0.3s ease;
}

.h2h-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--light-gray);
}

.h2h-player {
    flex: 1;
    text-align: center;
}

.h2h-name {
    font-weight: 700;
    font-size: 1rem;
}

.h2h-vs {
    padding: 0.5rem 1rem;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--gray);
}

.h2h-stats {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.h2h-row {
    display: flex;
    align-items: center;
    padding: 0.5rem 0;
}

.h2h-row .h2h-value {
    flex: 1;
    font-weight: 700;
    font-size: 1.1rem;
}

.h2h-row .h2h-value:first-child {
    text-align: left;
}

.h2h-row .h2h-value:last-child {
    text-align: right;
}

.h2h-row .h2h-label {
    flex: 2;
    text-align: center;
    font-size: 0.75rem;
    color: var(--gray);
    text-transform: uppercase;
}

.h2h-row .h2h-value.winner {
    color: var(--green);
}

.h2h-row .h2h-value.loser {
    color: var(--gray);
}

.h2h-verdict {
    margin-top: 1.5rem;
    padding: 1rem;
    text-align: center;
    border-radius: 8px;
    font-weight: 700;
}

.h2h-verdict.win {
    background-color: #e8f5e9;
    color: var(--green);
}

.h2h-verdict.lose {
    background-color: #ffebee;
    color: #c62828;
}

.h2h-verdict.tie {
    background-color: #fff3e0;
    color: #ef6c00;
}

/* Mobile adjustments for dashboard */
@media (max-width: 400px) {
    .tabs {
        gap: 0;
    }

    .tab {
        font-size: 0.7rem;
        padding: 0.6rem 0.25rem;
    }

    .performance-stats {
        grid-template-columns: 1fr;
    }

    .h2h-row .h2h-value {
        font-size: 1rem;
    }

    .h2h-row .h2h-label {
        font-size: 0.65rem;
    }

    .stats-grid {
        gap: 0.5rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.6rem;
    }
}

/* Header center */
.header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-mode-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    background-color: var(--yellow);
    color: var(--black);
    font-weight: 600;
    margin-top: 0.15rem;
}

.daily-plays {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    background-color: #f0f0f0;
    border-radius: 4px;
    font-weight: 600;
    color: var(--gray);
}

/* Daily limits display */
.daily-limits-display {
    display: flex;
    justify-content: space-around;
    padding: 0.75rem;
    background-color: #f5f5f5;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.limit-item {
    text-align: center;
}

.limit-label {
    display: block;
    font-size: 0.7rem;
    color: var(--gray);
    margin-bottom: 0.25rem;
}

.limit-value {
    font-weight: 700;
    font-size: 1rem;
}

/* Stats toggle */
.stats-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.toggle-btn {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--light-gray);
    background: var(--white);
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-btn.active {
    background-color: var(--green);
    color: var(--white);
    border-color: var(--green);
}

.toggle-btn:hover:not(.active) {
    background-color: #f0f0f0;
}

/* Challenge section */
.challenge-section {
    margin-bottom: 1.5rem;
}

.challenge-section h3 {
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.challenge-section h3 span {
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--gray);
}

.challenge-list {
    max-height: 200px;
    overflow-y: auto;
}

.empty-state {
    color: var(--gray);
    font-size: 0.85rem;
    text-align: center;
    padding: 1rem;
}

.challenge-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background-color: #f9f9f9;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.challenge-item-info {
    flex: 1;
}

.challenge-item-name {
    font-weight: 600;
    font-size: 0.85rem;
}

.challenge-item-date {
    font-size: 0.7rem;
    color: var(--gray);
}

.challenge-item-status {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
}

.challenge-item-status.pending {
    background-color: #fff3e0;
    color: #ef6c00;
}

.challenge-item-status.completed {
    background-color: #e8f5e9;
    color: var(--green);
}

.challenge-item-status.failed {
    background-color: #ffebee;
    color: #c62828;
}

.accept-btn {
    padding: 0.4rem 0.75rem;
    background-color: var(--green);
    color: var(--white);
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}

.accept-btn:hover {
    opacity: 0.9;
}

/* Create challenge form */
.create-challenge-form {
    background-color: #f9f9f9;
    padding: 1rem;
    border-radius: 8px;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray);
    margin-bottom: 0.35rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.65rem;
    border: 1px solid var(--light-gray);
    border-radius: 4px;
    font-size: 0.9rem;
}

.form-group input {
    text-transform: uppercase;
    letter-spacing: 0.2rem;
    font-weight: 700;
}

/* Invite result */
.invite-result {
    background-color: #e8f5e9;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.invite-result h3 {
    color: var(--green);
    margin-bottom: 0.5rem;
}

.invite-result p {
    font-size: 0.85rem;
    color: var(--gray);
    margin-bottom: 0.5rem;
}

.invite-link-box {
    display: flex;
    gap: 0.5rem;
}

.invite-link-box input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--light-gray);
    border-radius: 4px;
    font-size: 0.8rem;
    background-color: var(--white);
}

.copy-btn {
    padding: 0.5rem 1rem;
    background-color: var(--green);
    color: var(--white);
    border: none;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
}

.copy-btn:hover {
    opacity: 0.9;
}

/* Action buttons */
.action-buttons {
    margin-top: 1.5rem;
}

.action-buttons .primary-btn {
    width: 100%;
}

.primary-btn:disabled {
    background-color: var(--light-gray);
    cursor: not-allowed;
}
