/* ==========================================================================
   Everyday English - Main Stylesheet
   Author: Ziggy D.
   ========================================================================== */

/* --- 1. Global Styles & Variables (The Foundation) --- */
:root {
    --primary-color: #0056b3;
    --primary-color-dark: #004494;
    --secondary-color: #e9f5ff;
    --text-color: #333;
    --light-gray: #f4f4f4;
    --border-color: #ddd;
    --success-color: #28a745;
    --error-color: #dc3545;
    --font-family-sans: 'Lato',
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Helvetica,
        Arial,
        sans-serif;
    --font-family-serif: 'Lora', 'Georgia', 'Times New Roman', Times, serif;

    --gradient-start-color: #f7fbff;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: clamp(1rem, 0.9rem + 0.5vw, 1.25rem);
}

body {
    font-family: var(--font-family-sans);
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;
    background-color: #fff;
}

.container {
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

h1,
h2,
h3,
h4 {
    font-family: var(--font-family-serif);
    color: var(--primary-color);
    line-height: 1.2;
}

h1 {
    /* Scales from ~32px to ~48px */
    font-size: clamp(2rem, 1.5rem + 2.5vw, 3rem);
}

h2 {
    /* Scales from ~28px to ~36px */
    font-size: clamp(1.75rem, 1.4rem + 1.75vw, 2.25rem);
}

/* For h3 and h4, a fixed size is often fine, but you could make them fluid too if you like. */
h3 {
    font-size: 1.5rem;
}

h4 {
    font-size: 1.2rem;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s ease-in-out;
}

a:hover {
    text-decoration: underline;
    color: var(--primary-color-dark);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

h1 {
    /* Scales from ~32px to ~48px */
    font-size: clamp(2rem, 1.5rem + 2.5vw, 3rem);
}

h2 {
    /* Scales from ~28px to ~36px */
    font-size: clamp(1.75rem, 1.4rem + 1.75vw, 2.25rem);
}

/* For h3 and h4, a fixed size is often fine, but you could make them fluid too if you like. */
h3 {
    font-size: 1.5rem;
}

h4 {
    font-size: 1.2rem;
}

/* --- 2. Accessibility --- */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background-color: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    z-index: 1000;
    text-decoration: none;
    font-weight: bold;
    transition: top 0.3s ease-in-out;
}

.skip-link:focus {
    top: 0;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* --- 3. Reusable Button System --- */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-family: var(--font-family-sans);
    font-size: 0.9em;
    font-weight: bold;
    text-align: center;
    border-radius: 2rem;
    border: 1px solid var(--border-color);
    background-color: #f7f7f7;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s;
}

.button:hover {
    background-color: var(--secondary-color);
    border-color: var(--primary-color);
    text-decoration: none;
}

.button:active {
    transform: scale(0.96);
}

.button:disabled {
    background-color: #e0e0e0;
    color: #999;
    border-color: #ccc;
    cursor: not-allowed;
    transform: none;
}

.button--icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
}

.button--primary {
    background-color: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
    font-size: 1.1em;
}

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

a.button--primary:hover {
    color: #fff;
    text-decoration: none;
}

/* --- 4. Site Header & Navigation --- */
.site-header {
    background-color: #fff;
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 0;
    position: relative;
    z-index: 100;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar-brand img {
    height: 60px;
    width: auto;
}

.mobile-nav-toggle {
    display: block;
    background: transparent;
    border: 0;
    padding: 0.5rem;
    cursor: pointer;
    z-index: 1000;
}

.hamburger-icon {
    display: block;
    position: relative;
    width: 24px;
    height: 2px;
    background: var(--primary-color);
    transition: background 0.2s ease-in-out;
}

.hamburger-icon::before,
.hamburger-icon::after {
    content: '';
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--primary-color);
    transition: transform 0.3s ease-in-out;
}

.hamburger-icon::before {
    top: -8px;
}

.hamburger-icon::after {
    top: 8px;
}

.main-navbar {
    display: none;
}

.main-navbar.is-open {
    display: block;
    position: absolute;
    top: 77px;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.navbar-nav {
    list-style: none;
    margin: 0;
    padding: 1rem 0;
    text-align: center;
}

.navbar-item a {
    display: block;
    padding: 1rem;
    font-weight: bold;
}

.mobile-nav-toggle[aria-expanded="true"] .hamburger-icon {
    background: transparent;
}

.mobile-nav-toggle[aria-expanded="true"] .hamburger-icon::before {
    transform: rotate(45deg) translate(5px, 6px);
}

.mobile-nav-toggle[aria-expanded="true"] .hamburger-icon::after {
    transform: rotate(-45deg) translate(5px, -6px);
}

/* --- 5. General Page Layout & Components --- */
.page-hero {
    background-color: var(--secondary-color);
    background-image: linear-gradient(180deg, var(--gradient-start-color), var(--secondary-color));
    padding: 3rem 0;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.page-hero h1 {
    font-size: 2em;
}

.page-hero p {
    font-size: 1.1em;
    color: #555;
    max-width: 600px;
    margin: 1rem auto 1.5rem auto;
}

.hero-image {
    width: 100%;
    max-width: 18.75rem;
    margin: 0 auto;

}

.site-footer {
    background-color: #333;
    color: #eee;
    padding: 2rem 0;
    text-align: center;
    margin-top: 3rem;
}

.site-footer p {
    margin: 0;
}

/* --- 6. Homepage & Topic List Specifics --- */
.intro-section,
.featured-topics-section,
.topic-list-section,
.about-content-section {
    padding: 2rem 0;
}

.featured-topics-section {
    background-color: var(--light-gray);
    background-image: linear-gradient(180deg, #ffffff, var(--light-gray));
}

/* ==========================================================================
   Topic Card Component (Final Version)
   ========================================================================== */

.topic-grid {
    list-style: none;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr;
    /* 1 column on mobile */
    gap: 1.5rem;
    /* Space between the cards */
    margin-top: 2rem;
}

/* --- This is the main card style --- */
.topic-card {

    /* 1. Background and Border */
    background-color: #ffffff;
    /* Gives the card a solid white background */
    border: 1px solid var(--border-color);
    /* A subtle light gray border */

    /* 2. Rounded Corners */
    border-radius: 12px;
    /* This creates the rounded corners. Adjust the value as you like. */

    /* 3. Shadow for a "lifting" effect */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.07);
    /* A soft shadow to make it pop */

    /* 4. Overflow to contain the image */
    overflow: hidden;
    /* CRITICAL: This forces the image's corners to be rounded too */

    /* 5. Hover Animation */
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.topic-card:hover {
    transform: translateY(-5px);
    /* Lift the card up slightly on hover */
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    /* A more prominent shadow on hover */
}

/* The link inside the card should cover the whole area */
.topic-card a {
    display: block;
    color: var(--text-color);
    text-decoration: none;
    padding: 0;
    /* No padding on the link itself */
}

/* The banner image at the top of the card */
.topic-card-image {
    width: 100%;
    height: auto;
    aspect-ratio: 16/9;
    /* A good height for a banner image */
    object-fit: cover;
    /* Scales and crops the image to fit perfectly */

}

/* The container for the text content below the image */
.topic-card-content {
    padding: 1.5rem;
    /* Adds space inside the card for the text */
}

.topic-card-title {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 1.2em;
}

.topic-card-description {
    margin: 0;
    font-size: 0.9em;
    color: #666;
    line-height: 1.5;
}

.see-all-link {
    margin-top: 2rem;
    font-weight: bold;
}

.about-article {
    margin-bottom: 2.5rem;
}

/* --- 7. Topic Page Specifics (Dialogues, Exercises, Chat) --- */
.collapsible-section {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: #f7f7f7;
    cursor: pointer;
}

.section-header .toggle-button {
    font-size: 0.8em;
    font-weight: bold;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    background-color: #fff;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s;
}

.section-header .toggle-button:hover {
    background-color: var(--secondary-color);
    border-color: var(--primary-color);
}

.section-panel {
    max-height: 0;
    overflow: hidden;
    padding: 0 1rem;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
}

.section-panel.is-open {
    max-height: 5000px;
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.dialogue-line {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #eee;
    padding: 0.75rem 0;
    gap: 1rem;
}

.dialogue-line p {
    margin: 0;
}

.button-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.translation {
    display: none;
    color: #555;
    font-style: italic;
    font-size: 0.9em;
}

.translation.visible {
    display: block;
    margin-top: 4px;
}

.exercise-tabs {
    display: flex;
    /* On mobile, the default direction is a vertical stack */
    flex-direction: column;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    /* To make the corners look right */
}

/* This is the style for EACH tab button on mobile */
.tab-button {
    padding: 1rem;
    border: none;
    background-color: transparent;
    cursor: pointer;
    font-size: 1em;
    font-weight: 500;
    color: var(--text-color);
    text-align: left;
    /* Align text to the left for a cleaner list look */
    border-bottom: 1px solid var(--border-color);
    /* Separator line */
    transition: all 0.2s;
}

.tab-button:last-child {
    border-bottom: none;
}

.tab-button:hover {
    background-color: var(--light-gray);
    color: var(--primary-color);
}

.tab-button.active {
    font-weight: bold;
    color: var(--primary-color);
    background-color: var(--secondary-color);
    /* We use a left border to indicate the active tab in a vertical layout */
    border-left: 4px solid var(--primary-color);
}

tab-button:not(.active):hover {
    background-color: var(--light-gray);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.shadowing-line,
.pronunciation-checker,
.quick-fire-practice-area {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1.5rem;
    background-color: var(--light-gray);
}

.shadowing-controls,
.quick-fire-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
}

.sentence-selector {
    margin-bottom: 1.5rem;
    position: relative;
    /* This is needed for our custom arrow */
}

.sentence-selector select {
    /* --- 1. Fix the Layout --- */
    width: 100%;
    /* Make the element fill its container */
    display: block;
    /* Ensures it behaves correctly with width: 100% */

    /* --- 2. Fix the Appearance --- */
    font-size: 1em;
    /* Make the font size match the rest of the page */
    font-family: var(--font-family-sans);
    /* Use your site's font */
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    /* Top/Bottom, Right, Left. Extra right padding for the arrow. */
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: #fff;

    /* --- 3. Custom Arrow & Overflow Handling --- */
    /* This removes the default browser/OS dropdown arrow */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;

    /* --- 4. This is the magic for long text --- */
    text-overflow: ellipsis;
    /* If text overflows, it will show "..." */
    white-space: nowrap;
    overflow: hidden;
}

/* This creates our new, custom dropdown arrow */
.sentence-selector::after {
    content: '▼';
    position: absolute;
    top: 60%;
    /* Adjust vertical position of the arrow */
    right: 1rem;
    transform: translateY(-50%);
    pointer-events: none;
    /* Allows clicks to pass through to the select box */
    color: var(--primary-color);
    font-size: 0.8em;
}

.sentence-selector label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
}

.quick-fire-question-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
    background-color: #e9f5ff;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.quick-fire-question-area p {
    margin: 0;
}

/* --- 8. AI Voice Chat Component --- */
.scenario-selector {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background-color: var(--light-gray);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.scenario-selector label {
    display: block;
    font-weight: bold;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.scenario-selector select {
    width: 100%;
    padding: 0.75rem;
    font-size: 1em;
    font-family: var(--font-family-sans);
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background-color: #fff;
}

.voice-chat-window {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    height: 450px;
    background-color: #fff;
    overflow: hidden;
}

.chat-messages {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-message {
    padding: 0.75rem 1rem;
    border-radius: 18px;
    max-width: 80%;
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.user-message {
    background-color: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

.ai-message {
    background-color: #e9ecef;
    color: var(--text-color);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.ai-error-message {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    align-self: stretch;
    max-width: 100%;
    text-align: center;
}

.voice-chat-controls {
    border-top: 1px solid var(--border-color);
    padding: 1rem;
    text-align: center;
    background-color: var(--light-gray);
}

#mic-status {
    margin-top: 0.75rem;
    margin-bottom: 0;
    font-size: 0.9em;
    color: #666;
    min-height: 1.2em;
}

/* --- Styling for the "Read Aloud" button in chat --- */

/* Make the chat bubble a flex container to position the button */
.ai-message,
.ai-error-message {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    /* Space between text and button */
}

/* Ensure the text part takes up the available space */
.ai-message p,
.ai-error-message p {
    margin: 0;
    flex-grow: 1;
}

.read-aloud-button {
    /* Make the button smaller and less prominent */
    width: 32px;
    height: 32px;
    font-size: 0.8em;
    flex-shrink: 0;
    /* Prevents the button from shrinking */
}

/* ==========================================================================
   Aside / Sidebar Styles
   ========================================================================== */

.page-sidebar {
    padding: 2rem 0;
    background-color: var(--light-gray);
    border-top: 1px solid var(--border-color);
}

.legend {
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
}

.legend h3 {
    margin-top: 0;
    text-align: center;
}

.legend dl {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    /* Icon column, Text column */
    align-items: center;
    gap: 1rem;
}

.legend dt {
    /* This centers the icon within its grid cell */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* This is the rule to style our new SVG icons */
.legend dt svg {
    width: 36px;
    height: 36px;
    color: var(--primary-color);
    /* The magic! This sets the icon's color. */
}

/* ==========================================================================
   Site Footer
   ========================================================================== */

.site-footer {
    background-color: #333;
    background-image: linear-gradient(180deg, #444, #222);
    /* Dark background for contrast */
    color: #ccc;
    /* A softer white for better readability */
    padding: 2rem 0;
    text-align: center;
    margin-top: 3rem;
    font-size: 0.9em;
}

/* This is the new container for the footer content */
.footer-content {
    display: flex;
    flex-direction: column;
    /* Stack the copyright and license link vertically */
    gap: 0.5rem;
    /* Create a small space between the two lines */
}

/* Keep the copyright notice simple */
.site-footer p {
    margin: 0;
}

/* Style the license link to make it stand out */
.site-footer a {
    color: #fff;
    /* Make the link pure white to pop against the dark background */
    font-weight: bold;
    text-decoration: none;
    border-bottom: 1px dotted #888;
    /* A subtle underline */
    transition: color 0.2s, border-bottom-color 0.2s;
}

.site-footer a:hover {
    color: var(--secondary-color);
    /* A light blue on hover for a nice effect */
    border-bottom-color: var(--secondary-color);
}


/* --- Styles for the License Page --- */

.about-article {
    margin-bottom: 2.5rem;
}

.license-box {
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    /* A little more padding */
    margin-top: 1rem;
    border-radius: 8px;
    background-color: var(--light-gray);
    font-size: 0.9em;
    line-height: 1.7;
}

.license-box p {
    margin-bottom: 1em;
}

.license-box ul {
    padding-left: 20px;
}

/* ==========================================================================
   MEDIA QUERIES - Styles for larger screens
   ========================================================================== */
@media (min-width: 768px) {
    .mobile-nav-toggle {
        display: none;
    }

    .main-navbar {
        display: block;
        position: static;
        box-shadow: none;
    }

    .navbar-nav {
        display: flex;
        flex-direction: row;
        align-items: center;
        padding: 0;
        gap: 1.5rem;
    }

    .navbar-item a {
        padding: 0.5rem 0;
    }


    .hero-with-image .container {
        display: flex;
        /* This activates the two-column layout */
        align-items: center;
        /* Vertically aligns the image and text */
        gap: 1rem;
        /* Creates a nice space between the image and text */
        text-align: left;
        /* Align the text to the left on desktops */
    }

    .hero-image,
    .hero-text {
        /* Make each column take up half the space */
        flex: 0 0 40%;
        margin-bottom: 0;
    }

    .hero-image {
        margin-bottom: 0;
        /* Remove the bottom margin from the mobile style */
        max-width: 100%;
        /* Allow image to fill its column */
    }

    .hero-text {
        flex: 1;
        text-align: left;
    }

    .hero-text p {
        margin-left: 0;
        margin-right: 0;
    }


    .exercise-tabs {
        /* Switch back to a horizontal row */
        flex-direction: row;
        border: none;
        /* Remove the container border */
        border-bottom: 1px solid var(--border-color);
        /* Add the bottom line back */
        border-radius: 0;
    }

    .tab-button {
        text-align: center;
        /* Center the text for horizontal tabs */
        border-bottom: 3px solid transparent;
        /* Reset the separator line */
    }

    .tab-button:last-child {
        border-bottom: 3px solid transparent;
        /* Reset this too */
    }

    /* The active state is now an underline, not a side-border */
    .tab-button.active {
        border-left: none;
        /* Remove the side border */
        border-bottom-color: var(--primary-color);
        background-color: transparent;
        /* No background color on desktop */
    }
}

@media (min-width: 650px) {
    .topic-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .topic-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}