:root {
    --sp-blue: #2563eb;
    --sp-blue-dark: #1d4ed8;
    --sp-purple: #7c3aed;
    --sp-red: #ef4444;
    --sp-green: #22c55e;
    --sp-page: #eef4ff;
    --sp-card: #ffffff;
    --sp-text: #14213d;
    --sp-muted: #6b7280;
    --sp-line: #dbe4f1;
    --sp-soft: #f5f8ff;
    --sp-shadow: 0 22px 58px rgba(49, 76, 123, .16);
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
}

button,
a,
audio {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.sp-play-body {
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--sp-text);
    background:
        radial-gradient(circle at top, #ffffff 0, transparent 28rem),
        var(--sp-page);
    font-family: Arial, sans-serif;
}

.sp-game-shell {
    width: min(580px, 100%);
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0 auto;
    padding: 14px 14px 26px;
    overflow-x: hidden;
}

.sp-game-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 13px;
}

.sp-game-header span {
    display: block;
    margin-bottom: 4px;
    color: #52627c;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.sp-game-header h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.2;
}

.sp-game-header > a {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid var(--sp-line);
    border-radius: 11px;
    color: #334155;
    background: #ffffff;
    font-weight: 800;
    text-decoration: none;
}

.sp-statusbar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.sp-statusbar > div {
    padding: 9px 7px;
    border: 1px solid var(--sp-line);
    border-radius: 12px;
    background: rgba(255, 255, 255, .92);
    text-align: center;
}

.sp-statusbar small {
    display: block;
    margin-bottom: 3px;
    color: var(--sp-muted);
    font-size: 10px;
}

.sp-statusbar strong {
    font-size: 17px;
}

.sp-progress {
    height: 7px;
    margin-bottom: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: #dbe5f4;
}

.sp-progress i {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--sp-purple), var(--sp-blue));
    transition: width .25s ease;
}

.sp-card {
    width: 100%;
    padding: 16px;
    overflow: hidden;
    border: 1px solid var(--sp-line);
    border-radius: 23px;
    background: var(--sp-card);
    box-shadow: var(--sp-shadow);
}

.sp-image-box {
    position: relative;
    display: flex;
    width: 100%;
    height: clamp(230px, 34dvh, 310px);
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    overflow: hidden;
    border-radius: 18px;
    background: #ffffff;
    cursor: pointer;
}

.sp-image-box.is-portrait {
    height: clamp(300px, 43dvh, 390px);
}

.sp-image-box img {
    display: block;
    width: auto;
    height: auto;
    max-width: 82%;
    max-height: 82%;
    object-fit: contain;
    object-position: center;
}

.sp-image-box.is-portrait img {
    max-width: 70%;
    max-height: 74%;
}


.sp-word-block {
    text-align: center;
}

.sp-word-block h2 {
    margin: 0;
    font-size: clamp(42px, 10vw, 64px);
    line-height: 1.05;
    cursor: pointer;
}

.sp-ipa {
    min-height: 28px;
    margin-top: 7px;
    color: var(--sp-blue);
    font-size: clamp(18px, 4.5vw, 25px);
    font-weight: 700;
}

.sp-meaning {
    min-height: 27px;
    margin: 8px 0 0;
    color: #475569;
    font-size: clamp(18px, 4vw, 24px);
    font-weight: 600;
}

.sp-listen-button {
    display: flex;
    width: 100%;
    min-height: 54px;
    align-items: center;
    justify-content: center;
    gap: 9px;
    margin-top: 16px;
    border: 0;
    border-radius: 14px;
    color: #ffffff;
    background: var(--sp-blue);
    font-weight: 800;
    cursor: pointer;
}

.sp-listen-button:hover {
    background: var(--sp-blue-dark);
}

.sp-listen-button span {
    font-size: 21px;
}

.sp-record-panel {
    margin-top: 14px;
    padding: 14px;
    border: 1px solid var(--sp-line);
    border-radius: 18px;
    background: #fbfcff;
    text-align: center;
}

.sp-record-button {
    display: flex;
    width: min(260px, 100%);
    min-height: 72px;
    align-items: center;
    justify-content: center;
    gap: 11px;
    margin: 0 auto;
    border: 0;
    border-radius: 22px;
    color: #ffffff;
    background: linear-gradient(135deg, var(--sp-purple), var(--sp-blue));
    box-shadow: 0 14px 30px rgba(37, 99, 235, .24);
    font-weight: 800;
    cursor: pointer;
    user-select: none;
    touch-action: none;
    transition:
        transform .15s ease,
        box-shadow .15s ease,
        background .15s ease;
}

.sp-record-button:hover {
    transform: translateY(-1px);
}

.sp-record-button:active,
.sp-record-button.is-recording {
    transform: scale(.98);
}

.sp-record-button.is-recording {
    background: linear-gradient(135deg, #dc2626, var(--sp-red));
    box-shadow: 0 15px 34px rgba(239, 68, 68, .28);
}

.sp-record-icon {
    font-size: 30px;
}

.sp-record-state {
    min-height: 22px;
    margin-top: 10px;
    color: var(--sp-muted);
    font-size: 13px;
    font-weight: 700;
}

.sp-wave {
    display: flex;
    height: 34px;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 5px;
    opacity: .28;
}

.sp-wave i {
    display: block;
    width: 4px;
    height: 8px;
    border-radius: 999px;
    background: var(--sp-purple);
}

.sp-wave.is-active {
    opacity: 1;
}

.sp-wave.is-active i {
    animation: sp-wave 780ms ease-in-out infinite;
}

.sp-wave.is-active i:nth-child(2),
.sp-wave.is-active i:nth-child(8) {
    animation-delay: 80ms;
}

.sp-wave.is-active i:nth-child(3),
.sp-wave.is-active i:nth-child(7) {
    animation-delay: 160ms;
}

.sp-wave.is-active i:nth-child(4),
.sp-wave.is-active i:nth-child(6) {
    animation-delay: 240ms;
}

.sp-wave.is-active i:nth-child(5) {
    animation-delay: 320ms;
}

.sp-playback-panel {
    margin-top: 14px;
    padding: 14px;
    border: 1px solid #cfe0ff;
    border-radius: 16px;
    background: #f3f7ff;
}

.sp-playback-panel audio {
    width: 100%;
}

.sp-playback-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
    margin-top: 11px;
}

.sp-playback-actions button {
    min-height: 45px;
    border: 1px solid var(--sp-line);
    border-radius: 12px;
    color: #334155;
    background: #ffffff;
    font-weight: 800;
    cursor: pointer;
}


.sp-playback-actions button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

#saveRecordingStatus {
    display: none;
    margin: 9px 0 0;
    color: #b91c1c;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

#saveRecordingStatus.is-error {
    display: block;
}

.sp-navigation {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 15px;
}

.sp-navigation button {
    min-height: 49px;
    border: 1px solid var(--sp-line);
    border-radius: 13px;
    color: #1e293b;
    background: #ffffff;
    font-weight: 800;
    cursor: pointer;
}

.sp-navigation button:last-child {
    color: #ffffff;
    border-color: var(--sp-blue);
    background: var(--sp-blue);
}

.sp-navigation button:disabled {
    cursor: not-allowed;
    opacity: .42;
}

.sp-finish-panel {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    padding: 18px;
    place-items: center;
    background: rgba(20, 33, 61, .55);
    backdrop-filter: blur(7px);
}

.sp-finish-panel[hidden] {
    display: none;
}

.sp-finish-card {
    width: min(430px, 100%);
    padding: 28px 20px;
    border-radius: 24px;
    background: #ffffff;
    box-shadow: 0 30px 90px rgba(15, 23, 42, .28);
    text-align: center;
}

.sp-finish-icon {
    font-size: 58px;
}

.sp-finish-card h2 {
    margin: 8px 0;
    font-size: 29px;
}

.sp-finish-card p {
    color: var(--sp-muted);
}

.sp-finish-card button {
    width: 100%;
    min-height: 48px;
    border: 0;
    border-radius: 13px;
    color: #ffffff;
    background: var(--sp-blue);
    font-weight: 800;
    cursor: pointer;
}

.sp-finish-card > a {
    display: inline-block;
    margin-top: 15px;
    color: #5b21b6;
}

.sp-empty {
    padding: 50px 24px;
    border: 1px solid var(--sp-line);
    border-radius: 20px;
    background: #ffffff;
    text-align: center;
}

.sp-empty > div {
    font-size: 50px;
}

.sp-empty h2 {
    margin: 10px 0 7px;
}

.sp-empty p {
    color: var(--sp-muted);
}

.sp-empty a {
    color: #5b21b6;
}

@keyframes sp-wave {
    0%,
    100% {
        height: 8px;
    }

    50% {
        height: 28px;
    }
}

@media (max-width: 430px) {
    .sp-game-shell {
        padding: 10px 10px 18px;
    }

    .sp-game-header h1 {
        font-size: 22px;
    }

    .sp-statusbar {
        gap: 5px;
    }

    .sp-statusbar > div {
        padding: 8px 3px;
    }

    .sp-statusbar small {
        font-size: 9px;
    }

    .sp-statusbar strong {
        font-size: 15px;
    }

    .sp-card {
        padding: 13px;
        border-radius: 20px;
    }

    .sp-image-box {
        height: clamp(210px, 30dvh, 250px);
        margin-bottom: 13px;
    }

    .sp-image-box.is-portrait {
        height: clamp(280px, 39dvh, 340px);
    }

    .sp-image-box img {
        max-width: 78%;
        max-height: 78%;
    }

    .sp-image-box.is-portrait img {
        max-width: 66%;
        max-height: 70%;
    }

    .sp-record-panel {
        padding: 12px;
    }

    .sp-record-button {
        min-height: 68px;
    }

    .sp-playback-actions {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sp-progress i,
    .sp-record-button,
    .sp-wave i {
        transition: none;
        animation: none;
    }
}


.sp-image-box.is-empty {
    background: #ffffff;
}


/* ===== SPEAKING COMPACT LAYOUT v6 =====
   Keep the full practice flow visible on phone screens. */

.sp-game-shell {
    padding-top: 10px !important;
    padding-bottom: 14px !important;
}

.sp-game-header {
    margin-bottom: 8px !important;
}

.sp-statusbar {
    margin-bottom: 7px !important;
}

.sp-statusbar > div {
    padding-top: 7px !important;
    padding-bottom: 7px !important;
}

.sp-progress {
    margin-bottom: 9px !important;
}

.sp-card {
    padding: 13px !important;
}

.sp-image-box {
    height: clamp(190px, 27dvh, 245px) !important;
    margin-bottom: 9px !important;
    border-radius: 16px !important;
    background: #ffffff !important;
}

.sp-image-box.is-portrait {
    height: clamp(220px, 31dvh, 275px) !important;
}

.sp-image-box img {
    max-width: 76% !important;
    max-height: 76% !important;
}

.sp-image-box.is-portrait img {
    max-width: 66% !important;
    max-height: 69% !important;
}

.sp-word-block h2,
#speakingWord {
    margin: 0 0 8px !important;
    font-size: clamp(40px, 8vw, 54px) !important;
    line-height: 1 !important;
}

.sp-listen-button {
    min-height: 48px !important;
    margin-top: 6px !important;
}

.sp-record-panel {
    margin-top: 9px !important;
    padding: 10px !important;
}

.sp-record-button {
    min-height: 58px !important;
}

.sp-record-state {
    min-height: 16px !important;
    margin-top: 5px !important;
    font-size: 12px !important;
}

.sp-wave {
    height: 24px !important;
    margin-top: 1px !important;
}

.sp-playback-panel {
    margin-top: 9px !important;
    padding: 9px !important;
}

.sp-playback-panel audio {
    height: 42px !important;
}

.sp-playback-actions {
    margin-top: 7px !important;
}

.sp-playback-actions button {
    min-height: 40px !important;
}

.sp-navigation {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin-top: 9px !important;
    padding-top: 6px;
    background: #ffffff;
}

.sp-navigation button {
    min-height: 46px !important;
}

@media (max-width: 430px) {
    .sp-game-shell {
        padding: 7px 8px 10px !important;
    }

    .sp-game-header h1 {
        font-size: 20px !important;
    }

    .sp-statusbar {
        gap: 4px !important;
    }

    .sp-statusbar > div {
        padding: 6px 3px !important;
    }

    .sp-card {
        padding: 11px !important;
    }

    .sp-image-box {
        height: clamp(175px, 24dvh, 215px) !important;
    }

    .sp-image-box.is-portrait {
        height: clamp(205px, 28dvh, 245px) !important;
    }

    .sp-word-block h2,
    #speakingWord {
        font-size: clamp(38px, 11vw, 48px) !important;
    }

    .sp-listen-button {
        min-height: 46px !important;
    }

    .sp-record-panel {
        padding: 8px !important;
    }

    .sp-record-button {
        min-height: 54px !important;
    }

    .sp-playback-panel {
        padding: 8px !important;
    }
}


/* ===== DYNAMIC IPA DISPLAY v10 ===== */
.sp-ipa {
    min-height: 22px;
    margin: 4px 0 10px;
    color: #9ca3af;
    font-family: "Nunito", "Segoe UI", Arial, sans-serif;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    letter-spacing: .01em;
}

.sp-ipa:empty {
    display: none;
}


/* ===== NON-AI RECORDING FEEDBACK v11 ===== */
.sp-record-state {
    color: #64748b !important;
    font-weight: 600 !important;
}

.sp-record-state.is-success,
.sp-record-state.is-great {
    color: #64748b !important;
}


/* ===== AZURE PRONUNCIATION FEEDBACK v12 ===== */
.sp-ai-feedback {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    margin-top: 9px;
    padding: 11px;
    border: 1px solid #cfe0ff;
    border-radius: 15px;
    background: #f8fbff;
}

.sp-ai-feedback[hidden] {
    display: none !important;
}

.sp-ai-score {
    display: grid;
    place-items: center;
    min-height: 76px;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 5px 16px rgba(37, 99, 235, .08);
}

.sp-ai-score strong {
    color: #2563eb;
    font-size: 25px;
    font-weight: 900;
    line-height: 1;
}

.sp-ai-score span {
    color: #64748b;
    font-size: 10px;
    font-weight: 700;
}

.sp-ai-message {
    min-width: 0;
}

.sp-ai-message strong {
    display: block;
    color: #172554;
    font-size: 14px;
    font-weight: 800;
}

.sp-ai-message p {
    margin: 4px 0;
    color: #334155;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.35;
}

.sp-ai-message small {
    display: block;
    color: #64748b;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.35;
}

@media (max-width: 430px) {
    .sp-ai-feedback {
        grid-template-columns: 72px minmax(0, 1fr);
        gap: 9px;
        padding: 9px;
    }

    .sp-ai-score {
        min-height: 66px;
    }

    .sp-ai-score strong {
        font-size: 22px;
    }
}


/* ===== AZURE FEEDBACK UI v13 ===== */
.sp-ai-feedback {
    grid-template-columns: 100px minmax(0, 1fr) !important;
    gap: 14px !important;
    padding: 14px !important;
    border: 1px solid #bfdbfe !important;
    border-radius: 16px !important;
    background: #ffffff !important;
    box-shadow: 0 8px 24px rgba(37, 99, 235, .08) !important;
}

.sp-ai-score {
    min-height: 86px !important;
    padding: 10px 6px !important;
    border: 1px solid #dbeafe !important;
    box-shadow: none !important;
}

.sp-ai-score strong {
    color: #2563eb !important;
    font-size: 24px !important;
    font-weight: 900 !important;
    letter-spacing: -.025em;
    white-space: nowrap;
}

.sp-ai-score span {
    margin-top: 5px;
    color: #64748b !important;
    font-size: 10px !important;
    font-weight: 700 !important;
}

.sp-ai-message strong {
    color: #15803d !important;
    font-size: 14px !important;
    font-weight: 900 !important;
    line-height: 1.35 !important;
}

.sp-ai-message p {
    margin: 6px 0 !important;
    color: #c2410c !important;
    font-size: 13px !important;
    font-weight: 800 !important;
    line-height: 1.4 !important;
}

.sp-ai-message small {
    color: #64748b !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    line-height: 1.4 !important;
}

.sp-ai-progress {
    grid-column: 1 / -1;
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #e2e8f0;
}

.sp-ai-progress span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #7c3aed, #2563eb);
    transition: width .65s ease;
}

.sp-ai-feedback.is-high .sp-ai-score strong {
    color: #15803d !important;
}

.sp-ai-feedback.is-high .sp-ai-progress span {
    background: linear-gradient(90deg, #22c55e, #16a34a);
}

.sp-ai-feedback.is-medium .sp-ai-score strong {
    color: #2563eb !important;
}

.sp-ai-feedback.is-low .sp-ai-score strong {
    color: #ea580c !important;
}

.sp-ai-feedback.is-low .sp-ai-message strong {
    color: #c2410c !important;
}

.sp-ai-feedback.is-low .sp-ai-progress span {
    background: linear-gradient(90deg, #fb923c, #ea580c);
}

@media (max-width: 430px) {
    .sp-ai-feedback {
        grid-template-columns: 88px minmax(0, 1fr) !important;
        gap: 10px !important;
        padding: 11px !important;
    }

    .sp-ai-score {
        min-height: 76px !important;
    }

    .sp-ai-score strong {
        font-size: 21px !important;
    }

    .sp-ai-message strong {
        font-size: 13px !important;
    }

    .sp-ai-message p {
        font-size: 12px !important;
    }

    .sp-ai-message small {
        font-size: 10px !important;
    }
}


/* ===== FINISH RESULT BY AZURE SCORE v14 ===== */
.sp-finish-card-result {
    width: min(370px, calc(100vw - 28px));
    padding: 28px 18px 20px;
}

.sp-finish-card-result .sp-finish-icon {
    margin-bottom: 8px;
    font-size: 48px;
    line-height: 1;
}

.sp-finish-card-result h2 {
    margin: 0;
    color: #172554;
    font-size: 27px;
    font-weight: 900;
    line-height: 1.15;
}

.sp-finish-card-result .sp-finish-message {
    margin: 10px auto 14px;
    color: #64748b;
    font-size: 14px;
    font-weight: 650;
    line-height: 1.45;
}

.sp-finish-score-box {
    display: grid;
    place-items: center;
    margin: 14px 0 8px;
    padding: 13px;
    border: 1px solid #bfdbfe;
    border-radius: 16px;
    background: #f8fbff;
}

.sp-finish-score-box[hidden],
.sp-finish-rating[hidden] {
    display: none !important;
}

.sp-finish-score-box strong {
    color: #2563eb;
    font-size: 28px;
    font-weight: 900;
    line-height: 1;
}

.sp-finish-score-box span {
    margin-top: 5px;
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
}

.sp-finish-rating {
    margin: 0 0 10px;
    color: #15803d;
    font-size: 14px;
    font-weight: 800;
}

.sp-finish-card-result .sp-finish-count {
    margin: 12px 0 16px;
    color: #334155;
    font-size: 14px;
    font-weight: 650;
}

@media (max-width: 430px) {
    .sp-finish-card-result {
        padding: 24px 14px 16px;
    }

    .sp-finish-card-result h2 {
        font-size: 24px;
    }

    .sp-finish-score-box strong {
        font-size: 24px;
    }
}
