/* ---------- Hero ---------- */
.hero {
    position: relative;
    padding: 80px 24px 120px;
    text-align: center;
    background:
        linear-gradient(180deg, rgba(250, 250, 250, 0), rgba(250, 250, 250, 0.98)),
        url('hero-background.jpg') center / cover no-repeat;
    margin: 0 3rem;
    border-radius: var(--radius-lg);
}

.hero-title {
    max-width: 920px;
    margin: 0 auto 32px;
}

.typing-wrap {
    color: var(--text-highlight);
    display: inline-block;
}

.caret {
    display: inline-block;
    width: 2px;
    height: 0.9em;
    background: var(--text-highlight);
    margin-left: 4px;
    vertical-align: -0.1em;
    animation: blink 0.9s step-end infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

.hero-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    margin-bottom: 48px;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-weight: 600;
    border-radius: 40px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.btn-download {
    padding: 16px 36px;
    font-size: 1.05rem;
    background: linear-gradient(135deg, var(--btn-1), var(--btn-2));
    color: #fff;
    box-shadow: 0 8px 24px rgba(251, 108, 193, 0.35);
}

.btn-download:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(251, 108, 193, 0.45);
}

.btn-glass {
    padding: 16px 36px;
    font-size: 1.05rem;
    background: rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.7);
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
}

.btn-glass:hover {
    transform: translateY(-2px);
}

.btn-outline {
    padding: 16px 36px;
    font-size: 1.05rem;
    background: transparent;
    border: 2px solid var(--btn-1);
    color: var(--text-highlight);
}

.btn-outline:hover {
    background: var(--card-bg);
}

.btn-ghost {
    font-size: 0.95rem;
    color: var(--text-highlight);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid transparent;
}

.btn-ghost:hover {
    border-bottom-color: var(--text-highlight);
}

/* ---------- Hero demo (animated) ---------- */
.hero-demo {
    max-width: 820px;
    margin: 0 auto;
}

.demo-stage {
    position: relative;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    background: linear-gradient(135deg, var(--card-img-1), var(--card-img-2));
    aspect-ratio: 976 / 720;
    /* No clipping here: the pop-in blocks are allowed to hang off the video */
    --demo-gap: 0.2s;
    /* Gap between each block popping in — tweak this one value to retime */
}

.demo-video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-lg);
}

/* Layer of app-style blocks that pop in once the video ends */
.demo-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.demo-block {
    position: absolute;
    opacity: 0;
    transform: translateY(14px) scale(0.96);
    transform-origin: center;
    will-change: opacity, transform;
    /* The hero centres its text; blocks read better left-aligned */
    text-align: left;
}

.demo-stage.is-revealed .demo-block {
    /* Shorter than --demo-gap, so only one block is popping at a time */
    animation: demo-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    /* Read the per-block delay here: the `animation` shorthand above resets
       animation-delay to 0s, so a plain `.demo-block--x { animation-delay }`
       would be overridden. Driving it through a custom property avoids that. */
    animation-delay: var(--demo-delay, 0s);
}

/* Scatter the blocks over the video: a loose zig-zag, not four tidy corners.
   They deliberately hang off the edges a little. */
/* Stagger: each block starts only after the previous one has finished. */
.demo-block--theorem {
    top: -6%;
    left: -5%;
    width: 40%;
    --demo-delay: calc(var(--demo-gap) * 0);
}

.demo-block--example {
    top: 22%;
    right: -7%;
    width: 37%;
    --demo-delay: calc(var(--demo-gap) * 1);
}

.demo-block--hint {
    top: 52%;
    left: -6%;
    width: 45%;
    --demo-delay: calc(var(--demo-gap) * 2);
}

.demo-block--definition {
    top: 74%;
    right: -5%;
    width: 33%;
    --demo-delay: calc(var(--demo-gap) * 3);
}

/* Rescale the reused block styles so they fit inside the video frame */
.demo-block .theorem-block,
.demo-block .definition-block,
.demo-block .hint-block {
    max-width: none;
    width: 100%;
    padding: 18px 16px 14px;
    border-radius: 10px;
}

.demo-block .example-block {
    max-width: none;
    width: 100%;
    border-radius: 10px;
}

.demo-block .theorem-title,
.demo-block .definition-title,
.demo-block .hint-title {
    left: 16px;
    font-size: 0.85rem;
    padding: 2px 10px;
}

.demo-block .example-title {
    font-size: 0.85rem;
    padding: 3px 16px;
    margin: 0 -16px 10px;
}

.demo-block .theorem-formula,
.demo-block .definition-body,
.demo-block .example-body,
.demo-block .hint-body {
    font-size: 0.85rem;
    line-height: 1.5;
}

@keyframes demo-pop {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.96);
    }

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

.product-summary {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 24px 0;
    text-align: center;
}

.product-summary p {
    font-size: 1.05rem;
    line-height: 1.7;
    color: var(--text-muted);
}

/* ---------- Features ---------- */
.features {
    padding: 80px 0;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 80px;
}

.feature {
    position: relative;
    width: 100%;
    min-height: 360px;
}

.feature.flip .feature-card {
    margin-left: 3rem;
    margin-right: auto;
}

.feature.flip .feature-decoration {
    left: auto;
    right: 0;
    transform: translate(20%, -50%);
}

.feature-card {
    position: relative;
    z-index: 1;
    width: 70%;
    margin-left: auto;
    margin-right: 3rem;
    display: grid;
    grid-template-columns: 1fr 1.25fr;
    gap: 32px;
    align-items: center;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 120px 40px;
    box-shadow: var(--shadow-md);
}

.feature-card h2 {
    font-size: 1.375rem;
    margin-bottom: 16px;
}

.feature-card h2 code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.85em;
    background: var(--card-img-1);
    color: var(--text-highlight);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
}

.feature-card p {
    font-size: 1rem;
    max-width: 25ch;
}

.feature-media {
    background: linear-gradient(135deg, var(--card-img-1), var(--card-img-2));
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 240px;
}

.feature-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Decoration: theorem block */
.feature-decoration {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translate(-20%, -50%);
    z-index: 0;
    pointer-events: none;
    /* 純背景，不可互動 */
}

.theorem-block {
    position: relative;
    background: #fff0f0;
    border: 2px solid #f19a9a;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
    color: #8a1e1e;
    padding: 24px;
    margin-top: 14px;
    /* 留空間給騎在邊上的標籤 */
    max-width: 500px;
    /* transform: rotate(3deg) */
}

.theorem-title {
    position: absolute;
    top: 0;
    left: 24px;
    transform: translateY(-50%);
    background: #ca4646;
    color: #fff8f8;
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1.5;
    padding: 3px 12px;
    border-radius: 6px;
    width: fit-content;
    white-space: nowrap;
}

.theorem-formula {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.1rem;
    color: #8a1e1e;
}

.definition-block {
    position: relative;
    background: #fdf0fa;
    border: 2px solid #f19adb;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(241, 154, 154, 0.1);
    color: #8a1e6f;
    padding: 24px;
    max-width: 280px;
}

.definition-title {
    position: absolute;
    top: 0;
    left: 24px;
    transform: translateY(-50%);
    background: #dd6fbc;
    color: #fff8f8;
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1.5;
    padding: 3px 12px;
    border-radius: 6px;
    width: fit-content;
}

.definition-body {
    font-size: 1rem;
    color: #8a1e6f;
}

.example-block {
    background: linear-gradient(#f6faff, #f0f7ff);
    border: 2px solid #5779c4;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.1);
    color: #1e3a8a;
    overflow: hidden;
    /* 讓 bar 的方角被圓角裁掉 */
    padding: 0 16px 12px;
    /* 上方無 padding，bar 直接貼頂 */
    max-width: 280px;
}

.example-title {
    display: block;
    background: #5779c4;
    color: #f8fbff;
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1.5;
    padding: 4px 16px;
    margin: 0 -16px 12px;
    /* 負邊距讓 bar 撐到左右邊框 */
}

.example-body {
    font-size: 1rem;
    color: #1e3a8a;
}

/* ---------- 兩個 feature 之間的 hint block ---------- */
.feature-divider {
    display: flex;
    justify-content: center;
    padding: 0 16px;
}

.hint-block {
    position: relative;
    background: #fffbeb;
    border: 2px dashed #e8c87b;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.1);
    color: #92400e;
    padding: 24px 24px 20px;
    margin-top: 14px;
    /* 留空間給騎在頂邊的 chip */
    max-width: 460px;
}

.hint-title {
    position: absolute;
    top: 0;
    left: 24px;
    transform: translateY(-50%);
    background: #c99152;
    color: #fffdf5;
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1.5;
    padding: 3px 16px 3px 12px;
    /* app 原值 0.15rem 1rem 0.15rem 0.75rem */
    border-radius: 12px 20px 20px 12px;
    /* 藥丸形：左方右圓 */
    width: fit-content;
}

.hint-body {
    font-size: 1rem;
    color: #92400e;
    font-family: Georgia, 'Times New Roman', serif;
}

.collapsible-section {
    display: flex;
    justify-content: center;
    padding: 0 16px;
}

.collapsible-container {
    width: 100%;
    max-width: 640px;
    border-radius: 12px;
    overflow: hidden;
    background: white;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 8px rgba(124, 74, 110, 0.08);
}

.collapsible-trigger {
    width: 100%;
    padding: 1rem 1.5rem;
    background: #f8fafc;
    border: none;
    text-align: left;
    font-size: 1rem;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
    user-select: none;
}

.collapsible-trigger:hover {
    background: #f1f5f9;
    color: #3b82f6;
}

.collapsible-title-text {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    font-size: 1rem;
    color: #475569;
    line-height: 1.5;
}

.collapsible-trigger::after {
    content: '▼';
    font-size: 0.8rem;
    color: #94a3b8;
    flex-shrink: 0;
    margin-left: 1rem;
    transition: transform 0.3s ease;
}

.collapsible-container.open .collapsible-trigger::after {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background: white;
}

.collapsible-container.open .collapsible-content {
    max-height: 1000px;
    transition: max-height 0.5s ease-in;
}

.collapsible-inner {
    padding: 1.5rem;
}

.collapsible-inner p {
    font-size: 1rem;
    color: #475569;
}

/* ---------- FAQ ---------- */
.faq {
    padding: 80px 24px;
}

.faq-title {
    text-align: center;
    margin-bottom: 40px;
}

.faq-list {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 讓 FAQ 的 collapsible 填滿列表寬度 */
.faq-list .collapsible-container {
    width: 100%;
    max-width: none;
}

/* ---------- Final CTA ---------- */
.final-cta {
    padding: 100px 24px;
    text-align: center;
    background: rgb(254, 246, 246);
}

.final-cta h2 {
    margin-bottom: 32px;
}

.cta-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---------- Responsive ---------- */
@media (max-width: 620px) {
    .typing-wrap {
        min-width: 5.25em;
        white-space: nowrap;
    }
}

@media (max-width: 860px) {
    .feature,
    .feature.flip {
        grid-template-columns: 1fr;
    }

    .feature.flip .feature-decoration {
        order: -1;
    }

    .feature-card {
        width: 100%;
        margin: 0;
        grid-template-columns: 1fr;
        padding: 40px;
    }

    .feature.flip .feature-card {
        margin: 0;
    }

    .feature-decoration {
        display: none;
    }

    .features {
        padding: 56px 16px;
    }

    .feature-card p {
        max-width: none;
    }

    .hero {
        padding: 56px 16px 80px;
    }

    .cta-buttons {
        flex-direction: column;
        align-items: center;
    }

    .cta-buttons .btn {
        width: 100%;
        max-width: 320px;
    }

    /* Fewer blocks on small screens so the hero video stays readable */
    .demo-block--hint,
    .demo-block--definition {
        display: none;
    }

    /* Keep the two remaining blocks balanced and inside the viewport */
    .demo-block--theorem {
        top: -4%;
        left: -3%;
        width: 58%;
    }

    .demo-block--example {
        top: 56%;
        left: auto;
        right: -3%;
        width: 60%;
    }

    /* Only theorem + example are visible here; their base delays (0s and
       --demo-gap) already keep them sequential, so nothing to override. */

    .demo-block .theorem-formula,
    .demo-block .example-body {
        font-size: 0.75rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .demo-block {
        opacity: 1;
        transform: none;
    }

    .demo-stage.is-revealed .demo-block {
        animation: none;
    }
}

@media (min-width: 1024px) {
    .feature-card h2 {
        font-size: 1.75rem;
    }

    .feature-card p {
        font-size: 1.125rem;
    }
}