/* ==========================================================================
   clerk-typing-studio  听打练习组件
   命名空间：.cts   所有样式隔离，可安全嵌入任意宿主页面
   ========================================================================== */
.cts {
    --cts-line: #e4e7eb;
    --cts-line-strong: #c9ced6;
    --cts-text: #1f2329;
    --cts-muted: #7a818a;
    --cts-ink: #11151a;
    --cts-surface: #ffffff;
    --cts-surface-2: #f6f8fa;
    --cts-surface-3: #eef1f5;
    --cts-brand: #ffd100;
    --cts-brand-deep: #e8b400;
    --cts-brand-soft: rgba(255, 209, 0, .18);
    --cts-accent: #0086d2;
    --cts-ok: #22a06b;
    --cts-ok-soft: rgba(34, 160, 107, .12);
    --cts-danger: #d93f3f;
    --cts-danger-soft: rgba(217, 63, 63, .14);
    --cts-info-soft: rgba(11, 107, 181, .14);
    --cts-warn-soft: rgba(255, 209, 0, .26);
    --cts-focus: #2b8cff;
    --cts-radius: 12px;
    --cts-radius-sm: 6px;

    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--cts-text);
    background: var(--cts-surface);
    border: 1px solid var(--cts-line);
    border-radius: var(--cts-radius);
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

.cts *,
.cts *::before,
.cts *::after {
    box-sizing: border-box;
}

.cts [hidden] {
    display: none !important;
}

.cts button {
    font-family: inherit;
}

/* ---------- 头部 ---------- */
.cts__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 16px;
    min-height: 46px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--cts-line);
    background: var(--cts-surface);
}

.cts__title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--cts-ink);
}

.cts__title .glyphicon {
    font-size: 15px;
    color: var(--cts-accent);
}

.cts__subtitle {
    font-size: 12px;
    font-weight: 400;
    color: var(--cts-muted);
    padding-left: 8px;
    border-left: 1px solid var(--cts-line);
    white-space: nowrap;
}

.cts__hints {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 12px;
    color: var(--cts-muted);
}

.cts-kbd {
    display: inline-block;
    min-width: 20px;
    padding: 1px 6px;
    font-size: 11px;
    line-height: 16px;
    text-align: center;
    color: var(--cts-muted);
    background: var(--cts-surface-2);
    border: 1px solid var(--cts-line);
    border-bottom-width: 2px;
    border-radius: 4px;
}

/* ---------- 播放区 ---------- */
.cts__player {
    padding: 14px 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--cts-surface);
}

.cts__player-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    min-width: 0;
}

.cts-play {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    color: #4a3d00;
    background: var(--cts-brand);
    border: 1px solid var(--cts-brand-deep);
    border-radius: 50%;
    cursor: pointer;
    transition: background-color .16s ease, transform .1s ease;
}

.cts-play:hover {
    background: #ffd81f;
}

.cts-play:active {
    transform: scale(.94);
}

.cts-play:focus-visible {
    outline: 2px solid var(--cts-focus);
    outline-offset: 2px;
}

.cts-play.is-playing {
    color: var(--cts-text);
    background: var(--cts-surface);
    border-color: var(--cts-line-strong);
}

.cts-play.is-playing:hover {
    background: var(--cts-surface-2);
}

.cts-wave {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 3px;
    height: 32px;
    color: #ccd2da;
    transition: color .2s ease;
}

.cts-wave.is-playing {
    color: var(--cts-accent);
}

.cts-wave__bar {
    display: block;
    width: 3px;
    min-height: 6px;
    border-radius: 99px;
    background: currentColor;
    transform: scaleY(.5);
    transform-origin: 50% 50%;
    transition: opacity .18s ease, transform .18s ease;
}

.cts-wave.is-playing .cts-wave__bar {
    opacity: .78;
    will-change: transform;
    animation-name: cts-wave;
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
    animation-play-state: running;
}

@keyframes cts-wave {
    0%, 100% {
        transform: scaleY(.35);
    }
    38% {
        transform: scaleY(1);
    }
    68% {
        transform: scaleY(.6);
    }
}

.cts-status {
    flex: 1 1 150px;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: 13px;
}

.cts-status__text {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.cts-status__dot {
    flex: 0 0 auto;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #b9c0c9;
    transition: background-color .2s ease, box-shadow .2s ease;
}

.cts-status__dot.is-playing {
    background: var(--cts-ok);
    box-shadow: 0 0 0 4px var(--cts-ok-soft);
}

.cts-time {
    flex: 0 0 auto;
    font-size: 12px;
    color: var(--cts-muted);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

.cts-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-left: auto;
}

.cts-rate-group {
    display: inline-flex;
    vertical-align: middle;
}

.cts-rate-group .btn {
    padding: 4px 10px;
    font-size: 12px;
    line-height: 20px;
    color: var(--cts-muted);
    background: var(--cts-surface);
    border: 1px solid var(--cts-line);
    border-radius: 0;
    box-shadow: none;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

.cts-rate-group .btn + .btn {
    margin-left: -1px;
}

.cts-rate-group .btn:first-child {
    border-radius: var(--cts-radius-sm) 0 0 var(--cts-radius-sm);
}

.cts-rate-group .btn:last-child {
    border-radius: 0 var(--cts-radius-sm) var(--cts-radius-sm) 0;
}

.cts-rate-group .btn:hover {
    color: var(--cts-text);
    background: var(--cts-surface-2);
    border-color: var(--cts-line-strong);
}

.cts-rate-group .btn.is-active,
.cts-rate-group .btn.is-active:hover {
    position: relative;
    z-index: 2;
    color: #4a3d00;
    font-weight: 700;
    background: var(--cts-brand);
    border-color: var(--cts-brand-deep);
}

.cts-rate-group .btn:focus-visible {
    outline: 2px solid var(--cts-focus);
    outline-offset: -2px;
}

.cts-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 30px;
    padding: 0 12px;
    font-size: 12px;
    line-height: 1;
    color: var(--cts-text);
    background: var(--cts-surface);
    border: 1px solid var(--cts-line);
    border-radius: var(--cts-radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.cts-btn:hover:not(:disabled) {
    background: var(--cts-surface-2);
    border-color: var(--cts-line-strong);
}

.cts-btn:disabled {
    cursor: not-allowed;
    opacity: .42;
}

.cts-btn:focus-visible {
    outline: 2px solid var(--cts-focus);
    outline-offset: -2px;
}

.cts-btn .glyphicon {
    font-size: 11px;
}

.cts-btn.is-primary {
    color: #4a3d00;
    font-weight: 700;
    background: var(--cts-brand);
    border-color: var(--cts-brand-deep);
}

.cts-btn.is-primary:hover:not(:disabled) {
    background: #ffd81f;
}

/* ---------- 进度条 ---------- */
.cts-progress {
    position: relative;
    height: 8px;
    border-radius: 99px;
    background: #eceff2;
    cursor: pointer;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    outline: none;
}

.cts-progress:focus-visible {
    box-shadow: 0 0 0 3px var(--cts-brand-soft);
}

.cts-progress__fill {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    border-radius: 99px;
    background: linear-gradient(90deg, #ffd100 0%, #ffb300 100%);
    transform: scaleX(0);
    transform-origin: 0 50%;
    transition: transform .1s linear;
    will-change: transform;
}

.cts-progress.is-dragging .cts-progress__fill {
    transition: none;
}

.cts-progress__handle {
    position: absolute;
    top: 50%;
    left: 0;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--cts-brand-deep);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
    opacity: 0;
    pointer-events: none;
    transition: opacity .16s ease, transform .16s ease;
}

.cts-progress:hover .cts-progress__handle,
.cts-progress:focus-visible .cts-progress__handle,
.cts-progress.is-dragging .cts-progress__handle {
    opacity: 1;
}

.cts-progress.is-dragging .cts-progress__handle {
    transform: scale(1.12);
}

/* ---------- 指标区 ---------- */
.cts-metrics {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 1px;
    background: var(--cts-line);
    border-top: 1px solid var(--cts-line);
    border-bottom: 1px solid var(--cts-line);
}

.cts-metrics__cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 10px 12px;
    background: var(--cts-surface);
}

.cts-metrics__label {
    font-size: 12px;
    color: var(--cts-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cts-metrics__value {
    display: flex;
    align-items: baseline;
    gap: 2px;
    min-width: 0;
    font-size: 18px;
    font-weight: 800;
    line-height: 1.3;
    color: var(--cts-ink);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

.cts-metrics__value small {
    font-size: 11px;
    font-weight: 500;
    color: var(--cts-muted);
    white-space: nowrap;
}

.cts-metrics__cell.is-good .cts-metrics__value {
    color: var(--cts-ok);
}

.cts-metrics__cell.is-warn .cts-metrics__value {
    color: var(--cts-danger);
}

.cts-metrics__cell.is-muted .cts-metrics__value {
    color: var(--cts-muted);
}

/* ---------- 录入区 ---------- */
.cts-input {
    padding: 12px 16px 14px;
    background: var(--cts-surface);
}

.cts-input__area {
    display: block;
    width: 100%;
    min-height: 369px;
    max-height: 720px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.85;
    color: var(--cts-text);
    background: var(--cts-surface);
    border: 1px solid var(--cts-line);
    border-radius: var(--cts-radius-sm);
    resize: vertical;
    outline: none;
    transition: border-color .16s ease, box-shadow .16s ease;
    -webkit-appearance: none;
}

.cts-input__area::placeholder {
    color: #a8b0ba;
}

.cts-input__area:focus {
    border-color: var(--cts-brand-deep);
    box-shadow: 0 0 0 3px var(--cts-brand-soft);
}

.cts-input__area[readonly] {
    background: var(--cts-surface-2);
    color: var(--cts-muted);
    cursor: default;
}

.cts-input__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.cts-input__hint {
    font-size: 12px;
    color: var(--cts-muted);
    min-width: 0;
}

.cts-input__hint b {
    color: var(--cts-text);
    font-weight: 700;
}

.cts-input__tools {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.cts-completion {
    height: 4px;
    margin-top: 10px;
    border-radius: 99px;
    background: #eceff2;
    overflow: hidden;
}

.cts-completion__bar {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #7ad1ff, var(--cts-accent));
    transition: width .18s ease;
}

/* ---------- 复盘区 ---------- */
.cts-review {
    border-top: 1px solid var(--cts-line);
    background: var(--cts-surface);
}

.cts-review__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--cts-line);
    background: var(--cts-surface);
}

.cts-review__title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    color: var(--cts-ink);
}

.cts-review__title .glyphicon {
    color: var(--cts-accent);
}

.cts-review__tools {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.cts-switch {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: 12px;
    font-weight: 400;
    color: var(--cts-muted);
    cursor: pointer;
    user-select: none;
}

.cts-switch input {
    margin: 0;
    cursor: pointer;
}

.cts-review__summary {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
}

.cts-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 700;
    line-height: 18px;
    border-radius: 99px;
    border: 1px solid transparent;
}

.cts-chip.is-ok {
    color: #14603f;
    background: var(--cts-ok-soft);
    border-color: rgba(34, 160, 107, .3);
}

.cts-chip.is-sub {
    color: #97201f;
    background: var(--cts-danger-soft);
    border-color: rgba(217, 63, 63, .3);
}

.cts-chip.is-miss {
    color: #7a5c00;
    background: var(--cts-warn-soft);
    border-color: rgba(232, 180, 0, .4);
}

.cts-chip.is-extra {
    color: #0b5a99;
    background: var(--cts-info-soft);
    border-color: rgba(11, 107, 181, .3);
}

.cts-review__legend {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    padding: 0 16px 10px;
    font-size: 12px;
    color: var(--cts-muted);
}

.cts-legend {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.cts-legend i {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
}

.cts-legend i.is-ok {
    background: var(--cts-ok-soft);
    box-shadow: inset 0 0 0 1px rgba(34, 160, 107, .45);
}

.cts-legend i.is-sub {
    background: var(--cts-danger-soft);
    box-shadow: inset 0 0 0 1px rgba(217, 63, 63, .45);
}

.cts-legend i.is-miss {
    background: var(--cts-warn-soft);
    box-shadow: inset 0 0 0 1px rgba(232, 180, 0, .6);
}

.cts-legend i.is-extra {
    background: var(--cts-info-soft);
    box-shadow: inset 0 0 0 1px rgba(11, 107, 181, .45);
}

.cts-review__body {
    margin: 0 16px;
    padding: 12px 14px;
    max-height: 340px;
    overflow-y: auto;
    font-size: 16px;
    line-height: 2.2;
    word-break: break-all;
    background: var(--cts-surface-2);
    border: 1px solid var(--cts-line);
    border-radius: var(--cts-radius-sm);
    -webkit-overflow-scrolling: touch;
}

.cts-review__body.is-errors-only .cts-tok.is-ok,
.cts-review__body.is-errors-only .cts-fold {
    display: none;
}

.cts-review__empty {
    margin: 0;
    font-size: 13px;
    color: var(--cts-muted);
    line-height: 1.8;
}

.cts-tok {
    display: inline-block;
    margin: 1px 1px;
    padding: 0 3px;
    border-radius: 3px;
    transition: background-color .12s ease, box-shadow .12s ease;
}

.cts-tok.is-ok {
    color: #234;
    background: var(--cts-ok-soft);
}

.cts-tok.is-sub {
    color: #97201f;
    background: var(--cts-danger-soft);
    box-shadow: inset 0 -2px 0 rgba(217, 63, 63, .55);
}

.cts-tok.is-sub i {
    font-style: normal;
    margin-left: 3px;
    font-size: 11px;
    color: #b32020;
    text-decoration: line-through;
    opacity: .85;
}

.cts-tok.is-miss {
    color: #7a5c00;
    background: var(--cts-warn-soft);
    box-shadow: inset 0 -2px 0 rgba(232, 180, 0, .65);
    opacity: .9;
}

.cts-tok.is-extra {
    color: #0b5a99;
    background: var(--cts-info-soft);
    text-decoration: line-through;
    text-decoration-color: rgba(11, 107, 181, .55);
}

.cts-tok.is-focus {
    outline: 2px solid var(--cts-focus);
    outline-offset: 1px;
    animation: cts-focus-pulse .6s ease-out;
}

@keyframes cts-focus-pulse {
    from {
        background-color: rgba(43, 140, 255, .35);
    }
}

.cts-fold {
    display: inline-block;
    padding: 0 8px;
    margin: 1px 2px;
    font-size: 12px;
    line-height: 22px;
    color: var(--cts-muted);
    background: #fff;
    border: 1px dashed var(--cts-line-strong);
    border-radius: 99px;
    cursor: pointer;
    vertical-align: middle;
    transition: color .15s ease, border-color .15s ease;
}

.cts-fold:hover {
    color: var(--cts-text);
    border-color: var(--cts-muted);
}

.cts-review__section {
    padding: 14px 16px 4px;
}

.cts-review__h4 {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 700;
    color: var(--cts-ink);
}

.cts-review__h4 small {
    font-size: 12px;
    font-weight: 400;
    color: var(--cts-muted);
}

.cts-err-wrap {
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--cts-line);
    border-radius: var(--cts-radius-sm);
    -webkit-overflow-scrolling: touch;
}

.cts-err-table {
    width: 100%;
    margin: 0;
    border-collapse: collapse;
    font-size: 13px;
}

.cts-err-table th,
.cts-err-table td {
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid var(--cts-line);
    vertical-align: middle;
}

.cts-err-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    font-size: 12px;
    font-weight: 600;
    color: var(--cts-muted);
    background: var(--cts-surface-2);
    white-space: nowrap;
}

.cts-err-table tbody tr {
    cursor: pointer;
    transition: background-color .12s ease;
}

.cts-err-table tbody tr:hover {
    background: var(--cts-surface-2);
}

.cts-err-table tbody tr:last-child td {
    border-bottom: 0;
}

.cts-err-table td.is-pos {
    color: var(--cts-muted);
    white-space: nowrap;
}

.cts-err-table td.is-char {
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
}

.cts-tag {
    display: inline-block;
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    border-radius: 99px;
    white-space: nowrap;
}

.cts-tag.is-sub {
    color: #97201f;
    background: var(--cts-danger-soft);
}

.cts-tag.is-miss {
    color: #7a5c00;
    background: var(--cts-warn-soft);
}

.cts-tag.is-extra {
    color: #0b5a99;
    background: var(--cts-info-soft);
}

.cts-advice {
    list-style: none;
    margin: 0;
    padding: 0 0 14px;
    display: grid;
    gap: 8px;
}

.cts-advice li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--cts-text);
    background: var(--cts-surface);
    border: 1px solid var(--cts-line);
    border-radius: 8px;
}

.cts-advice li::before {
    content: '';
    flex: 0 0 auto;
    width: 5px;
    align-self: stretch;
    min-height: 18px;
    border-radius: 99px;
    background: #ccd2da;
}

.cts-advice li.is-ok::before {
    background: var(--cts-ok);
}

.cts-advice li.is-info::before {
    background: var(--cts-accent);
}

.cts-advice li.is-warn::before {
    background: var(--cts-brand-deep);
}

.cts-advice li.is-danger::before {
    background: var(--cts-danger);
}

.cts-advice li b {
    color: var(--cts-ink);
}

/* ---------- 响应式 ---------- */
@media (max-width: 1199px) {
    .cts-metrics {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 767px) {
    .cts__subtitle, .cts__hints {
        display: none;
    }

    .cts__player {
        padding: 12px 12px 10px;
    }

    .cts-actions {
        flex: 1 1 100%;
        margin-left: 0;
        justify-content: space-between;
    }

    .cts-status {
        flex: 1 1 120px;
        font-size: 12px;
    }

    .cts-wave {
        height: 26px;
    }

    .cts-play {
        width: 36px;
        height: 36px;
    }

    .cts-input {
        padding: 12px;
    }

    .cts-input__area {
        min-height: 110px;
        font-size: 16px;
    }

    .cts-review__body {
        margin: 0 12px;
        font-size: 15px;
        line-height: 2.1;
    }

    .cts-review__section {
        padding: 12px 12px 4px;
    }

    .cts-err-table th:nth-child(1),
    .cts-err-table td:nth-child(1) {
        display: none;
    }
}

@media (max-width: 575px) {
    .cts-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .cts-metrics__cell {
        padding: 9px 12px;
    }

    .cts-metrics__value {
        font-size: 16px;
    }

    .cts-review__head {
        padding: 10px 12px;
    }

    .cts-review__summary {
        padding: 8px 12px;
    }

    .cts-review__legend {
        padding: 0 12px 8px;
        gap: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cts-wave.is-playing .cts-wave__bar {
        animation: none;
        transform: scaleY(.6);
        opacity: .55;
    }

    .cts-progress__fill, .cts-completion__bar, .cts-tok {
        transition: none;
    }

    .cts-tok.is-focus {
        animation: none;
    }
}