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

:root {
    --bg: #000;
    --text: #fff;
    --text-dim: #888;
    --border: #333;
    --spacing: 20px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Courier New', Courier, monospace;
    font-size: 16px;
    line-height: 1.7;
    padding: var(--spacing);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior-y: contain;
}

/* Touch-specific optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Touch device styles */
    * {
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
    }

    button,
    a,
    .autocomplete-item,
    .close {
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.15);
    }

    /* Ensure all interactive elements have adequate touch targets */
    button,
    a,
    input,
    .autocomplete-item {
        min-height: 44px;
    }
}

.container {
    max-width: 600px;
    margin: 0 auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: var(--spacing);
}

.round-info {
    text-align: center;
    margin-bottom: 15px;
    font-size: 12px;
    color: var(--text-dim);
    height: 18px;
}

.hint-counter {
    text-align: right;
    margin-bottom: 8px;
    font-size: 11px;
    color: var(--text-dim);
    height: 14px;
}

.year-title {
    opacity: 0;
    transition: opacity 0.8s ease;
    text-align: center;
    margin-bottom: 15px;
    font-size: 16px;
    height: 24px;
}

.year-title.show {
    opacity: 1;
}

.quotes {
    margin-bottom: 20px;
    height: 280px;
    width: 500px;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    position: relative;
}

.quote {
    opacity: 0;
    margin-bottom: 25px;
    transition: opacity 0.6s ease;
    font-size: 12pt;
    line-height: 1.5;
    text-align: left;
    padding-left: 20px;
    padding-right: 20px;
    width: 100%;
    position: relative;
}

.quote.show {
    opacity: 1;
}

.actor-inline {
    opacity: 0;
    margin-top: 5px;
    margin-bottom: 8px;
    font-size: 12pt;
    text-align: center;
    text-transform: uppercase;
    transition: opacity 0.6s ease;
    letter-spacing: 0.5px;
    height: 18px;
    width: 100%;
    position: relative;
}

.actor-inline.show {
    opacity: 1;
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
    20%, 40%, 60%, 80% { transform: translateX(10px); }
}

@keyframes celebrate {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.shake {
    animation: shake 0.5s;
}

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

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

.message {
    height: 24px;
    margin-bottom: var(--spacing);
    text-align: center;
    font-size: 12pt;
    color: var(--text-dim);
}

.controls {
    display: flex;
    gap: 10px;
    margin-bottom: var(--spacing);
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.autocomplete-wrapper {
    position: relative;
    flex: 1;
}

#guess {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
}

#guess:focus {
    outline: none;
    border-color: var(--text);
}

#guess:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#guess::placeholder {
    color: var(--text-dim);
}

.autocomplete-items {
    position: absolute;
    border: 1px solid var(--border);
    border-top: none;
    z-index: 99;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg);
    /* Smooth momentum scrolling on iOS */
    -webkit-overflow-scrolling: touch;
    /* Prevent scroll chaining */
    overscroll-behavior: contain;
}

.autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.autocomplete-item:hover,
.autocomplete-active {
    background: var(--text);
    color: var(--bg);
}

/* Touch feedback for autocomplete items */
.autocomplete-item:active {
    background: var(--text);
    color: var(--bg);
    transform: scale(0.98);
    transition: transform 0.1s ease;
}

button {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 16px;
    min-height: 44px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

button:hover:not(:disabled) {
    background: var(--text);
    color: var(--bg);
}

button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Button utility classes */
.btn-full-width {
    width: 100%;
}

.btn-with-margin {
    margin-top: 12px;
}

.hidden {
    display: none;
}

#give-up {
    opacity: 0.6;
}

#give-up:hover:not(:disabled) {
    opacity: 1;
}

kbd {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 2px 6px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 11px;
}

.countdown {
    text-align: center;
    font-size: 12pt;
    color: var(--text-dim);
    margin-top: var(--spacing);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    /* Prevent scroll chaining in modal */
    overscroll-behavior: contain;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 40px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    /* Smooth momentum scrolling on iOS */
    -webkit-overflow-scrolling: touch;
    /* Prevent scroll chaining */
    overscroll-behavior: contain;
}

.close {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-dim);
    transition: color 0.2s ease;
    line-height: 1;
}

.close:hover {
    color: var(--text);
}

h2 {
    margin-bottom: 30px;
    font-weight: normal;
    font-size: 16px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 30px;
    text-align: center;
}

.stats div {
    padding: 10px;
}

.stats span {
    display: block;
    font-size: 20px;
    margin-bottom: 4px;
}

.dist {
    margin-bottom: 30px;
}

.bar {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    gap: 10px;
}

.bar-label {
    width: 20px;
    font-size: 12pt;
}

.bar-fill {
    background: var(--text);
    color: var(--bg);
    padding: 4px 12px;
    min-width: 30px;
    transition: width 0.5s ease;
    font-size: 12pt;
}

#share {
    width: 100%;
}

#next-round-btn {
    width: 100%;
    margin-top: var(--spacing);
}

.button-spacer {
    min-height: 20px;
    margin-bottom: var(--spacing);
}

.help-content {
    text-align: left;
}

.help-content h3 {
    margin-top: 30px;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.help-content h3:first-child {
    margin-top: 0;
}

.help-content ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.help-content li {
    margin-bottom: 6px;
    line-height: 1.6;
}

.help-content p {
    margin-bottom: 12px;
    line-height: 1.6;
}

.difficulty-stats {
    margin-top: 30px;
    border-top: 1px solid var(--border);
    padding-top: 30px;
}

.difficulty-stats h3 {
    margin-bottom: 15px;
}

.difficulty-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 12pt;
}

.difficulty-row .label {
    color: var(--text-dim);
}

.difficulty-row .value {
    color: var(--text);
}

/* Mobile Portrait - Primary mobile breakpoint */
@media (max-width: 767px) {
    body {
        font-size: 14px;
        padding: 0;
        padding-top: env(safe-area-inset-top);
        /* Extra padding for iOS Safari bottom bar */
        padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
    }

    .container {
        padding: 16px;
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    /* Typography - Maintain readability on small screens */
    h2 {
        font-size: 14px;
        margin-bottom: 20px;
    }

    /* Header optimizations */
    .logo {
        font-size: 16px;
        gap: 6px;
        margin-bottom: 10px;
    }

    .logo-icon {
        font-size: 16px;
    }

    .nav-links {
        gap: 10px;
        flex-wrap: wrap;
    }

    .nav-links a {
        font-size: 10px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 8px 12px;
    }

    /* Game description */
    .game-description {
        font-size: 13px;
        padding: 0;
    }

    /* Round info & hint counter */
    .round-info {
        font-size: 11px;
        margin-bottom: 10px;
    }

    .hint-counter {
        font-size: 10px;
        margin-bottom: 6px;
    }

    /* Quotes section - optimize for mobile */
    .quotes {
        height: auto;
        min-height: 200px;
        width: 100%;
        margin-bottom: 16px;
    }

    .quote {
        font-size: 14px;
        padding-left: 8px;
        padding-right: 8px;
        margin-bottom: 18px;
        line-height: 1.5;
    }

    .actor-inline {
        font-size: 13px;
        margin-bottom: 8px;
    }

    .year-title {
        font-size: 14px;
        margin-bottom: 10px;
    }

    /* Message */
    .message {
        font-size: 13px;
        margin-bottom: 14px;
        height: auto;
        min-height: 20px;
    }

    /* Controls - Stack vertically for easier touch */
    .controls {
        flex-direction: column;
        gap: 10px;
        max-width: 100%;
        margin-bottom: 14px;
    }

    /* Input - Prevent iOS zoom with 16px minimum */
    #guess {
        font-size: 16px;
        padding: 12px 14px;
        min-height: 48px;
        border-radius: 0;
        -webkit-appearance: none;
    }

    #guess::placeholder {
        font-size: 15px;
    }

    /* Autocomplete - Better mobile UX */
    .autocomplete-items {
        max-height: 200px;
        border-radius: 0;
    }

    .autocomplete-item {
        font-size: 14px;
        padding: 12px 14px;
        min-height: 44px;
    }

    /* Buttons - Ensure 48px minimum touch target */
    button {
        font-size: 14px;
        padding: 12px 18px;
        min-height: 48px;
        width: 100%;
    }

    #next,
    #give-up {
        width: 100%;
    }

    /* Modal - Better mobile experience */
    .modal-content {
        width: 92%;
        max-width: 92%;
        padding: 24px 18px;
        max-height: 80vh;
        border-radius: 0;
    }

    .close {
        top: 12px;
        right: 12px;
        font-size: 26px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Stats - Optimize layout */
    .stats {
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 20px;
    }

    .stats div {
        flex: 1 1 30%;
        min-width: 75px;
        padding: 6px;
    }

    .stats span {
        font-size: 16px;
    }

    /* Distribution bars */
    .bar {
        margin-bottom: 8px;
        gap: 6px;
    }

    .bar-label {
        font-size: 13px;
        width: 16px;
    }

    .bar-fill {
        font-size: 13px;
        padding: 4px 8px;
    }

    /* Difficulty stats */
    .difficulty-stats {
        margin-top: 20px;
        padding-top: 20px;
    }

    .difficulty-row {
        font-size: 13px;
        margin-bottom: 8px;
        flex-wrap: wrap;
    }

    /* Help modal */
    .help-content {
        font-size: 13px;
    }

    .help-content h3 {
        font-size: 13px;
        margin-top: 20px;
        margin-bottom: 8px;
    }

    .help-content ul {
        margin-left: 16px;
    }

    .help-content li {
        line-height: 1.6;
        margin-bottom: 6px;
    }

    .help-content p {
        font-size: 13px;
    }

    kbd {
        font-size: 10px;
        padding: 2px 5px;
    }

    /* Footer */
    .footer {
        margin-top: 28px;
        padding-top: 20px;
        font-size: 10px;
    }

    .footer-description {
        font-size: 11px;
        padding: 0;
    }

    .footer-small {
        font-size: 10px;
    }

    /* Countdown */
    .countdown {
        font-size: 13px;
        margin-top: 14px;
    }

    /* Button spacer */
    .button-spacer {
        min-height: 14px;
        margin-bottom: 14px;
    }

    /* Ad containers */
    .ad-container {
        margin: 14px auto;
    }
}

/* Mobile Landscape - Optimize for horizontal space */
@media (max-width: 767px) and (orientation: landscape) {
    body {
        /* Reduce vertical padding in landscape */
        padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
    }

    .quotes {
        min-height: 150px; /* Reduce vertical space in landscape */
    }

    .modal-content {
        max-height: 70vh; /* More compact modal in landscape */
        padding: 24px 32px; /* Adjust padding */
    }

    .help-content h3 {
        margin-top: 15px; /* Reduce spacing */
    }

    .stats {
        margin-bottom: 16px; /* Tighter spacing */
    }
}

/* Header & Navigation */
header {
    text-align: center;
    margin-bottom: 20px;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: normal;
    margin: 0 0 10px 0;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.logo-icon {
    font-size: 20px;
}

.nav-links {
    display: flex;
    justify-content: center;
    gap: 20px;
}

.nav-links a {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: color 0.2s ease;
}

.nav-links a:hover {
    color: var(--text);
}

/* Footer */
.footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 30px;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 11px;
}

.footer a {
    color: var(--text-dim);
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer a:hover {
    color: var(--text);
}

.footer-small {
    margin-top: 10px;
    font-size: 11px;
    opacity: 0.6;
}

/* Ad Containers */
.ad-container {
    margin: var(--spacing) auto;
    text-align: center;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-top {
    margin-bottom: 30px;
    max-width: 728px;
}

.ad-mid {
    margin-top: 30px;
    margin-bottom: 30px;
    max-width: 336px;
}

/* Tablet & Mobile Landscape - Intermediate breakpoint */
@media (min-width: 768px) and (max-width: 1024px) {
    .container {
        max-width: 700px;
        padding: 24px;
    }

    .quotes {
        max-width: 600px;
    }

    .controls {
        max-width: 600px;
    }

    button {
        min-height: 44px;
    }

    #guess {
        font-size: 16px;
        min-height: 44px;
    }

    .autocomplete-item {
        min-height: 44px;
    }

    .modal-content {
        max-width: 600px;
        width: 85%;
    }
}

/* Small tablets and large phones in landscape */
@media (max-width: 1024px) {
    .ad-top,
    .ad-mid {
        max-width: 100%;
    }
}

/* AdSense */
.adsbygoogle {
    display: block;
}

/* Additional button styles */
#stats,
#help,
#dev-reset {
    opacity: 0.6;
}

#stats:hover,
#help:hover,
#dev-reset:hover {
    opacity: 1;
}

/* SEO Elements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.game-intro {
    text-align: center;
    margin-bottom: 20px;
}

.game-description {
    font-size: 0.95em;
    color: #999;
    line-height: 1.5;
    max-width: 500px;
    margin: 0 auto;
}

.game-description strong {
    color: #6B46C1;
}

.game-features {
    margin: 30px 0 20px;
    padding: 20px;
    background: rgba(107, 70, 193, 0.05);
    border-radius: 10px;
}

.feature-list {
    list-style: none;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    font-size: 0.9em;
    color: #bbb;
}

.feature-list li {
    display: flex;
    align-items: center;
    gap: 8px;
}

.feature-list strong {
    color: #fff;
}

.footer-description {
    font-size: 0.85em;
    color: #888;
    max-width: 500px;
    margin: 15px auto 10px;
    line-height: 1.5;
}

.footer-description strong {
    color: #6B46C1;
}

@media (max-width: 600px) {
    .feature-list {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .game-features {
        padding: 15px;
        margin: 20px 0 15px;
    }

    .game-description {
        font-size: 0.9em;
    }
}
