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

html {
    /* Prevent zoom on iOS when clicking inputs */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #a29bfe 0%, #6c5ce7 100%);
    height: 100vh;
    padding: 20px;
    margin: 0;
    /* Prevent all scrolling */
    overflow: hidden;
    /* Smooth scrolling for better UX */
    scroll-behavior: smooth;
}

/* Touch-friendly buttons and inputs */
button, input, select {
    /* Prevent zoom on iOS */
    font-size: 16px;
    /* Touch-friendly minimum size */
    min-height: 44px;
}

/* Improve text readability on all devices */
p, label, span {
    line-height: 1.6;
    word-wrap: break-word;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    /* Ensure container fits viewport exactly */
    width: calc(100% - 40px);
    height: calc(100vh - 40px);
    position: relative;
    display: flex;
    flex-direction: column;
}

header {
    background: linear-gradient(135deg, #00b894, #55a3ff);
    color: white;
    padding: 30px;
    text-align: center;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.cow-icon, .bull-icon {
    font-size: 3rem;
    animation: bounce 2s infinite;
}

.cow-icon {
    animation-delay: 0s;
}

.bull-icon {
    animation-delay: 1s;
}

.header-text {
    flex-shrink: 0;
    text-align: center;
}

.header-text h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.header-text p {
    font-size: 1.2rem;
    opacity: 0.9;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

main {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.game-section {
    padding: 30px;
    border-bottom: 2px solid #f0f0f0;
}

.difficulty-selector {
    margin-bottom: 20px;
}

.difficulty-selector label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
}

.difficulty-selector select {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
}

.game-info {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 25px;
}

.game-info p {
    margin-bottom: 10px;
    color: #555;
}

.rules {
    font-size: 0.9rem;
    line-height: 1.5;
}

.input-section {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

#guess-input {
    flex: 1;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 1.2rem;
    text-align: center;
    transition: border-color 0.3s;
    -moz-appearance: textfield;
}

#guess-input::-webkit-outer-spin-button,
#guess-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

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

#submit-guess {
    padding: 15px 25px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

#submit-guess:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

#submit-guess:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.game-controls {
    display: flex;
    gap: 15px;
}

.game-controls button {
    flex: 1;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 10px;
    background: white;
    color: #666;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.game-controls button:hover {
    background: #f8f9fa;
    border-color: #bbb;
}

.history-section {
    padding: 30px;
    background: #fafafa;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.history-section h3 {
    margin-bottom: 20px;
    color: #333;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.guess-item {
    background: white;
    padding: 10px 12px;
    margin-bottom: 6px;
    border-radius: 8px;
    border-left: 3px solid #667eea;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.guess-item.recent {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.15), rgba(118, 75, 162, 0.15));
    color: #333;
    border-left: 3px solid #667eea;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.2);
}

.guess-item.recent .guess-number {
    color: #333;
}

.guess-item.recent .cows,
.guess-item.recent .bulls {
    background: rgba(102, 126, 234, 0.1);
    color: #333;
    border: 1px solid rgba(102, 126, 234, 0.2);
}

.guess-number {
    font-weight: normal;
    font-size: 1rem;
    color: #333;
}

.guess-result {
    display: flex;
    gap: 8px;
    align-items: center;
}

.cows, .bulls {
    padding: 4px 8px;
    border-radius: 12px;
    font-weight: normal;
    font-size: 0.8rem;
}

.cows {
    background: #fff3cd;
    color: #856404;
}

.bulls {
    background: #d1ecf1;
    color: #0c5460;
}

.no-guesses {
    text-align: center;
    color: #888;
    font-style: italic;
    padding: 40px;
}

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

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 400px;
    margin: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    margin-bottom: 15px;
    color: #333;
}

.modal-content p {
    margin-bottom: 25px;
    color: #666;
    font-size: 1.1rem;
}

#play-again {
    padding: 15px 30px;
    background: linear-gradient(135deg, #ff6b6b, #ff8e53);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

#play-again:hover {
    transform: translateY(-2px);
}

/* Mobile First - Base styles for mobile devices (320px - 767px) */
@media (max-width: 767px) {
    body {
        padding: 5px;
        overflow: hidden;
    }
    
    .container {
        margin: 0;
        border-radius: 10px;
        width: calc(100% - 10px);
        height: calc(100vh - 10px);
        display: flex;
        flex-direction: column;
    }
    
    header {
        padding: 10px;
    }
    
    .header-content {
        flex-direction: row;
        gap: 8px;
        justify-content: center;
        align-items: center;
    }
    
    .cow-icon, .bull-icon {
        font-size: 1.2rem;
    }
    
    .header-text {
        text-align: center;
    }
    
    .header-text h1 {
        font-size: 1.3rem;
        margin-bottom: 2px;
    }
    
    .header-text p {
        font-size: 0.8rem;
        opacity: 0.9;
    }
    
    .game-section, .history-section {
        padding: 12px;
    }
    
    .difficulty-selector {
        margin-bottom: 15px;
    }
    
    .difficulty-selector label {
        font-size: 0.9rem;
        margin-bottom: 5px;
    }
    
    .difficulty-selector select {
        padding: 8px;
        font-size: 0.9rem;
    }
    
    .game-info {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .game-info p {
        font-size: 0.85rem;
        margin-bottom: 8px;
    }
    
    .rules {
        font-size: 0.8rem;
    }
    
    .input-section {
        flex-direction: column;
        gap: 8px;
        margin-bottom: 15px;
    }
    
    #guess-input {
        margin-bottom: 0;
        font-size: 1rem;
        padding: 10px;
    }
    
    #submit-guess {
        padding: 10px 18px;
        font-size: 0.9rem;
    }
    
    .game-controls {
        flex-direction: row;
        gap: 8px;
        margin-bottom: 0;
    }
    
    .game-controls button {
        padding: 8px;
        font-size: 0.85rem;
    }
    
    .history-section h3 {
        font-size: 1.1rem;
        margin-bottom: 12px;
    }
    
    main {
        flex: 1;
        overflow: hidden;
    }
    
    .history-section {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    .history-list {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .guess-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 12px;
    }
    
    .guess-result {
        align-self: flex-end;
    }
    
    .modal-content {
        margin: 15px;
        padding: 25px;
    }
}

/* Small Mobile (320px - 479px) */
@media (max-width: 479px) {
    body {
        padding: 3px;
        overflow: hidden;
    }
    
    .container {
        border-radius: 8px;
        width: calc(100% - 6px);
        height: calc(100vh - 6px);
    }
    
    header {
        padding: 8px;
    }
    
    .header-content {
        gap: 5px;
    }
    
    .header-text h1 {
        font-size: 1.1rem;
        margin-bottom: 1px;
    }
    
    .header-text p {
        font-size: 0.75rem;
    }
    
    .cow-icon, .bull-icon {
        font-size: 1rem;
    }
    
    .game-section, .history-section {
        padding: 10px;
    }
    
    .difficulty-selector {
        margin-bottom: 12px;
    }
    
    .difficulty-selector select {
        font-size: 0.85rem;
        padding: 6px;
    }
    
    .game-info {
        padding: 10px;
        margin-bottom: 12px;
    }
    
    .game-info p {
        font-size: 0.8rem;
        margin-bottom: 6px;
    }
    
    .rules {
        font-size: 0.75rem;
    }
    
    .input-section {
        gap: 6px;
        margin-bottom: 12px;
    }
    
    #guess-input {
        padding: 8px;
        font-size: 0.95rem;
    }
    
    #submit-guess {
        padding: 8px 15px;
        font-size: 0.85rem;
    }
    
    .game-controls {
        gap: 6px;
    }
    
    .game-controls button {
        padding: 6px;
        font-size: 0.8rem;
    }
    
    .history-section h3 {
        font-size: 1rem;
        margin-bottom: 10px;
    }
    
    .history-list {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .cows, .bulls {
        font-size: 0.7rem;
        padding: 2px 5px;
    }
    
    .guess-item {
        padding: 8px;
        gap: 6px;
    }
}

/* Tablet Portrait (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    body {
        padding: 15px;
        overflow: hidden;
    }
    
    .header-content {
        gap: 12px;
    }
    
    .container {
        max-width: 90%;
        margin: 0 auto;
        width: calc(100% - 30px);
        height: calc(100vh - 30px);
    }
    
    main {
        flex-direction: row;
        flex: 1;
        overflow: hidden;
    }
    
    .game-section {
        flex: 1;
        border-bottom: none;
        border-right: 2px solid #f0f0f0;
        padding: 25px;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .history-section {
        flex: 1;
        background: white;
        padding: 25px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    .input-section {
        flex-direction: column;
        gap: 15px;
    }
    
    #guess-input {
        margin-bottom: 0;
    }
    
    .history-list {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
    }
}

/* Tablet Landscape & Small Desktop (1024px - 1199px) */
@media (min-width: 1024px) and (max-width: 1199px) {
    body {
        overflow: hidden;
    }
    
    .container {
        max-width: 900px;
        width: calc(100% - 40px);
        height: calc(100vh - 40px);
    }
    
    main {
        flex-direction: row;
        flex: 1;
        overflow: hidden;
    }
    
    .game-section {
        flex: 1;
        border-bottom: none;
        border-right: 2px solid #f0f0f0;
        padding: 30px;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .history-section {
        flex: 1;
        background: white;
        padding: 30px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    .input-section {
        flex-direction: row;
        gap: 15px;
    }
    
    .history-list {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .header-text h1 {
        font-size: 2.8rem;
    }
    
    .cow-icon, .bull-icon {
        font-size: 3.5rem;
    }
}

/* Large Desktop (1200px+) */
@media (min-width: 1200px) {
    body {
        overflow: hidden;
    }
    
    .header-content {
        gap: 18px;
    }
    
    .container {
        max-width: 1000px;
        width: calc(100% - 40px);
        height: calc(100vh - 40px);
    }
    
    main {
        flex-direction: row;
        flex: 1;
        overflow: hidden;
    }
    
    .game-section {
        flex: 1;
        border-bottom: none;
        border-right: 2px solid #f0f0f0;
        padding: 40px;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .history-section {
        flex: 1;
        background: white;
        padding: 40px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    .input-section {
        flex-direction: row;
        gap: 20px;
    }
    
    .history-list {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .header-text h1 {
        font-size: 3rem;
    }
    
    .cow-icon, .bull-icon {
        font-size: 4rem;
    }
    
    .game-info {
        padding: 25px;
        margin-bottom: 30px;
    }
}

/* Ultra-wide screens (1400px+) */
@media (min-width: 1400px) {
    .header-content {
        gap: 20px;
    }
    
    .container {
        max-width: 1200px;
        width: calc(100% - 40px);
        height: calc(100vh - 40px);
    }
    
    .game-section, .history-section {
        padding: 50px;
    }
    
    .header-text h1 {
        font-size: 3.5rem;
    }
    
    .cow-icon, .bull-icon {
        font-size: 4.5rem;
    }
}

/* Landscape orientation optimizations */
@media (orientation: landscape) and (max-height: 500px) {
    body {
        padding: 5px;
        overflow: hidden;
    }
    
    .container {
        margin: 0 auto;
        width: calc(100% - 10px);
        height: calc(100vh - 10px);
        display: flex;
        flex-direction: column;
    }
    
    header {
        padding: 10px;
        flex-shrink: 0;
    }
    
    .header-text h1 {
        font-size: 1.8rem;
        margin-bottom: 5px;
    }
    
    .cow-icon, .bull-icon {
        font-size: 2rem;
    }
    
    main {
        flex: 1;
        overflow: hidden;
    }
    
    .game-section, .history-section {
        padding: 15px;
    }
    
    .history-section {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    .history-list {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
    }
}

/* Enhanced Modal */
.modal {
    overflow: hidden;
}