/* ===================================
   CSS Reset & Base Styles
   =================================== */

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

/* ===================================
   CSS Variables
   =================================== */

:root {
    /* Colors */
    --color-primary: #4d65ff;
    --color-primary-dark: #3d52cc;
    --color-text-dark: #2d3748;
    --color-text-gray: #4a5568;
    --color-bg-light: #f7fafc;
    --color-white: #ffffff;
    --color-success: #48bb78;
    --color-error: #f56565;
    --color-orange: #ed8936;

    /* Level Badge Colors */
    --badge-a2-bg: #bee3f8;
    --badge-a2-text: #2c5282;
    --badge-b1-bg: #c6f6d5;
    --badge-b1-text: #276749;
    --badge-b2-bg: #feebc8;
    --badge-b2-text: #c05621;

    /* Typography */
    --font-family: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    --font-size-hero: 48px;
    --font-size-section: 36px;
    --font-size-subheading: 24px;
    --font-size-body: 18px;
    --font-size-small: 14px;
    --font-size-button: 18px;

    /* Spacing */
    --spacing-section: 80px;
    --spacing-container: 24px;

    /* Breakpoints (used in media queries) */
    --breakpoint-mobile: 640px;
    --breakpoint-tablet: 1024px;
}

/* ===================================
   Typography & Base
   =================================== */

body {
    font-family: var(--font-family);
    font-size: var(--font-size-body);
    line-height: 1.6;
    color: var(--color-text-dark);
    background-color: var(--color-white);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    line-height: 1.2;
    font-weight: 700;
}

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

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

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

/* ===================================
   Container
   =================================== */

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-container);
}

/* ===================================
   Header
   =================================== */

.header {
    background-color: var(--color-white);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    padding: 20px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-text-dark);
}

.logo__link {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo__link:hover {
    color: var(--color-primary);
}

.logo__images {
    position: relative;
    height: 40px;
    width: auto;
}

.logo__image {
    height: 40px;
    width: auto;
    display: block;
}

.logo__image--blue {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.logo__link:hover .logo__image--blue {
    opacity: 1;
}

/* ===================================
   Hero Section
   =================================== */

.hero {
    background: linear-gradient(180deg, var(--color-white) 0%, var(--color-bg-light) 100%);
    padding: var(--spacing-section) 0;
    text-align: center;
}

.hero__title {
    font-size: var(--font-size-hero);
    color: var(--color-primary);
    margin-bottom: 16px;
}

.hero__subtitle {
    font-size: var(--font-size-subheading);
    color: var(--color-text-gray);
    margin-bottom: 24px;
    font-weight: 600;
}

.hero__description {
    font-size: var(--font-size-body);
    color: var(--color-text-gray);
    max-width: 600px;
    margin: 0 auto;
}

/* ===================================
   Books Section
   =================================== */

.books {
    background-color: var(--color-white);
    padding: var(--spacing-section) 0;
}

.books__title {
    font-size: var(--font-size-section);
    text-align: center;
    margin-bottom: 32px;
    color: var(--color-text-dark);
}

/* ===================================
   Level Tabs (Sheet Design)
   =================================== */

.level-tabs {
    display: flex;
    justify-content: center;
    gap: 0;
    margin-bottom: 16px;
    position: relative;
}

.level-tab {
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
}

.level-tab::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(to right, transparent, #e2e8f0, transparent);
}

.level-tab .badge {
    padding: 12px 32px;
    font-size: 16px;
    border-radius: 8px 8px 0 0;
    border: 2px solid transparent;
    border-bottom: none;
    transition: all 0.3s ease;
    display: block;
    position: relative;
    background: #f7fafc;
}

.level-tab:hover .badge {
    transform: translateY(-2px);
}

.level-tab--active .badge {
    background: white;
    border-color: #e2e8f0;
    border-bottom-color: white;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
    transform: translateY(0);
    z-index: 2;
}

.level-tab:not(.level-tab--active) .badge {
    opacity: 0.7;
}

/* ===================================
   Country Selector
   =================================== */

.country-selector {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin: 0 auto 32px;
    flex-wrap: wrap;
    max-width: 700px;
}

.country-flag {
    background: transparent;
    border: none;
    border-radius: 6px;
    padding: 6px;
    font-size: 22px;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    min-height: 38px;
}

.country-flag:hover {
    transform: scale(1.08);
    background-color: #e6f2ff;
}

.country-flag--active {
    background-color: #d1e7ff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    outline: 1px solid rgba(77, 101, 255, 0.4);
    outline-offset: 1px;
}

.country-flag:focus {
    outline: 1px solid rgba(77, 101, 255, 0.2);
    outline-offset: 1px;
}

.books__grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 24px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.books__grid[hidden] {
    display: none;
}

.books__grid--active {
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===================================
   Book Card
   =================================== */

.book-card {
    background-color: var(--color-white);
    border-radius: 8px;
    padding: 24px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}

.book-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.book-card__cover {
    width: 200px;
    height: 300px;
    object-fit: contain;
    border-radius: 4px;
    margin-bottom: 16px;
    display: block;
}

.book-card__levels {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    justify-content: center;
}

.book-card__title {
    font-size: var(--font-size-subheading);
    margin-bottom: 16px;
    text-align: center;
    color: var(--color-text-dark);
    flex-grow: 1;
    display: flex;
    align-items: center;
}

.book-card__link {
    display: inline-block;
    padding: 10px 20px;
    border: 2px solid var(--color-primary);
    border-radius: 6px;
    color: var(--color-primary);
    font-weight: 600;
    transition: all 0.3s ease;
    margin-top: auto;
}

.book-card__link:hover {
    background-color: var(--color-primary);
    color: var(--color-white);
}

/* ===================================
   Badge Component
   =================================== */

.badge {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: var(--font-size-small);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge--a2 {
    background-color: var(--badge-a2-bg);
    color: var(--badge-a2-text);
}

.badge--b1 {
    background-color: var(--badge-b1-bg);
    color: var(--badge-b1-text);
}

.badge--b2 {
    background-color: var(--badge-b2-bg);
    color: var(--badge-b2-text);
}

.badge--large {
    padding: 12px 24px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.badge--large:hover {
    transform: scale(1.05);
}

/* ===================================
   Form Section
   =================================== */

.form-section {
    background-color: var(--color-bg-light);
    padding: var(--spacing-section) 0;
}

.form-wrapper {
    max-width: 500px;
    margin: 0 auto;
    background-color: var(--color-white);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.form__title {
    font-size: var(--font-size-section);
    text-align: center;
    margin-bottom: 16px;
    color: var(--color-text-dark);
}

.form__description {
    text-align: center;
    color: var(--color-text-gray);
    margin-bottom: 32px;
}

/* ===================================
   Form Elements
   =================================== */

.form__group {
    margin-bottom: 24px;
}

.form__label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-text-dark);
}

.form__input {
    width: 100%;
    height: 48px;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 16px;
    font-family: var(--font-family);
    transition: all 0.3s ease;
}

.form__input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(77, 101, 255, 0.1);
}

.form__input.error {
    border-color: var(--color-error);
}

.form__error {
    display: block;
    color: var(--color-error);
    font-size: var(--font-size-small);
    margin-top: 8px;
    min-height: 20px;
}

/* ===================================
   Radio Button Group
   =================================== */

.form__fieldset {
    border: none;
    padding: 0;
}

.form__legend {
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--color-text-dark);
}

.form__radio-group {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.form__radio-label {
    cursor: pointer;
}

.form__radio {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.form__radio-label .badge {
    background: #f7fafc;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.form__radio-label:hover .badge {
    transform: scale(1.05);
}

.form__radio:not(:checked) + .badge {
    opacity: 0.7;
}

.form__radio:checked + .badge {
    background: white;
    border-color: #e2e8f0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transform: scale(1.05);
    opacity: 1;
}

.form__radio:focus + .badge {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ===================================
   Button
   =================================== */

.btn {
    width: 100%;
    height: 52px;
    padding: 0 32px;
    border: none;
    border-radius: 6px;
    font-size: var(--font-size-button);
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

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

.btn--primary:active:not(:disabled) {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn__spinner {
    display: none;
}

.btn.loading .btn__text {
    display: none;
}

.btn.loading .btn__spinner {
    display: block;
}

/* ===================================
   Spinner Animation
   =================================== */

.spinner {
    width: 24px;
    height: 24px;
    animation: rotate 1s linear infinite;
}

.spinner__path {
    stroke: var(--color-white);
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
}

@keyframes rotate {
    100% {
        transform: rotate(360deg);
    }
}

@keyframes dash {
    0% {
        stroke-dasharray: 1, 150;
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -35;
    }
    100% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -124;
    }
}

/* ===================================
   Privacy Note
   =================================== */

.form__privacy {
    font-size: var(--font-size-small);
    color: var(--color-text-gray);
    text-align: center;
    margin-top: 16px;
}

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

.footer {
    background-color: var(--color-text-dark);
    color: var(--color-white);
    padding: 20px 0;
    text-align: center;
}

.footer__text {
    font-size: var(--font-size-small);
}

/* ===================================
   Thank You Page Specific Styles
   =================================== */

.success {
    padding: var(--spacing-section) 0;
    text-align: center;
}

.success + .books {
    padding-top: 0;
    margin-top: -20px;
}

/* On thank-you page, tabs and country selector appear after books */
.success + .books .level-tabs {
    margin-top: 48px;
    margin-bottom: 16px;
}

.success + .books .country-selector {
    margin-bottom: 0;
}

.success__icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
    background-color: var(--color-success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: scaleIn 0.5s ease;
}

.success__icon svg {
    width: 40px;
    height: 40px;
    stroke: var(--color-white);
    stroke-width: 3px;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

@keyframes scaleIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.success__title {
    font-size: var(--font-size-hero);
    color: var(--color-text-dark);
    margin-bottom: 16px;
}

.success__subtitle {
    font-size: var(--font-size-subheading);
    color: var(--color-text-gray);
    margin-bottom: 32px;
}

.success__message {
    font-size: var(--font-size-body);
    color: var(--color-text-gray);
    max-width: 600px;
    margin: 0 auto 16px;
}

.success__note {
    font-size: var(--font-size-body);
    color: var(--color-text-gray);
    max-width: 600px;
    margin: 4px auto;
    font-style: italic;
}

/* ===================================
   CTA Section
   =================================== */

.cta-section {
    max-width: 700px;
    margin: 32px auto 0;
    padding: 32px;
    background: linear-gradient(135deg, #f8f9ff 0%, #fff5f5 100%);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.cta-intro {
    font-size: var(--font-size-body);
    color: var(--color-text-gray);
    margin-bottom: 16px;
}

.cta-question {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text-dark);
    margin-bottom: 24px;
    line-height: 1.4;
}

.cta-text {
    font-size: var(--font-size-body);
    color: var(--color-text-gray);
    margin-bottom: 16px;
    line-height: 1.6;
}

.cta-highlight {
    font-size: var(--font-size-body);
    color: var(--color-text-dark);
    margin: 24px 0;
    padding: 20px;
    background: white;
    border-left: 4px solid var(--color-primary);
    border-radius: 6px;
    line-height: 1.6;
}

.cta-action {
    font-size: var(--font-size-body);
    color: var(--color-text-gray);
    margin-top: 24px;
    margin-bottom: 0;
    line-height: 1.6;
}

/* ===================================
   Shake Animation (for errors)
   =================================== */

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

.shake {
    animation: shake 0.5s;
}

/* ===================================
   Responsive Design
   =================================== */

/* Large Tablet (3 column grid) */
@media (max-width: 1200px) {
    .books__grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Tablet (2 column grid) */
@media (max-width: 1024px) {
    :root {
        --font-size-hero: 40px;
        --font-size-section: 32px;
        --font-size-subheading: 22px;
        --spacing-section: 60px;
    }

    .books__grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .level-tab .badge {
        padding: 10px 24px;
        font-size: 14px;
    }
}

/* Mobile (1 column grid) */
@media (max-width: 640px) {
    :root {
        --font-size-hero: 32px;
        --font-size-section: 28px;
        --font-size-subheading: 20px;
        --font-size-body: 16px;
        --spacing-section: 40px;
    }

    .header {
        padding: 16px 0;
    }

    .logo {
        font-size: 20px;
    }

    .logo__images {
        height: 32px;
    }

    .logo__image {
        height: 32px;
    }

    .books__grid {
        grid-template-columns: 1fr;
    }

    .book-card__cover {
        width: 150px;
    }

    .form-wrapper {
        padding: 24px;
    }

    .form__radio-group {
        flex-direction: column;
        align-items: stretch;
    }

    .badge--large {
        width: 100%;
        text-align: center;
    }

    .success__icon {
        width: 60px;
        height: 60px;
    }

    .success__icon svg {
        width: 30px;
        height: 30px;
    }
}
