* {
    box-sizing: border-box;
}

/* The hidden attribute must always win, even over display:flex/grid rules. */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
    background: #f7f5f2;
    color: #26221c;
    line-height: 1.5;
}

h1 {
    font-weight: 600;
}

/* --- Login --- */

.auth-card {
    max-width: 22rem;
    margin: 15vh auto 0;
    padding: 2rem;
    background: #fff;
    border: 1px solid #e5e0d8;
    border-radius: 12px;
}

.auth-card h1 {
    margin: 0;
    font-size: 1.6rem;
}

.auth-card .tagline {
    margin-top: 0.25rem;
    color: #6f675c;
    font-size: 0.9rem;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 1.25rem;
}

.auth-card label {
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

.auth-card input {
    padding: 0.55rem 0.7rem;
    border: 1px solid #d8d2c8;
    border-radius: 8px;
    font-size: 1rem;
}

.auth-card button {
    margin-top: 1rem;
    padding: 0.6rem;
    border: none;
    border-radius: 8px;
    background: #1f6feb;
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
}

.auth-card button:hover {
    background: #1a5fd0;
}

.form-errors,
.errorlist {
    color: #b3261e;
    font-size: 0.85rem;
    margin: 0;
    padding-left: 0;
    list-style: none;
}

/* --- Home --- */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    background: #fff;
    border-bottom: 1px solid #e5e0d8;
}

.topbar .brand {
    font-weight: 700;
    color: #26221c;
    text-decoration: none;
}

.topbar .account {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    color: #6f675c;
}

.topbar form {
    margin: 0;
}

.link-button {
    border: none;
    background: none;
    padding: 0;
    color: #1f6feb;
    font-size: 0.9rem;
    cursor: pointer;
}

.link-button:hover {
    text-decoration: underline;
}

.canvas {
    max-width: 40rem;
    margin: 4rem auto;
    padding: 0 1.25rem;
    text-align: center;
}

/* --- Home: status row --- */

.home {
    margin-top: 2.5rem;
}

.greeting {
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
}

.status-row {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    align-items: stretch;
}

.stat {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.9rem 1rem;
    background: #fff;
    border: 1px solid #e5e0d8;
    border-radius: 12px;
    min-width: 5.5rem;
}

.stat-course {
    flex: 1;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}

.stat-of {
    font-size: 0.9rem;
    font-weight: 400;
    color: #6f675c;
}

.stat-label {
    font-size: 0.78rem;
    color: #6f675c;
}

.stat-sub {
    font-size: 0.75rem;
    color: #6f675c;
}

.progress {
    height: 0.55rem;
    background: #ece7df;
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: #2da44e;
    border-radius: 999px;
    transition: width 0.4s ease;
}

/* --- Home: action buttons --- */

.actions {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    margin-top: 2rem;
}

.cta {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 1.1rem 1.25rem;
    border-radius: 14px;
    text-decoration: none;
    text-align: center;
}

.cta-title {
    font-size: 1.15rem;
    font-weight: 700;
}

.cta-sub {
    font-size: 0.85rem;
    opacity: 0.85;
}

.cta-primary {
    background: #1f6feb;
    color: #fff;
}

.cta-primary:hover {
    background: #1a5fd0;
}

.cta-secondary {
    background: #fff;
    color: #26221c;
    border: 1px solid #e5e0d8;
}

.cta-disabled {
    color: #a49b8d;
    cursor: default;
}

.cta-due {
    background: #2da44e;
    color: #fff;
}

.cta-due:hover {
    background: #26893f;
}

.cta .progress {
    width: 100%;
    margin: 0.35rem 0 0.15rem;
}

.cta-due .progress {
    background: rgba(255, 255, 255, 0.35);
}

.cta-due .progress-fill {
    background: #fff;
}

/* --- Learn: level teach screen --- */

.learn {
    margin-top: 1rem;
}

.level-kicker {
    margin: 0;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6f675c;
}

.learn h1 {
    margin: 0.25rem 0 0;
}

.level-title {
    margin: 0.25rem 0 1.5rem;
    color: #6f675c;
}

.letter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.letter-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 2rem 1.25rem 1.5rem;
    background: #fff;
    border: 1px solid #e5e0d8;
    border-radius: 14px;
}

.class-badge {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.class-mid {
    background: #dbeafe;
    color: #1d4ed8;
}

.class-high {
    background: #fef3c7;
    color: #b45309;
}

.class-low {
    background: #fee2e2;
    color: #b91c1c;
}

.letter-glyph {
    font-size: 6rem;
    line-height: 1.1;
    color: #26221c;
    text-decoration: none;
}

a.letter-glyph:hover {
    color: #1f6feb;
}

.letter-glyph-large {
    font-size: 15rem;
    line-height: 0.95;
}

.letter-illustration {
    width: 8.5rem;
    height: 8.5rem;
    object-fit: contain;
    border-radius: 10px;
}

.letter-step {
    max-width: 24rem;
    margin: 0.5rem auto 0;
    padding: 1rem 1.25rem;
    gap: 0.3rem;
}

/* Compact overview cards: whole card is a link, no images or audio */

.letter-grid-compact {
    grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
    max-width: 32rem;
    margin-left: auto;
    margin-right: auto;
}

.letter-card-compact {
    padding: 1.4rem 0.75rem 1rem;
    gap: 0.15rem;
    text-decoration: none;
    color: inherit;
}

.letter-card-compact:hover {
    border-color: #1f6feb;
}

.letter-glyph-small {
    font-size: 3.2rem;
}

.letter-card-compact .letter-name {
    font-size: 1rem;
}

.letter-card-compact .letter-rtgs {
    font-size: 0.8rem;
}

.letter-step .letter-illustration {
    width: 5rem;
    height: 5rem;
}

.cta-study {
    display: inline-flex;
    margin-top: 1rem;
    background: #1f6feb;
    color: #fff;
    padding: 0.75rem 1.5rem;
}

.cta-study:hover {
    background: #1a5fd0;
}

.step-nav {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 0.75rem;
}

.step-link {
    color: #1f6feb;
    text-decoration: none;
    font-weight: 600;
}

.step-link:hover {
    text-decoration: underline;
}

.step-link-disabled {
    color: #c5bdb1;
    font-weight: 600;
}

.step-overview {
    color: #6f675c;
}

.step-done {
    color: #2da44e;
}

.letter-name {
    font-size: 1.3rem;
    font-weight: 600;
}

.letter-rtgs {
    font-size: 0.9rem;
    color: #6f675c;
}

.audio-buttons {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.4rem;
}

.audio-button {
    padding: 0.45rem 0.9rem;
    border: 1px solid #d8d2c8;
    border-radius: 999px;
    background: #f7f5f2;
    font-size: 0.85rem;
    cursor: pointer;
}

.audio-button:hover {
    background: #ece7df;
}

.audio-primary {
    background: #1f6feb;
    border-color: #1f6feb;
    color: #fff;
    font-weight: 700;
    padding: 0.55rem 1.6rem;
}

.audio-primary:hover {
    background: #1a5fd0;
}

/* Attention pulse for the replay button when autoplay was blocked and
   nothing has been heard yet. */
@keyframes pulse-attention {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(31, 111, 235, 0.4);
    }
    50% {
        transform: scale(1.06);
        box-shadow: 0 0 0 9px rgba(31, 111, 235, 0);
    }
}

.pulse {
    animation: pulse-attention 1.2s ease-in-out infinite;
    border-color: #1f6feb;
    color: #1f6feb;
}

.level-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-top: 2rem;
}

.cta-start {
    background: #2da44e;
    color: #fff;
    padding: 0.75rem 2rem;
    font-size: 1.05rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
}

.cta-start:hover {
    background: #26893f;
}

/* --- Quiz --- */

.quiz-panel {
    max-width: 26rem;
    margin: 1.5rem auto 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.quiz-intro-text {
    color: #6f675c;
    margin: 0;
}

.quiz-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.quiz-question {
    margin: 0;
    font-size: 1.1rem;
}

.quiz-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(7rem, 1fr));
    gap: 0.75rem;
    width: 100%;
}

.quiz-option {
    font-size: 3.2rem;
    line-height: 1.2;
    padding: 1.1rem 0;
    background: #fff;
    border: 1px solid #e5e0d8;
    border-radius: 14px;
    cursor: pointer;
}

.quiz-option:hover {
    border-color: #1f6feb;
}

.option-correct {
    background: #d1f0db;
    border-color: #2da44e;
}

.option-wrong {
    background: #fadcd9;
    border-color: #b3261e;
}

.quiz-progress {
    margin: 0;
    font-size: 0.85rem;
    color: #6f675c;
}

.review-glyph {
    font-size: 7rem;
    line-height: 1;
}

.review-progressbar {
    width: 100%;
    max-width: 20rem;
}

.quiz-option-text {
    font-size: 1rem;
    line-height: 1.4;
    padding: 1.1rem 0.75rem;
}

.quiz-result-emoji {
    font-size: 3rem;
    margin: 0;
}

.quiz-result-score {
    color: #6f675c;
    margin: 0;
}

/* --- Practice chooser --- */

.practice-choices {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
}

.practice-choice {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 1rem 1.25rem;
    background: #fff;
    border: 1px solid #e5e0d8;
    border-radius: 14px;
    font: inherit;
    text-align: center;
    cursor: pointer;
}

.practice-choice:hover {
    border-color: #1f6feb;
}

.quiz-save-status {
    margin: 0;
    font-size: 0.85rem;
    color: #6f675c;
}

.back-link {
    font-size: 0.9rem;
    color: #1f6feb;
    text-decoration: none;
}

.back-link:hover {
    text-decoration: underline;
}

/* --- Small screens --- */

@media (max-width: 480px) {
    .status-row {
        flex-wrap: wrap;
    }

    .stat-course {
        flex-basis: 100%;
        order: 3;
    }
}
