/* --- Monkeyread Theme --- */
:root {
    --font-heading: 'Nunito Sans', sans-serif;
    --font-body: 'Open Sans', sans-serif;

    --color-bg: #FFFBEA;
    /* Banana Cream */
    --color-text: #4B3F2F;
    /* Jungle Bark */
    --color-text-light: #7E7C80;

    --color-primary-accent: #7AC74F;
    /* Jungle Green */
    --color-primary-accent-hover: #5DA23A;
    --color-secondary-accent: #FFE156;
    /* Banana Yellow */

    --color-letter-flash-bg: #F9E79F;
    /* Banana Peel */
    --color-letter-flash-text: #F4A259;
    /* Orange Banana */

    --color-success: #FFD166;
    /* Ripe Banana */
    --color-alert: #F76E11;
    /* Monkey Orange */
    --color-info: #43BCCD;
    /* Sky Blue */

    --color-pos-1: #FF2D2D;
    /* Vivid Red */
    --color-pos-2: #16C172;
    /* Darker Green */
    --color-pos-3: #2D9CFF;
    /* Vivid Blue */

    --border-radius-soft: 16px;
    --border-radius-medium: 24px;
    --shadow-subtle: 0 4px 16px rgba(93, 83, 74, 0.10);
    --shadow-interactive: 0 2px 8px rgba(93, 83, 74, 0.18);
    --wood-gradient: linear-gradient(135deg, #E2B07A 0%, #C68642 100%);
    --leaf-gradient: linear-gradient(135deg, #A8E063 0%, #56AB2F 100%);
    --difficulty-thumb-color: #16C172;
    /* Default to green */
}

/* --- Base & Typography --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.65;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background-image: repeating-linear-gradient(135deg, #FFFBEA 0 40px, #FFF9D6 40px 80px);
}

h1,
h2,
h3,
h4,
legend {
    font-family: var(--font-heading);
    color: var(--color-primary-accent);
    margin-bottom: 0.75em;
    line-height: 1.3;
}

h1 {
    font-size: 2.5rem;
    color: var(--color-text);
    margin-bottom: 0.25em;
}

h2 {
    font-size: 1.5rem;
    border-bottom: 1px solid var(--color-secondary-accent);
    padding-bottom: 0.3em;
    margin-top: 1.5em;
}

legend {
    font-size: 1.2rem;
    font-weight: 700;
    padding: 0 0.5em;
}

p {
    margin-bottom: 1em;
}

ul,
ol {
    margin-bottom: 1em;
    padding-left: 20px;
}

li {
    margin-bottom: 0.5em;
}

/* --- Layout & Container --- */
.container {
    background-color: var(--color-bg);
    /* Beige background for all containers */
    padding: 25px 40px;
    border-radius: var(--border-radius-medium);
    border: 2px solid var(--color-secondary-accent);
    box-shadow: var(--shadow-subtle);
    text-align: center;
    width: 100%;
    max-width: 700px;
}

.game-header {
    margin-bottom: 25px;
    position: relative;
}

.game-header h1::before {
    content: '🐵';
    font-size: 2.2rem;
    margin-right: 0.3em;
    vertical-align: middle;
}

.game-header h1::after {
    content: '🙈';
    font-size: 2.2rem;
    margin-left: 0.3em;
}

.tagline {
    font-size: 1.1rem;
    color: var(--color-primary-accent);
    margin-top: -0.5em;
    font-style: italic;
    letter-spacing: 0.5px;
}

/* --- Game Options --- */
#game-options {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    gap: 20px;
    margin-bottom: 25px;
    padding: 15px;
    background-color: var(--color-bg);
    border-radius: var(--border-radius-soft);
}

#game-mode-selection,
#progression-style-selection,
#difficulty-selection {
    text-align: left;
    flex: 1;
    min-width: 250px;
}

#game-options fieldset {
    border: 1px solid var(--color-secondary-accent);
    padding: 15px 20px 20px 20px;
    border-radius: var(--border-radius-soft);
}

#game-options label {
    display: block;
    margin-bottom: 0.8em;
    cursor: pointer;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
}

#game-options input[type="radio"] {
    margin-right: 8px;
    accent-color: var(--color-primary-accent);
}

#difficulty-selection label,
#difficulty-selection select {
    font-size: 1rem;
    margin-bottom: 0.5em;
    display: inline-block;
}

#difficulty-selection select {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--color-secondary-accent);
    background: #fff;
    color: var(--color-text);
    font-family: var(--font-body);
    margin-left: 8px;
}

#difficulty-selection legend {
    color: var(--color-primary-accent);
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.5em;
}

/* --- Controls & Buttons --- */
#controls-area {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.button {
    border: none;
    padding: 14px 32px;
    font-size: 1.1rem;
    font-family: var(--font-heading);
    font-weight: 700;
    border-radius: 30px;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s, transform 0.1s;
    box-shadow: var(--shadow-interactive);
    letter-spacing: 1px;
    background: var(--leaf-gradient);
    color: #fff;
    position: relative;
    overflow: hidden;
}

.button:active {
    transform: scale(0.97) rotate(-2deg);
}

.button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

.button-primary {
    background: var(--color-secondary-accent);
    color: #4B3F2F;
    border: 2px solid var(--color-primary-accent);
}

.button-primary:hover:not(:disabled) {
    background: var(--color-primary-accent);
    color: #fff;
}

.button-secondary {
    background: #fff;
    color: var(--color-primary-accent);
    border: 2px solid var(--color-primary-accent);
}

.button-secondary:hover:not(:disabled) {
    background: var(--color-primary-accent-hover);
    color: #fff;
}

.button-submit {
    background: var(--color-success);
    color: #4B3F2F;
    border: 2px solid var(--color-alert);
}

.button-submit:hover:not(:disabled) {
    background: var(--color-alert);
    color: #fff;
}

/* --- Letter Display --- */
#letter-display-area {
    background: #fff;
    border: 6px solid #A47149;
    margin: 35px auto;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 48px 48px 60px 60px/60px 60px 48px 48px;
    box-shadow: 0 10px 36px rgba(80, 60, 20, 0.22), 0 2px 0 #C68642 inset;
    position: relative;
    height: 360px;
    padding: 20px;
    animation: none;
    overflow: hidden;
}

#flashing-letter {
    font-family: var(--font-heading);
    font-size: 120px;
    font-weight: 900;
    color: #111;
    text-shadow: none;
    background: none;
    border-radius: 40px;
    padding: 0.2em 0.6em;
    box-shadow: none;
    visibility: hidden;
    transition: none;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    box-sizing: border-box;
}

/* --- Input Area --- */
#input-area {
    margin-top: 20px;
    padding: 20px;
    background: --wood-gradient;
    border-radius: var(--border-radius-medium);
    box-shadow: 0 2px 12px #7AC74F22;
    border: 2px solid var(--color-primary-accent);
}

.input-instruction {
    display: none !important;
}

.color-hint {
    display: none !important;
}

.color-hint.pos1 {
    display: none !important;
}

.color-hint.pos2 {
    display: none !important;
}

.color-hint.pos3 {
    display: none !important;
}

.letter-inputs-wrapper {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

#input-area input[type="text"] {
    width: 60px;
    height: 60px;
    text-align: center;
    font-size: 1.8rem;
    font-family: var(--font-heading);
    border: 2px solid #bbb;
    border-radius: var(--border-radius-soft);
    text-transform: uppercase;
    background-color: #FFFFFF;
    color: #111;
    box-shadow: var(--shadow-interactive);
    transition: border-color 0.2s ease;
}

#input-area input[type="text"]:focus {
    outline: none;
    border-width: 3px;
    border-color: var(--color-primary-accent);
}

#input-area input[type="text"]::placeholder {
    color: #bbb;
    opacity: 1;
    font-size: 1.2rem;
}

/* --- Feedback & Score --- */
#countdown-area {
    min-height: 30px;
    margin: 15px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-primary-accent);
}

#feedback-area {
    margin-top: 20px;
    min-height: 25px;
    font-size: 1.05rem;
}

#message {
    font-weight: 600;
    padding: 8px 12px;
    border-radius: var(--border-radius-soft);
    display: inline-block;
}

#message.correct {
    color: #fff;
    background: var(--color-success);
    border: 2px solid var(--color-primary-accent);
    box-shadow: 0 2px 8px #FFD16655;
}

#message.incorrect {
    color: #fff;
    background: var(--color-alert);
    border: 2px solid #fff;
    box-shadow: 0 2px 8px #F76E1155;
}

#message.bonus {
    color: #fff;
    background: var(--color-primary-accent);
    border: 2px solid var(--color-secondary-accent);
    box-shadow: 0 2px 8px #7AC74F55;
}

#message.correct::before {
    content: '';
}

#message.incorrect::before {
    content: '';
}

#message.bonus::before {
    content: '';
}

#message:empty {
    padding: 0;
}


#score-area {
    margin-top: 25px;
    font-size: 1.1rem;
    padding: 18px;
    background: #fffbead9;
    border-radius: var(--border-radius-medium);
    color: var(--color-text-light);
    border: 2px solid var(--color-secondary-accent);
    box-shadow: 0 2px 8px #FFE15633;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    justify-items: left;
    align-items: left;
    width: 100%;
    box-sizing: border-box;
    overflow-wrap: anywhere;
}

#score-area p {
    margin: 8px 0;
    font-size: 1em;
    display: flex;
    align-items: center;
    gap: 0.4em;
    justify-content: center;
    min-width: 0;
    word-break: break-word;
}

#score-area span {
    font-weight: 700;
    color: var(--color-primary-accent);
    font-size: 1.2em;
}

#score-area span#current-score::before {
    content: '🍌';
    margin-right: 0.1em;
}

#score-area span#current-level::before {
    content: '🌴';
    margin-right: 0.1em;
}

#score-area span#current-speed::before {
    content: '⏱️';
    margin-right: 0.1em;
}

#score-area span#accuracy-rating::before {
    content: '🎯';
    margin-right: 0.1em;
}

/* --- Instructions --- */
#instructions {
    margin-top: 30px;
    text-align: left;
    font-size: 1.05rem;
    color: #4B3F2F;
    padding: 24px;
    border-top: 2px dashed var(--color-primary-accent);
    background: #fffbead9;
    border-radius: 0 0 24px 24px;
    box-shadow: 0 2px 8px #FFE15622;
}

#instructions h2 {
    margin-top: 0;
    color: var(--color-primary-accent);
    text-align: center;
    font-size: 1.4rem;
    letter-spacing: 1px;
    text-shadow: 0 1px 2px #7AC74F33;
}

#instructions ul {
    list-style-type: disc;
    padding-left: 25px;
}

#instructions ul li {
    margin-bottom: 0.3em;
}


/* --- Utility --- */
.hidden {
    display: none !important;
}

/* --- Accessibility: Focus Visible --- */
*:focus-visible {
    outline: 3px solid var(--color-primary-accent);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--color-bg), 0 0 0 6px var(--color-primary-accent);
}

#input-area input[type="text"]:focus-visible {
    outline: none;
    /* Already handled by its :focus border change */
    box-shadow: none;
}


/* --- Responsive Adjustments --- */
@media (max-width: 700px) {
    body {
        padding: 0;
        overflow-x: hidden;
    }

    .container,
    .how-fast-section {
        padding: 8vw 2vw;
        max-width: 100vw;
        width: 100vw;
        border-radius: 0;
        box-sizing: border-box;
    }

    h1 {
        font-size: 1.4rem;
        word-break: break-word;
    }

    h2,
    legend {
        font-size: 1.05rem;
    }

    .tagline {
        font-size: 0.95rem;
    }

    #game-options {
        flex-direction: column;
        gap: 10px;
        padding: 8px 0;
    }

    #game-options fieldset {
        padding: 10px 6px 12px 6px;
        min-width: 0;
    }

    #game-options label {
        font-size: 0.92rem;
        margin-bottom: 0.5em;
    }

    .button {
        padding: 16px 0;
        font-size: 1.1rem;
        min-width: 44vw;
        min-height: 48px;
        margin: 0.5em 0;
        border-radius: 24px;
    }

    #controls-area {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }

    #letter-display-area {
        height: 36vw;
        min-height: 120px;
        max-height: 180px;
        padding: 2vw;
        margin: 18px 0;
        border-radius: 24px;
    }

    #flashing-letter {
        font-size: 2.8rem;
        border-radius: 12px;
        padding: 0.1em 0.2em;
    }

    #input-area {
        padding: 10px 2vw;
        margin-top: 10px;
        border-radius: 18px;
    }

    .letter-inputs-wrapper {
        gap: 2vw;
        margin-bottom: 10px;
    }

    #input-area input[type="text"] {
        width: 14vw;
        min-width: 38px;
        max-width: 48px;
        height: 14vw;
        min-height: 38px;
        max-height: 48px;
        font-size: 1.3rem;
        border-radius: 10px;
    }

    #input-area input[type="text"]::placeholder {
        font-size: 0.95rem;
    }

    .input-instruction {
        font-size: 0.92rem;
        display: block !important;
        margin-bottom: 6px;
    }

    #score-area {
        grid-template-columns: 1fr;
        padding: 6px 2vw;
        gap: 4px;
        font-size: 0.98rem;
    }

    #score-area p {
        font-size: 0.98em;
        padding: 0 2px;
        justify-content: flex-start;
    }

    #instructions {
        padding: 10px 2vw;
        font-size: 0.98rem;
        border-radius: 0 0 14px 14px;
    }

    .how-fast-title {
        font-size: 1.05rem;
    }

    .how-fast-subhead {
        font-size: 0.95rem;
    }

    .how-fast-section p {
        font-size: 0.98em;
    }

    #difficulty-slider {
        width: 90vw;
        min-width: 0;
        max-width: 100vw;
        height: 36px;
    }

    #difficulty-slider::-webkit-slider-thumb,
    #difficulty-slider::-moz-range-thumb,
    #difficulty-slider::-ms-thumb {
        width: 40px;
        height: 40px;
    }

    .difficulty-slider-row {
        flex-direction: column;
        gap: 6px;
        align-items: flex-start;
        margin: 0;
    }

    .difficulty-slider-row label {
        font-size: 1em;
        padding-top: 0;
    }

    #difficulty-value {
        font-size: 1.1em;
        margin-left: 4px;
    }

    #pause-countdown-display {
        font-size: 1.1rem;
    }

    #countdown-area {
        font-size: 1rem;
        margin: 8px 0;
    }

    #feedback-area {
        font-size: 1rem;
        min-height: 20px;
    }

    #message {
        font-size: 1rem;
        padding: 6px 8px;
    }

    #next-round-hint {
        font-size: 0.92em;
    }
}

/* --- How Fast Can We See Section --- */
.how-fast-section {
    margin-top: 32px;
    background: #fffbead9;
    box-shadow: 0 2px 8px #FFE15633;
    border-radius: 24px;
    padding: 32px 24px;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
    text-align: left;
}

.how-fast-title {
    color: var(--color-primary-accent);
    text-align: center;
    margin-bottom: 0.5em;
    font-size: 1.6rem;
    border-bottom: none;
}

.how-fast-subhead {
    color: var(--color-letter-flash-text);
    margin-top: 1.2em;
    margin-bottom: 0.5em;
    font-size: 1.15rem;
    font-family: var(--font-heading);
    font-weight: 700;
}

.how-fast-section p {
    font-size: 1.08em;
    margin-bottom: 1.2em;
    color: var(--color-text);
}

.how-fast-section ul,
.how-fast-section ol {
    margin-bottom: 1.2em;
    padding-left: 24px;
}

.how-fast-section li {
    margin-bottom: 0.5em;
}

@media (max-width: 600px) {
    .how-fast-section {
        padding: 16px 6px;
        border-radius: 14px;
    }

    .how-fast-title {
        font-size: 1.1rem;
    }

    .how-fast-subhead {
        font-size: 1rem;
    }
}

#reflash-button.button-secondary {
    background: #fff;
    color: var(--color-primary-accent);
    border: 2px solid var(--color-primary-accent);
}

#reflash-button.button-secondary:hover:not(:disabled) {
    background: var(--color-primary-accent-hover);
    color: #fff;
}

#reflash-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

#progression-style-selection {
    display: none;
}

/* --- Custom Difficulty Slider --- */
#difficulty-slider {
    width: 220px;
    margin: 18px 0 8px 0;
    -webkit-appearance: none;
    appearance: none;
    height: 28px;
    /* Larger track */
    background: linear-gradient(90deg, #16C172 0%, #FFE156 50%, #FF2D2D 100%);
    border-radius: 16px;
    box-shadow: 0 2px 8px #FFE15655;
    outline: none;
    transition: background 0.3s;
    position: relative;
    display: block;
    vertical-align: middle;
}

#difficulty-slider:hover {
    background: linear-gradient(90deg, #16C172 0%, #FFE156 50%, #FF2D2D 100%);
}

#difficulty-slider:focus {
    box-shadow: 0 0 0 4px var(--color-primary-accent), 0 2px 8px #FFE15655;
}

#difficulty-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 32px;
    height: 32px;
    margin-top: -2px;
    /* Center thumb on larger track */
    border-radius: 50%;
    background: var(--difficulty-thumb-color);
    border: 3px solid #fff;
    box-shadow: 0 4px 12px #7AC74F55;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

#difficulty-slider:active::-webkit-slider-thumb {
    background: var(--difficulty-thumb-color);
    transform: scale(1.08);
}

#difficulty-slider::-webkit-slider-runnable-track {
    height: 28px;
    border-radius: 16px;
    background: transparent;
}

#difficulty-slider::-moz-range-thumb {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--difficulty-thumb-color);
    border: 3px solid #fff;
    box-shadow: 0 4px 12px #7AC74F55;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

#difficulty-slider:active::-moz-range-thumb {
    background: var(--difficulty-thumb-color);
    transform: scale(1.08);
}

#difficulty-slider::-moz-range-track {
    height: 28px;
    border-radius: 16px;
    background: linear-gradient(90deg, #16C172 0%, #FFE156 50%, #FF2D2D 100%);
}

#difficulty-slider::-ms-thumb {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--difficulty-thumb-color);
    border: 3px solid #fff;
    box-shadow: 0 4px 12px #7AC74F55;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

#difficulty-slider:active::-ms-thumb {
    background: var(--difficulty-thumb-color);
    transform: scale(1.08);
}

#difficulty-slider::-ms-fill-lower {
    background: linear-gradient(90deg, #16C172 0%, #FFE156 50%, #FF2D2D 100%);
    border-radius: 16px;
}

#difficulty-slider::-ms-fill-upper {
    background: linear-gradient(90deg, #16C172 0%, #FFE156 50%, #FF2D2D 100%);
    border-radius: 16px;
}

#difficulty-slider:focus::-ms-fill-lower {
    background: linear-gradient(90deg, #16C172 0%, #FFE156 50%, #FF2D2D 100%);
}

#difficulty-slider:focus::-ms-fill-upper {
    background: linear-gradient(90deg, #16C172 0%, #FFE156 50%, #FF2D2D 100%);
}

#difficulty-value {
    font-weight: bold;
    color: var(--color-primary-accent);
    font-size: 1.25em;
    margin-left: 6px;
    vertical-align: middle;
    letter-spacing: 1px;
}

.difficulty-slider-row {
    display: flex;
    align-items: center;
    gap: 18px;
    margin: -16px 0 0 0;
    justify-content: center;
}

.difficulty-slider-row label {
    display: flex;
    align-items: center;
    font-size: 1.15em;
    line-height: 1;
    margin: 0;
    padding-top: 16px;
}

#score-info-note {
    font-size: 0.95em;
    color: #888;
    margin-top: -10px;
    margin-bottom: 10px;
    text-align: center;
}

#next-round-hint {
    display: none;
    /* Hidden by default */
    margin-top: 10px;
    margin-bottom: 10px;
    font-size: 0.95em;
    color: var(--color-text-light);
    text-align: center;
}

#next-round-hint.visible-hint {
    display: block;
    /* Or inline-block, depending on desired flow */
}