:root {
    --bg: #08121f;
    --surface: rgba(10, 26, 45, 0.9);
    --surface-strong: rgba(12, 32, 55, 0.97);
    --border: #27486f;
    --text: #eef6ff;
    --muted: #fff;
    --accent: #fff200;
    --accent-2: #fb8500;
    --good: #54d48d;
    --bad: #ff6b6b;
    --lane-bg: rgba(255, 255, 255, 0.05);
    --lane-fill: linear-gradient(90deg, #ffb703, #fb8500);
    --ai-fill: linear-gradient(90deg, #5aa9ff, #7cf2c3);
    --font-display: "Segoe UI", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100%;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
    background: transparent;
    color: var(--text);
    font-family: var(--font-display);
}

body.start-screen-mode .layout {
    visibility: hidden;
}

body.start-screen-mode .app-shell {
    padding-bottom: 0;
}

.app-shell {
    position: relative;
    width: min(960px, calc(100vw - 32px));
    min-height: 100vh;
    height: auto;
    margin: 0 auto;
    padding: 0;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transform-origin: top center;
}

.hero-logo {
    width: min(337px, 100%);
    height: 155px;
    background: url("../assets/images/translate/en/typing_race.png") center/contain no-repeat;
    filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.28));
}

.start-screen {
    position: absolute;
    inset: 0;
    z-index: 30;
    overflow: hidden;
    width: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
    box-shadow: none;
    display: grid;
    place-items: center;
    background: url("../assets/images/bg_02.png") center/cover no-repeat;
}

.start-screen[hidden] {
    display: none;
}

.start-difficulty-panel {
    position: absolute;
    left: 50%;
    bottom: 325px;
    transform: translateX(-50%);
    display: grid;
    gap: 12px;
    justify-items: center;
    padding: 14px 18px 16px;
    min-width: 360px;
    border-radius: 18px;
    background: rgba(5, 15, 27, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
}

.start-difficulty-title {
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.start-difficulty-options {
    display: flex;
    gap: 10px;
}

.start-difficulty-option {
    min-width: 96px;
    min-height: 42px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(19, 35, 58, 0.72);
    color: rgba(255, 255, 255, 0.88);
    font-weight: 800;
    letter-spacing: 0.03em;
}

.start-difficulty-option.active {
    background: linear-gradient(180deg, #ffcb3c, #f79516);
    color: #151515;
    border-color: rgba(255, 214, 90, 0.92);
    text-shadow: none;
}

.start-main-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    min-width: 220px;
    min-height: 64px;
    padding: 0 24px;
    font-size: 1.45rem;
    font-weight: 800;
    text-transform: uppercase;
    transform: translateY(130px);
    border-radius: 8px;
    border: 1px solid rgba(255, 214, 90, 0.92);
    background: linear-gradient(180deg, #ffcb3c, #f79516);
    color: #151515;
    text-shadow: none;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.start-main-button::before,
.start-main-button::after {
    display: none;
}

.layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 0;
    flex: 1;
    min-height: 0;
}

.layout-single {
    grid-template-columns: 1fr;
}

.panel {
    border: none;
    background: var(--surface);
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    backdrop-filter: blur(12px);
}

.action-title {
    min-height: 52px;
    padding: 12px 18px;
    border-radius: 16px;
    background:
        linear-gradient(180deg, rgba(4, 10, 18, 0.18), rgba(4, 10, 18, 0.18)),
        url("../assets/images/Action_bar.png") center/100% 100% no-repeat;
    color: #eef6ff;
}

.panel-title-row,
.track-header,
.button-row,
.scoreboard {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel h2 {
    margin: 0;
    font-size: 1.25rem;
}

.panel-title-row.action-title {
    padding: 10px 14px 10px 18px;
}

.panel-title-row.action-title h2 {
    margin: 0;
}

.track-header h2.action-title {
    display: inline-flex;
    align-items: center;
    min-width: 180px;
    margin-bottom: 0;
}

.status-badge {
    border-radius: 999px;
    padding: 8px 12px;
    background: rgba(255, 183, 3, 0.12);
    color: var(--accent);
    border: 1px solid rgba(255, 183, 3, 0.28);
    font-size: 0.88rem;
}

.field {
    display: grid;
    gap: 8px;
}

select,
input,
button {
    font: inherit;
}

select,
input {
    width: 100%;
    min-height: 48px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    padding: 0 14px;
}

button {
    min-height: 48px;
    border: 0;
    padding: 0 18px;
    color: #08101b;
    font-weight: 700;
    cursor: pointer;
}

.legacy-button {
    position: relative;
    min-width: 154px;
    min-height: 46px;
    padding: 0 30px;
    background-position: center;
    background-repeat: repeat-x;
    background-size: calc(100% - 34px) 100%;
    border-radius: 0;
    color: #ffffff;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.5);
}

.legacy-button::before,
.legacy-button::after {
    content: "";
    position: absolute;
    top: 0;
    width: 18px;
    height: 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

.legacy-button::before {
    left: 0;
}

.legacy-button::after {
    right: 0;
    transform: scaleX(-1);
}

.legacy-button-64 {
    background-image: url("../assets/images/buttons/middle64.png");
}

.legacy-button-64::before,
.legacy-button-64::after {
    background-image: url("../assets/images/buttons/margin64.png");
}

.legacy-button-64:hover:not(:disabled) {
    background-image: url("../assets/images/buttons/middle64On.png");
}

.legacy-button-64:hover:not(:disabled)::before,
.legacy-button-64:hover:not(:disabled)::after {
    background-image: url("../assets/images/buttons/margin64On.png");
}

.legacy-button-65 {
    background-image: url("../assets/images/buttons/middle65.png");
}

.legacy-button-65::before,
.legacy-button-65::after {
    background-image: url("../assets/images/buttons/margin65.png");
}

.legacy-button-65:hover:not(:disabled) {
    background-image: url("../assets/images/buttons/middle65On.png");
}

.legacy-button-65:hover:not(:disabled)::before,
.legacy-button-65:hover:not(:disabled)::after {
    background-image: url("../assets/images/buttons/margin65On.png");
}

.start-main-button:hover:not(:disabled) {
    filter: brightness(1.04);
}

.topbar-button {
    min-width: 138px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: linear-gradient(180deg, #71788a, #4f5668);
    color: #ffffff;
    text-shadow: none;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
}

.topbar-button::before,
.topbar-button::after {
    display: none;
}

.topbar-button:hover:not(:disabled) {
    filter: brightness(1.04);
    transform: translateY(-1px);
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    filter: grayscale(0.35);
    animation: none;
}

.sentence-preview,
.sentence-text,
.track-meta {
    margin: 0;
    color: #10263f;
    line-height: 1.7;
}

.hud-plate {
    display: flex;
    align-items: center;
    min-height: 72px;
    padding: 10px 18px;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background:
        linear-gradient(180deg, rgba(8, 18, 31, 0.82), rgba(8, 18, 31, 0.92)),
        url("../assets/images/race/Typing_Frame.png") center/100% 100% no-repeat;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.hud-plate-preview {
    min-height: 84px;
}

.hud-plate-race {
    min-height: 92px;
}

.sentence-preview,
.sentence-text {
    width: 100%;
    padding: 0 4px;
    min-height: 0;
    background: transparent;
    text-shadow: none;
}

.track-meta {
    color: var(--muted);
}

.scoreboard {
    flex-wrap: wrap;
}

.track-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.scoreboard div {
    min-width: 88px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
}

.scoreboard span {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
}

.scoreboard strong {
    display: block;
    margin-top: 4px;
    font-size: 1.2rem;
}

.race-scene {
    position: relative;
    height: 100%;
    min-height: 0;
    border-radius: 0;
    overflow: hidden;
    border: 0;
    background:
        linear-gradient(180deg, #97dcff 0 17%, #d7f2ff 17% 27%, transparent 27%),
        linear-gradient(180deg, transparent 0 27%, rgba(24, 24, 34, 0.72) 27% 100%);
}

.race-scene.crash-active {
    animation: crash-scene-shake 220ms linear infinite;
}

.race-scene.crash-active::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 9;
    pointer-events: none;
    background:
        radial-gradient(circle at 50% 52%, rgba(255, 220, 150, 0.9), rgba(255, 120, 70, 0.45) 22%, rgba(255, 80, 40, 0.08) 46%, transparent 65%);
    mix-blend-mode: screen;
    animation: crash-scene-flash 520ms ease-out 1 both;
}

.race-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    backdrop-filter: none;
}

.race-stage {
    position: relative;
    flex: 1;
    min-height: 710px;
    margin-top: 0;
    display: grid;
    grid-template-rows: minmax(500px, 1fr) 210px;
    gap: 0;
    overflow: hidden;
    border: none;
    background: #4b4b4b;
}

.game-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 58px;
    padding: 0 12px 0 18px;
    border-radius: 0;
    background: linear-gradient(180deg, #707070, #525252);
    border: none;
}

.game-track {
    position: relative;
    min-height: 500px;
    background: #1d1f28;
}

.game-track::before {
    display: none;
}

.game-track::after {
    display: none;
}

.game-hud {
    display: grid;
    grid-template-columns: 150px 1fr 150px;
    gap: 20px;
    align-items: center;
    padding: 18px 22px 20px;
    background: linear-gradient(180deg, #656565, #464646);
    border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.hud-side {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 12px;
    min-height: 100%;
}

.hud-center {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 10px;
    min-width: 0;
}

.typing-panel {
    display: grid;
    position: relative;
    top: -45px;
    justify-items: center;
    align-content: center;
    gap: 10px;
    width: 100%;
    transition: opacity 420ms ease, transform 420ms ease, filter 420ms ease;
    transform-origin: center bottom;
}

.typing-panel.is-hidden {
    opacity: 0;
    transform: translateY(20px) scale(0.97);
    filter: blur(6px);
    pointer-events: none;
}

.results-panel {
    position: absolute;
    inset: 18px 18px 18px 18px;
    z-index: 40;
    padding: 18px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.04)),
        url("../assets/images/bg_03.png") center/cover no-repeat;
}

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

.results-title {
    margin: 0 0 16px;
    min-height: 52px;
    padding: 12px 18px;
    font-size: 1.1rem;
    color: #eef6ff;
    background: url("../assets/images/Action_bar.png") center/100% 100% no-repeat;
}

.results-hero {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 18px;
    align-items: center;
    margin-bottom: 16px;
}

.results-car-stage {
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    border-radius: 18px;
    background:
        linear-gradient(180deg, rgba(8, 18, 31, 0.72), rgba(8, 18, 31, 0.9)),
        url("../assets/images/race/RaceBG.png") center/cover no-repeat;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.results-car-image {
    max-width: 100%;
    max-height: 92px;
    filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.28));
}

.results-hero-copy {
    display: grid;
    gap: 8px;
}

.results-place {
    margin: 0;
    color: #fff200;
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    font-weight: 800;
    letter-spacing: 0.06em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
}

.results-place span {
    font-size: 0.65em;
}

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

.results-card {
    padding: 12px;
    border-radius: 16px;
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.results-card span {
    display: block;
    color: var(--muted);
    font-size: 0.76rem;
}

.results-card strong {
    display: block;
    margin-top: 6px;
    font-size: 1.15rem;
}

.results-summary {
    margin: 0;
    color: var(--accent);
    font-weight: 700;
    font-size: 1rem;
}

.results-score {
    margin: 0;
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 700;
}

.results-actions {
    position: absolute;
    left: 50%;
    bottom: -105px;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    margin-top: 0;
    flex-wrap: wrap;
    justify-content: center;
    z-index: 41;
}

.results-actions .legacy-button {
    min-width: 154px;
    min-height: 46px;
    border-radius: 8px;
    background: rgba(19, 35, 58, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.92);
    text-shadow: none;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
}

.results-actions .legacy-button::before,
.results-actions .legacy-button::after {
    display: none;
}

.results-actions .legacy-button[data-results-action="race-again"] {
    background: linear-gradient(180deg, #ffcb3c, #f79516);
    border-color: rgba(255, 214, 90, 0.92);
    color: #151515;
}

.results-actions .legacy-button[data-results-action="reset"] {
    background: linear-gradient(180deg, #71788a, #4f5668);
    border-color: rgba(255, 255, 255, 0.18);
    color: #ffffff;
}

.results-actions .legacy-button:hover:not(:disabled) {
    filter: brightness(1.04);
    transform: translateY(-1px);
}

.race-scene::after {
    content: "";
    position: absolute;
    inset: auto 0 0;
    height: 56px;
    background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.28));
}

.track-start,
.track-finish {
    position: absolute;
    top: 110px;
    width: 54px;
    height: 238px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.95;
}

.track-start {
    left: 70px;
    background-image: url("../assets/images/race/Start.png");
}

.track-finish {
    left: calc(100% - 110px);
    background-image: url("../assets/images/race/Finish.png");
}

.scene-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(180deg, transparent 0 28%, rgba(255, 255, 255, 0.04) 28% 29%, transparent 29%),
        linear-gradient(180deg, transparent 0 100%);
}

.scene-trackback {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background:
        url("../assets/images/race/RaceBG.png") left center/auto 100% repeat-x;
    will-change: background-position;
}

.scene-lane {
    position: absolute;
    left: 0;
    right: 0;
    height: 52px;
    border-top: 2px solid rgba(255, 255, 255, 0.18);
}

.scene-lane:nth-child(1) { top: 236px; }
.scene-lane:nth-child(2) { top: 282px; }
.scene-lane:nth-child(3) { top: 328px; }
.scene-lane:nth-child(4) { top: 374px; }
.scene-lane:nth-child(5) { top: 420px; }

.scene-car {
    position: absolute;
    left: 0;
    bottom: 10px;
    width: 128px;
    height: 74px;
    object-fit: contain;
    object-position: left bottom;
    opacity: 0;
    transform: none;
    transition: opacity 80ms linear, filter 140ms ease, transform 240ms ease;
    pointer-events: none;
}

.scene-car.is-active {
    opacity: 1;
}

.scene-car.player {
    z-index: 2;
    filter: drop-shadow(0 10px 12px rgba(255, 183, 3, 0.26));
}

.scene-car.ai {
    z-index: 1;
    filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.25));
}

.scene-car.car-type-4 {
    z-index: 0;
    filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.22));
}

.scene-car.crash {
    filter: grayscale(0.6) saturate(0.7) drop-shadow(0 8px 10px rgba(255, 80, 80, 0.35));
    transform: rotate(-6deg);
}

.scene-car.finish {
    transform: translateY(-2px) scale(1.03);
}

.scene-car-wrap {
    position: absolute;
    transform: translateX(-50%);
    width: 128px;
    height: 86px;
    z-index: 3;
    transition:
        left 320ms cubic-bezier(0.22, 0.61, 0.36, 1),
        top 260ms cubic-bezier(0.22, 0.61, 0.36, 1);
    will-change: left, top;
}

.scene-car-wrap.car-type-4 {
    z-index: 0;
    transition: left 320ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.scene-car-wrap .scene-car {
    animation: car-float 520ms ease-in-out infinite;
}

.scene-car-wrap.car-type-4 .scene-car {
    animation: none;
    transform: none;
}

.scene-car-wrap .scene-car.crash,
.scene-car-wrap .scene-car.finish {
    animation: none;
}

.scene-fx {
    position: absolute;
    pointer-events: none;
    z-index: 2;
}

.scene-fx.smoke {
    left: 74px;
    top: 15px;
    width: 42px;
    opacity: 0.86;
}

.scene-fx.smoke.crash-smoke {
    left: 54px;
    top: -20px;
    width: 72px;
    opacity: 0.92;
    filter: drop-shadow(0 4px 10px rgba(80, 80, 80, 0.35));
    animation: crash-smoke-rise 560ms ease-in-out infinite alternate;
}

.scene-fx.fire {
    left: 97px;
    top: 35px;
    width: 24px;
    opacity: 0.92;
}

.scene-fx.fire.crash-fire {
    left: 66px;
    top: 26px;
    width: 44px;
    opacity: 0.98;
    filter: drop-shadow(0 0 16px rgba(255, 120, 40, 0.5));
    animation: crash-fire-flicker 180ms ease-in-out infinite alternate;
}

.scene-fx.tires {
    left: 8px;
    top: 34px;
    width: 34px;
    opacity: 0.6;
}

.scene-fx.exhaust-smoke {
    left: -28px;
    top: 10px;
    width: 60px;
    opacity: 0.92;
    filter: drop-shadow(0 2px 8px rgba(80, 80, 80, 0.35));
    animation: exhaust-smoke-pulse 180ms ease-out infinite alternate;
}

.scene-fx.exhaust-fire {
    left: -39px;
    top: 44px;
    width: 52px;
    opacity: 0.98;
    z-index: 4;
    filter: drop-shadow(0 0 12px rgba(255, 120, 40, 0.45));
    animation: exhaust-fire-burst 110ms ease-in-out infinite alternate;
}

.scene-car-wrap.car-type-4 .scene-fx.exhaust-smoke {
    left: -12px;
    top: 18px;
    width: 64px;
}

.scene-car-wrap.car-type-4 .scene-fx.exhaust-fire {
    left: -41px;
    top: 52px;
    width: 54px;
}

.scene-error-pop {
    position: absolute;
    left: 28px;
    top: -20px;
    color: #ff5a5a;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.scene-label {
    position: absolute;
    transform: translateY(-50%);
    padding: 3px 8px;
    border-radius: 12px;
    background: rgba(8, 18, 31, 0.84);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text);
    font-size: 0.7rem;
    white-space: nowrap;
    z-index: 1;
    pointer-events: none;
}

.scene-label.player {
    color: var(--accent);
}

.scene-light {
    position: absolute;
    top: 16px;
    right: 20px;
    width: 94px;
    height: 94px;
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35));
    will-change: transform, opacity;
}

.scene-light.red {
    background-image: url("../assets/images/race/redlight.png");
}

.scene-light.yellow {
    background-image: url("../assets/images/race/yellowLight.png");
}

.scene-light.green {
    background-image: url("../assets/images/race/greenlight.png");
}

.scene-light.flash {
    animation: light-pulse 300ms ease-in-out 2;
}

.scene-idle-warning {
    position: absolute;
    left: 50%;
    top: 54px;
    transform: translateX(-50%);
    z-index: 14;
    min-width: 320px;
    max-width: 520px;
    padding: 18px 28px;
    border-radius: 22px;
    border: 1px solid rgba(255, 212, 94, 0.7);
    background:
        linear-gradient(180deg, rgba(28, 18, 5, 0.9), rgba(60, 18, 12, 0.92)),
        url("../assets/images/race/bigToolTip.png") center/100% 100% no-repeat;
    color: #fff3b0;
    text-align: center;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.45);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
}

@keyframes crash-fire-flicker {
    from {
        transform: translateY(0) scale(1);
        opacity: 0.9;
    }
    to {
        transform: translateY(-2px) scale(1.08);
        opacity: 1;
    }
}

@keyframes crash-smoke-rise {
    from {
        transform: translateY(0) scale(1);
    }
    to {
        transform: translateY(-6px) scale(1.06);
    }
}

@keyframes exhaust-fire-burst {
    from {
        transform: translateX(0) scale(0.92);
        opacity: 0.8;
    }
    to {
        transform: translateX(-4px) scale(1.08);
        opacity: 1;
    }
}

@keyframes exhaust-smoke-pulse {
    from {
        transform: translateX(0) translateY(0) scale(0.94);
        opacity: 0.72;
    }
    to {
        transform: translateX(-6px) translateY(-2px) scale(1.06);
        opacity: 0.9;
    }
}

@keyframes crash-scene-shake {
    0% { transform: translate3d(0, 0, 0); }
    25% { transform: translate3d(-4px, 1px, 0); }
    50% { transform: translate3d(3px, -2px, 0); }
    75% { transform: translate3d(-2px, 2px, 0); }
    100% { transform: translate3d(0, 0, 0); }
}

@keyframes crash-scene-flash {
    0% {
        opacity: 0;
    }
    18% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

.gauge-face,
.gauge-dial {
    position: absolute;
}

.gauge-face {
    inset: 0;
    width: 100%;
    height: 100%;
}

.gauge-dial {
    left: 47px;
    top: 46px;
    width: 45px;
    height: auto;
    transform-origin: 17.3% 54.4%;
    transform-box: fill-box;
}

.hud-gauge-error .gauge-dial {
    left: 48px;
    top: 49px;
    width: 39px;
    transform-origin: 16.7% 50.7%;
}

.race-tools {
    width: 100%;
    justify-content: space-between;
    align-items: center;
}

.hint-strip {
    display: flex;
    align-items: center;
    min-height: 42px;
    gap: 16px;
    padding: 6px 18px;
    background: url("../assets/images/race/hintLeftBG.png") left center/100% 100% no-repeat;
    position: relative;
    width: min(80%, 560px);
    min-width: 0;
    overflow: hidden;
}

.hint-controls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

.hint-lamp {
    display: block;
    flex: 0 0 18px;
    width: 18px;
    height: 33px;
    min-width: 18px;
    min-height: 33px;
    padding: 0;
    border: 0;
    appearance: none;
    background: url("../assets/images/race/HintBTN-BG.png") center/contain no-repeat;
    box-shadow: 0 0 10px rgba(255, 208, 64, 0.45);
    cursor: pointer;
}

.hint-lamp.is-off {
    opacity: 0.35;
    filter: grayscale(1) brightness(0.8);
    box-shadow: none;
    cursor: default;
}

.hint-label {
    color: #fff5ad;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.hint-text {
    margin: 0;
    min-height: 22px;
    opacity: 0;
    transition: opacity 180ms ease;
    color: var(--accent);
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hint-text.is-visible {
    opacity: 1;
}

.typing-frame {
    display: flex;
    width: min(100%, 560px);
    min-height: 88px;
    padding: 10px 18px;
    border-radius: 6px;
    background: linear-gradient(180deg, #f2f2f2, #ffffff 55%, #f6f6f6);
    min-width: 0;
    overflow: hidden;
    border: 0;
    box-shadow: none;
}

.typing-frame-content {
    display: grid;
    grid-template-columns: 1fr;
    align-content: start;
    gap: 8px;
    width: 100%;
    min-width: 0;
}

.typing-frame input {
    min-height: 32px;
    border: 0;
    outline: 0;
    background: transparent;
    box-shadow: none;
    appearance: none;
    padding: 0;
    color: #10263f;
    font-weight: 700;
    letter-spacing: 0.02em;
    width: 100%;
    max-width: 100%;
    font-size: 1.15rem;
}

.typing-frame input:focus,
.typing-frame input:focus-visible {
    outline: 0;
    box-shadow: none;
}

.typing-field input.good {
    color: var(--good);
}

.typing-field input.bad {
    color: #a12626;
}

.sentence-text {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: center;
    min-height: 42px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    font-size: 1.5rem;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sentence-text::-webkit-scrollbar {
    display: none;
}

.spell-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    min-height: 38px;
    padding: 0 0 3px;
    border: 0;
    border-bottom: 2px solid rgba(16, 38, 63, 0.75);
    background: transparent;
    box-shadow: none;
    font-size: 1.05rem;
    font-weight: 800;
    line-height: 1;
    flex: 0 0 auto;
}

.spell-slot.done {
    color: #1f7a45;
    border-bottom-color: rgba(31, 122, 69, 0.7);
}

.spell-slot.current {
    color: #b35b00;
    border-bottom-color: rgba(179, 91, 0, 0.9);
}

.spell-slot.todo {
    color: rgba(16, 38, 63, 0.52);
}

.spell-gap {
    width: 14px;
    min-height: 38px;
}

.hud-gauge {
    position: relative;
    top: -25px;
    width: 110px;
    height: 110px;
}

#hudWpmGauge {
    top: -40px;
}

.hud-gauge-face,
.hud-timer-face {
    position: relative;
    width: 100%;
    height: 100%;
}

.hud-timer {
    width: 132px;
    min-height: 40px;
}

.hud-timer-face img {
    display: block;
    width: 100%;
    height: auto;
}

.hud-timer-face span {
    position: absolute;
    inset: 8px 0 0 0;
    color: #ffffff;
    text-align: center;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.audio-button {
    width: 58px;
    min-width: 58px;
    min-height: 58px;
    position: relative;
    top: 60px;
    left: -25px;
    padding: 0;
    border-radius: 50%;
    background:
        radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.45), transparent 25%),
        #3e3e3e url("../assets/images/race/replay.png") center/38px 38px no-repeat;
    border: 2px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.26);
    text-indent: -9999px;
    overflow: hidden;
}

.compact-scoreboard {
    position: relative;
    top: -20px;
    width: 100%;
    justify-content: center;
    gap: 8px;
}

.compact-scoreboard div {
    min-width: 64px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.08);
}

.compact-scoreboard span {
    color: rgba(255, 255, 255, 0.78);
}

.compact-scoreboard strong {
    color: #ffffff;
}

.track-meta {
    color: #ffffff;
    font-weight: 700;
    letter-spacing: 0.02em;
}

@media (max-width: 920px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .app-shell {
        width: min(100vw - 20px, 960px);
    }

    .race-stage {
        min-height: 620px;
        grid-template-rows: minmax(340px, 1fr) auto;
    }

    .track-start,
    .track-finish {
        top: 98px;
        height: 206px;
    }

    .scene-trackback {
        top: 0;
    }

    .scene-lane:nth-child(1) { top: 208px; }
    .scene-lane:nth-child(2) { top: 250px; }
    .scene-lane:nth-child(3) { top: 292px; }
    .scene-lane:nth-child(4) { top: 334px; }
    .scene-lane:nth-child(5) { top: 376px; }

    .scene-car {
        width: 98px;
    }

    .scene-car-wrap {
        width: 98px;
        height: 68px;
    }

    .scene-light {
        top: 12px;
        right: 12px;
        width: 76px;
        height: 76px;
    }

    .game-hud {
        grid-template-columns: 1fr;
        gap: 14px;
        padding: 16px;
    }

    .hud-side {
        grid-template-columns: repeat(2, auto);
        justify-content: center;
        gap: 16px;
    }

    .hud-right {
        grid-template-columns: auto auto 1fr;
        align-items: center;
    }

    .compact-scoreboard {
        width: auto;
    }

    .results-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .results-hero {
        grid-template-columns: 1fr;
    }

    .results-actions {
        flex-direction: column;
    }

    .results-panel {
        inset: 12px;
        max-height: calc(100% - 24px);
        overflow: auto;
    }

    .hero-logo {
        height: 118px;
    }

    .start-screen {
        inset: 20px 0 auto 0;
        min-height: 560px;
    }

    .start-main-button {
        min-width: 180px;
        min-height: 56px;
        font-size: 1.2rem;
    }

    .start-difficulty-panel {
        min-width: min(92vw, 360px);
        bottom: 108px;
        padding: 12px 14px 14px;
    }

    .start-difficulty-options {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .hint-strip,
    .typing-frame {
        width: 100%;
    }

    .game-topbar {
        flex-wrap: wrap;
        justify-content: center;
    }
}

@keyframes light-pulse {
    0% { opacity: 0.7; transform: scale(0.98); }
    50% { opacity: 1; transform: scale(1.05); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes fade-up {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes car-float {
    0% { transform: translateY(0); }
    50% { transform: translateY(-1px); }
    100% { transform: translateY(0); }
}
