:root {
    --panel-soft: #fafaf5;
    --line-soft: #dde0d5;
    --green-deep: #3b5b2e;
    --text: #22261b;
    --muted: #5a6050;
    --gap: 12px;

    --minitext: 16px;
    --mediumtext: 18px;
    --normaltext: 20px;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100vh;
    height: 100vh;
    min-height: 100dvh;
    height: 100dvh;
    margin: 0;
    overflow: hidden;
    color: var(--text);
    font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
    background: #f4f4ec;
}

body {
    overscroll-behavior: none;
}

.app {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 100vh;
    height: 100vh;
    min-height: 100dvh;
    height: 100dvh;
}

.topbar {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(env(safe-area-inset-top) + 12px) 16px 8px;
    background: #1e3217;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 10px rgba(30, 50, 23, 0.14);
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1 220px;
}

.brand-logo {
    height: 58px;
    width: auto;
    flex: 0 0 auto;
    margin: -12px 0;
}

/* .brand-copy {
    min-width: 0;
    line-height: 1.1;
}

.brand-title {
    color: #fff;
    font-size: 18px;
    font-weight: 900;
    letter-spacing: 0.02em;
    line-height: 1.2;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.brand-sub {
    margin-top: 2px;
    font-size: 11px;
    letter-spacing: 0.32em;
    color: rgba(30, 30, 30, 0.72);
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
} */

.page-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    min-width: 0;
}

.page-nav {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 25px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: opacity 160ms ease, background 160ms ease;
}

.page-nav:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.2);
}

.page-nav:disabled {
    opacity: 0.28;
    cursor: not-allowed;
}

.page-nav:focus-visible {
    outline: 3px solid rgba(168, 206, 232, 0.8);
    outline-offset: 2px;
}

.viewport {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    position: relative;
    padding: 0;
}

.pages {
    width: 100%;
    max-width: 100%;
    min-width: 100%;
    flex: 0 0 100%;
    height: 100%;
    display: flex;
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    user-select: none;
}

.pages::-webkit-scrollbar {
    display: none;
}

.page {
    flex: 0 0 100%;
    min-width: 100%;
    max-width: 100%;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    scroll-snap-align: start;
    padding: 8px var(--gap) 10px;
}

.task-page {
    display: grid;
    grid-template-rows: minmax(0, 40%) minmax(0, 1fr) auto;
    /* grid-template-rows: minmax(0, 45fr) minmax(0, 55fr) auto; */
    align-content: stretch;
}

.review-page {
    min-height: 0;
    height: 100%;
}

.ad-page {
    min-height: 0;
    height: 100%;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 10px;
}

.ad-page frame-panel {
    min-height: 0;
    height: auto;
}

.ad-action-row {
    flex: 0 0 auto;
    padding: 0 4px;
}

.ad-action-row .btn-next {
    width: 100%;
    max-width: none;
    border-color: rgba(72, 44, 126, 0.92);
    background: linear-gradient(180deg, #e8dbff, #bea4f2);
    color: #2e1f4c;
    box-shadow: 0 8px 18px rgba(83, 56, 130, 0.16);
}

.ad-layout {
    min-height: 0;
    height: 100%;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px;
}

.ad-cta {
    display: flex;
    justify-content: center;
    align-items: stretch;
}

.btn-next {
    max-width: 360px;
}

.ad-card {
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(180px, 1fr) auto;
    gap: 12px;
    padding: 12px;
    border-radius: 18px;
    border: 1px solid rgba(72, 44, 126, 0.18);
    background:
        radial-gradient(circle at 12% 10%, rgba(255, 255, 255, 0.9), transparent 30%),
        linear-gradient(160deg, rgba(255, 255, 255, 0.98), rgba(236, 226, 250, 0.96));
    box-shadow: 0 10px 24px rgba(72, 44, 126, 0.09);
    text-decoration: none;
    color: inherit;
    overflow: hidden;
}

.ad-image-link {
    display: block;
    min-height: 180px;
    border-radius: 14px;
    overflow: hidden;
}

.ad-card:focus-visible {
    outline: 2px solid rgba(131, 104, 189, 0.62);
    outline-offset: 3px;
}

.ad-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: linear-gradient(135deg, #f1e8fb, #d9c7ef);
    border: 1px solid rgba(72, 44, 126, 0.08);
}

.ad-image-link:focus-visible {
    outline: 2px solid rgba(131, 104, 189, 0.62);
    outline-offset: 3px;
}

.ad-midle {
    text-align: center;
}
.ad-button {
    width: 80%;
    /* outline: 2px solid rgba(131, 104, 189, 0.62); */
    outline-offset: 3px;

}

.ad-copy {
    display: grid;
    gap: 4px;
    align-content: start;
}

.ad-label {
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.18em;
    color: rgba(72, 44, 126, 0.72);
}

.ad-copy strong {
    font-size: 16px;
    line-height: 1.4;
    color: #37245f;
}

.ad-copy p {
    margin: 0;
    font-size: 12px;
    line-height: 1.6;
    color: rgba(36, 48, 34, 0.72);
    overflow-wrap: anywhere;
    word-break: break-word;
}


.meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.chip {
    padding: 5px 9px;
    border-radius: 999px;
    border: 1px solid var(--line-soft);
    background: var(--panel-soft);
    font-size: 11px;
    color: var(--muted);
}

.problem {
    margin: 0;
    line-height: 1.8;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.choice-list {
    display: grid;
    gap: 10px;
}

.choice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid rgba(47, 59, 33, 0.13);
    background: linear-gradient(180deg, #fffdf8, #f9f6ee);
    box-shadow: 0 2px 8px rgba(36, 48, 34, 0.04);
}

.choice.is-locked {
    cursor: default;
}

.choice input {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--green-deep);
    align-self: center;
}

.choice input:disabled {
    opacity: 1;
    cursor: default;
}

.choice-id {
    flex: 0 0 auto;
    min-width: 2.2em;
    font-size: 14px;
    font-weight: 800;
    line-height: 1.6;
    color: #2f3f25;
    text-align: center;
}

.choice-copy {
    flex: 1 1 auto;
    min-width: 0;
}

.choice-text {
    line-height: 1.6;
    display: flex;
    align-items: center;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.action-bar {
    position: sticky;
    bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
}

.btn {
    width: 100%;
    appearance: none;
    border: 2px solid rgba(47, 59, 33, 0.9);
    border-radius: 14px;
    padding: 12px 14px;
    background: linear-gradient(180deg, #d9f19f, #b6d56e);
    color: #243022;
    font-size: 14px;
    font-weight: 900;
    box-shadow: 0 6px 16px rgba(90, 118, 55, 0.18);
}

.score {
    font-size: 28px;
    line-height: 1;
    font-weight: 900;
    color: #47641f;
    text-align: right;
}

.score small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 700;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.analysis {
    display: grid;
    gap: 14px;
}

.analysis-card {
    padding: 12px;
    border: 1px solid rgba(47, 59, 33, 0.14);
    border-radius: 14px;
    background: linear-gradient(180deg, #fffef9, #f8f5ec);
    box-shadow: 0 2px 8px rgba(36, 48, 34, 0.04);
}

.analysis-card h3 {
    margin: 0 0 6px;
    font-size: 14px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.analysis-card p {
    margin: 0;
    font-size: 13px;
    line-height: 1.6;
    color: var(--muted);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.bar {
    margin-top: 10px;
    height: 12px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.bar>span {
    display: block;
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--green-deep), #b5dd85);
    transition: width 420ms ease;
}

.review-list {
    display: grid;
    gap: 8px;
}

.review-item {
    width: 100%;
    appearance: none;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: #fff;
    padding: 10px 12px 0px 12px;
    border-radius: 10px;
    color: inherit;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    display: block;
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-y;
}

.review-item:active {
    background: #fff;
}

.review-item:focus {
    outline: none;
}

.review-item:focus-visible {
    outline: 2px solid rgba(95, 137, 196, 0.45);
    outline-offset: 3px;
}

.review-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 0;
}

.review-name {
    min-width: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.review-chevron {
    flex: 0 0 auto;
    font-size: 30px;
    line-height: 1;
    color: rgba(36, 48, 34, 0.48);
    transition: transform 180ms ease;
}

.review-item.is-expanded .review-chevron {
    transform: rotate(180deg);
}

.review-note {
    margin-top: 0;
    display: grid;
    grid-template-rows: 0fr;
    opacity: 0;
    transform: translateY(-1px);
    transition:
        grid-template-rows 520ms cubic-bezier(0.16, 1, 0.3, 1),
        opacity 320ms ease,
        transform 520ms cubic-bezier(0.16, 1, 0.3, 1),
        margin-top 520ms cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.review-item.is-expanded .review-note {
    grid-template-rows: 1fr;
    opacity: 1;
    transform: translateY(0);
    margin-top: 9px;
}

.review-note-inner {
    min-height: 0;
    overflow: hidden;
    padding-top: 8px;
    border-top: 1px dashed rgba(47, 59, 33, 0.16);
}

.review-item.is-expanded .review-note-inner {
    animation: note-pop 520ms cubic-bezier(0.16, 1, 0.3, 1);
}

.review-option {
    margin-top: 8px;
}

.review-option p {
    margin: 0;
    line-height: 1.6;
    color: var(--text);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.review-option math-show {
    max-width: 100%;
}

.review-note p {
    margin: 0;
    line-height: 1.6;
    color: var(--muted);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.review-note math-show {
    max-width: 100%;
}

@keyframes note-pop {
    from {
        opacity: 0.55;
        transform: translateY(-1px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.status-ok {
    color: #3f7a2e;
}

.status-bad {
    color: #9e4922;
}

.status-neutral {
    color: rgba(0, 0, 0, 0.58);
}

.review-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 1.5px solid rgba(47, 59, 33, 0.34);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
    vertical-align: middle;
    flex: 0 0 auto;
}

.review-check input {
    width: 100%;
    height: 100%;
    margin: 0;
    accent-color: var(--green-deep);
    pointer-events: none;
    cursor: default;
}

.review-check.is-unselected {
    opacity: 0.72;
}

.review-check.is-selected {
    border-color: rgba(63, 122, 46, 0.55);
}

#feedbackText {
    overflow-wrap: anywhere;
    word-break: break-word;
}

#feedbackText math-show {
    max-width: 100%;
    font-size: 1.5em;
}

/* MathJax 公式含分數、根號或上下標時，替該段文字保留足夠的上下空間。 */
.problem:has(mjx-container),
.choice-text:has(mjx-container),
.review-option p:has(mjx-container),
.review-note p:has(mjx-container) {
    line-height: 2.3;
}

/* 回饋區公式會放大為 1.5em，因此需要額外的行距。 */
#feedbackText:has(mjx-container) {
    line-height: 2.7;
}

math-show[inline]:has(mjx-container) {
    margin-block: 0.12em;
}

.shake {
    animation: shake 260ms ease-in-out;
}

.problem,
.choice-text,
.review-head,
.review-option p,
.review-note p,
.feedbackText {
    font-size: var(--normaltext);
    white-space: pre-line;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-3px);
    }

    40% {
        transform: translateX(3px);
    }

    60% {
        transform: translateX(-2px);
    }

    80% {
        transform: translateX(2px);
    }
}

@media (max-width: 520px) {
    .topbar {
        gap: 10px;
        padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
    }

    .brand-title {
        font-size: 16px;
    }

    .brand-sub {
        font-size: 10px;
        letter-spacing: 0.24em;
        line-height: 1.3;
    }

    .page-nav {
        width: 30px;
        height: 30px;
        font-size: 22px;
    }

    .score {
        font-size: 24px;
    }

    .problem,
    .choice-text,
    .review-head,
    .review-option p,
    .review-note p,
    .feedbackText {
        font-size: var(--mediumtext);
    }
}

@media (max-width: 390px) {
    .brand-sub {
        display: none;
    }

    .problem,
    .choice-text,
    .review-head,
    .review-option p,
    .review-note p,
    .feedbackText {
        font-size: var(--minitext);
    }
}

/* MetaMath diagnostic visual system */
.viewport {
    padding: 8px 0 0;
}

.page {
    padding: 8px 14px 14px;
    gap: 14px;
}

frame-panel[data-theme] {
    --panel-head-start: #1e3217;
    --panel-head-end: #2a4520;
    --panel-border: #dde0d5;
    --panel-body-start: #ffffff;
    --panel-body-end: #fafaf5;
    --panel-title: #ffffff;
}

.frame-panel-head {
    align-items: center;
    min-height: 30px;
    margin: 0 14px -15px;
    padding: 4px 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    box-shadow: 0 3px 8px rgba(30, 50, 23, 0.16);
    backdrop-filter: none;
}

.frame-panel-title {
    font-family: "Noto Serif TC", "Source Han Serif TC", "Songti TC", Georgia, serif;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.frame-panel-body {
    border-width: 1px;
    border-radius: 14px;
    box-shadow: 0 2px 6px rgba(30, 50, 23, 0.05), 0 1px 2px rgba(30, 50, 23, 0.04);
}

.panel-pad {
    padding: 22px 16px 18px;
}

.meta-row {
    gap: 7px;
    margin-bottom: 8px;
}

.chip {
    padding: 5px 10px;
    border: 0;
    background: #edf2e6;
    color: #3b5b2e;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 11px;
    font-weight: 700;
}

.choice-list {
    gap: 8px;
}

.choice {
    min-height: 56px;
    padding: 11px 12px;
    border: 1px solid #dde0d5;
    border-radius: 10px;
    background: #fff;
    box-shadow: none;
    transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.choice:has(input:checked) {
    border-color: #4d7440;
    background: #f6f9f1;
    box-shadow: inset 3px 0 #4d7440;
}

.choice input {
    width: 18px;
    height: 18px;
    accent-color: #3b5b2e;
}

.choice-id {
    min-width: 2em;
    color: #3b5b2e;
    font-family: "JetBrains Mono", ui-monospace, monospace;
}

.action-bar {
    padding: 0 2px env(safe-area-inset-bottom);
}

.btn {
    min-height: 46px;
    border: 1px solid #3b5b2e;
    border-radius: 9px;
    padding: 11px 14px;
    background: #3b5b2e;
    color: #fff;
    font-size: 14px;
    box-shadow: 0 4px 10px rgba(30, 50, 23, 0.16);
    transition: background 160ms ease, transform 160ms ease;
}

.btn:active {
    background: #2a4520;
    transform: translateY(1px);
}

.btn:focus-visible,
.choice:has(input:focus-visible),
.review-item:focus-visible {
    outline: 3px solid rgba(74, 134, 176, 0.42);
    outline-offset: 2px;
}

.ad-action-row .btn-next {
    border-color: #3b5b2e;
    background: #3b5b2e;
    color: #fff;
    box-shadow: 0 4px 10px rgba(30, 50, 23, 0.16);
}

.ad-card {
    padding: 10px;
    border: 1px solid #dde0d5;
    border-radius: 12px;
    background: #fff;
    box-shadow: none;
}

.ad-image {
    border: 0;
    border-radius: 8px;
    background: #f4f4ec;
}

.ad-button {
    width: min(80%, 360px);
}

.analysis-card {
    padding: 14px;
    border: 1px solid #dde0d5;
    border-radius: 12px;
    background: #fff;
    box-shadow: none;
}

.analysis-card h3 {
    font-family: "Noto Serif TC", "Source Han Serif TC", "Songti TC", Georgia, serif;
    font-size: 17px;
    font-weight: 600;
}

.review-item {
    border-color: #dde0d5;
    border-radius: 10px;
    background: #fff;
    padding: 11px 12px 2px;
}

.review-item.is-expanded {
    border-color: #b9cdb0;
    background: #f6f9f1;
}

.review-chevron {
    color: #4d7440;
}

.review-note-inner {
    border-top-color: #d5dfcf;
}

.status-ok { color: #3b6e30; }
.status-bad { color: #b4483c; }

.review-check {
    border-color: #aeb9a8;
    border-radius: 50%;
    box-shadow: none;
}

.review-check.is-selected {
    border-color: #3b5b2e;
}

@media (min-width: 720px) {
    .page {
        max-width: 840px;
        margin: 0 auto;
        padding-inline: 20px;
    }
}

@media (max-width: 520px) {
    .viewport { padding-top: 5px; }
    .page { padding: 7px 10px 10px; gap: 10px; }
    .panel-pad { padding: 20px 13px 14px; }
    .topbar { padding: calc(env(safe-area-inset-top) + 9px) 12px 6px; }
    .brand-logo { height: 52px; }
}
