@font-face {
    font-family: 'Playwrite VN Primary';
    src: url('../fonts/PlaywriteVN-VariableFont_wght.ttf') format('truetype');
    font-style: normal;
    font-weight: 100 400;
    font-display: swap;
}

.handwriting-page {
    max-width: 1280px;
    margin: auto;
}

.handwriting-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin: 22px 0;
}

.handwriting-heading span {
    color: #7056df;
    font-weight: 900;
    letter-spacing: 1.4px;
}

.handwriting-heading h1 {
    font-size: 38px;
    margin: 7px 0;
}

.writing-progress {
    background: #fff1b9;
    border-radius: 20px;
    padding: 16px 24px;
    text-align: center;
}

.writing-progress b {
    display: block;
    font-size: 28px;
}

.writing-progress small {
    font-weight: 800;
}

.track-tabs,
.writing-modes {
    display: flex;
    gap: 10px;
    margin: 16px 0;
}

.track-tabs a,
.writing-modes button {
    border: 2px solid #ded6fb;
    background: #fff;
    color: #4f3a9f;
    border-radius: 14px;
    padding: 12px 18px;
    font-weight: 900;
}

.track-tabs .active,
.writing-modes .active {
    background: #6e52dd;
    color: #fff;
    border-color: #6e52dd;
}

.writing-workspace {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 22px;
}

.writing-model,
.writing-practice {
    background: #fff;
    border: 2px solid #e9e3fa;
    border-radius: 26px;
    padding: 24px;
}

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

.writing-model small {
    color: #7056df;
    font-weight: 900;
}

.model-style-note {
    display: block;
    width: max-content;
    max-width: 100%;
    margin: 8px auto 0;
    padding: 5px 9px;
    border-radius: 999px;
    background: #f1edff;
    color: #6954b6;
    font-size: 11px;
    font-weight: 800;
}

.model-glyph {
    min-height: 190px;
    display: grid;
    place-items: center;
    font-size: 150px;
    line-height: 1.25;
    font-family: 'Microsoft YaHei', 'Noto Sans CJK SC', Arial, sans-serif;
    overflow-wrap: anywhere;
}

.vietnamese-writing .model-glyph {
    min-height: 205px;
    font-family: 'Playwrite VN Primary', 'Segoe Print', cursive;
    font-size: 120px;
    font-weight: 300;
    line-height: 1.45;
    color: #20305f;
}

.writing-model > b {
    font-size: 22px;
    color: #e64b4b;
}

.writing-model p {
    font-size: 18px;
    font-weight: 800;
}

.speak-button {
    border: 0;
    border-radius: 12px;
    background: #fff1b9;
    padding: 12px 18px;
    font-weight: 900;
}

.writing-board {
    position: relative;
    border: 3px solid #d8cdfa;
    border-radius: 22px;
    overflow: hidden;
    background: #fff;
    aspect-ratio: 9 / 5;
}

.vietnamese-writing .writing-board {
    border-color: #cfc1f2;
    box-shadow: inset 0 0 0 1px #fff;
}

.writing-board canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    overscroll-behavior: contain;
    user-select: none;
}

.pen-hint {
    position: absolute;
    pointer-events: none;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: #fff9;
    padding: 10px 15px;
    border-radius: 12px;
    color: #7664a8;
    font-weight: 900;
}

.writing-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

.writing-actions button,
.next-writing {
    border: 0;
    border-radius: 13px;
    padding: 13px 17px;
    font-weight: 900;
    background: #eee9ff;
}

.writing-actions .primary {
    background: #6e52dd;
    color: #fff;
}

.next-writing {
    margin-left: auto;
}

.writing-result {
    margin-top: 15px;
    padding: 15px;
    border-radius: 16px;
    background: #e9fff5;
}

.writing-result strong {
    font-size: 25px;
}

.writing-result p {
    margin: 4px 0;
}

.glyph-library {
    margin: 28px 0;
    background: #fff;
    border: 2px solid #eee8ff;
    border-radius: 24px;
    padding: 22px;
}

.glyph-library > div {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    max-height: 330px;
    overflow: auto;
}

.glyph-library a {
    width: 76px;
    min-height: 72px;
    border: 2px solid #e7e0f7;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.glyph-library a b {
    font-size: 27px;
}

.vietnamese-writing .glyph-library a b {
    font-family: 'Playwrite VN Primary', 'Segoe Print', cursive;
    font-size: 30px;
    font-weight: 300;
    line-height: 1.45;
}

.glyph-library a small {
    font-size: 10px;
}

.glyph-library a.active {
    border-color: #7056df;
    background: #eee9ff;
}

.glyph-library a.mastered::after {
    content: '✓';
    color: #0a9d72;
    font-weight: 900;
}

@media (max-width: 850px) {
    .writing-workspace {
        grid-template-columns: 1fr;
    }

    .writing-model {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: center;
    }

    .model-style-note {
        grid-column: 1;
    }

    .model-glyph {
        font-size: 100px;
    }

    .vietnamese-writing .model-glyph {
        font-size: 94px;
    }

    .writing-practice {
        padding: 14px;
    }

    .writing-board {
        width: 100%;
    }
}

@media (max-width: 540px) {
    .handwriting-heading {
        align-items: flex-start;
    }

    .handwriting-heading h1 {
        font-size: 28px;
    }

    .writing-progress {
        padding: 10px;
    }

    .writing-modes,
    .track-tabs {
        overflow: auto;
    }

    .writing-modes button,
    .track-tabs a {
        white-space: nowrap;
        padding: 10px;
    }

    .writing-actions > * {
        flex: 1;
    }

    .next-writing {
        margin-left: 0;
        text-align: center;
    }
}
