/*
 * Bats: Fact or Fiction — Widget Styles
 *
 * THEMING — Trail Conservancy brand palette
 * ------------------------------------------
 * Colors pulled directly from thetrailconservancy.org (ttc-child/style.css).
 *
 *   --primary-color   #fc5000 — their brand orange. Used as header bg, button borders,
 *                     and hover fills. Note: #fc5000 on white is 3.26:1 — passes for
 *                     large text (buttons, h1) but not body text. For any small orange
 *                     text on white, use --primary-dark instead.
 *   --primary-dark    #1d252b — their dark charcoal. Used for outlined button text and
 *                     focus rings. 12:1 contrast on white — WCAG AAA.
 *   --accent-color    Focus rings. Kept as charcoal to match their dark.
 *   --success-color   "Correct!" result header.
 *   --error-color     "Incorrect!" result header.
 */

:root {
    /* --- Trail Conservancy brand colors --- */
    --primary-color: #fc5000;     /* brand orange — thetrailconservancy.org */
    --primary-dark:  #1d252b;     /* charcoal — their dark bg / high-contrast text */
    --accent-color:  #1d252b;     /* focus rings */

    /* --- Status colors --- */
    --success-color: #2e7d32;
    --error-color:   #d32f2f;

    /* --- Neutral palette --- */
    --text-color:       #333333;
    --text-color-muted: #666666;
    --bg-color:         #ffffff;
    --card-bg:          #ffffff;
    --border-color:     #e0e0e0;

    /* --- Typography --- */
    --font-family: 'Outfit', 'Helvetica Neue', Helvetica, Arial, sans-serif;

    /* --- Layout --- */
    --border-radius: 8px;
}

/* ======================================
   Base
====================================== */
body {
    margin: 0;
    padding: 20px;
    font-family: var(--font-family);
    background-color: #f5f5f5;
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    box-sizing: border-box;
}

/* ======================================
   Widget container
====================================== */
.bats-widget-container {
    background-color: var(--card-bg);
    width: 100%;
    max-width: 700px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

/* ======================================
   Header
====================================== */
.widget-header {
    background-color: var(--primary-color);
    color: white;
    padding: 1.25rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.widget-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    color: white;
}

/* Visually hidden but available to screen readers */
.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;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.progress-indicator {
    font-size: 0.95rem;
    font-weight: 500;
    opacity: 0.9;
    color: white;
}

/* ======================================
   Progress bar
====================================== */
.progress-bar-track {
    height: 5px;
    background-color: #ececec;
    width: 100%;
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--primary-dark);
    width: 0%;
    transition: width 0.4s ease;
}

/* ======================================
   Language toggle
====================================== */
.lang-toggle {
    font-family: var(--font-family);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 0.25rem 0.6rem;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.lang-toggle:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.3);
}

.lang-toggle:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ======================================
   Game area
====================================== */
.game-card {
    padding: 3rem 2rem;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.view {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

.view-enter {
    animation: view-enter 0.34s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.view-exit {
    animation: view-exit 0.17s ease-in both;
    pointer-events: none;
}

@keyframes view-enter {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes view-exit {
    to {
        opacity: 0;
        transform: translateY(-6px);
    }
}

.hidden {
    display: none !important;
}

/* ======================================
   Level badge
====================================== */
.level-badge {
    display: inline-block;
    align-self: flex-start;
    padding: 0.25rem 0.75rem;
    background-color: #eeeeee;
    color: #444;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-radius: 4px;
}

/* ======================================
   Question statement
====================================== */
.question-statement {
    font-size: 1.75rem;
    line-height: 1.35;
    font-weight: 400;
    margin: 0;
    color: #222;
}

/* These headings get programmatic focus after an answer / question change so
   screen readers announce them. They aren't keyboard-tabbable (tabindex="-1"),
   so hide the focus outline that would otherwise flash for sighted users. */
#question-text:focus,
#result-title:focus {
    outline: none;
}

/* ======================================
   Buttons
====================================== */
.answer-slot {
    min-height: 9.5rem;
    display: flex;
    align-items: stretch;
}

.button-group {
    display: flex;
    gap: 1.5rem;
    width: 100%;
}

.game-btn {
    flex: 1;
    padding: 1rem 1.5rem;
    min-height: 3.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    font-size: 1.1rem;
    font-weight: 600;
    font-family: var(--font-family);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background-color: white;
    border: 2px solid var(--primary-color);
    color: var(--primary-dark); /* charcoal on white = 12:1, WCAG AAA */
    border-radius: 4px;
    cursor: pointer;
    transition:
        background-color 0.2s,
        border-color 0.2s,
        color 0.2s,
        opacity 0.18s,
        transform 0.18s,
        box-shadow 0.18s;
}

.game-btn:hover {
    background-color: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(29, 37, 43, 0.12);
}

.game-btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: none;
}

.game-btn:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

.game-btn:disabled {
    cursor: default;
}

.game-btn.is-selected {
    background-color: var(--primary-color);
    color: white;
    transform: scale(0.97);
}

.game-btn.is-unselected {
    opacity: 0.38;
    transform: scale(0.97);
}

.button-group.is-resolving {
    animation: answer-buttons-exit 0.22s ease-in both;
    pointer-events: none;
}

@keyframes answer-buttons-exit {
    55% {
        opacity: 1;
    }

    to {
        opacity: 0;
        transform: translateY(6px);
    }
}

.next-btn {
    background-color: var(--primary-color);
    color: white;
    align-self: flex-start;
    justify-self: start;
    padding: 1rem 2rem;
    flex: 0;
    min-width: 150px;
}

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

/* ======================================
   Answer / result
====================================== */
.answer-feedback {
    width: 100%;
    padding: 1.1rem 1.25rem;
    background: #f8f8f8;
    border: 1px solid var(--border-color);
    border-left: 5px solid var(--primary-color);
    border-radius: 6px;
    box-sizing: border-box;
    display: grid;
    gap: 0.85rem;
}

.answer-feedback.correct {
    border-left-color: var(--success-color);
    background: #f5fbf5;
}

.answer-feedback.incorrect {
    border-left-color: var(--error-color);
    background: #fff7f7;
}

.answer-feedback.is-revealing {
    animation: feedback-enter 0.38s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.answer-feedback.is-revealing .result-header {
    animation: result-pop 0.38s 0.08s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.answer-feedback.is-revealing .explanation {
    animation: content-rise 0.34s 0.16s ease-out both;
}

.answer-feedback.is-revealing .next-btn {
    animation: content-rise 0.34s 0.24s ease-out both;
}

@keyframes feedback-enter {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.985);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes result-pop {
    from {
        opacity: 0;
        transform: scale(0.88);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes content-rise {
    from {
        opacity: 0;
        transform: translateY(7px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-header h3 {
    font-size: 1.5rem;
    margin: 0;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.result-header.correct h3 {
    color: var(--success-color);
}

/* The "/ ''" gives the decorative symbol empty alt text so screen readers
   skip it — the word "Correct!" already conveys the state. */
.result-header.correct h3::before {
    content: "✓" / "";
}

.result-header.incorrect h3 {
    color: var(--error-color);
}

.result-header.incorrect h3::before {
    content: "✕" / "";
}

.explanation {
    font-size: 1.05rem;
    line-height: 1.5;
    color: #444;
    margin: 0;
}

/* "The fact is: …" lead — the corrected true fact, emphasized */
.fact-lead {
    color: #222;
    font-weight: 700;
}

/* ======================================
   Images
====================================== */
.image-container {
    position: relative;
    background-color: #f9f9f9;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid #eee;
    width: 100%;
    aspect-ratio: 16 / 9;
}

.image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Species label + photo credit over the bottom of each image */
.media-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    padding: 1.25rem 0.9rem 0.5rem;
    font-size: 0.8rem;
    line-height: 1.3;
    color: #fff;
    text-align: left;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0));
    pointer-events: none;
}

.media-caption em {
    font-style: italic;
    opacity: 0.92;
}

.media-credit {
    opacity: 0.8;
    white-space: nowrap;
}

.media-image {
    opacity: 0;
    transform: scale(1.015);
}

.media-image.is-loaded {
    opacity: 1;
    transform: scale(1);
    transition: opacity 0.38s ease, transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.media-image--incoming {
    position: absolute;
    inset: 0;
    z-index: 1;
    transform: none;
}

.media-image--incoming.is-loaded {
    transform: none;
    transition: opacity 2s ease;
}

.placeholder-box {
    width: 100%;
    height: 100%;
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
    color: #888;
    font-style: italic;
    font-size: 0.9rem;
    box-sizing: border-box;
}

.placeholder-box p {
    margin: 0;
    max-width: 80%;
}

/* ======================================
   End screen
====================================== */
#end-view {
    text-align: center;
    align-items: center;
    min-height: 34rem;
}

#end-view h3 {
    color: var(--primary-color);
    font-size: 2.4rem;
    margin: 0;
}

#end-view p {
    font-size: 1.4rem;
    color: #555;
    margin: 0;
}

/* Score line — make the numbers pop */
#end-view .score-line {
    font-size: 1.6rem;
    font-weight: 500;
    color: #444;
}

#final-score,
#final-total {
    font-weight: 900;
    color: var(--primary-color);
    font-size: 1.35em;
}

/* The celebratory result message — the fun, headline moment */
#end-message {
    font-size: 2rem;
    line-height: 1.25;
    font-weight: 700;
    color: var(--primary-dark);
    margin-top: 0.25rem;
}

.end-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    width: 100%;
}

.restart-btn,
.confetti-btn {
    flex: 0 0 auto;
    min-width: 12rem;
    white-space: nowrap;
}

.confetti-btn {
    background-color: var(--primary-color);
    color: white;
}

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

@media (prefers-reduced-motion: reduce) {
    .progress-bar-fill,
    .game-btn,
    .media-image,
    .media-image.is-loaded {
        transition-duration: 0.01ms !important;
    }

    .view-enter,
    .view-exit,
    .button-group.is-resolving,
    .answer-feedback.is-revealing,
    .answer-feedback.is-revealing .result-header,
    .answer-feedback.is-revealing .explanation,
    .answer-feedback.is-revealing .next-btn {
        animation-duration: 0.01ms !important;
        animation-delay: 0ms !important;
    }

    .game-btn:hover,
    .game-btn:active,
    .game-btn.is-selected,
    .game-btn.is-unselected,
    .media-image,
    .media-image.is-loaded {
        transform: none;
    }
}

/* ======================================
   Mobile
====================================== */
@media (max-width: 500px) {
    .widget-header {
        padding: 1rem;
    }

    .widget-header h2 {
        font-size: 1.2rem;
    }

    .game-card {
        padding: 1.5rem;
    }

    .question-statement {
        font-size: 1.35rem;
    }

    .button-group {
        flex-direction: column;
        gap: 0.75rem;
    }

    .next-btn {
        align-self: stretch;
        justify-self: stretch;
    }

    .answer-slot {
        min-height: 12rem;
    }

    #end-view {
        min-height: 30rem;
    }

    .end-actions {
        flex-direction: column;
    }

    .restart-btn,
    .confetti-btn {
        width: 100%;
    }
}
