:root {
    --bg: #f7fbff;
    --surface: #ffffff;
    --surface-soft: #eef7f2;
    --ink: #20324a;
    --muted: #6a7d91;
    --line: rgba(32, 50, 74, 0.12);
    --blue: #2f80ed;
    --green: #38a169;
    --orange: #f59e0b;
    --red: #dc6262;
    --shadow: 0 20px 52px rgba(55, 91, 128, 0.16);
    --radius: 24px;
    --font: "Trebuchet MS", "Microsoft YaHei", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    color: var(--ink);
    background:
        linear-gradient(135deg, rgba(47, 128, 237, 0.12), transparent 32%),
        linear-gradient(225deg, rgba(56, 161, 105, 0.13), transparent 28%),
        linear-gradient(180deg, #fffdf7 0%, var(--bg) 58%, #fff8ef 100%);
    font-family: var(--font);
}

button {
    font: inherit;
}

.app-shell {
    width: min(1280px, calc(100% - 24px));
    margin: 6px auto 14px;
}

.topbar {
    display: grid;
    justify-items: center;
    text-align: center;
    gap: 4px;
    margin-bottom: 12px;
    padding: 8px 12px;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--blue);
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(1.6rem, 3.1vw, 2.55rem);
    line-height: 1.05;
}

.stage-position,
.chip,
.ghost-button,
.primary-button,
.icon-button {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.88);
}

.practice-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: min(1220px, 100%);
    margin: 0 auto;
}

.practice-bar,
.stage,
.empty-state {
    border: 1px solid rgba(255, 255, 255, 0.82);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.86);
    box-shadow: var(--shadow);
}

.practice-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
}

.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 36px;
    padding: 0 13px;
    border-radius: 999px;
    color: var(--ink);
    cursor: pointer;
}

.chip.active {
    color: #fff;
    background: linear-gradient(135deg, var(--blue), #61a7ff);
    border-color: transparent;
}

.chip strong {
    font-size: 0.9rem;
}

.stage {
    min-width: 0;
    display: grid;
    gap: 8px;
    padding: 10px 14px;
}

.stage-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: center;
}

.stage-card-shell {
    position: relative;
    display: grid;
    grid-template-columns: 72px minmax(0, 860px) 72px;
    justify-content: center;
    gap: 14px;
    align-items: center;
}

.icon-button {
    display: grid;
    place-items: center;
    height: 48px;
    border-radius: 15px;
    color: var(--blue);
    font-size: 2.1rem;
    font-weight: 900;
    cursor: pointer;
}

.stage-nav-button {
    width: 88px;
    height: 88px;
    align-self: center;
    justify-self: center;
    border-radius: 999px;
    border-color: rgba(47, 128, 237, 0.16);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(235, 246, 255, 0.94));
    box-shadow:
        0 18px 34px rgba(47, 128, 237, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.92);
    color: #ff6b6b;
    font-size: 4.3rem;
    line-height: 1;
    transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.stage-nav-button:hover {
    transform: scale(1.03);
    box-shadow:
        0 22px 42px rgba(47, 128, 237, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.96);
}

.stage-nav-button:active {
    transform: scale(0.98);
}

.stage-nav-button:disabled {
    opacity: 0.42;
    cursor: not-allowed;
    box-shadow: none;
}

.stage-position {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 38px;
    padding: 0 14px;
    border-radius: 15px;
}

.stage-position span {
    color: var(--muted);
    font-weight: 800;
}

.stage-position strong {
    color: var(--ink);
}

.flashcard {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 8px;
    min-height: 0;
    min-width: 0;
    width: 100%;
    max-width: 860px;
    min-height: 0;
    justify-self: center;
    padding: 8px 12px;
    overflow: hidden;
    border-radius: 28px;
    background:
        linear-gradient(180deg, rgba(238, 247, 242, 0.72), rgba(255, 255, 255, 0.92));
    border: 1px solid var(--line);
    touch-action: pan-y;
}

.flashcard.is-swapping {
    animation: cardIn 0.2s ease;
}

.flashcard.is-playing .image-button {
    filter: drop-shadow(0 0 12px rgba(47, 128, 237, 0.22));
}

.image-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: min(100%, 780px);
    max-height: min(58vh, 660px);
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
}

.image-button img {
    display: block;
    width: 100%;
    max-width: 100%;
    max-height: min(58vh, 660px);
    height: auto;
    object-fit: contain;
    border-radius: 22px;
    box-shadow: 0 22px 44px rgba(34, 77, 118, 0.16);
}

.word-block {
    display: grid;
    justify-items: center;
    gap: 5px;
    text-align: center;
}

.sr-card-copy {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.word {
    margin: 0;
    font-size: clamp(3rem, 8vw, 5.6rem);
    font-weight: 900;
    line-height: 0.95;
}

.translation {
    margin: 0;
    color: var(--blue);
    font-size: clamp(1.35rem, 3vw, 2rem);
    font-weight: 900;
}

.hint {
    margin: 0;
    color: var(--muted);
    font-size: 1rem;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 0;
}

.primary-button,
.ghost-button {
    min-height: 40px;
    padding: 0 20px;
    border-radius: 16px;
    font-weight: 900;
    cursor: pointer;
}

.primary-button {
    color: #fff;
    border-color: transparent;
    background: linear-gradient(135deg, var(--orange), #ff7c57);
    box-shadow: 0 14px 26px rgba(245, 158, 11, 0.25);
}

.primary-button:disabled,
.ghost-button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    box-shadow: none;
}

.ghost-button {
    color: var(--ink);
}

.ghost-button.is-active {
    color: #fff;
    background: linear-gradient(135deg, var(--green), #5cc98b);
    border-color: transparent;
}

.speed-control {
    display: inline-grid;
    grid-template-columns: repeat(3, minmax(58px, 1fr));
    gap: 4px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.76);
}

.speed-button {
    min-height: 30px;
    padding: 0 10px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-weight: 900;
    cursor: pointer;
}

.speed-button.is-active {
    color: #fff;
    background: linear-gradient(135deg, var(--blue), #61a7ff);
    box-shadow: 0 8px 18px rgba(47, 128, 237, 0.2);
}

.audio-status {
    min-height: 18px;
    margin: 0;
    color: var(--muted);
    font-weight: 800;
    text-align: center;
}

.audio-status.ready {
    color: var(--green);
}

.audio-status.playing {
    color: var(--blue);
}

.audio-status.missing {
    color: var(--red);
}

.thumb-strip {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(90px, 1fr);
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.thumb {
    display: grid;
    gap: 6px;
    justify-items: center;
    min-width: 90px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.86);
    color: var(--ink);
    font-weight: 900;
    cursor: pointer;
}

.thumb.active {
    border-color: rgba(47, 128, 237, 0.72);
    box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.12);
}

.thumb img {
    width: 100%;
    height: 48px;
    object-fit: contain;
}

.empty-state {
    padding: 34px;
}

.empty-state h2 {
    margin: 0 0 12px;
}

.empty-state p {
    margin: 0;
    color: var(--muted);
}

@keyframes cardIn {
    from {
        opacity: 0.6;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 900px) {
    .app-shell {
        width: min(100% - 18px, 820px);
        margin: 4px auto 10px;
    }

    .topbar {
        margin-bottom: 8px;
        padding: 4px 8px;
        gap: 2px;
    }

    .eyebrow {
        margin-bottom: 2px;
        font-size: 0.72rem;
    }

    h1 {
        font-size: clamp(1.45rem, 4.8vw, 2rem);
        line-height: 1;
    }

    .practice-layout {
        width: 100%;
        gap: 6px;
    }

    .practice-bar {
        padding: 6px;
        gap: 6px;
        overflow: hidden;
    }

    .chip-list {
        flex: 1 1 auto;
        min-width: 0;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .chip-list::-webkit-scrollbar {
        display: none;
    }

    .chip {
        flex: 0 0 auto;
        min-height: 34px;
        padding: 0 11px;
        white-space: nowrap;
    }

    #reviewButton {
        flex: 0 0 auto;
        min-height: 34px;
        padding: 0 12px;
        white-space: nowrap;
    }

    .stage {
        gap: 6px;
        padding: 8px;
    }

    .stage-position {
        min-height: 34px;
        border-radius: 14px;
    }

    .stage-card-shell {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
    }

    .stage-nav-button {
        position: absolute;
        z-index: 3;
        top: 50%;
        width: 64px;
        height: 64px;
        transform: translateY(-50%);
        background: rgba(255, 255, 255, 0.9);
        font-size: 3rem;
    }

    .stage-nav-button:hover {
        transform: translateY(-50%) scale(1.03);
    }

    .stage-nav-button:active {
        transform: translateY(-50%) scale(0.98);
    }

    #prevButton {
        left: 8px;
    }

    #nextButton {
        right: 8px;
    }

    .flashcard {
        max-width: 100%;
        min-height: 0;
        padding: 7px;
        border-radius: 22px;
    }

    .image-button {
        width: min(100%, 620px);
        max-height: min(58vh, 620px);
    }

    .image-button img {
        max-height: min(58vh, 620px);
    }
}

@media (max-width: 640px) {
    .app-shell {
        width: 100%;
        margin: 0 auto 6px;
        padding: 0 5px;
    }

    .topbar {
        margin-bottom: 5px;
        padding: 5px 6px 3px;
    }

    .eyebrow {
        display: none;
    }

    h1 {
        font-size: 1.42rem;
    }

    .practice-bar {
        padding: 5px;
        border-radius: 16px;
        box-shadow: 0 10px 26px rgba(55, 91, 128, 0.1);
    }

    .chip-list {
        gap: 6px;
    }

    .chip {
        min-height: 32px;
        padding: 0 10px;
        gap: 7px;
        font-size: 0.94rem;
    }

    #reviewButton {
        min-height: 32px;
        padding: 0 10px;
        font-size: 0.94rem;
    }

    .stage {
        gap: 5px;
        padding: 6px;
        border-radius: 18px;
    }

    .stage-toolbar {
        grid-template-columns: minmax(0, 1fr);
    }

    .stage-position {
        min-height: 32px;
        height: 32px;
        border-radius: 14px;
        display: grid;
        gap: 0;
        padding: 2px 8px;
        font-size: 0.96rem;
    }

    .flashcard {
        min-height: 0;
        padding: 6px;
        border-radius: 16px;
    }

    .image-button {
        width: 100%;
        max-height: 58vh;
    }

    .image-button img {
        max-height: 58vh;
        border-radius: 16px;
    }

    .stage-nav-button {
        width: 48px;
        height: 48px;
        border-color: rgba(255, 107, 107, 0.16);
        box-shadow: 0 12px 28px rgba(47, 128, 237, 0.14);
        font-size: 2.35rem;
    }

    #prevButton {
        left: 5px;
    }

    #nextButton {
        right: 5px;
    }

    .actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .speed-control {
        width: 100%;
        grid-template-columns: repeat(3, 1fr);
    }

    .primary-button,
    .ghost-button {
        min-height: 40px;
        padding: 0 12px;
        font-size: 0.95rem;
    }

    .speed-button {
        min-height: 30px;
    }

    .thumb-strip {
        grid-auto-columns: 96px;
    }

    .thumb {
        min-width: 96px;
    }
}
