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

html {
    background-color: #2a5298;
    min-height: 100vh;
}

:root {
    --primary: #4a90e2;
    --primary-dark: #357abd;
    --success: #5cb85c;
    --danger: #d9534f;
    --warning: #f0ad4e;
    --info: #5bc0de;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background-color: #2a5298; /* Fallback color */
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    color: white;
    position: relative;
}

/* Fixed gradient background using pseudo-element for better Safari compatibility */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    z-index: -1;
    pointer-events: none;
}

.container {
    max-width: 900px;
    width: 100%;
    position: relative;
    z-index: 1;
}

.game-header {
    margin-bottom: 1rem;
}

.back-link {
    display: inline-block;
    color: white;
    text-decoration: none;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.back-link:hover {
    text-decoration: underline;
}

.title {
    text-align: center;
    font-size: 1.75rem;
    margin-bottom: 1rem;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.player-info {
    text-align: center;
    margin-bottom: 1rem;
}

.player-info-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.player-welcome-text {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.welcome-label {
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.player-badge {
    display: inline-block;
    background: white;
    color: var(--primary);
    padding: 0.5rem 1.25rem;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-change-name {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid white;
    padding: 0.4rem 1rem;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-change-name:hover {
    background: white;
    color: var(--primary);
}

/* GAME MODES */
.game-modes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.mode-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    text-decoration: none;
    color: #333;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.2s;
}

.mode-card:hover:not(.disabled) {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.mode-card.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.mode-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.mode-card h2 {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
    color: var(--primary);
}

.mode-card p {
    color: #666;
    font-size: 0.875rem;
}

/* GAME CONTAINER */
.game-container {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    color: #333;
}

.game-info {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.attempts-badge {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
}

.range-info {
    font-size: 0.875rem;
    color: #666;
    font-weight: 600;
}

.round-info {
    font-size: 0.875rem;
    color: var(--primary);
    font-weight: 600;
}

/* FEEDBACK MESSAGES */
.feedback-message {
    padding: 0.75rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    text-align: center;
    font-size: 1rem;
    font-weight: 500;
}

.feedback-message.hint-higher {
    background: #fff3cd;
    color: #856404;
    border: 2px solid var(--warning);
}

.feedback-message.hint-lower {
    background: #dbeafe;
    color: #1e40af;
    border: 2px solid var(--info);
}

/* GUESS FORM */
.guess-form {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.guess-input {
    flex: 1;
    padding: 0.625rem;
    font-size: 1rem;
    border: 2px solid #ddd;
    border-radius: 8px;
}

.guess-input:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.625rem 1.5rem;
    font-size: 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

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

.game-start form,
.new-game-form {
    text-align: center;
}

.error-message {
    color: var(--danger);
    text-align: center;
    padding: 1rem;
    background: #f8d7da;
    border-radius: 8px;
    border: 1px solid var(--danger);
}

/* WIN MESSAGE */
.win-message {
    margin-bottom: 1rem;
    text-align: center;
}

.celebration {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: #ffc107;
}

.celebration i {
    animation: celebrate 0.6s ease-in-out;
}

@keyframes celebrate {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.15) rotate(-10deg); }
    75% { transform: scale(1.15) rotate(10deg); }
}

.win-title {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
    transition: color 0.3s ease;
}

.win-title i {
    margin-right: 0.5rem;
}

/* Winner: black text with gold icon */
.win-title.winner {
    color: #333; /* Black text */
}

.win-title.winner i {
    color: #ffc107; /* Gold icon */
}

/* Loser: black text with black icon */
.win-title.loser {
    color: #333; /* Black text */
}

.win-title.loser i {
    color: #333; /* Black icon */
}

.mystery-reveal {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.75rem 0;
    padding: 0.5rem 1rem;
    background: rgba(74, 144, 226, 0.1);
    border-radius: 8px;
    border: 1px solid var(--success);
}

.mystery-label {
    font-size: 0.875rem;
    color: #666;
}

.mystery-number {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
}

.attempts-info,
.range-info-text {
    font-size: 0.875rem;
    color: #666;
    margin: 0.5rem 0;
}

/* ATTEMPTS HISTORY (in game) */
.attempts-history {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.attempts-history-title {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.attempts-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: 250px;
    overflow-y: auto;
}

.attempt-item,
.history-attempt {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: white;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    font-size: 0.9rem;
    transition: box-shadow 0.2s ease;
}

.attempt-item:hover,
.history-attempt:hover {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.attempt-number {
    font-weight: 500;
    color: #999;
    font-size: 0.75rem;
    min-width: 1.5rem;
}

.attempt-guess {
    font-weight: 700;
    font-size: 1rem;
    color: #333;
    min-width: 2rem;
    text-align: center;
}

.attempt-result {
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    background: #f8f9fa;
}

.attempt-higher .attempt-result {
    color: #856404;
}

.attempt-lower .attempt-result {
    color: #1e40af;
}

.attempt-win .attempt-result {
    color: var(--success);
    background: #f0fdf4;
}

/* GAME HISTORY */
.history-container {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-top: 1rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.history-title {
    color: var(--primary);
    font-size: 1.125rem;
    margin-bottom: 1rem;
    text-align: center;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.history-item {
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.history-header {
    margin-bottom: 0.5rem;
}

.history-player {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.history-name {
    font-weight: 600;
    color: var(--primary);
    font-size: 0.9rem;
}

.history-date {
    font-size: 0.75rem;
    color: #888;
}

.history-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: #666;
    flex-wrap: wrap;
}

.history-attempts {
    font-weight: 500;
}

.history-mystery {
    font-weight: 600;
    color: var(--primary);
}

.history-range {
    color: #888;
}

.history-attempts-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e0e0e0;
}

/* SETUP FORM */
.setup-content {
    text-align: center;
}

.setup-subtitle {
    color: var(--primary);
    font-size: 1.25rem;
    margin-bottom: 1rem;
}

.setup-form {
    max-width: 500px;
    margin: 0 auto;
}

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

.form-group label {
    display: block;
    font-weight: 600;
    color: #555;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

.form-input {
    width: 100%;
    padding: 0.625rem;
    font-size: 0.9rem;
    border: 2px solid #ddd;
    border-radius: 8px;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
}

.input-hint {
    font-size: 0.75rem;
    color: #888;
    margin-top: 0.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.btn-large {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    margin-top: 0.5rem;
}

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

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.modal-content p {
    color: #666;
    margin-bottom: 1.5rem;
}

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

/* RESPONSIVE */
@media (max-width: 768px) {
    .title {
        font-size: 1.5rem;
    }

    .game-container,
    .history-container {
        padding: 1rem;
    }

    .guess-form {
        flex-direction: column;
    }

    .game-info {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .player-badge {
        font-size: 0.875rem;
        padding: 0.5rem 1rem;
    }

    .history-player {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .mystery-number {
        font-size: 1.25rem;
    }

    .mode-card {
        padding: 1.25rem;
    }
}

/* MULTIPLAYER SPECIFIC STYLES */
.multiplayer-setup {
    padding: 1rem;
}

.multiplayer-setup h2 {
    text-align: center;
    color: var(--primary);
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.player-welcome {
    text-align: center;
    color: #666;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.player-welcome strong {
    color: var(--primary);
    font-size: 1.05rem;
}

.multiplayer-setup h3 {
    color: var(--primary);
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
}

.room-actions {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 1.5rem;
    align-items: start;
}

.divider {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-weight: 600;
    font-size: 1rem;
    padding-top: 2rem;
}

.create-room-section,
.join-room-section {
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
}

.range-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.range-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.range-input-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
}

.range-input {
    padding: 0.5rem;
    font-size: 0.9rem;
    border: 2px solid #ddd;
    border-radius: 6px;
}

.range-input:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 0.625rem 1.5rem;
    font-size: 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
    margin-bottom: 1rem;
    width: 100%;
}

.btn-secondary:hover {
    background: #5a6268;
}

.rooms-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
}

.room-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: white;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.room-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.room-name-text {
    font-weight: 600;
    color: #333;
}

.room-range {
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 600;
}

.room-players {
    font-size: 0.85rem;
    color: #666;
}

.btn-join {
    background: var(--success);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-join:hover {
    background: #4cae4c;
}

.info-message {
    text-align: center;
    color: #666;
    padding: 1rem;
}

/* Waiting Room */
.waiting-room {
    text-align: center;
    padding: 2rem;
}

.waiting-room h2 {
    color: var(--primary);
    margin-bottom: 1.5rem;
}

.waiting-message {
    margin: 2rem 0;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.player-count {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary);
    margin-top: 1rem;
}

/* Notification Bar */
.notification-bar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
    min-height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.notification-bar.success {
    background: linear-gradient(135deg, #56ab2f 0%, #a8e063 100%);
}

.notification-bar.info {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.notification-bar.waiting {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.notification-bar i {
    margin-right: 0.5rem;
}

/* Game Screen */
.game-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.room-name {
    font-weight: 600;
    color: var(--primary);
}

.players-list {
    display: flex;
    gap: 0.5rem;
}

.current-player {
    background: var(--success) !important;
    color: white !important;
}


.feedback-message.success {
    background: #d4edda;
    color: #155724;
    border: 2px solid var(--success);
}

.feedback-message.info {
    background: #d1ecf1;
    color: #0c5460;
    border: 2px solid var(--info);
}

.feedback-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 2px solid var(--danger);
}

/* Game Over Screen */
.game-over {
    text-align: center;
    padding: 1.5rem;
}

.players-results {
    margin: 2rem 0;
}

.players-results h3 {
    color: var(--primary);
    margin-bottom: 1rem;
}

.player-result {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    text-align: left;
}

.player-result h4 {
    color: var(--primary);
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.player-result h4 i {
    margin-left: 0.5rem;
}

.player-result p {
    color: #666;
    margin-bottom: 0.5rem;
}

.winner-result {
    border: 1px solid #e0e0e0;
    background: #f8f9fa;
}

.winner-result h4 {
    color: var(--success);
}

.loser-result {
    border: 1px solid #e0e0e0;
    background: #f8f9fa;
}

.loser-result h4 {
    color: #666;
}

.player-result .attempts-history {
    margin-top: 1rem;
}

.player-result .attempts-history h5 {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.5rem;
}

@media (max-width: 768px) {
    .room-actions {
        grid-template-columns: 1fr;
    }

    .divider {
        padding: 0.5rem 0;
    }

    .game-info-header {
        flex-direction: column;
        text-align: center;
    }

    .players-list {
        justify-content: center;
    }
}

/* Extra small mobiles */
@media (max-width: 480px) {
    .container {
        padding: 0.5rem;
    }

    .range-inputs {
        grid-template-columns: 1fr;
    }

    .room-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .room-name-text {
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .btn-primary,
    .btn-secondary,
    .btn-join {
        width: 100%;
    }

    .guess-form {
        gap: 0.5rem;
    }
}
