/* ===================================================================
   Chinese Word Reading Assessment — Styles
   =================================================================== */

/* ---- Reset & Base ------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --red:       #C41E3A;
    --red-light: #E63946;
    --blue:      #1D3557;
    --blue-mid:  #457B9D;
    --teal:      #2A9D8F;
    --gold:      #E9C46A;
    --bg:        #F8F9FA;
    --card-bg:   #FFFFFF;
    --text:      #1D3557;
    --text-dim:  #6C757D;
    --border:    #DEE2E6;
    --success:   #2A9D8F;
    --danger:    #E63946;
    --warning:   #E9C46A;
    --shadow:    0 4px 24px rgba(0,0,0,.08);
    --shadow-lg: 0 8px 40px rgba(0,0,0,.12);
    --radius:    16px;
    --radius-sm: 10px;
    --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ---- Page switching ----------------------------------------------- */
.page {
    display: none;
    min-height: 100vh;
    padding: 24px;
}
.page.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* ---- Card --------------------------------------------------------- */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 40px 36px;
    max-width: 560px;
    width: 100%;
    text-align: center;
}

/* ---- Name Entry --------------------------------------------------- */
.name-card .logo {
    font-size: 56px;
    margin-bottom: 8px;
}
.name-card h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--red);
    margin-bottom: 4px;
}
.name-card .subtitle {
    font-size: 15px;
    color: var(--text-dim);
    margin-bottom: 16px;
}
.name-card .desc {
    font-size: 14px;
    color: var(--blue-mid);
    margin-bottom: 28px;
    line-height: 1.8;
}
.name-card .desc strong {
    color: var(--red);
}

.form-group {
    text-align: left;
    margin-bottom: 20px;
}
.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--blue);
}
.form-group input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .2s;
    font-family: var(--font);
}
.form-group input:focus {
    border-color: var(--blue-mid);
}

/* ---- Buttons ------------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 28px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all .2s;
    font-family: var(--font);
    text-decoration: none;
}
.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}
.btn-primary {
    background: var(--red);
    color: #fff;
}
.btn-primary:hover:not(:disabled) {
    background: #A01830;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(196,30,58,.35);
}
.btn-lg {
    padding: 14px 36px;
    font-size: 18px;
    border-radius: 30px;
}
.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
    border-radius: 20px;
    background: var(--bg);
    color: var(--blue-mid);
    border: 1px solid var(--border);
}
.btn-sm:hover {
    background: var(--border);
}

/* Play button */
.btn-play {
    background: var(--blue-mid);
    color: #fff;
    padding: 16px 36px;
    font-size: 18px;
    border-radius: 30px;
    margin: 8px 0;
}
.btn-play:hover:not(:disabled) {
    background: var(--blue);
    transform: translateY(-1px);
}
.btn-play.playing {
    background: var(--success);
    animation: playPulse 1s infinite;
}
@keyframes playPulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(42,157,143,.4); }
    50%      { box-shadow: 0 0 0 14px rgba(42,157,143,0); }
}

/* Record button */
.btn-record {
    background: var(--red);
    color: #fff;
    padding: 16px 36px;
    font-size: 18px;
    border-radius: 30px;
}
.btn-record:hover:not(:disabled) {
    background: #A01830;
}
.btn-record.recording {
    background: #555;
    animation: recordPulse 1.2s infinite;
}
@keyframes recordPulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(196,30,58,.5); }
    50%      { box-shadow: 0 0 0 16px rgba(196,30,58,0); }
}

.btn-replay {
    background: var(--teal);
    color: #fff;
    padding: 12px 24px;
    font-size: 15px;
    border-radius: 30px;
}
.btn-replay:hover:not(:disabled) {
    background: #21867A;
}

.btn-retry {
    background: var(--warning);
    color: var(--blue);
    padding: 12px 28px;
    font-size: 15px;
    border-radius: 30px;
}
.btn-retry:hover:not(:disabled) {
    background: #D4B04A;
}

.btn-logout {
    color: var(--danger) !important;
    border-color: var(--danger) !important;
}

/* ---- Top Bar & Progress ------------------------------------------- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 560px;
    width: 100%;
    margin-bottom: 8px;
    padding: 0 4px;
}
.student-name {
    font-weight: 600;
    color: var(--blue);
    font-size: 15px;
}
.progress-text {
    font-size: 14px;
    color: var(--text-dim);
}

.progress-bar-container {
    max-width: 560px;
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    margin-bottom: 20px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--red-light), var(--teal));
    border-radius: 4px;
    transition: width .4s ease;
    width: 0%;
}

/* ---- Practice Card ------------------------------------------------ */
.practice-card {
    position: relative;
}
.word-number {
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 8px;
    background: var(--bg);
    display: inline-block;
    padding: 4px 16px;
    border-radius: 20px;
}

.audio-section {
    margin: 20px 0;
}
.audio-section .hint,
.record-section .hint {
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 12px;
}

.record-section {
    margin: 20px 0;
    padding: 20px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.record-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.recording-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 14px;
    color: var(--red);
    font-weight: 600;
}
.pulse {
    width: 12px;
    height: 12px;
    background: var(--red);
    border-radius: 50%;
    animation: pulseAnim 1s infinite;
}
@keyframes pulseAnim {
    0%,100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.5); opacity: .5; }
}
.timer {
    font-family: monospace;
    font-size: 16px;
    margin-left: 8px;
}

/* ---- Score Section ------------------------------------------------ */
.score-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.score-circle {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    margin: 0 auto 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 6px solid var(--border);
    transition: all .5s ease;
}
.score-circle.pass {
    border-color: var(--success);
    background: rgba(42,157,143,.08);
}
.score-circle.fail {
    border-color: var(--danger);
    background: rgba(230,57,70,.06);
}
.score-value {
    font-size: 36px;
    font-weight: 800;
    line-height: 1;
    color: var(--text);
}
.score-unit {
    font-size: 14px;
    color: var(--text-dim);
}

.score-details {
    text-align: left;
    margin: 16px auto;
    max-width: 320px;
}
.score-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.score-row:last-child {
    border-bottom: none;
}
.score-label {
    color: var(--text-dim);
}
.score-num {
    font-weight: 700;
    color: var(--blue);
}

.result-message {
    margin: 16px 0;
    font-size: 18px;
    font-weight: 700;
    padding: 12px;
    border-radius: var(--radius-sm);
}
.result-message.pass {
    color: var(--success);
    background: rgba(42,157,143,.1);
}
.result-message.fail {
    color: var(--danger);
    background: rgba(230,57,70,.08);
}

/* Feedback box */
.feedback-box {
    text-align: left;
    background: #F8FAFD;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    margin: 16px 0;
}
.feedback-box h4 {
    font-size: 15px;
    color: var(--blue);
    margin-bottom: 10px;
}
.feedback-box pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: var(--font);
    font-size: 13.5px;
    line-height: 1.8;
    color: var(--text);
    margin: 0;
}

/* Chart button */
.btn-chart {
    background: #6C5CE7;
    color: #fff;
    padding: 10px 24px;
    font-size: 14px;
    border-radius: 30px;
    margin-top: 8px;
}
.btn-chart:hover:not(:disabled) {
    background: #5A4BD1;
}

/* ---- Completion --------------------------------------------------- */
.complete-card .trophy {
    font-size: 72px;
    margin-bottom: 8px;
}
.complete-card h1 {
    font-size: 28px;
    color: var(--success);
    margin-bottom: 4px;
}
.complete-card .subtitle {
    font-size: 15px;
    color: var(--text-dim);
    margin-bottom: 24px;
}

.final-stats {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.stat-item {
    background: var(--bg);
    padding: 16px 24px;
    border-radius: var(--radius-sm);
    text-align: center;
    min-width: 100px;
}
.stat-value {
    display: block;
    font-size: 28px;
    font-weight: 800;
    color: var(--blue);
}
.stat-label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 4px;
}

.final-name {
    font-size: 16px;
    color: var(--blue-mid);
    margin-bottom: 8px;
}
.encouragement {
    font-size: 15px;
    color: var(--gold);
    margin-bottom: 20px;
}

/* ---- Error Banner ------------------------------------------------- */
.error-banner {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: #FFF3F3;
    color: var(--danger);
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    border: 1px solid #F5C6CB;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
}
.error-banner button {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 18px;
    font-weight: 700;
}

.error-text {
    color: var(--danger);
    font-size: 13px;
    min-height: 18px;
    margin-top: 4px;
}
.success-text {
    color: var(--success);
    font-size: 13px;
    min-height: 18px;
    margin-top: 4px;
}

/* ---- Teacher Styles ----------------------------------------------- */
.teacher-body {
    background: #F0F2F5;
}
.teacher-body .page {
    padding: 32px 24px;
}

.teacher-login-card {
    max-width: 400px;
}
.teacher-login-card .logo {
    font-size: 56px;
    margin-bottom: 8px;
}
.teacher-login-card h1 {
    font-size: 26px;
    color: var(--blue);
    margin-bottom: 4px;
}
.teacher-login-card .subtitle {
    font-size: 15px;
    color: var(--text-dim);
    margin-bottom: 20px;
}

.back-link {
    margin-top: 20px;
}
.back-link a {
    color: var(--blue-mid);
    text-decoration: none;
    font-size: 14px;
}
.back-link a:hover {
    text-decoration: underline;
}

/* Dashboard */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1100px;
    width: 100%;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.dashboard-header h1 {
    font-size: 24px;
    color: var(--blue);
}
.header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Summary cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    max-width: 1100px;
    width: 100%;
    margin-bottom: 24px;
}
.summary-card {
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow);
}
.summary-value {
    display: block;
    font-size: 32px;
    font-weight: 800;
    color: var(--blue);
}
.summary-label {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: 4px;
}

/* Table */
.table-card {
    max-width: 1100px;
    text-align: left;
    padding: 24px;
}
.table-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}
.table-controls h3 {
    font-size: 18px;
    color: var(--blue);
}
.table-controls input {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    width: 220px;
    font-family: var(--font);
}
.table-controls input:focus {
    border-color: var(--blue-mid);
}

.table-wrapper {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
thead th {
    background: var(--bg);
    padding: 10px 12px;
    text-align: left;
    font-weight: 700;
    color: var(--blue);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody tr:hover {
    background: rgba(69,123,157,.04);
}
.empty-row {
    text-align: center !important;
    color: var(--text-dim);
    padding: 40px !important;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}
.badge-pass {
    background: rgba(42,157,143,.15);
    color: var(--success);
}
.badge-in-progress {
    background: rgba(233,196,106,.2);
    color: #B8902A;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 24px;
}
.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    max-width: 750px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-sm {
    max-width: 420px;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 0;
}
.modal-header h2, .modal-header h3 {
    color: var(--blue);
}
.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-dim);
    padding: 4px;
}
.modal-close:hover {
    color: var(--text);
}
.modal-body {
    padding: 20px 24px 24px;
}

.detail-summary {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.detail-summary .stat-item {
    min-width: 90px;
}

.word-scores-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-top: 12px;
}
.word-scores-table th,
.word-scores-table td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    text-align: center;
}
.word-scores-table th {
    background: var(--bg);
    font-weight: 700;
}

/* ---- Responsive --------------------------------------------------- */
@media (max-width: 640px) {
    .card {
        padding: 24px 18px;
    }
    .name-card h1 {
        font-size: 22px;
    }
    .score-circle {
        width: 90px;
        height: 90px;
    }
    .score-value {
        font-size: 28px;
    }
    .btn {
        padding: 10px 20px;
        font-size: 14px;
    }
    .btn-lg {
        padding: 12px 28px;
        font-size: 16px;
    }
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    .top-bar {
        flex-direction: column;
        gap: 4px;
        align-items: flex-start;
    }
    .header-actions {
        flex-direction: column;
    }
}

@media (max-width: 400px) {
    .btn-play, .btn-record {
        padding: 12px 24px;
        font-size: 15px;
    }
    .final-stats {
        flex-direction: column;
    }
    .record-controls {
        flex-direction: column;
        align-items: center;
    }
}
