/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    overscroll-behavior-y: none;
    /* Prevent iOS rubber-banding */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    font-size: 18px;
    line-height: 1.6;
    color: #333;
    background: #f5f5f5;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Container */
#app {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    /* Use dynamic viewport height for mobile browsers */
    min-height: 0;
    overflow: hidden;
    background: white;
    display: flex;
    flex-direction: column;
}

/* Direct children of #app (router-view renders component directly) fill full height */
#app>* {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.header h1 {
    font-size: 24px;
    font-weight: 600;
}

/* Back to the Kids Portal: same house icon as the other kids apps */
.header-with-portal {
    position: relative;
    padding-left: 60px;
    padding-right: 60px;
}

.portal-link {
    position: absolute;
    top: 50%;
    left: max(8px, env(safe-area-inset-left));
    transform: translateY(-50%);
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: white;
}

.portal-link svg {
    width: 26px;
    height: 26px;
}

.portal-link:active {
    background: rgba(255, 255, 255, 0.2);
}

/* Navigation */
.nav-buttons {
    padding: 15px;
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

/* Buttons */
.btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 20px;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    touch-action: manipulation;
    position: relative;
    overflow: hidden; /* For ripple effect */
}

/* Ripple effect for buttons */
.btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: rgba(255, 255, 255, 0.4);
    opacity: 0;
    border-radius: 100%;
    transform: translate(-50%, -50%) scale(0);
}

.btn-secondary::after {
    background: rgba(0, 0, 0, 0.1);
}

@keyframes ripple {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0.5;
    }
    100% {
        transform: translate(-50%, -50%) scale(40);
        opacity: 0;
    }
}

.btn:active::after {
    animation: ripple 0.4s ease-out;
}

.btn-primary {
    background: #5568d3; /* one shade under the #667eea brand so white text reads (4.9:1) */
    color: white;
}

.btn-primary:active {
    background: #4553c0;
    transform: scale(0.98);
}

/* Pale like the other disabled buttons, so "nothing selected yet" is visible */
.btn-primary:disabled {
    background: #b3bdf3;
    cursor: not-allowed;
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-secondary:active {
    background: #d0d0d0;
    transform: scale(0.98);
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:active {
    background: #c0392b;
    transform: scale(0.98);
}

.btn-large {
    width: 100%;
    font-size: 20px;
    padding: 16px;
}

.btn-full {
    width: 100%;
    display: block;
}

.mt-10 {
    margin-top: 10px;
}

/* Content Area */
.content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    /* Important for nested flex scrolling */
}

/* Page wrapper - ensures pages fill #app and allow content scrolling */
.page-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    flex: 1;
}

.content.full-height {
    padding: 0;
    height: 100%;
}

/* Home Page - Lesson Selector */
.lesson-selector {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.lesson-selector h2 {
    font-size: 22px;
    margin: 15px 20px;
    color: #667eea;
    display: none;
    /* Hide H2 in fullscreen mode layout */
}

/* Drag Selection Box */
.selection-box {
    position: fixed;
    border: 1px solid rgba(102, 126, 234, 0.8);
    background-color: rgba(102, 126, 234, 0.2);
    pointer-events: none;
    z-index: 1000;
}

/* Split Layout */
.lesson-selection-container {
    display: flex;
    flex: 1;
    height: 100%;
    /* Take full remaining height */
    overflow: hidden;
}

/* Left Panel */
.selection-sidebar {
    width: 33.33%;
    min-width: 280px;
    max-width: 350px;
    /* Fixed width */
    background: #f8f8f8;
    padding: 20px;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    flex-shrink: 0;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-label {
    font-weight: 600;
    font-size: 16px;
    color: #555;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.filter-mini-btn {
    font-size: 14px;
    padding: 6px 14px;
    min-height: 34px;
    border-radius: 17px;
    border: 1px solid #d1d5db;
    background: white;
    color: #4b5563;
    cursor: pointer;
    font-weight: 500;
}

.filter-mini-btn:hover {
    background: #f3f4f6;
}

.year-chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.year-chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border: 1px solid #d1d5db;
    border-radius: 16px;
    background: white;
    color: #4b5563;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.year-chip.active {
    background: #16a085;
    color: white;
    border-color: #16a085;
}

.year-chip input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.filter-select {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 16px;
    background: white;
}

.selection-stats {
    padding: 15px 0;
    border-top: 1px solid #e0e0e0;
    border-bottom: 1px solid #e0e0e0;
    text-align: center;
}

.selection-stats p {
    margin-bottom: 10px;
    font-weight: 600;
    color: #667eea;
}

.btn-small {
    padding: 8px 16px;
    font-size: 14px;
    width: 100%;
}

/* Right Panel */
.selection-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: white;
}

/* Sidebar Test Config */
.test-config-sidebar {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.config-section-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
}

.config-row-sidebar {
    margin-bottom: 10px;
}

.config-label-small {
    font-weight: 600;
    font-size: 14px;
    display: block;
    margin-bottom: 5px;
    color: #666;
}

.config-input-small {
    width: 100%;
    min-height: 44px;
    padding: 8px;
    font-size: 16px;
    border: 1px solid #ddd;
    border-radius: 6px;
}

/* Shown above the disabled start buttons until a lesson is picked */
/* "?" button with the date of the last update, under the home page buttons */
.home-changelog {
    margin-top: 14px;
    text-align: center;
    font-size: 14px;
    color: #5f6b7a;
}

.config-hint {
    background: #eef2ff;
    color: #3f51b5;
    font-size: 15px;
    text-align: center;
    padding: 10px 12px;
    border-radius: 8px;
}

.radio-group-sidebar {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-item-small {
    display: flex;
    align-items: center;
    min-height: 44px; /* whole row is the tap target */
    font-size: 16px;
    cursor: pointer;
}

.radio-item-small input {
    margin-right: 8px;
    width: 18px;
    height: 18px;
}

/* 「（共 N 題）」 beside 全部複習 */
.config-count-note {
    color: #555;
}

/* =============================================
   Mobile Tab Bar (hidden on desktop)
   ============================================= */
.mobile-tab-bar {
    display: none;
}

/* Desktop: sidebar-filters and sidebar-config are transparent wrappers
   so the parent .selection-sidebar gap applies directly to their children */
.sidebar-filters,
.sidebar-config {
    display: contents;
}

/* Mobile Responsiveness */
@media (max-width: 767px) {
    html, body {
        height: auto;
        overflow-y: auto;
    }

    #app {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    /* Allow the home page wrapper to grow beyond the viewport on mobile */
    .test-container-wrapper {
        height: auto;
        overflow: visible;
    }

    /* Allow full-height content to expand naturally on mobile */
    .content.full-height {
        height: auto;
    }

    /* Allow lesson selector to expand naturally on mobile */
    .lesson-selector {
        height: auto;
    }

    /* Show mobile tab bar */
    .mobile-tab-bar {
        display: flex;
        border-bottom: 2px solid #e0e0e0;
        background: white;
        flex-shrink: 0;
    }

    .mobile-tab-btn {
        flex: 1;
        padding: 12px 8px;
        font-size: 16px;
        background: none;
        border: none;
        border-bottom: 3px solid transparent;
        margin-bottom: -2px;
        cursor: pointer;
        color: #999;
        font-weight: 500;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        min-height: 48px;
        touch-action: manipulation;
        transition: color 0.2s;
    }

    .mobile-tab-btn.active {
        color: #667eea;
        border-bottom-color: #667eea;
    }

    .tab-badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: #667eea;
        color: white;
        border-radius: 10px;
        font-size: 12px;
        min-width: 20px;
        height: 20px;
        padding: 0 5px;
        font-weight: 700;
    }

    /* Wrappers become real flex columns on mobile */
    .sidebar-filters,
    .sidebar-config {
        display: flex;
        flex-direction: column;
        gap: 20px;
    }

    .lesson-selection-container {
        flex-direction: column;
        height: auto;
    }

    .selection-sidebar {
        width: 100%;
        max-width: none;
        height: auto;
        border-right: none;
        overflow-y: visible;
    }

    /* Tab 1 (lessons): show filters + lesson list, hide config */
    .lesson-selector[data-mobile-tab="lessons"] .sidebar-config {
        display: none;
    }

    .lesson-selector[data-mobile-tab="lessons"] .selection-sidebar {
        border-bottom: 1px solid #ddd;
        padding-bottom: 15px;
    }

    .lesson-selector[data-mobile-tab="lessons"] .selection-content {
        height: auto;
        min-height: 300px;
    }

    /* Tab 2 (config): hide filters + lesson list, show config full-width */
    .lesson-selector[data-mobile-tab="config"] .sidebar-filters {
        display: none;
    }

    .lesson-selector[data-mobile-tab="config"] .selection-content {
        display: none;
    }

    .lesson-selector[data-mobile-tab="config"] .selection-sidebar {
        border-bottom: none;
    }

    .lesson-selector h2 {
        display: block;
    }
}

/* "下一步：測驗設定 →" — floats over the lesson list on the narrow-screen lessons tab */
.mobile-next-btn {
    display: none;
}

@media (max-width: 767px) {
    .mobile-next-btn {
        display: block;
        position: fixed;
        left: 16px;
        right: 16px;
        bottom: calc(16px + env(safe-area-inset-bottom));
        z-index: 50;
        min-height: 52px;
        font-size: 17px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    }

    /* Keep the last lesson clear of the floating button */
    .lesson-selector[data-mobile-tab="lessons"] .selection-content {
        padding-bottom: 88px;
    }
}

.grade-group {
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
}

.grade-header {
    background: #f8f8f8;
    padding: 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
    user-select: none;
    -webkit-user-select: none;
}

.grade-header-left {
    display: flex;
    align-items: center;
}

.grade-checkbox {
    width: 20px;
    height: 20px;
    margin-right: 12px;
}

.selected-chapters-label {
    font-size: 14px;
    color: #667eea;
    margin-left: 8px;
    font-weight: normal;
}

.grade-header:active {
    background: #efefef;
}

.grade-title {
    font-weight: 600;
    font-size: 18px;
}

.grade-arrow {
    font-size: 20px;
    transition: transform 0.3s;
}

.grade-arrow.expanded {
    transform: rotate(90deg);
}

.semester-group {
    border-top: 1px solid #ddd;
}

.semester-header {
    background: #fafafa;
    padding: 12px 15px 12px 30px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
}

.semester-header:active {
    background: #f0f0f0;
}

.book-group {
    border-top: 1px solid #eee;
}

.book-header {
    background: #fcfcfc;
    padding: 10px 15px 10px 45px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
}

.book-header:active {
    background: #f5f5f5;
}

.lesson-list {
    padding: 10px 15px 10px 60px;
}

.lesson-item {
    display: flex;
    align-items: center;
    padding: 10px 0;
    min-height: 44px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.lesson-item:active {
    background: #f9f9f9;
}

.lesson-checkbox {
    width: 20px;
    height: 20px;
    margin-right: 12px;
}

.lesson-label {
    font-size: 16px;
    flex: 1;
    display: flex;
    align-items: center;
}

.lesson-chapter {
    min-width: 90px;
    display: inline-block;
    padding-right: 20px;
}

.lesson-title {
    font-weight: 600;
}

.lesson-feature-badges {
    margin-left: 8px;
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.lesson-badge {
    display: inline-block;
    min-width: 20px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    background: #eef2ff;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    line-height: 1.3;
    text-align: center;
    user-select: none;
}

/* Narrow screens: let the badges drop to their own line instead of squeezing
   the title down to one character per line (no change when everything fits) */
@media (max-width: 767px) {
    .lesson-label {
        flex-wrap: wrap;
        row-gap: 4px;
    }
}

/* Test Configuration */
.test-config {
    background: #f8f8f8;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.config-row {
    margin-bottom: 20px;
}

.config-row:last-child {
    margin-bottom: 0;
}

.config-label {
    font-weight: 600;
    margin-bottom: 10px;
    display: block;
    font-size: 18px;
}

.config-input {
    width: 100%;
    padding: 12px;
    font-size: 18px;
    border: 1px solid #ddd;
    border-radius: 6px;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.radio-item {
    display: flex;
    align-items: center;
    min-height: 44px;
    cursor: pointer;
}

.radio-item input[type="radio"] {
    width: 20px;
    height: 20px;
    margin-right: 12px;
}

/* Test Page Container Wrapper */
.test-container-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Test Page */
.test-container {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 60px);
}

.progress-bar {
    background: #f0f0f0;
    padding: 15px 20px;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    color: #667eea;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

/* Bouncy Pop (Spring effect for Stars) */
@keyframes bouncyPop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.4); }
    70%  { transform: scale(0.85); }
    100% { transform: scale(1); }
}

.btn-star {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #ccc;
    padding: 0 5px;
    transition: transform 0.2s, color 0.2s;
    line-height: 1;
}

.btn-star.active {
    color: #f1c40f;
    animation: bouncyPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-star:active {
    transform: scale(0.8);
}

.btn-warning {
    background: #f1c40f;
    color: #333; /* white on yellow was 1.7:1 */
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.btn-warning:active {
    background: #d4ac0d;
    transform: scale(0.98);
}


.question-display {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 20px;
}

.question-word {
    font-size: 48px;
    text-align: center;
    margin-bottom: 0;
    line-height: 1.5;
}

.test-item {
    color: #e74c3c;
    text-decoration: underline;
    text-decoration-thickness: 3px;
    text-underline-offset: 4px;
    font-weight: 600;
}

/* Canvas Container */
.canvas-tools {
    position: relative;
    /* Let JS styling handle the flex/justify */
}

.canvas-container {
    display: flex;
    justify-content: center;
    margin: 5px 0;
}

.canvas-wrapper {
    border: 2px solid #667eea;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

canvas {
    display: block;
    touch-action: none;
    background: white;
    /* [PORTAL_SHRINK_STYLE_START] */
    transition: transform 0.5s ease-in-out, opacity 0.5s ease-in-out;
    /* [PORTAL_SHRINK_STYLE_END] */
}

/* [PORTAL_SHRINK_ANIMATION_START] */
.canvas-portal-shrink {
    transform: rotate(360deg) scale(0);
    opacity: 0;
}
/* [PORTAL_SHRINK_ANIMATION_END] */

/* Test Card Component (Unified for Vocab & Similar) */
.test-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
    gap: 8px;
}

.vocab-card {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.card-actions {
    display: flex;
    gap: 15px;
    width: 100%;
    justify-content: center;
    margin-top: 0;
}

.card-actions .btn {
    flex: 1;
    max-width: 200px;
}

/* Specific button overrides */
.btn-clear {
    background: #e0e0e0;
    color: #333;
}

.btn-next {
    background: #667eea;
    color: white;
}

/* --- Older Actions (Keep for footer if needed, but we'll use card-actions mostly) --- */
.test-actions {
    display: flex;
    gap: 15px;
    padding: 20px;
}

/* Review Page */
.session-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.session-item {
    background: #f8f8f8;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.session-date {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #667eea;
}

.session-info {
    font-size: 16px;
    color: #666;
    margin-bottom: 12px;
}

.session-actions {
    display: flex;
    gap: 10px;
}

.session-actions .btn {
    flex: 1;
}

/* Answer Grid */
.answer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.answer-card {
    background: #f8f8f8;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
}

.answer-question {
    font-size: 24px;
    margin-bottom: 8px;
    font-weight: 600;
}

.answer-type {
    font-size: 14px;
    color: #666;
    margin-bottom: 12px;
}

/* The correct answer: large and dark enough to read 注音 tone marks */
.answer-key {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.answer-image {
    width: 100%;
    height: auto;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
}

/* Blank answer: same square frame as a handwriting image, so skipped questions stand out */
.no-answer-placeholder {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed #ccc;
    border-radius: 4px;
    background: #fafafa;
    color: #767676;
    font-size: 18px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.empty-state-text {
    font-size: 20px;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 40px;
    font-size: 20px;
    color: #667eea;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-20 {
    margin-top: 20px;
}

.mb-20 {
    margin-bottom: 20px;
}

/* iPad Landscape Optimizations */
@media (min-width: 768px) {
    .answer-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    /* HTML canvas attributes will control size now */
}


.no-data {
    text-align: center;
    padding: 50px;
    color: #a0a0a0;
    font-size: 18px;
}

/* Loading hint in lesson list */
.loading-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 20px;
    color: #667eea;
    font-size: 17px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-spinner {
    display: inline-block;
    width: 22px;
    height: 22px;
    border: 3px solid #d0d7f7;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

/* Prevent text selection during touch */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Teal button (形近字測驗) */
.btn-teal {
    background: #16a085;
    color: white;
}

.btn-teal:active {
    background: #138d75;
    transform: scale(0.98);
}

.btn-teal:disabled {
    background: #a0cfc8;
    cursor: not-allowed;
}

/* Info button (多音字測驗) */
.btn-info {
    background: #3498db;
    color: white;
}

.btn-info:active {
    background: #2980b9;
    transform: scale(0.98);
}

.btn-info:disabled {
    background: #a9d1eb;
    cursor: not-allowed;
}

/* Outline button */
.btn-outline {
    background: transparent;
    color: #667eea;
    border: 2px solid #667eea;
}

.btn-outline:active {
    background: #f0f2ff;
    transform: scale(0.98);
}

/* =============================================
   Test Page Shell Layout (new structure)
   ============================================= */

/* Full-page flex column fixed to viewport — footer always visible */
.test-page-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

@media (max-width: 767px) {
    /* body is height:auto on mobile (for home page scrolling), so
       100% won't resolve to viewport height — pin explicitly.
       flex:none (with #app for specificity) — otherwise `#app > * { flex: 1 1 0% }`
       wins over the height and the page grows past the screen, hiding the footer */
    #app > .test-page-shell {
        flex: none;
        height: 100dvh;
    }
}

/* Header bar — mirrors .progress-bar from ceb9 */
.test-header {
    background: #f0f0f0;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.test-header-title {
    flex: 1;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.test-mode-label {
    font-size: 14px;
    color: #555; /* was #888 (3.1:1 on the gray header) */
    font-weight: 500;
}

.test-progress {
    font-size: 20px;
    font-weight: 600;
    color: #4c5fd5; /* was #667eea (3.2:1 on the gray header) */
}

.test-header-marks {
    display: flex;
    gap: 6px;
    min-width: 60px;
    justify-content: flex-end;
}

/* Small icon button (home icon) */
.btn-icon {
    padding: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    /* Symbol/Emoji fallback sizes */
    font-size: 24px;
}

/* Canvas tool buttons should be rounded rectangles */
.canvas-tools .btn-icon {
    border-radius: 8px;
}

/* Star toggle button in question card header */
.star-btn {
    background: none;
    border: none;
    color: #767676;
    /* ☆ empty = muted gray (was #aaa, 2.2:1) */
    font-size: 24px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.15s, transform 0.15s;
    -webkit-text-stroke: 0px transparent;
}

/* ★ starred: golden yellow with gray rim */
.star-btn[title='取消標記'] {
    color: #f1c40f;
    -webkit-text-stroke: 1px #888;
    animation: bouncyPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.star-btn:active {
    transform: scale(0.8);
}


.svg-icon {
    width: 24px;
    height: 24px;
    display: inline-block;
}

/* Body area — scrollable, flex column */
.test-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 20px;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Footer button row — mirrors .test-actions from ceb9 */
.test-footer {
    display: flex;
    gap: 15px;
    padding: 15px 20px;
    /* Reduced padding */
    background: white;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

.test-footer .btn {
    flex: 1;
}

/* =============================================
   Similar Shapes (形近字) Question Styles
   ============================================= */

/* Context bar showing the full group */
.similar-group-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    background: #eaf6f6;
    border: 1px solid #a0d9d0;
    border-radius: 10px;
    padding: 10px 16px;
    margin-bottom: 20px;
    font-size: 18px;
}

.similar-group-label {
    font-size: 15px;
    color: #555;
    font-weight: 600;
    flex-shrink: 0;
}

.similar-group-char {
    background: white;
    border: 1px solid #cce5e0;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 20px;
    color: #2d7d73;
    letter-spacing: 0.05em;
}

/* Highlight the character currently being tested */
.similar-group-char--active {
    background: #16a085;
    color: white;
    border-color: #16a085;
    font-weight: 700;
}

/* The blank target in the question word */
.test-item-similar {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    margin: 0 4px;
    vertical-align: middle;
    line-height: 1;
}

/* Phonetic hint shown above the blank */
.similar-hint {
    font-size: 0.45em;
    color: #16a085;
    font-weight: 600;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
    line-height: 1;
}

/* The blank box character */
.similar-blank {
    color: #e74c3c;
    text-decoration: underline;
    text-decoration-thickness: 3px;
    text-underline-offset: 4px;
    font-weight: 700;
    line-height: 1;
}

/* =============================================
   Similar Shapes Group Page Layout
   ============================================= */

/* Flexbox row override — centers any number of cards horizontally */
.similar-group-page {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    gap: 12px;
    padding: 12px;
    width: 100%;
    margin: 0 auto;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Each slot is a .test-card (Similar mode) */
.similar-slot {
    flex: 0 1 auto;
    /* Allow shrinking */
    width: auto;
}

/* Portrait: 2 per row (~45vw each) */
@media (orientation: portrait) {
    .similar-slot {
        flex: 0 0 calc(45vw - 16px);
    }
}

/* Landscape: 3 per row (~30vw each) */
@media (orientation: landscape) {
    .similar-slot {
        flex: 0 0 calc(30vw - 16px);
    }
}

.similar-slot .question-word {
    font-size: 32px;
    /* Smaller font for similar group cards */
    margin-bottom: 5px;
}

.similar-slot .test-card {
    padding: 12px;
}

.similar-clear-btn {
    padding: 6px 14px;
    font-size: 14px;
    min-height: 36px;
    min-width: 60px;
}

/* =============================================
   Polyphonic Test Page
   ============================================= */
.polyphonic-group-page {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* =============================================
   Toast Notification
   ============================================= */
.toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    z-index: 1000;
    font-size: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    transition: opacity 0.3s;
}

.toast-fade-enter-active,
.toast-fade-leave-active {
    transition: opacity 0.5s;
}

.toast-fade-enter-from,
.toast-fade-leave-to {
    opacity: 0;
}

/* =============================================
   Additional Button Variants
   ============================================= */
.btn-teal {
    background: #117a65; /* was #1abc9c (2.4:1 with white) */
    color: white;
}

.btn-teal:active {
    background: #0e6655;
    transform: scale(0.98);
}

.btn-info {
    background: #2471a3; /* was #3498db (3.2:1 with white) */
    color: white;
}

.btn-info:active {
    background: #1f618d;
    transform: scale(0.98);
}

.btn-purple {
    background: #8e44ad;
    color: white;
}

.btn-purple:active {
    background: #7d3c98;
    transform: scale(0.98);
}

.btn-purple:disabled {
    background: #c39bd3;
    cursor: not-allowed;
}

/* 編輯詞庫 link at the bottom of the 歷史紀錄 list (parents only) */
.parent-tools {
    text-align: center;
    margin-top: 24px;
}

.parent-tool-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 16px;
    color: #555;
    font-size: 15px;
}

.btn-reading {
    background: #0e6655; /* was #16a085 (3.3:1 with white) */
    color: white;
}

.btn-reading:active {
    background: #0b5345;
    transform: scale(0.98);
}

.btn-reading:disabled {
    background: #a3d6cc;
    cursor: not-allowed;
}

/* =============================================
   Reading Page (課文閱覽)
   ============================================= */
.reading-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #fafafa;
}

.reading-page .header {
    flex-wrap: wrap;
    gap: 8px;
}

.reading-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-left: auto;
    align-items: center;
}

.reading-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: #555;
    cursor: pointer;
    user-select: none;
}

.reading-toggle input {
    accent-color: #16a085;
}

.reading-page .content {
    overflow-y: auto;
    padding: 16px;
}

.reading-lesson-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 960px;
    margin: 0 auto;
}

.reading-lesson-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    overflow: hidden;
}

.reading-lesson-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 14px 20px;
    background: linear-gradient(90deg, #eef7f5 0%, #ffffff 60%);
    cursor: pointer;
    border-bottom: 1px solid #e5e7eb;
}

.reading-lesson-chapter {
    font-weight: 600;
    color: #16a085;
}

.reading-lesson-title {
    font-size: 20px;
    font-weight: 700;
    color: #222;
    flex: 1;
}

.reading-lesson-meta {
    font-size: 12px;
    color: #888;
}

.reading-lesson-toggle {
    font-size: 20px;
    color: #16a085;
    min-width: 20px;
    text-align: center;
}

.reading-lesson-body {
    padding: 12px 20px 20px;
}

.reading-section {
    padding: 12px 0;
    border-top: 1px dashed #e5e7eb;
}

.reading-section:first-child {
    border-top: none;
}

.reading-section-title {
    font-size: 15px;
    font-weight: 700;
    color: #16a085;
    margin: 4px 0 12px;
}

.reading-vocab-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.reading-vocab-row {
    display: flex;
    gap: 14px;
    padding: 10px 12px;
    background: #fafbfc;
    border-radius: 8px;
    border-left: 3px solid #16a085;
}

.reading-vocab-char {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 52px;
}

.reading-hanzi {
    font-size: 28px;
    font-weight: 700;
    color: #1f2937;
    line-height: 1.1;
}

.reading-zhuyin {
    font-size: 12px;
    color: #6b7280;
    margin-top: 4px;
    text-align: center;
    letter-spacing: 1px;
}

.reading-vocab-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.reading-vocab-word {
    font-weight: 600;
    color: #333;
}

.reading-word-han {
    font-size: 17px;
    margin-right: 6px;
    color: inherit;
}

.reading-word-zhuyin {
    font-size: 12px;
    color: #6b7280;
    letter-spacing: 1px;
}

.reading-vocab-def {
    color: #444;
    font-size: 14px;
    line-height: 1.5;
}

.reading-vocab-example {
    color: #555;
    font-size: 14px;
    line-height: 1.6;
}

.reading-vocab-words {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-top: 2px;
}

.reading-tag {
    display: inline-block;
    font-size: 11px;
    padding: 2px 6px;
    color: #16a085;
    background: #e6f4f1;
    border-radius: 6px;
    margin-right: 6px;
    font-weight: 600;
}

.reading-word-chip {
    display: inline-block;
    padding: 2px 8px;
    background: #f3f4f6;
    color: #333;
    border-radius: 10px;
    font-size: 13px;
    margin-right: 4px;
}

/* Tap a 生字 or word chip to open the dictionary in a new tab */
.reading-dict-link {
    text-decoration: underline dotted #a5b4fc 2px;
    text-underline-offset: 4px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
}

.reading-word-chip.reading-dict-link {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 4px 12px;
    background: #eef2ff;
    color: #3730a3;
    border-radius: 18px;
    font-size: 15px;
    text-decoration: none;
}

.reading-dict-link:active {
    opacity: 0.7;
}

.reading-dict-link:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 2px;
    border-radius: 6px;
}

.reading-similar-group,
.reading-poly-item,
.reading-sentence-item,
.reading-idiom-item {
    padding: 10px 12px;
    background: #fafbfc;
    border-radius: 8px;
    margin-bottom: 10px;
}

.reading-similar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
}

.reading-similar-char {
    font-weight: 700;
    color: #1f2937;
    min-width: 90px;
}

.reading-poly-head {
    font-size: 22px;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 6px;
}

.reading-poly-variant {
    display: flex;
    gap: 10px;
    padding: 4px 0;
    align-items: center;
}

.reading-poly-phonetic {
    display: inline-block;
    min-width: 70px;
    padding: 2px 8px;
    background: #e6f4f1;
    color: #16a085;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 1px;
}

.reading-sentence-phrase {
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.reading-pattern-badge {
    font-size: 11px;
    padding: 2px 8px;
    background: #fff5e6;
    color: #b8730d;
    border-radius: 10px;
    font-weight: 500;
}

.reading-sentence-struct,
.reading-sentence-orig {
    font-size: 13px;
    color: #555;
    margin: 3px 0;
}

.reading-sentence-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: baseline;
    margin-top: 4px;
}

.reading-sentence-example {
    background: #f3f4f6;
    padding: 3px 10px;
    border-radius: 8px;
    font-size: 13px;
    color: #333;
}

.reading-idiom-head {
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 4px;
}

.reading-idiom-def {
    color: #444;
    font-size: 14px;
    line-height: 1.5;
}

.reading-idiom-example {
    color: #555;
    font-size: 14px;
    line-height: 1.6;
    margin-top: 4px;
}

.reading-empty-note {
    color: #9ca3af;
    text-align: center;
    padding: 20px;
    font-size: 13px;
}

@media (max-width: 720px) {
    .reading-lesson-header {
        flex-wrap: wrap;
    }
    .reading-lesson-title {
        font-size: 17px;
        width: 100%;
    }
    .reading-vocab-row {
        gap: 10px;
    }
    .reading-hanzi {
        font-size: 24px;
    }
    .reading-page .content {
        padding: 12px;
    }
}

/* =============================================
   Idiom Test Page (成語填空)
   ============================================= */
.idiom-legend-section {
    background: #f8f9ff;
    border: 1px solid #dce3f7;
    border-radius: 12px;
    padding: 20px;
    margin: 0 0 24px 0;
}

.idiom-legend-title {
    font-size: 18px;
    font-weight: 600;
    color: #4a3aaa;
    margin-bottom: 16px;
}

.idiom-legend-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* 2 in a row when portrait/mobile */
    gap: 10px;
}

/* 4 in a row on landscape/desktop */
@media (min-width: 768px) and (orientation: landscape),
(min-width: 1024px) {
    .idiom-legend-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.idiom-legend-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    background: white;
    border-radius: 8px;
    border: 1px solid #e0e5f7;
}

.idiom-code-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #8e44ad;
    color: white;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.idiom-legend-text {
    display: flex;
    flex-direction: column;
    line-height: 1.4;
}

.idiom-full {
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.idiom-explanation {
    font-size: 13px;
    color: #888;
}

.idiom-explanation-toggle {
    display: inline-block;
    margin-left: 4px;
    padding: 4px 10px;
    font-size: 13px;
    color: var(--color-primary, #007aff);
    background: none;
    border: 1px solid currentColor;
    border-radius: 10px;
    cursor: pointer;
    line-height: 1.6;
}

/* Questions section */
.idiom-questions-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.idiom-questions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.idiom-score {
    font-size: 18px;
    font-weight: 700;
    padding: 6px 16px;
    border-radius: 20px;
}

.score-great {
    background: #d4edda;
    color: #155724;
}

.score-ok {
    background: #fff3cd;
    color: #856404;
}

.score-poor {
    background: #f8d7da;
    color: #721c24;
}

.idiom-question-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 16px 20px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.idiom-question-num {
    font-size: 13px;
    font-weight: 600;
    color: #8e44ad;
    margin-bottom: 8px;
}

.idiom-sentence {
    font-size: 20px;
    line-height: 2;
    color: #333;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

.idiom-blank-slot {
    display: inline-flex;
    align-items: center;
}

.idiom-select {
    font-size: 16px;
    min-height: 44px;
    padding: 6px 10px;
    border: 2px solid #8e44ad;
    border-radius: 8px;
    background: #faf5ff;
    color: #333;
    cursor: pointer;
    appearance: auto;
    min-width: 160px;
}

.idiom-select:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(142, 68, 173, 0.2);
}

/* Answer reveal inline */
.idiom-result-wrong-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.idiom-result-correct {
    font-weight: 700;
    color: #27ae60;
    background: #eafaf1;
    padding: 3px 10px;
    border-radius: 6px;
    border: 1px solid #a9dfbf;
}

.idiom-result-wrong {
    font-weight: 700;
    color: #e74c3c;
    background: #fdf2f2;
    padding: 3px 10px;
    border-radius: 6px;
    border: 1px solid #f5c6cb;
}

.idiom-result-right-answer {
    font-weight: 700;
    color: #2ecc71;
    /* Success green but slightly different from .idiom-result-correct maybe? */
    background: #eafaf1;
    padding: 3px 10px;
    border-radius: 6px;
    border: 1px solid #d4efdf;
}

.idiom-question-hint {
    margin-top: 8px;
    font-size: 13px;
    color: #888;
}

/* Actions */
.idiom-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 20px 0 40px;
}

.idiom-actions .btn {
    min-width: 120px;
}

/* =============================================
   聽寫測驗 (Dictation)
   ============================================= */
.btn-dictation {
    background: #b4470f;
    color: white;
}

.btn-dictation:active {
    background: #93390b;
    transform: scale(0.98);
}

.btn-dictation:disabled {
    background: #efc9b4;
    cursor: not-allowed;
}

.dictation-start {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    width: 100%;
    max-width: 520px;
}

.dictation-start-title {
    font-size: 28px;
    text-align: center;
}

.dictation-start-text {
    text-align: center;
    color: #555;
}

.dictation-mode-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.dictation-mode {
    min-height: 96px;
    padding: 12px;
    font: inherit;
    font-size: 20px;
    color: #333;
    background: white;
    border: 2px solid #ccc;
    border-radius: 12px;
    cursor: pointer;
}

.dictation-mode.active {
    color: #3a48b0;
    background: #eef0fd;
    border-color: #5568d3;
    font-weight: 700;
}

.dictation-wide {
    width: 100%;
    min-height: 56px;
    font-size: 20px;
}

.dictation-message {
    color: #b3261e;
    text-align: center;
}

.dictation-note {
    max-width: 520px;
    margin: 0;
    padding: 8px 14px;
    color: #6b4700;
    background: #fff4d6;
    border-radius: 8px;
    text-align: center;
}

.dictation-audio-note {
    font-size: 14px;
    color: #8a5a00;
}

/* Keep each 注音 with its tone mark; break only between the parts */
.dictation-audio-note-part {
    display: inline-block;
    margin-right: 0.6em;
    white-space: nowrap;
}

.dictation-body {
    gap: 12px;
    padding: 16px;
}

.dictation-number {
    font-size: clamp(96px, 24vh, 200px);
    font-weight: 700;
    line-height: 1.1;
    color: #5568d3;
    font-variant-numeric: tabular-nums;
}

.dictation-replay {
    min-height: 64px;
    min-width: 240px;
    font-size: 22px;
}

.dictation-tools {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.dictation-score {
    width: 100%;
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 12px;
}

.dictation-result-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.dictation-result-row {
    display: grid;
    grid-template-columns: 36px 48px minmax(120px, 1fr) minmax(120px, 2fr) auto;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
}

.dictation-result-number {
    font-size: 20px;
    font-weight: 700;
    text-align: right;
    color: #666;
    font-variant-numeric: tabular-nums;
}

.dictation-result-key {
    min-width: 0;
}

.dictation-result-zhuyin {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.3;
}

.dictation-result-word {
    font-size: 16px;
    color: #666;
}

.dictation-result-answer {
    min-width: 0;
    color: #666;
}

.dictation-result-answer img {
    display: block;
    max-width: 100%;
    max-height: 120px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
}

.dictation-marks {
    display: flex;
    gap: 8px;
}

.dictation-mark {
    width: 56px;
    height: 56px;
    font-size: 26px;
    font-weight: 700;
    color: #555;
    background: #f0f0f0;
    border: 2px solid #ccc;
    border-radius: 10px;
    cursor: pointer;
}

.dictation-mark.mark-right.active {
    color: white;
    background: #1e7e45;
    border-color: #1e7e45;
}

.dictation-mark.mark-wrong.active {
    color: white;
    background: #c0392b;
    border-color: #c0392b;
}

.dictation-check-lesson {
    width: 100%;
    margin-bottom: 20px;
}

.dictation-check-title {
    font-size: 18px;
    margin-bottom: 8px;
}

.dictation-check-row {
    grid-template-columns: 48px minmax(0, 1fr) auto;
    margin-bottom: 8px;
}

.dictation-flag-list {
    width: 100%;
    margin-bottom: 12px;
    color: #b3261e;
}

.reading-dictation-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px 16px;
}

.reading-dictation-item {
    display: flex;
    flex-direction: column;
}

@media (max-width: 767px) {
    .dictation-result-row {
        grid-template-columns: 28px 48px minmax(0, 1fr) auto;
    }

    .dictation-result-answer {
        grid-column: 1 / -1;
    }
}

/* =============================================
   Vertical 注音 (css/zhuyin.css + js/utils/zhuyin.js)
   Characters regular, 注音 bold; sizes are the character size.
   ============================================= */
/* 看注音寫國字 / 形近字: a 注音 box in place of the character */
.zy-target {
    display: inline-block;
    vertical-align: middle;
    margin: 0 .04em;
    color: #e74c3c;
}

/* Review: the answer key is the character with its 注音 */
.answer-type .answer-key {
    display: inline-block;
    vertical-align: middle;
    margin-left: 6px;
    font-size: 28px;
    font-weight: 400;
    color: #333;
}

/* Reading page */
.reading-vocab-char { min-width: 64px; }
.reading-char-cell { font-size: 32px; color: #1f2937; }
.reading-char-cell .reading-hanzi { font-size: inherit; font-weight: 400; line-height: 1; }
.reading-word-han { font-size: 24px; }
.reading-dictation-zhuyin { font-size: 30px; color: #1f2937; }
.reading-similar-char { font-size: 24px; font-weight: 400; }
.reading-poly-phonetic { font-size: 24px; font-weight: 400; letter-spacing: 0; padding: 4px 10px; }
.reading-idiom-head { font-size: 24px; font-weight: 400; margin-bottom: 8px; }

/* 聽寫 result and parent check: the key as 注音 columns (or the word with 注音) */
.dictation-result-zhuyin { font-size: 32px; font-weight: 400; line-height: 1.2; }

/* =============================================
   改錯字 (ProofreadingPage, ProofreadingResultPage)
   ============================================= */
.btn-proofreading {
    background: #7d3c98; /* 7.0:1 with white */
    color: white;
}

.btn-proofreading:active {
    background: #643079;
    transform: scale(0.98);
}

.btn-proofreading:disabled {
    background: #d7c1e0;
    cursor: not-allowed;
}

/* 換一句 in the test header */
.btn-regen {
    font-size: 16px;
    padding: 8px 12px;
    min-height: 44px;
    white-space: nowrap;
    background: #fff;
    color: #7d3c98; /* 7.0:1 on white */
    border: 2px solid #7d3c98;
}

.btn-regen:active {
    background: #f3e9f7;
}

.btn-regen:disabled {
    opacity: 0.6;
    cursor: wait;
}

.proof-body {
    gap: 16px;
    padding: 16px;
    justify-content: flex-start;
}

.proof-instruction {
    font-size: 22px;
    font-weight: 700;
    color: #333;
    margin: 0;
    text-align: center;
}

.proof-sentence {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 2px;
    max-width: 900px;
    line-height: 1;
}

/* Each character is a tap target of at least 48 × 48 px */
.proof-char {
    min-width: 52px;
    height: 60px;
    padding: 0 2px;
    font-size: 40px;
    font-family: inherit;
    color: #222;
    background: transparent;
    border: 3px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.proof-char:disabled {
    cursor: default;
    color: #222;
    opacity: 1;
}

.proof-punct {
    min-width: 24px;
    font-size: 40px;
    color: #222;
}

.proof-char.is-miss {
    color: #999;
    background: #f0f0f0;
    border-radius: 10px;
}

.proof-char.is-found {
    color: #c0392b;
    border-color: #c0392b;
}

.proof-char.is-shown {
    color: #b4470f;
    border-color: #e67e22;
    border-style: dashed;
}

.proof-char.is-shaking {
    animation: proofShake 0.4s;
}

@keyframes proofShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

@media (prefers-reduced-motion: reduce) {
    .proof-char.is-shaking { animation: none; }
}

@media (max-width: 767px) {
    .proof-char { min-width: 44px; height: 52px; font-size: 32px; }
    .proof-punct { font-size: 32px; min-width: 18px; }
}

.proof-result-row {
    display: grid;
    grid-template-columns: 36px minmax(0, 3fr) 64px minmax(100px, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
}

.proof-result-sentence {
    font-size: 22px;
    line-height: 1.6;
}

.proof-result-wrong {
    color: #c0392b;
    font-weight: 700;
    text-decoration: line-through;
    text-decoration-thickness: 2px;
}

.proof-result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    font-size: 16px;
    color: #555;
}

.proof-found { color: #1e7e45; font-weight: 700; }
.proof-missed { color: #b4470f; font-weight: 700; }

.proof-result-key {
    font-size: 48px;
    line-height: 1;
    text-align: center;
    color: #1e7e45;
}

.proof-result-answer img {
    max-height: 96px;
}

/* Phone width: sentence on the first line; key, drawing and marks below */
@media (max-width: 767px) {
    .proof-result-row {
        grid-template-columns: 56px minmax(0, 1fr) auto;
    }
    .proof-result-main { grid-column: 2 / -1; }
    .proof-result-key { grid-column: 1 / 2; font-size: 40px; }
    .dictation-result-answer.proof-result-answer { grid-column: 2 / 3; }
}
