#game-root {
    --hd-accent: #10B981;
    --hd-accent-dark: #0c8d64;
    --hd-accent-light: #e3f9ef;
    --hd-accent-border: #a7f3d0;
    --hd-glass-bg: rgba(255, 255, 255, .72);
    --hd-glass-border: rgba(255, 255, 255, .5);
    --hd-text: var(--kw-text, #2D2A32);
}

#game-root .kwi-muted { color: #cbd5e1; }

.hd-wrap {
    max-width: 920px;
    margin: 0 auto;
}

.hd-wrap-narrow {
    max-width: 560px;
}

.hd-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 12px;
}

.hd-row-between {
    justify-content: space-between;
}

.hd-spacer {
    flex: 1 1 auto;
}

/* ---- loading / error ---- */

.hd-status {
    text-align: center;
    padding: 48px 16px;
}

.hd-status-icon {
    font-size: 44px;
    margin-bottom: 10px;
    color: #fff;
}

.hd-pulse {
    animation: hd-pulse 1.2s ease-in-out infinite;
}

.hd-status-text {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

.hd-status-error {
    display: inline-block;
    background: #EF4444;
    padding: 6px 16px;
    border-radius: 999px;
    text-shadow: none;
}

/* ---- header / level picker ---- */

.hd-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 16px;
}

.hd-header-icon {
    display: flex;
    font-size: 32px;
    line-height: 1;
}

.hd-header-icon img {
    display: block;
    height: 38px;
    width: auto;
}

.hd-header-title {
    font-size: 24px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .22);
}

.hd-levels {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.hd-level-card {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--hd-glass-border);
    border-radius: var(--kw-radius, 12px);
    background: var(--hd-glass-bg);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    padding: 0;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
    transition: transform .15s ease, box-shadow .15s ease;
}

.hd-level-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 18px rgba(0, 0, 0, .14);
}

.hd-level-thumb {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 70px;
    font-size: 38px;
    background: linear-gradient(135deg, var(--hd-accent-light), var(--hd-accent-border));
    background-size: 70px 70px;
    background-repeat: no-repeat;
    background-position: center;
}

.hd-level-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 10px 16px;
}

.hd-level-name {
    font-size: 17px;
    font-weight: 800;
    color: var(--hd-text);
}

.hd-level-age {
    font-size: 14px;
    font-weight: 700;
    color: var(--hd-accent-dark);
    background: var(--hd-accent-light);
    padding: 2px 10px;
    border-radius: 999px;
}

/* ---- pills and small buttons ---- */

.hd-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--hd-accent-light);
    color: var(--hd-accent-dark);
    border-radius: 999px;
    padding: 6px 12px;
    font-weight: 800;
    font-size: 12px;
    line-height: 1.2;
}

.hd-pill-icon {
    display: inline-flex;
    line-height: 1;
}

.hd-pill-icon img {
    display: block;
    width: 14px;
    height: 14px;
    object-fit: cover;
    border-radius: 50%;
}

.hd-pill-icon svg {
    width: 12px;
    height: 12px;
}

.hd-pill-horse {
    background: var(--hd-silk);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}

.hd-chip-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--hd-glass-border);
    background: var(--hd-glass-bg);
    color: var(--hd-accent-dark);
    border-radius: 999px;
    font-weight: 800;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 7px 12px 7px 10px;
    transition: transform .1s ease, background .15s ease;
}

.hd-chip-btn svg {
    width: 12px;
    height: 12px;
}

.hd-chip-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, .9);
    transform: translateY(-1px);
}

.hd-chip-btn:disabled {
    opacity: .5;
    cursor: default;
}

/* ---- setup ---- */

.hd-panel {
    background: var(--hd-glass-bg);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid var(--hd-glass-border);
    border-radius: var(--kw-radius, 12px);
    padding: 14px;
    margin-bottom: 12px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, .1);
}

.hd-panel-title {
    font-size: 16px;
    font-weight: 900;
    color: var(--hd-accent-dark);
    margin-bottom: 10px;
}

.hd-horse-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.hd-horse-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px 10px;
    border: 3px solid transparent;
    border-radius: var(--kw-radius, 12px);
    background: #fff;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .08);
    transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.hd-horse-card:hover {
    transform: translateY(-3px);
}

.hd-horse-card.hd-selected {
    border-color: var(--hd-silk);
    background: color-mix(in srgb, var(--hd-silk) 14%, #fff);
    box-shadow: 0 6px 14px rgba(0, 0, 0, .14);
}

.hd-horse-canvas {
    display: block;
    width: 100%;
    max-width: 160px;
    aspect-ratio: 200 / 140;
    height: auto;
}

.hd-horse-name {
    font-size: 15px;
    font-weight: 900;
    color: var(--hd-text);
}

.hd-horse-coat {
    font-size: 11px;
    font-weight: 700;
    color: #6b7280;
}

.hd-topic-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.hd-topic {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border: 2px solid var(--hd-accent-border);
    border-radius: 999px;
    background: #fff;
    color: var(--hd-text);
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    transition: transform .1s ease, background .12s ease;
}

.hd-topic:hover {
    transform: translateY(-1px);
}

.hd-topic.hd-selected {
    background: var(--hd-accent);
    border-color: var(--hd-accent-dark);
    color: #fff;
}

.hd-topic-emoji {
    font-size: 16px;
    line-height: 1;
}

.hd-how {
    text-align: center;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    margin: 4px 8px 14px;
}

.hd-btn-primary,
.hd-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    padding: 12px 20px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    transition: transform .1s ease;
}

.hd-btn-primary svg,
.hd-btn-secondary svg {
    width: 14px;
    height: 14px;
}

.hd-btn-primary {
    background: var(--hd-accent);
    color: #fff;
    box-shadow: 0 3px 0 var(--hd-accent-dark);
}

.hd-btn-primary:hover {
    transform: translateY(-1px);
}

.hd-btn-secondary {
    background: var(--hd-accent-light);
    color: var(--hd-accent-dark);
}

.hd-btn-secondary:hover {
    background: var(--hd-accent-border);
}

.hd-btn-big {
    display: flex;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    padding: 16px 24px;
    font-size: 19px;
    box-shadow: 0 4px 0 var(--hd-accent-dark);
}

.hd-btn-big svg {
    width: 18px;
    height: 18px;
}

/* ---- race ---- */

.hd-toolbar {
    margin-bottom: 8px;
}

.hd-stage {
    position: relative;
    border-radius: var(--kw-radius, 12px);
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
    background: #c7ecf7;
    touch-action: manipulation;
}

.hd-canvas {
    display: block;
    width: 100%;
    height: 300px;
}

.hd-paused {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    border: none;
    background: rgba(15, 23, 42, .45);
    color: #fff;
    cursor: pointer;
    font: inherit;
}

.hd-paused[hidden] {
    display: none;
}

.hd-paused-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--hd-accent);
    box-shadow: 0 4px 0 var(--hd-accent-dark);
}

.hd-paused-icon svg {
    width: 30px;
    height: 30px;
}

.hd-paused-title {
    font-size: 24px;
    font-weight: 900;
}

.hd-paused-sub {
    font-size: 14px;
    font-weight: 700;
    opacity: .9;
}

.hd-qcard {
    position: relative;
    margin-top: 12px;
    min-height: 176px;
    padding: 14px 16px 16px;
    background: var(--hd-glass-bg);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid var(--hd-glass-border);
    border-radius: var(--kw-radius, 12px);
    box-shadow: 0 3px 12px rgba(0, 0, 0, .12);
    text-align: center;
}

.hd-qcard-in {
    animation: hd-card-in .22s ease;
}

.hd-qcard-paused .hd-q-picture,
.hd-qcard-paused .hd-q-expr,
.hd-qcard-paused .hd-answers {
    visibility: hidden;
}

.hd-q-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 36px;
}

.hd-q-top .kw-speak-btn[hidden] {
    display: none;
}

.hd-q-prompt {
    font-size: 17px;
    font-weight: 800;
    color: var(--hd-accent-dark);
}

.hd-streak {
    position: absolute;
    top: 12px;
    right: 14px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #fff7ed;
    color: #ea580c;
    font-size: 14px;
    font-weight: 900;
    box-shadow: inset 0 0 0 2px #fdba74;
    animation: hd-pop .25s ease;
}

.hd-streak[hidden] {
    display: none;
}

.hd-streak svg {
    width: 14px;
    height: 14px;
}

.hd-q-picture {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 2px 4px;
    margin: 4px auto 2px;
    max-width: 520px;
    font-size: 34px;
    line-height: 1.15;
}

.hd-q-picture[hidden] {
    display: none;
}

.hd-pic {
    position: relative;
    display: inline-block;
}

.hd-pic-away {
    opacity: .45;
}

.hd-pic-away::after {
    content: '';
    position: absolute;
    left: -2px;
    right: -2px;
    top: 50%;
    height: 4px;
    margin-top: -2px;
    background: #ef4444;
    border-radius: 2px;
    transform: rotate(-35deg);
}

.hd-pic-plus {
    margin: 0 6px;
    font-size: 26px;
    font-weight: 900;
    color: var(--hd-accent-dark);
}

.hd-q-expr {
    font-size: 34px;
    font-weight: 900;
    color: var(--hd-text);
    letter-spacing: .5px;
    margin: 2px 0 10px;
}

.hd-q-expr[hidden] {
    display: none;
}

.hd-answers {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(4, 1fr);
    max-width: 640px;
    margin: 0 auto;
}

.hd-answers-3 {
    grid-template-columns: repeat(3, 1fr);
    max-width: 480px;
}

.hd-answer {
    position: relative;
    padding: 14px 6px;
    border: none;
    border-radius: var(--kw-radius, 12px);
    background: linear-gradient(135deg, var(--hd-accent), var(--hd-accent-dark));
    color: #fff;
    font-size: 26px;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 4px 0 rgba(0, 0, 0, .15);
    transition: transform .1s ease, box-shadow .1s ease;
    -webkit-tap-highlight-color: transparent;
}

.hd-answer:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.03);
}

.hd-answer:active:not(:disabled) {
    transform: translateY(2px) scale(.98);
    box-shadow: 0 1px 0 rgba(0, 0, 0, .15);
}

.hd-answer:disabled {
    cursor: default;
}

.hd-answer-key {
    position: absolute;
    top: 5px;
    left: 8px;
    font-size: 11px;
    font-weight: 800;
    opacity: .7;
}

.hd-answer.hd-correct {
    background: linear-gradient(135deg, #34d399, #059669);
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px #10B981;
    animation: hd-pop .3s ease;
}

.hd-answer.hd-wrong {
    background: linear-gradient(135deg, #FCA5A5, #EF4444);
    opacity: .75;
    animation: hd-shake .35s ease;
}

.hd-answer:disabled:not(.hd-correct):not(.hd-wrong) {
    opacity: .45;
}

/* ---- distance-to-fence bar and the waiting nudge ---- */

.hd-jump {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 520px;
    margin: 0 auto 6px;
}

.hd-jump[hidden] {
    display: none;
}

.hd-fence-chip {
    flex: 0 0 auto;
    padding: 3px 10px;
    border-radius: 999px;
    background: #fef2f2;
    color: #dc2626;
    font-size: 12px;
    font-weight: 900;
    box-shadow: inset 0 0 0 2px #fecaca;
}

.hd-jump-track {
    position: relative;
    flex: 1 1 auto;
    height: 10px;
    margin-right: 14px;
    border-radius: 999px;
    background: var(--hd-accent-light);
    box-shadow: inset 0 0 0 1px var(--hd-accent-border);
}

.hd-jump-fill {
    display: block;
    width: 0;
    height: 100%;
    border-radius: 999px;
    background: var(--hd-accent);
}

.hd-jump-horse {
    position: absolute;
    top: 50%;
    left: 0;
    font-size: 20px;
    line-height: 1;
    transform: translate(-50%, -58%);
}

/* a tiny show-jump fence: two posts and a red-and-white rail */
.hd-jump-fence {
    position: absolute;
    right: -14px;
    top: -9px;
    width: 14px;
    height: 20px;
    border-left: 3px solid #fff;
    border-right: 3px solid #fff;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .25));
}

.hd-jump-fence::before {
    content: '';
    position: absolute;
    left: -5px;
    right: -5px;
    top: 5px;
    height: 4px;
    border-radius: 2px;
    background: repeating-linear-gradient(90deg, #ef4444 0 4px, #fff 4px 8px);
}

.hd-qcard-waiting {
    animation: hd-nudge 1s ease-in-out infinite;
}

.hd-qcard-waiting .hd-q-prompt::after {
    content: ' Your horse is waiting!';
    color: #ea580c;
}

/* ---- results ---- */

.hd-done-card {
    text-align: center;
    background: var(--hd-glass-bg);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid var(--hd-glass-border);
    border-radius: var(--kw-radius, 12px);
    padding: 20px 18px 22px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, .12);
    animation: hd-pop .3s ease;
}

.hd-done-hero {
    position: relative;
    display: inline-block;
}

.hd-done-horse {
    display: block;
    width: 220px;
    height: auto;
    aspect-ratio: 240 / 170;
}

.hd-medal {
    position: absolute;
    top: 4px;
    left: -30px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    color: #fff;
    box-shadow: 0 3px 0 rgba(0, 0, 0, .15);
}

.hd-medal svg {
    width: 24px;
    height: 24px;
}

.hd-medal-1 { background: #f59e0b; }
.hd-medal-2 { background: #94a3b8; }
.hd-medal-3 { background: #c2703d; }
.hd-medal-4 { background: var(--hd-accent); }

.hd-done-title {
    font-size: 22px;
    font-weight: 900;
    color: var(--hd-accent-dark);
    margin: 6px 0 4px;
}

.hd-done-stars {
    color: #f59e0b;
    font-size: 24px;
    letter-spacing: 3px;
}

.hd-star svg {
    width: 24px;
    height: 24px;
}

.hd-done-score {
    font-size: 16px;
    font-weight: 700;
    color: #4b5563;
    margin: 4px 0 10px;
}

.hd-done-score b {
    color: var(--hd-text);
    font-size: 20px;
}

.hd-done-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-bottom: 12px;
}

.hd-done-stats[hidden] {
    display: none;
}

.hd-stat {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border-radius: 999px;
    background: var(--hd-accent-light);
    color: var(--hd-accent-dark);
    font-size: 13px;
    font-weight: 800;
}

.hd-stat svg {
    width: 13px;
    height: 13px;
}

.hd-stat-miss {
    background: #fef2f2;
    color: #dc2626;
}

.hd-stat-carrot {
    background: #fff7ed;
    color: #ea580c;
}

.hd-podium {
    list-style: none;
    margin: 0 auto;
    padding: 0;
    max-width: 380px;
    text-align: left;
}

.hd-podium-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    margin-bottom: 6px;
    border-radius: 12px;
    background: #fff;
    border-left: 6px solid var(--hd-silk);
}

.hd-podium-me {
    background: color-mix(in srgb, var(--hd-silk) 16%, #fff);
    box-shadow: 0 0 0 2px var(--hd-silk);
}

.hd-podium-place {
    width: 34px;
    font-size: 15px;
    font-weight: 900;
    color: var(--hd-text);
}

.hd-podium-horse {
    width: 56px;
    height: auto;
    aspect-ratio: 80 / 60;
}

.hd-podium-name {
    flex: 1 1 auto;
    font-size: 15px;
    font-weight: 800;
    color: var(--hd-text);
}

.hd-podium-time {
    font-size: 13px;
    font-weight: 700;
    color: #6b7280;
}

.hd-done-share {
    justify-content: center;
    margin-top: 14px;
}

.hd-done-actions {
    justify-content: center;
    margin-top: 16px;
}

/* ---- phones ---- */

@media (max-width: 560px) {
    .hd-pill-topic {
        display: none;
    }

    .hd-horse-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .hd-qcard-waiting .hd-q-prompt::after {
        content: ' Waiting!';
    }

    .hd-qcard {
        padding: 12px 10px 12px;
        min-height: 160px;
    }

    .hd-q-expr {
        font-size: 28px;
        margin-bottom: 8px;
    }

    .hd-q-picture {
        font-size: 24px;
    }

    .hd-answers {
        gap: 8px;
        grid-template-columns: repeat(2, 1fr);
    }

    .hd-answers-3 {
        grid-template-columns: repeat(3, 1fr);
    }

    .hd-answer {
        padding: 12px 4px;
        font-size: 24px;
    }

    .hd-streak {
        position: static;
    }

    .hd-q-top {
        flex-wrap: wrap;
    }
}

@keyframes hd-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: .7; }
}

@keyframes hd-card-in {
    from { opacity: .4; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes hd-pop {
    0% { transform: scale(.85); }
    100% { transform: scale(1); }
}

@keyframes hd-nudge {
    0%, 100% { box-shadow: 0 3px 12px rgba(0, 0, 0, .12), 0 0 0 0 rgba(249, 115, 22, 0); }
    50% { box-shadow: 0 3px 12px rgba(0, 0, 0, .12), 0 0 0 5px rgba(249, 115, 22, .55); }
}

@keyframes hd-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}
