/* =========================================================
   中文故事學堂 UI v2
   Mobile-first
   ========================================================= */

:root {
    --primary: #6c4cff;
    --primary-dark: #5034d7;
    --primary-soft: #eeeaff;

    --accent: #ffb020;
    --success: #15965f;
    --danger: #d14343;

    --background: #f6f7fb;
    --surface: #ffffff;
    --surface-soft: #f8f7ff;

    --text: #202238;
    --muted: #6d7285;
    --border: #e7e8f0;

    --shadow-sm: 0 4px 16px rgba(35, 38, 70, 0.06);
    --shadow-md: 0 12px 35px rgba(35, 38, 70, 0.10);

    --radius-sm: 12px;
    --radius-md: 18px;
    --radius-lg: 26px;

    --page-width: 1080px;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

/* ---------- Reset ---------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--background);
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        "PingFang TC",
        "Noto Sans TC",
        "Microsoft JhengHei",
        sans-serif;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

img {
    display: block;
    max-width: 100%;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea,
select {
    font: inherit;
}

button,
a,
label {
    -webkit-tap-highlight-color: transparent;
}

button,
.primary-link,
.option {
    touch-action: manipulation;
}

button {
    cursor: pointer;
}

h1,
h2,
h3,
p {
    overflow-wrap: break-word;
}

h1 {
    margin: 0;
    font-size: clamp(1.8rem, 7vw, 3.2rem);
    line-height: 1.2;
    letter-spacing: -0.025em;
}

h2 {
    font-size: clamp(1.35rem, 5vw, 1.9rem);
    line-height: 1.3;
}

h3 {
    line-height: 1.5;
}

/* ---------- Common ---------- */

.eyebrow {
    margin: 0 0 6px;
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.logo {
    display: grid;
    width: 64px;
    height: 64px;
    margin: 0 auto 18px;
    border-radius: 20px;
    background:
        linear-gradient(
            145deg,
            var(--primary),
            #8d74ff
        );
    color: #ffffff;
    place-items: center;
    font-size: 2rem;
    font-weight: 900;
    box-shadow: 0 12px 28px rgba(108, 76, 255, 0.28);
}

.primary-button,
.primary-link {
    display: inline-flex;
    width: 100%;
    min-height: 52px;
    padding: 12px 22px;
    border: 0;
    border-radius: 16px;
    background:
        linear-gradient(
            135deg,
            var(--primary),
            #8063ff
        );
    color: #ffffff;
    align-items: center;
    justify-content: center;
    font-weight: 850;
    line-height: 1.3;
    text-align: center;
    box-shadow: 0 8px 20px rgba(108, 76, 255, 0.22);
    transition:
        transform 150ms ease,
        box-shadow 150ms ease,
        opacity 150ms ease;
}

.primary-button:active,
.primary-link:active {
    transform: scale(0.98);
    box-shadow: 0 4px 12px rgba(108, 76, 255, 0.18);
}

.primary-button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.alert {
    margin-bottom: 18px;
    padding: 14px 16px;
    border-radius: 14px;
    font-size: 0.94rem;
    line-height: 1.65;
}

.alert ul {
    margin: 8px 0 0;
    padding-left: 20px;
}

.alert-success {
    background: #e8f8f0;
    color: #09683f;
}

.alert-error {
    background: #ffeded;
    color: #9c2929;
}

/* =========================================================
   Landing page
   ========================================================= */

.landing {
    display: grid;
    min-height: 100vh;
    min-height: 100dvh;
    padding:
        calc(24px + var(--safe-top))
        calc(16px + var(--safe-right))
        calc(24px + var(--safe-bottom))
        calc(16px + var(--safe-left));
    place-items: center;
    background:
        radial-gradient(
            circle at 10% 5%,
            #e8e1ff 0,
            transparent 35%
        ),
        radial-gradient(
            circle at 95% 95%,
            #dff6ee 0,
            transparent 32%
        ),
        var(--background);
}

.hero {
    width: 100%;
    max-width: 920px;
    padding: clamp(26px, 6vw, 52px);
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.93);
    box-shadow: var(--shadow-md);
    text-align: center;
    backdrop-filter: blur(16px);
}

.intro {
    max-width: 660px;
    margin: 16px auto 26px;
    color: var(--muted);
    font-size: clamp(1rem, 3.5vw, 1.15rem);
    line-height: 1.8;
}

.features {
    display: grid;
    gap: 12px;
    margin: 24px 0;
}

.feature {
    display: grid;
    min-height: 108px;
    padding: 18px;
    border-radius: 18px;
    background: var(--surface-soft);
    grid-template-columns: 48px 1fr;
    align-items: center;
    text-align: left;
}

.feature span {
    grid-row: span 2;
    font-size: 1.8rem;
}

.feature strong {
    font-size: 1rem;
}

.feature small {
    color: var(--muted);
    line-height: 1.5;
}

.status {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

/* =========================================================
   Auth
   ========================================================= */

.auth-page {
    display: grid;
    min-height: 100vh;
    min-height: 100dvh;
    padding:
        calc(20px + var(--safe-top))
        calc(16px + var(--safe-right))
        calc(20px + var(--safe-bottom))
        calc(16px + var(--safe-left));
    place-items: center;
    background:
        radial-gradient(
            circle at top,
            #eae5ff,
            transparent 44%
        ),
        var(--background);
}

.auth-card {
    width: 100%;
    max-width: 500px;
    padding: clamp(22px, 6vw, 38px);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-md);
}

.auth-card h1 {
    text-align: center;
}

.auth-intro {
    margin: 10px 0 24px;
    color: var(--muted);
    text-align: center;
}

.auth-form {
    display: grid;
    gap: 17px;
}

.auth-form label {
    display: grid;
    gap: 7px;
    font-size: 0.94rem;
    font-weight: 750;
}

.auth-form input,
.auth-form select {
    width: 100%;
    min-height: 52px;
    padding: 10px 14px;
    border: 1.5px solid #d8dbe6;
    border-radius: 14px;
    background: #ffffff;
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition:
        border-color 150ms ease,
        box-shadow 150ms ease;
}

.auth-form input:focus,
.auth-form select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(108, 76, 255, 0.12);
}

.auth-form small {
    color: var(--muted);
    font-weight: 400;
}

.back-link {
    display: block;
    min-height: 44px;
    margin-top: 16px;
    padding: 10px;
    color: var(--muted);
    text-align: center;
}

/* =========================================================
   App header
   ========================================================= */

.app-body {
    padding-bottom: var(--safe-bottom);
}

.app-header {
    position: sticky;
    z-index: 100;
    top: 0;
    display: flex;
    min-height: calc(62px + var(--safe-top));
    padding:
        calc(8px + var(--safe-top))
        calc(14px + var(--safe-right))
        8px
        calc(14px + var(--safe-left));
    border-bottom: 1px solid rgba(224, 226, 236, 0.85);
    background: rgba(255, 255, 255, 0.9);
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(18px);
}

.brand {
    display: flex;
    min-width: 0;
    gap: 9px;
    align-items: center;
    font-size: 0.94rem;
    font-weight: 850;
}

.brand-logo {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border-radius: 12px;
    background: var(--primary);
    color: #ffffff;
    place-items: center;
    font-weight: 900;
}

.app-header nav {
    display: flex;
    gap: 12px;
    align-items: center;
    color: var(--muted);
    font-size: 0.85rem;
}

.app-header nav a {
    display: inline-flex;
    min-height: 40px;
    padding: 8px 10px;
    border-radius: 10px;
    color: var(--primary-dark);
    align-items: center;
    font-weight: 750;
}

/* =========================================================
   Dashboard
   ========================================================= */

.dashboard {
    width: min(
        var(--page-width),
        calc(100% - 28px - var(--safe-left) - var(--safe-right))
    );
    margin: 18px auto 60px;
}

.welcome-panel {
    display: grid;
    padding: clamp(22px, 6vw, 34px);
    border-radius: 24px;
    background:
        linear-gradient(
            145deg,
            #6041ed,
            #8b70ff
        );
    color: #ffffff;
    gap: 18px;
    box-shadow: 0 14px 30px rgba(88, 59, 220, 0.2);
}

.welcome-panel .eyebrow {
    color: #e8e2ff;
}

.welcome-panel h1 {
    font-size: clamp(1.7rem, 7vw, 2.7rem);
}

.welcome-panel p {
    margin-bottom: 0;
    color: #f0edff;
}

.grade-badge {
    display: inline-grid;
    width: max-content;
    min-width: 92px;
    padding: 12px 18px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.14);
    place-items: center;
    font-size: 1.2rem;
    font-weight: 900;
}

.grade-badge small {
    font-size: 0.72rem;
    font-weight: 650;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
    margin: 14px 0;
}

.stat-card {
    display: grid;
    min-width: 0;
    padding: 14px 6px;
    border-radius: 17px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.stat-card span {
    font-size: 1.45rem;
}

.stat-card strong {
    margin-top: 4px;
    font-size: clamp(0.95rem, 4vw, 1.35rem);
}

.stat-card small {
    color: var(--muted);
    font-size: 0.68rem;
    line-height: 1.3;
}

.daily-lesson-card {
    display: grid;
    padding: 20px;
    border-radius: 22px;
    background: var(--surface);
    gap: 17px;
    box-shadow: var(--shadow-sm);
}

.lesson-icon {
    display: grid;
    width: 58px;
    height: 58px;
    border-radius: 18px;
    background: var(--primary-soft);
    place-items: center;
    font-size: 1.8rem;
}

.lesson-summary h2 {
    margin: 3px 0 8px;
}

.lesson-summary p {
    color: var(--muted);
}

.lesson-summary ul {
    display: flex;
    margin: 14px 0 0;
    padding: 0;
    gap: 7px;
    flex-wrap: wrap;
    list-style: none;
}

.lesson-summary li {
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 0.75rem;
    font-weight: 750;
}

.lesson-action {
    display: grid;
    gap: 9px;
}

.lesson-action > span {
    color: var(--muted);
    font-size: 0.8rem;
    text-align: center;
}

.lesson-action form {
    width: 100%;
}

.history-section {
    margin-top: 15px;
    padding: 20px;
    border-radius: 22px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.history-section h2 {
    margin-top: 0;
}

.empty-state {
    padding: 28px 18px;
    border-radius: 17px;
    background: var(--surface-soft);
    color: var(--muted);
    text-align: center;
}

.empty-state span {
    font-size: 2rem;
}

.attempt-list {
    display: grid;
}

.attempt-list article {
    display: flex;
    padding: 15px 3px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.attempt-list article:last-child {
    border-bottom: 0;
}

.attempt-list article div {
    display: grid;
}

.attempt-list small {
    color: var(--muted);
}

/* =========================================================
   Lesson
   ========================================================= */

.lesson-container,
.result-container {
    width: min(
        900px,
        calc(100% - 24px - var(--safe-left) - var(--safe-right))
    );
    margin: 14px auto 50px;
}

.lesson-heading {
    padding: 23px 20px;
    border-radius: 22px;
    background:
        linear-gradient(
            145deg,
            #6041ed,
            #8b70ff
        );
    color: #ffffff;
    box-shadow: 0 12px 28px rgba(88, 59, 220, 0.18);
}

.lesson-heading .eyebrow {
    color: #e8e2ff;
}

.lesson-heading p:last-child {
    margin-bottom: 0;
    color: #f0edff;
}

.vocabulary-box,
.story-card,
.questions-card,
.answer-review {
    margin-top: 14px;
    padding: 20px 16px;
    border-radius: 22px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.vocabulary-box h2,
.story-card > h2,
.answer-review > h2 {
    margin-top: 0;
}

/*
 * 手機：詞語卡左右滑動
 */
.vocabulary-grid {
    display: grid;
    margin-right: -16px;
    padding-right: 16px;
    grid-auto-columns: minmax(230px, 82%);
    grid-auto-flow: column;
    gap: 11px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: inline mandatory;
    scrollbar-width: none;
}

.vocabulary-grid::-webkit-scrollbar {
    display: none;
}

.vocabulary-grid article {
    min-height: 165px;
    padding: 17px;
    border: 1px solid #ebe8ff;
    border-radius: 17px;
    background: var(--surface-soft);
    scroll-snap-align: start;
}

.vocabulary-grid strong {
    color: var(--primary-dark);
    font-size: 1.25rem;
}

.vocabulary-grid p {
    margin: 7px 0;
}

.vocabulary-grid small {
    color: var(--muted);
    line-height: 1.65;
}

.story-section {
    padding: 18px 0;
    border-bottom: 1px solid var(--border);
}

.story-section:last-child {
    border-bottom: 0;
}

.story-section h3 {
    margin: 0 0 9px;
    color: var(--primary-dark);
    font-size: 1.08rem;
}

.story-section p {
    margin: 0;
    color: #292c3d;
    font-size: clamp(1.05rem, 4.3vw, 1.18rem);
    line-height: 2;
    letter-spacing: 0.02em;
}

.questions-heading {
    padding-bottom: 8px;
}

.questions-heading h2 {
    margin: 0;
}

.task-progress {
    position: sticky;
    z-index: 30;
    top: calc(63px + var(--safe-top));
    margin: 0 -16px;
    padding: 11px 16px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
}

.task-progress-text {
    display: flex;
    margin-bottom: 7px;
    color: var(--muted);
    justify-content: space-between;
    font-size: 0.76rem;
    font-weight: 700;
}

.task-progress-track {
    height: 7px;
    border-radius: 999px;
    background: #e8e6f0;
    overflow: hidden;
}

.task-progress-bar {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background:
        linear-gradient(
            90deg,
            var(--primary),
            #9a7fff
        );
    transition: width 250ms ease;
}

.question-block {
    display: grid;
    padding: 24px 0;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.question-number {
    display: grid;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    place-items: center;
    font-weight: 900;
}

.question-content h3 {
    margin: 0 0 14px;
    font-size: 1.05rem;
}

.option-list {
    display: grid;
    gap: 10px;
}

.option {
    display: grid;
    min-height: 58px;
    padding: 13px 14px;
    border: 1.5px solid #dcdeea;
    border-radius: 15px;
    background: #ffffff;
    grid-template-columns: 24px 1fr;
    gap: 10px;
    align-items: center;
    cursor: pointer;
    transition:
        border-color 140ms ease,
        background 140ms ease,
        transform 140ms ease;
}

.option:active {
    transform: scale(0.99);
}

.option:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 0 0 3px rgba(108, 76, 255, 0.09);
}

.option input {
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--primary);
}

.option span {
    line-height: 1.55;
}

.question-content textarea {
    width: 100%;
    min-height: 140px;
    padding: 15px;
    border: 1.5px solid #d9dce7;
    border-radius: 15px;
    background: #ffffff;
    color: var(--text);
    font-size: 1rem;
    line-height: 1.8;
    outline: none;
    resize: vertical;
}

.question-content textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(108, 76, 255, 0.11);
}

.question-help {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 0.78rem;
}

.submit-area {
    position: sticky;
    z-index: 40;
    bottom: 0;
    margin:
        20px -16px
        calc(-20px - var(--safe-bottom));
    padding:
        12px 16px
        calc(12px + var(--safe-bottom));
    border-top: 1px solid rgba(220, 222, 234, 0.9);
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 -10px 24px rgba(35, 38, 70, 0.08);
    backdrop-filter: blur(16px);
}

.submit-area p {
    display: none;
}

.submit-area .primary-button {
    min-height: 56px;
}

/* =========================================================
   Result
   ========================================================= */

.result-summary {
    display: grid;
    padding: 24px 20px;
    border-radius: 22px;
    background:
        linear-gradient(
            145deg,
            #6041ed,
            #8b70ff
        );
    color: #ffffff;
    gap: 18px;
    box-shadow: 0 12px 28px rgba(88, 59, 220, 0.2);
}

.result-summary .eyebrow {
    color: #e8e2ff;
}

.result-summary h1 {
    font-size: 2rem;
}

.result-score {
    display: grid;
    width: 106px;
    height: 106px;
    border: 4px solid rgba(255, 255, 255, 0.38);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    place-items: center;
    font-size: 1.75rem;
    font-weight: 900;
}

.review-item {
    display: grid;
    padding: 22px 0;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}

.review-item:last-child {
    border-bottom: 0;
}

.review-status {
    font-size: 1.7rem;
}

.review-content h3 {
    margin: 0 0 12px;
    font-size: 1rem;
}

.review-content p {
    line-height: 1.7;
}

.correct-answer {
    color: var(--success);
}

.feedback-text {
    padding: 13px 14px;
    border-radius: 13px;
    background: var(--surface-soft);
    color: #555a6d;
    font-size: 0.9rem;
}

.student-sentence {
    padding: 14px;
    border-left: 4px solid var(--primary);
    border-radius: 0 12px 12px 0;
    background: var(--surface-soft);
    line-height: 1.8;
}

.result-actions {
    position: sticky;
    z-index: 30;
    bottom: 0;
    margin-top: 16px;
    padding:
        12px 0
        calc(12px + var(--safe-bottom));
    background:
        linear-gradient(
            transparent,
            var(--background) 28%
        );
}

/* =========================================================
   Tablet / Desktop
   ========================================================= */

@media (min-width: 700px) {
    .primary-button,
    .primary-link {
        width: auto;
    }

    .features {
        grid-template-columns: repeat(3, 1fr);
    }

    .feature {
        min-height: 150px;
        grid-template-columns: 1fr;
        text-align: center;
    }

    .feature span {
        grid-row: auto;
    }

    .app-header {
        padding-right:
            max(24px, calc((100% - var(--page-width)) / 2));
        padding-left:
            max(24px, calc((100% - var(--page-width)) / 2));
    }

    .dashboard {
        margin-top: 28px;
    }

    .welcome-panel {
        grid-template-columns: 1fr auto;
        align-items: center;
    }

    .grade-badge {
        min-width: 115px;
        min-height: 115px;
        border-radius: 50%;
        align-content: center;
    }

    .stats-grid {
        gap: 15px;
        margin: 20px 0;
    }

    .stat-card {
        padding: 22px;
    }

    .stat-card small {
        font-size: 0.8rem;
    }

    .daily-lesson-card {
        padding: 27px;
        grid-template-columns: auto 1fr auto;
        align-items: center;
    }

    .lesson-action {
        min-width: 165px;
    }

    .vocabulary-box,
    .story-card,
    .questions-card,
    .answer-review {
        padding: 28px;
    }

    .vocabulary-grid {
        margin-right: 0;
        padding-right: 0;
        grid-template-columns: repeat(2, 1fr);
        grid-auto-flow: row;
        overflow: visible;
    }

    .question-block {
        grid-template-columns: 42px 1fr;
        gap: 16px;
    }

    .submit-area {
        margin-right: -28px;
        margin-bottom: -28px;
        margin-left: -28px;
        padding-right: 28px;
        padding-left: 28px;
    }

    .result-summary {
        grid-template-columns: auto 1fr;
        padding: 32px;
        align-items: center;
    }

    .review-item {
        grid-template-columns: 42px 1fr;
    }
}

@media (min-width: 980px) {
    .vocabulary-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .lesson-heading {
        padding: 34px;
    }
}

/* ---------- Accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* =========================================================
   P1 learning mode
   ========================================================= */

.p1-body {
    background:
        radial-gradient(
            circle at top right,
            #eee9ff,
            transparent 36%
        ),
        #f7f8fc;
}

.p1-header {
    position: sticky;
    z-index: 100;
    top: 0;
    display: grid;
    min-height: calc(66px + var(--safe-top));
    padding:
        calc(8px + var(--safe-top))
        calc(14px + var(--safe-right))
        8px
        calc(14px + var(--safe-left));
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.94);
    grid-template-columns: 44px 1fr auto;
    gap: 10px;
    align-items: center;
    backdrop-filter: blur(16px);
}

.p1-back {
    display: grid;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    place-items: center;
    font-size: 2rem;
    line-height: 1;
}

.p1-header-title {
    display: grid;
    min-width: 0;
}

.p1-header-title strong {
    overflow: hidden;
    font-size: 0.95rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.p1-header-title small {
    color: var(--muted);
    font-size: 0.72rem;
}

.p1-step-count {
    color: var(--primary-dark);
    font-size: 0.85rem;
    font-weight: 850;
}

.p1-progress {
    position: sticky;
    z-index: 90;
    top: calc(66px + var(--safe-top));
    height: 7px;
    background: #e8e6f0;
}

.p1-progress span {
    display: block;
    height: 100%;
    border-radius: 0 999px 999px 0;
    background:
        linear-gradient(
            90deg,
            var(--primary),
            #9a81ff
        );
    transition: width 250ms ease;
}

.p1-learning-app {
    width: min(680px, calc(100% - 24px));
    margin: 0 auto;
    padding: 22px 0 130px;
}

.p1-step {
    display: none;
    min-height: calc(100dvh - 220px);
}

.p1-step.is-active {
    display: block;
    animation: p1StepIn 220ms ease;
}

@keyframes p1StepIn {
    from {
        opacity: 0;
        transform: translateX(10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.p1-step-heading {
    margin-bottom: 22px;
    text-align: center;
}

.p1-step-heading h1 {
    margin-top: 8px;
    font-size: clamp(1.65rem, 7vw, 2.5rem);
    line-height: 1.4;
}

.p1-mode-label {
    display: inline-flex;
    padding: 7px 13px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 0.78rem;
    font-weight: 850;
}

.p1-flashcard {
    position: relative;
    display: grid;
    min-height: 390px;
    padding: 25px 20px;
    border: 2px solid #e9e5ff;
    border-radius: 30px;
    background: #ffffff;
    box-shadow: 0 18px 45px rgba(53, 46, 110, 0.1);
    place-items: center;
    align-content: center;
}

.p1-character {
    font-family:
        "Noto Sans TC",
        "PingFang TC",
        "Microsoft JhengHei",
        sans-serif;
    font-size: clamp(7rem, 38vw, 11rem);
    font-weight: 700;
    line-height: 1;
}

.p1-speak-button {
    position: absolute;
    top: 18px;
    right: 18px;
    display: grid;
    width: 50px;
    height: 50px;
    border: 0;
    border-radius: 16px;
    background: var(--primary-soft);
    place-items: center;
    font-size: 1.35rem;
}

.p1-reveal-button,
.p1-reset-sentence,
.p1-listen-prompt {
    min-height: 48px;
    padding: 10px 18px;
    border: 0;
    border-radius: 14px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 850;
}

.p1-card-detail {
    width: 100%;
    margin-top: 18px;
    text-align: center;
}

.p1-card-detail strong {
    color: var(--primary-dark);
    font-size: 2rem;
}

.p1-card-detail p {
    font-size: 1.12rem;
}

.p1-example {
    padding: 13px;
    border-radius: 13px;
    background: #f7f6fb;
    font-size: 1.12rem;
}

.p1-confidence-options {
    display: grid;
    margin-top: 15px;
    gap: 9px;
}

.p1-confidence-options label {
    cursor: pointer;
}

.p1-confidence-options input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.p1-confidence-options span {
    display: flex;
    min-height: 58px;
    padding: 12px 16px;
    border: 2px solid #e1e2eb;
    border-radius: 16px;
    background: #fff;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    font-weight: 800;
}

.p1-confidence-options input:checked + span {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.p1-listen-prompt {
    display: flex;
    margin: 0 auto 18px;
    align-items: center;
    justify-content: center;
}

.p1-choice-grid {
    display: grid;
    gap: 12px;
}

.p1-choice {
    cursor: pointer;
}

.p1-choice input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.p1-choice span {
    display: grid;
    min-height: 72px;
    padding: 14px 18px;
    border: 2px solid #dfe1eb;
    border-radius: 19px;
    background: #ffffff;
    place-items: center;
    font-size: clamp(1.25rem, 5.5vw, 1.65rem);
    font-weight: 750;
    line-height: 1.45;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.p1-choice input:checked + span {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary-dark);
    box-shadow: 0 0 0 4px rgba(108, 76, 255, 0.1);
}

.p1-character-options {
    grid-template-columns: repeat(2, 1fr);
}

.p1-character-options .p1-choice span {
    min-height: 140px;
    font-size: clamp(4rem, 22vw, 6rem);
    font-weight: 650;
}

.p1-sentence-builder {
    display: grid;
    gap: 18px;
}

.p1-answer-zone {
    min-height: 160px;
    padding: 17px;
    border: 3px dashed #d7d3eb;
    border-radius: 22px;
    background: #fbfaff;
}

.p1-answer-zone > p {
    margin: 0;
    color: var(--muted);
    text-align: center;
}

.p1-answer-zone.has-tokens > p {
    display: none;
}

.p1-selected-tokens,
.p1-token-bank {
    display: flex;
    min-height: 70px;
    gap: 9px;
    flex-wrap: wrap;
    align-content: flex-start;
}

.p1-selected-tokens {
    align-items: center;
}

.p1-token-bank {
    padding: 18px;
    border-radius: 20px;
    background: #ffffff;
    box-shadow: var(--shadow-sm);
}

.p1-token {
    min-height: 54px;
    padding: 10px 15px;
    border: 2px solid #dcdde8;
    border-radius: 14px;
    background: #ffffff;
    color: var(--text);
    font-size: clamp(1.25rem, 6vw, 1.7rem);
    font-weight: 800;
}

.p1-selected-tokens .p1-token {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.p1-reset-sentence {
    justify-self: center;
}

.p1-mini-story {
    display: grid;
    gap: 13px;
}

.p1-mini-story article {
    display: grid;
    min-height: 100px;
    padding: 18px;
    border-radius: 20px;
    background: #ffffff;
    grid-template-columns: 48px 1fr;
    gap: 12px;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.p1-mini-story button {
    display: grid;
    width: 46px;
    height: 46px;
    border: 0;
    border-radius: 14px;
    background: var(--primary-soft);
    place-items: center;
}

.p1-mini-story p {
    margin: 0;
    font-size: clamp(1.35rem, 6vw, 1.8rem);
    line-height: 1.8;
}

.p1-ready-box {
    margin-top: 20px;
    padding: 23px;
    border-radius: 22px;
    background: #eaf8f1;
    color: #09683f;
    text-align: center;
}

.p1-ready-box span {
    display: block;
    font-size: 2.5rem;
}

.p1-ready-box strong {
    display: block;
    font-size: 1.25rem;
}

.p1-bottom-controls {
    position: fixed;
    z-index: 120;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    padding:
        12px
        calc(12px + var(--safe-right))
        calc(12px + var(--safe-bottom))
        calc(12px + var(--safe-left));
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.96);
    grid-template-columns: minmax(90px, 0.4fr) 1fr;
    gap: 10px;
    box-shadow: 0 -12px 30px rgba(35, 38, 70, 0.09);
    backdrop-filter: blur(16px);
}

.p1-bottom-controls .primary-button {
    width: 100%;
}

.p1-secondary-button {
    min-height: 54px;
    padding: 10px 14px;
    border: 0;
    border-radius: 16px;
    background: #eff0f5;
    color: var(--text);
    font-weight: 800;
}

.p1-secondary-button:disabled {
    opacity: 0.45;
}

.p1-message {
    position: fixed;
    z-index: 200;
    right: 18px;
    bottom: calc(92px + var(--safe-bottom));
    left: 18px;
    max-width: 500px;
    margin: auto;
    padding: 14px 18px;
    border-radius: 15px;
    background: #29283b;
    color: #ffffff;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.p1-result-page {
    width: min(700px, calc(100% - 24px));
    margin: 0 auto;
    padding:
        calc(24px + var(--safe-top))
        0
        calc(40px + var(--safe-bottom));
}

.p1-result-hero {
    padding: 28px 20px;
    border-radius: 28px;
    background:
        linear-gradient(
            145deg,
            #6041ed,
            #8b70ff
        );
    color: #ffffff;
    text-align: center;
    box-shadow: 0 15px 36px rgba(88, 59, 220, 0.22);
}

.p1-result-hero .eyebrow {
    color: #e9e4ff;
}

.p1-result-emoji {
    font-size: 4rem;
}

.p1-result-score {
    display: grid;
    width: 110px;
    height: 110px;
    margin: 20px auto;
    border: 4px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    place-items: center;
    font-size: 2rem;
    font-weight: 900;
}

.p1-result-section {
    margin-top: 16px;
    padding: 20px;
    border-radius: 22px;
    background: #ffffff;
    box-shadow: var(--shadow-sm);
}

.p1-word-status-list {
    display: grid;
    gap: 10px;
}

.p1-word-status-list article {
    display: grid;
    padding: 13px;
    border-radius: 16px;
    background: #f7f6fb;
    grid-template-columns: 70px 1fr;
    gap: 13px;
    align-items: center;
}

.p1-word-status-list article > strong {
    font-size: 3.5rem;
    line-height: 1;
    text-align: center;
}

.p1-word-status-list article div {
    display: grid;
}

.p1-word-status-list small {
    color: var(--muted);
}

.p1-challenge-results {
    display: grid;
}

.p1-challenge-results article {
    display: grid;
    padding: 17px 0;
    border-bottom: 1px solid var(--border);
    grid-template-columns: 42px 1fr;
    gap: 12px;
}

.p1-challenge-results article:last-child {
    border-bottom: 0;
}

.p1-result-icon {
    display: grid;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    place-items: center;
    font-weight: 900;
}

.p1-challenge-results .is-correct .p1-result-icon {
    background: #e5f8ee;
    color: #087045;
}

.p1-challenge-results .is-wrong .p1-result-icon {
    background: #fff2dd;
    color: #a85b00;
}

.p1-challenge-results p {
    margin-bottom: 0;
    color: var(--muted);
}

.p1-built-sentence {
    margin-top: 10px;
    padding: 12px;
    border-radius: 12px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 1.2rem;
    font-weight: 800;
}

.p1-result-actions {
    margin-top: 18px;
}

@media (min-width: 650px) {
    .p1-confidence-options {
        grid-template-columns: repeat(3, 1fr);
    }

    .p1-choice-grid:not(.p1-character-options) {
        grid-template-columns: repeat(2, 1fr);
    }

    .p1-bottom-controls {
        right: auto;
        left: 50%;
        width: min(680px, calc(100% - 24px));
        transform: translateX(-50%);
        border: 1px solid var(--border);
        border-bottom: 0;
        border-radius: 20px 20px 0 0;
    }
}