@import url("/static/css/base.css");

/* ── Base ───────────────────────────────────── */
*, :after, :before { box-sizing: inherit }

*,
:after,
:before {
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    line-height: 1.7;
    color: var(--text-color);
    background-color: var(--secondary-color);
    margin: 0; padding: 0;
    display: flex; flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-color); text-decoration: none; transition: color .2s ease }

h1, h2, h3 {
    font-family: var(--font-primary);
    color: var(--heading-color);
    margin-bottom: .6em; line-height: 1.3; font-weight: 600;
}

.main-content { flex-grow: 1; padding: 2.5rem 1.5rem }

/* ── Stories container ──────────────────────── */
.stories-container {
    max-width: 1040px;
    margin: 0 auto;
}

.stories-header h1 {
    font-size: 1.8rem;
    margin-bottom: .25rem;
}

.stories-header p {
    color: var(--text-muted);
    font-size: .95rem;
    margin-bottom: 1.5rem;
}

/* ── Level tabs ─────────────────────────────── */
.level-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.level-tab {
    padding: .55rem 1.2rem;
    font-size: .9rem;
    font-weight: 600;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    cursor: pointer;
    transition: all .2s ease;
}

.level-tab:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.level-tab.active {
    background: var(--primary-color);
    color: var(--card-bg);
    border-color: var(--primary-color);
}

/* ── Story cards grid ───────────────────────── */
.story-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.story-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: border-color .18s ease;
    box-shadow: 0 10px 30px -24px var(--shadow-color);
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.story-card:hover {
    border-color: color-mix(in srgb, var(--primary-color) 58%, transparent);
}

.story-card-media {
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: linear-gradient(180deg, color-mix(in srgb, var(--primary-color) 20%, var(--card-bg)), var(--card-bg)), var(--secondary-color);
}

.story-card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .35s ease;
}

.story-card:hover .story-card-image {
    transform: scale(1.03);
}

.story-card-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 1rem;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    background:
        linear-gradient(160deg, rgba(20, 83, 45, .68), rgba(37, 99, 235, .72)),
        radial-gradient(circle at top left, rgba(255, 255, 255, .24), rgba(255, 255, 255, 0) 40%);
}

.story-card-media.is-missing .story-card-fallback {
    opacity: 1;
}

.story-card-fallback-title {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.15;
    text-shadow: 0 4px 18px rgba(15, 23, 42, .22);
}

.story-card-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: .55rem;
    padding: 1rem 1rem 1.05rem;
}

.story-card-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--heading-color);
    line-height: 1.2;
}

.story-card-subtitle {
    font-size: .9rem;
    color: var(--text-muted);
    line-height: 1.45;
    min-height: 2.6em;
}

.story-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-top: auto;
    padding-top: .2rem;
}

.story-card-meta {
    font-size: .8rem;
    color: var(--text-muted-light);
}

.story-card-meta .fas { margin-right: 4px; }

.story-card-cta {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-size: .8rem;
    font-weight: 600;
    color: var(--primary-color);
    white-space: nowrap;
}

/* ── Back button ────────────────────────────── */
.reader-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: .5rem 1rem;
    font-size: .85rem;
    font-weight: 600;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    cursor: pointer;
    transition: all .2s ease;
}

.back-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* ── Story reader (fixed overlay, independent scroll) ── */
.story-reader { display: none; }
.story-reader.visible {
    display: block;
    position: fixed;
    top: 60px;
    right: 0;
    bottom: 0;
    left: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 2;
    background: var(--secondary-color);
}

.reader-inner {
    max-width: 1040px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem;
}

.story-header-row {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color-light);
}

.story-title-section {
    flex: 1 1 40%;
    min-width: 0;
}

.story-title-hanzi {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--heading-color);
    margin-bottom: .2rem;
}

.story-title-english {
    font-size: 1rem;
    color: var(--text-muted);
}

.story-meta-info {
    display: flex;
    gap: 1rem;
    margin-top: .5rem;
    flex-wrap: wrap;
}

.story-meta-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: .78rem;
    padding: .25rem .65rem;
    border-radius: 20px;
    background: var(--surface-alt);
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Sentences ──────────────────────────────── */
.sentences-section { margin-bottom: 2rem; }

.story-text {
    font-size: 1.35rem;
    line-height: 2.0;
}

.sentence-word {
    cursor: pointer;
    border-radius: 3px;
    padding: 1px 0;
    transition: background .15s ease, color .15s ease;
    position: relative;
}

.sentence-word:hover,
.sentence-word.active {
    background: color-mix(in srgb, var(--primary-color) 12%, transparent);
    color: var(--primary-color);
}

.sentence-word.non-han {
    cursor: default;
}
.sentence-word.non-han:hover,
.sentence-word.non-han.active {
    background: transparent;
    color: inherit;
}

.sentence-word.punctuation {
    cursor: default;
}
.sentence-word.punctuation:hover,
.sentence-word.punctuation.active {
    background: transparent;
    color: inherit;
}

/* ── Per-sentence translation ────────────────── */
.sentence-block {
    display: inline;
}

.sentence-block.newline::before {
    content: '\A\2003\2003';
    white-space: pre;
}

.sentence-block.indent-only::before {
    content: '\2003\2003';
    white-space: pre;
}

.sentence-translation {
    display: none;
    font-size: .82rem;
    color: var(--text-muted);
    padding: .2rem 0 .3rem .25rem;
    line-height: 1.5;
}

.show-translations .sentence-block {
    display: block;
    text-indent: 0;
    padding: .15rem 0;
}

.show-translations .sentence-block.newline::before,
.show-translations .sentence-block.indent-only::before {
    content: none;
}

.show-translations .sentence-translation {
    display: block;
    text-indent: 0;
    margin-bottom: .35rem;
    padding-left: .25rem;
    border-left: 2px solid var(--border-color-light);
}

/* ── Word tooltip ───────────────────────────── */
.word-tooltip {
    position: fixed;
    z-index: 3;
    background-color: #2a2a2a;
    color: #f0f0f0;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    padding: 10px 15px;
    min-width: 300px;
    max-width: 300px;
    font-size: 14px;
    line-height: 1.7;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s ease, transform .2s ease;
}

.word-tooltip .hsk-badge {
    position: absolute;
    top: 11px;
    right: 2.2rem;
}

.word-tooltip.visible {
    opacity: 1;
    pointer-events: auto;
}

.word-tooltip-close {
    display: none;
}

.word-tooltip-link {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: .6rem;
    right: .6rem;
    width: 20px;
    height: 20px;
    color: rgba(255,255,255,.4);
    font-size: .7rem;
    text-decoration: none;
    cursor: pointer;
    border-radius: 4px;
    transition: color .15s ease, background .15s ease;
}

.word-tooltip-link:hover {
    color: rgba(255,255,255,.85);
    background: rgba(255,255,255,.08);
}

/* Bottom modal mode (mobile) */
.word-tooltip.bottom-modal {
    top: auto !important;
    bottom: 0;
    left: 0 !important;
    right: 0;
    width: 100%;
    max-width: 100%;
    max-height: 40vh;
    overflow-y: auto;
    border-radius: 8px 8px 0 0;
    box-shadow: none;
    padding: .2rem 1rem calc(.4rem + env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .1rem .6rem;
}

.word-tooltip.bottom-modal.visible {
    transform: translateY(0);
}

.word-tooltip.bottom-modal .word-tooltip-close {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 9px;
    right: 10px;
    width: 20px;
    height: 20px;
    border: none;
    background: none;
    border-radius: 4px;
    cursor: pointer;
    color: rgba(255,255,255,.45);
    font-size: .8rem;
    padding: 0;
    transition: color .15s ease, background .15s ease;
}

.word-tooltip.bottom-modal .word-tooltip-link {
    position: absolute;
    top: 9px;
    right: 35px;
    width: 20px;
    height: 20px;
    font-size: .75rem;
    color: rgba(255,255,255,.45);
}

.word-tooltip.bottom-modal .word-tooltip-link:hover {
    color: rgba(255,255,255,.85);
}

.word-tooltip.bottom-modal .word-tooltip-close:hover {
    color: rgba(255,255,255,.85);
    background: rgba(255,255,255,.08);
}

.word-tooltip.bottom-modal .hsk-badge {
    position: absolute;
    top: 10px;
    right: 62px;
    margin-bottom: 0;
}

.word-tooltip.bottom-modal .word-tooltip-char {
    font-size: 1.4rem;
    margin-bottom: 0;
}

.word-tooltip.bottom-modal .word-tooltip-pinyin {
    font-size: .92rem;
    margin-bottom: 0;
}

.word-tooltip.bottom-modal .word-tooltip-def {
    flex-basis: 100%;
    font-size: .85rem;
    margin-bottom: 0;
    padding-right: 1.8rem;
}

.word-tooltip-char {
    font-size: 1.3rem;
    font-weight: 700;
    color: #d0d0d0;
    margin-bottom: .15rem;
    display: inline;
    margin-right: .4rem;
}

.word-tooltip-pinyin {
    font-size: .88rem;
    color: color-mix(in srgb, color-mix(in srgb, var(--accent-color) 70%, var(--primary-color-alt) 50%), white 40%);
    font-weight: 600;
    margin-bottom: .3rem;
    display: inline;
}

.word-tooltip-def {
    font-size: .82rem;
    color: #f0f0f0;
    line-height: 1.5;
    margin-bottom: .3rem;
}

.word-tooltip-def .definition-line {
    padding: .1rem 0;
}

.word-tooltip-def .definition-line + .definition-line {
    border-top: 1px solid rgba(255,255,255,.12);
    margin-top: .15rem;
    padding-top: .25rem;
}

.word-tooltip-def .def-pinyin {
    color: color-mix(in srgb, color-mix(in srgb, var(--accent-color) 70%, var(--primary-color-alt) 50%), white 40%);
    font-weight: 600;
    margin-right: .3rem;
    font-size: .8rem;
}

.word-tooltip-def .def-pos {
    color: #aaa;
    font-style: italic;
    font-size: .78rem;
    margin-right: .25rem;
}

.word-tooltip-def .def-gloss {
    color: #f0f0f0;
}

[data-theme="dark"] .word-tooltip-pinyin {
    color: color-mix(in srgb, color-mix(in srgb, var(--accent-color) 40%, var(--primary-hover) 60%), white 20%);
}

[data-theme="dark"] .word-tooltip-def .def-pinyin {
    color: color-mix(in srgb, color-mix(in srgb, var(--accent-color) 40%, var(--primary-hover) 60%), white 20%);
}

.hsk-badge { 
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .65rem;
    width: 17px;
    height: 17px;
    padding: 0;
    border-radius: 4px;
    font-weight: 700;
    line-height: normal;
    letter-spacing: .01em;
    white-space: nowrap;
    border: 1px solid transparent;
}

.hsk-1 { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.hsk-2 { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.hsk-3 { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.hsk-4 { background: #fce7f3; color: #9d174d; border-color: #fbcfe8; }
.hsk-5 { background: #e0e7ff; color: #3730a3; border-color: #c7d2fe; }
.hsk-6 { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.hsk-7 { background: #f3e8ff; color: #6b21a8; border-color: #e9d5ff; }

/* Popup is always dark — scope dark palette inside .word-tooltip */
.word-tooltip .hsk-1 { background: #14532d; color: #86efac; border-color: #166534; }
.word-tooltip .hsk-2 { background: #1e3a5f; color: #93c5fd; border-color: #1e40af; }
.word-tooltip .hsk-3 { background: #451a03; color: #fcd34d; border-color: #78350f; }
.word-tooltip .hsk-4 { background: #4a0728; color: #f9a8d4; border-color: #831843; }
.word-tooltip .hsk-5 { background: #1e1b4b; color: #a5b4fc; border-color: #312e81; }
.word-tooltip .hsk-6 { background: #2e1065; color: #c4b5fd; border-color: #4c1d95; }
.word-tooltip .hsk-7 { background: #3b0764; color: #d8b4fe; border-color: #581c87; }

[data-theme="dark"] .hsk-1 { background: #14532d; color: #86efac; border-color: #166534; }
[data-theme="dark"] .hsk-2 { background: #1e3a5f; color: #93c5fd; border-color: #1e40af; }
[data-theme="dark"] .hsk-3 { background: #451a03; color: #fcd34d; border-color: #78350f; }
[data-theme="dark"] .hsk-4 { background: #4a0728; color: #f9a8d4; border-color: #831843; }
[data-theme="dark"] .hsk-5 { background: #1e1b4b; color: #a5b4fc; border-color: #312e81; }
[data-theme="dark"] .hsk-6 { background: #2e1065; color: #c4b5fd; border-color: #4c1d95; }
[data-theme="dark"] .hsk-7 { background: #3b0764; color: #d8b4fe; border-color: #581c87; }

/* ── HSK Color-coded words ──────────────────── */
.hsk-colored .sentence-word[data-hsk="1"] { background: #dcfce7; color: #166534; border-radius: 3px; }
.hsk-colored .sentence-word[data-hsk="2"] { background: #dbeafe; color: #1e40af; border-radius: 3px; }
.hsk-colored .sentence-word[data-hsk="3"] { background: #fef3c7; color: #92400e; border-radius: 3px; }
.hsk-colored .sentence-word[data-hsk="4"] { background: #fce7f3; color: #9d174d; border-radius: 3px; }
.hsk-colored .sentence-word[data-hsk="5"] { background: #e0e7ff; color: #3730a3; border-radius: 3px; }
.hsk-colored .sentence-word[data-hsk="6"] { background: #ede9fe; color: #5b21b6; border-radius: 3px; }
.hsk-colored .sentence-word[data-hsk="7"] { background: #f3e8ff; color: #6b21a8; border-radius: 3px; }

[data-theme="dark"] .hsk-colored .sentence-word[data-hsk="1"] { background: #14532d; color: #86efac; }
[data-theme="dark"] .hsk-colored .sentence-word[data-hsk="2"] { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .hsk-colored .sentence-word[data-hsk="3"] { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .hsk-colored .sentence-word[data-hsk="4"] { background: #4a0728; color: #f9a8d4; }
[data-theme="dark"] .hsk-colored .sentence-word[data-hsk="5"] { background: #1e1b4b; color: #a5b4fc; }
[data-theme="dark"] .hsk-colored .sentence-word[data-hsk="6"] { background: #2e1065; color: #c4b5fd; }
[data-theme="dark"] .hsk-colored .sentence-word[data-hsk="7"] { background: #3b0764; color: #d8b4fe; }

.reveal-toggle.active {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 8%, var(--card-bg));
}

.reader-top-toggles {
    display: flex;
    gap: 8px;
    align-items: center;
}

.font-size-control {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-right: 4px;
}

.size-btn {
    padding: .3rem .5rem;
    font-size: .72rem;
    font-weight: 600;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm, 4px);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .15s ease;
    line-height: 1;
}

.size-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.size-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--card-bg);
}

/* ── HSK Stats panel ────────────────────────── */
.stats-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 1rem 1.2rem;
    box-shadow: 0 1px 3px var(--shadow-light);
    flex: 1 1 50%;
    min-width: 0;
    width: 100%;
}

.stats-title {
    font-size: .9rem;
    font-weight: 600;
    color: var(--heading-color);
    margin-bottom: .75rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.stats-title .fas { color: var(--primary-color); font-size: .85rem; }

.stats-grid {
    display: flex;
    height: 30px;
    border-radius: 6px;
    overflow: hidden;
}

.stats-segment {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .9rem;
    font-weight: 700;
    min-width: 30px;
    overflow: hidden;
    white-space: nowrap;
    cursor: default;
    line-height: normal;
}

/* Slightly darker segment backgrounds for light mode */
.stats-segment.hsk-1 { background: #bbf7d0; }
.stats-segment.hsk-2 { background: #bfdbfe; }
.stats-segment.hsk-3 { background: #fde68a; }
.stats-segment.hsk-4 { background: #fbcfe8; }
.stats-segment.hsk-5 { background: #c7d2fe; }
.stats-segment.hsk-6 { background: #ddd6fe; }
.stats-segment.hsk-7 { background: #e9d5ff; }

[data-theme="dark"] .stats-segment.hsk-1 { background: #14532d; color: #86efac; }
[data-theme="dark"] .stats-segment.hsk-2 { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .stats-segment.hsk-3 { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .stats-segment.hsk-4 { background: #4a0728; color: #f9a8d4; }
[data-theme="dark"] .stats-segment.hsk-5 { background: #1e1b4b; color: #a5b4fc; }
[data-theme="dark"] .stats-segment.hsk-6 { background: #2e1065; color: #c4b5fd; }
[data-theme="dark"] .stats-segment.hsk-7 { background: #3b0764; color: #d8b4fe; }

/* ── Grammar section ────────────────────────── */
.grammar-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color-light);
}

.grammar-section h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.grammar-section h2 .fas { color: var(--primary-color); font-size: .95rem; }

.grammar-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 1rem 1.2rem;
    margin-bottom: .75rem;
    box-shadow: 0 1px 3px var(--shadow-light);
}

.grammar-structure {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: .3rem;
}

.grammar-explanation {
    font-size: .88rem;
    color: var(--text-secondary);
    margin-bottom: .5rem;
    line-height: 1.6;
}

.grammar-example {
    font-size: .92rem;
    color: var(--text-color);
    padding: .5rem .75rem;
    background: var(--surface-alt);
    border-radius: var(--border-radius-sm);
    border-left: 3px solid var(--primary-color);
}

/* ── Default font toggle ────────────────────── */
.story-text.default-font {
    font-family: system-ui, -apple-system, sans-serif;
}

/* ── Reveal all toggle ──────────────────────── */
.reveal-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: .45rem .9rem;
    font-size: .82rem;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-muted);
    cursor: pointer;
    transition: all .2s ease;
    -webkit-tap-highlight-color: transparent;
}

.reveal-toggle:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.reveal-toggle:focus {
    outline: none;
}

.reveal-toggle:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--primary-color) 35%, transparent);
    outline-offset: 2px;
}

/* ── Loading state ──────────────────────────── */
.story-loading {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.story-loading .fas {
    font-size: 1.5rem;
    margin-bottom: .75rem;
    animation: spin 1s linear infinite;
    display: block;
}

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

/* ── Audio player bar ──────────────────────── */
.audio-player-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: .65rem 1rem;
    margin-bottom: 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    box-shadow: 0 1px 3px var(--shadow-light);
}

.audio-play-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: var(--card-bg);
    cursor: pointer;
    font-size: .85rem;
    transition: background .15s ease, transform .1s ease;
    -webkit-tap-highlight-color: transparent;
}

.audio-play-btn:hover {
    background: var(--primary-hover, var(--primary-color));
    transform: scale(1.06);
}

.audio-play-btn:active {
    transform: scale(0.96);
}

.audio-voice-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.audio-voice-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .35rem;
    font-size: .92rem;
    font-weight: 700;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm, 4px);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .15s ease;
    line-height: 1;
    width: 34px;
    height: 30px;
    -webkit-tap-highlight-color: transparent;
}

.audio-voice-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.audio-voice-btn.active {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 12%, transparent);
    color: var(--primary-color);
}

.audio-progress-wrap {
    flex: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.audio-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary-color);
    border-radius: 3px;
    transition: width 0.15s linear;
}

.audio-progress-wrap:hover .audio-progress-bar {
    background: var(--primary-hover, var(--primary-color));
}

.audio-time {
    font-size: .75rem;
    color: var(--text-muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    min-width: 72px;
    text-align: center;
    flex-shrink: 0;
}

.audio-speed-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .35rem .4rem;
    font-size: .72rem;
    font-weight: 700;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm, 4px);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .15s ease;
    line-height: 1;
    width: 58px;
    height: 30px;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.audio-speed-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.audio-karaoke-toggle {
    flex-shrink: 0;
}

.audio-play-btn:focus,
.audio-voice-btn:focus,
.audio-speed-btn:focus,
.audio-karaoke-toggle:focus {
    outline: none;
}

.audio-play-btn:focus-visible,
.audio-voice-btn:focus-visible,
.audio-speed-btn:focus-visible,
.audio-karaoke-toggle:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--primary-color) 35%, transparent);
    outline-offset: 2px;
}

/* ── Karaoke word highlights ───────────────── */
.sentence-word.audio-active {
    background: color-mix(in srgb, var(--primary-color) 22%, transparent) !important;
    color: var(--primary-color) !important;
    border-radius: 3px;
    /* animation: karaoke-pulse 0.8s ease-in-out infinite alternate; */
    position: relative;
    z-index: 1;
}

@keyframes karaoke-pulse {
    0% {
        background: color-mix(in srgb, var(--primary-color) 18%, transparent);
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary-color) 12%, transparent);
    }
    100% {
        background: color-mix(in srgb, var(--primary-color) 28%, transparent);
        box-shadow: 0 0 8px 2px color-mix(in srgb, var(--primary-color) 16%, transparent);
    }
}

.sentence-word.audio-spoken {
    opacity: 0.45;
    transition: opacity .25s ease;
}

/* Ensure karaoke overrides HSK colors */
.hsk-colored .sentence-word.audio-active {
    background: color-mix(in srgb, var(--primary-color) 22%, transparent) !important;
    color: var(--primary-color) !important;
}

.hsk-colored .sentence-word.audio-spoken {
    opacity: 0.4;
}

/* Dark theme karaoke */
[data-theme="dark"] .sentence-word.audio-active {
    background: color-mix(in srgb, var(--primary-color) 30%, transparent) !important;
    color: var(--primary-hover, var(--primary-color)) !important;
}

[data-theme="dark"] .sentence-word.audio-spoken {
    opacity: 0.35;
}

[data-theme="dark"] .hsk-colored .sentence-word.audio-active {
    background: color-mix(in srgb, var(--primary-color) 30%, transparent) !important;
    color: var(--primary-hover, var(--primary-color)) !important;
}

/* ── Responsive ─────────────────────────────── */
@media (max-width: 768px) {
    .stories-header h1 { font-size: 1.5rem; }
    .story-text { line-height: 2.0; }
    .story-title-hanzi { font-size: 1.35rem; }
    .story-cards { grid-template-columns: 1fr; }
    .main-content { padding: 2rem 1rem; }
    .reader-inner { padding: 2rem 1rem; }
    .story-header-row { flex-direction: column; gap: .75rem; }
    .story-card-subtitle { min-height: 0; }

    .reader-top-bar { flex-wrap: wrap; gap: 8px; }
    .reader-top-toggles { gap: 6px; }
    .reveal-toggle .toggle-label { display: none; }
    .reveal-toggle { padding: .45rem .6rem; font-size: .9rem; }

    .audio-player-bar { gap: 8px; padding: .55rem .75rem; }
    .audio-time { font-size: .7rem; min-width: 60px; }
    .audio-voice-btn { width: 32px; height: 30px; padding: .35rem; font-size: .88rem; }
}

@media (max-width: 480px) {
    .stories-header h1 { font-size: 1.3rem; }
    .story-text { line-height: 2.0; }
    .story-title-hanzi { font-size: 1.2rem; }
    .level-tabs { gap: 6px; }
    .level-tab { padding: .45rem .9rem; font-size: .82rem; }
    .main-content { padding: 1.5rem .75rem; }
    .reader-inner { padding: 1.5rem .75rem; }
    .story-card-footer { flex-direction: column; align-items: flex-start; }
    .sentence-block.newline::before { content: '\A\2003'; }
    .sentence-block.indent-only::before { content: '\2003'; }

    .audio-player-bar { gap: 6px; padding: .45rem .6rem; }
    .audio-time { display: none; }
    .audio-speed-btn { width: 54px; height: 28px; font-size: .68rem; padding: .3rem .35rem; }
    .audio-voice-btn { width: 30px; height: 28px; font-size: .82rem; padding: .3rem; }
}
