html.races-active .app-view { padding: 0; }
html.races-active .app-header,
html.races-active .bottom-nav { display: none; }
html.races-active.races-list-active .bottom-nav { display: grid; }
html.races-active.races-list-active .races-shell { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
.races-shell { min-height: 100dvh; padding: calc(14px + env(safe-area-inset-top)) 14px calc(22px + env(safe-area-inset-bottom)); background: #edf3e9; color: #1e3528; }
html.telegram-fullscreen .races-shell {
  padding-top: calc(14px + max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px)));
  padding-right: calc(14px + max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px), var(--tg-content-safe-area-inset-right, 0px)));
  padding-bottom: calc(22px + max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px)));
  padding-left: calc(14px + max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px), var(--tg-content-safe-area-inset-left, 0px)));
}
.race-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.race-title h2 { margin: 0; font: 900 24px/1.05 Georgia, serif; }
.race-title p { margin: 4px 0 0; color: #68776d; font-size: 11px; }
.race-close, .race-icon { width: 40px; height: 40px; flex: 0 0 40px; border: 1px solid #cbd6c8; border-radius: 50%; background: #fff; color: #304638; font-size: 24px; }
.race-icon { border-radius: 6px; font-size: 19px; }
.race-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; padding: 5px; margin: 0 -14px 12px; background: #dce7d8; border-block: 1px solid #c8d5c5; }
.race-tabs button { min-height: 39px; border: 1px solid #c6d0c3; border-radius: 5px; background: #fff; color: #536259; font-size: 10px; font-weight: 900; }
.race-tabs button.active { background: #244f38; border-color: #244f38; color: #fff; }
.race-list-actions { display: grid; grid-template-columns: 1fr 44px; gap: 8px; margin-bottom: 12px; }
.race-primary, .race-secondary, .race-danger { min-height: 44px; border: 0; border-radius: 6px; padding: 10px 14px; font-size: 12px; font-weight: 900; }
.race-primary { background: #34724e; color: #fff; }
.race-secondary { width: 100%; background: #dfe8dc; color: #294033; }
.race-danger { background: #f0d8d2; color: #8a3029; }
.race-primary:disabled { opacity: .5; }
.race-room-list { display: grid; gap: 9px; }
.race-room-card { display: grid; width: 100%; gap: 6px; padding: 12px; border: 1px solid #cbd6c8; border-left: 5px solid #dba541; border-radius: 7px; background: #fff; color: inherit; text-align: left; box-shadow: 0 2px 0 rgba(30, 60, 40, .08); }
.race-room-card-top { display: flex; justify-content: space-between; align-items: start; gap: 8px; font: 800 16px/1.1 Georgia, serif; }
.race-room-card-top i, .race-room-facts i { font-style: normal; }
.race-room-owner, .race-room-state { color: #68776d; font-size: 10px; }
.race-room-state { justify-self: end; color: #35684b; font-weight: 900; }
.race-room-facts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.race-room-facts i { padding: 6px 3px; border-radius: 4px; background: #edf3e9; text-align: center; font-size: 9px; font-weight: 800; }
.race-empty { min-height: 250px; display: grid; place-content: center; justify-items: center; gap: 8px; padding: 24px; text-align: center; color: #617065; }
.race-empty span { font-size: 42px; }
.race-empty b { color: #2f4437; }
.race-empty p { max-width: 290px; margin: 0; font-size: 11px; line-height: 1.5; }
.race-rules { padding: 14px; border: 1px solid #cbd6c8; border-radius: 7px; background: #fff; font-size: 12px; line-height: 1.55; }
.race-rules h3 { margin: 6px 0 8px; font: 900 18px Georgia, serif; }
.race-rules ol { padding-left: 20px; }
.race-rules li { margin-bottom: 8px; }
.race-warning { padding: 10px; border-left: 4px solid #c45845; background: #f7e7df; }
.race-create-form { display: grid; gap: 12px; padding-bottom: 70px; }
.race-create-form label { display: grid; gap: 5px; color: #4f6156; font-size: 10px; font-weight: 900; }
.race-create-form input, .race-chat-form input, .race-answer-form input, .race-modal input { width: 100%; min-width: 0; height: 44px; border: 1px solid #c2cec0; border-radius: 5px; background: #fff; color: #1f3428; padding: 0 11px; font: 600 14px/1 sans-serif; }
.race-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.race-form-note { padding: 11px; border: 1px solid #d7c28e; border-radius: 6px; background: #fff4ce; font-size: 11px; line-height: 1.45; }
.race-sticky-action { position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 8; box-shadow: 0 7px 18px rgba(21, 58, 37, .2); }
.race-settings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.race-settings span { display: grid; justify-items: center; gap: 2px; padding: 8px 3px; border: 1px solid #ccd7c9; border-radius: 6px; background: #fff; }
.race-settings i { font-style: normal; font-size: 17px; }
.race-settings b { font-size: 12px; }
.race-settings small { color: #77847b; font-size: 8px; }
.race-join-card, .race-panel { margin-bottom: 10px; padding: 12px; border: 1px solid #cbd6c8; border-radius: 7px; background: #fff; }
.race-join-card p { margin: 0 0 10px; color: #65736a; font-size: 11px; line-height: 1.4; }
.race-join-card button { width: 100%; }
.race-panel-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.race-panel-title h3 { margin: 0; font: 900 17px Georgia, serif; }
.race-panel-title button { border: 0; background: transparent; color: #34724e; font-size: 10px; font-weight: 900; }
.race-panel-title small { color: #758178; font-size: 9px; }
.race-player-list { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
.race-player-list li { display: grid; grid-template-columns: 34px 1fr 32px; align-items: center; min-height: 43px; gap: 8px; padding: 5px 7px; border-radius: 5px; background: #edf3e9; }
.race-player-list li > span:nth-child(2) { min-width: 0; }
.race-player-list b, .race-player-list small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.race-player-list b { font-size: 11px; }.race-player-list small { color: #728078; font-size: 8px; }
.race-player-list button { width: 30px; height: 30px; border: 0; border-radius: 50%; background: #f1d9d4; color: #8b352c; }
.race-player-avatar { font-size: 21px; }
.race-room-chat { padding-bottom: 9px; }
.race-chat-messages { max-height: 230px; overflow-y: auto; overscroll-behavior: contain; display: grid; gap: 5px; padding: 4px; }
.race-chat-messages p { justify-self: start; max-width: 85%; display: grid; gap: 2px; margin: 0; padding: 7px 9px; border-radius: 3px 7px 7px; background: #e8eee5; font-size: 10px; }
.race-chat-messages p.mine { justify-self: end; background: #d4ead8; border-radius: 7px 3px 7px 7px; }
.race-chat-messages p.system { justify-self: center; background: transparent; color: #718078; text-align: center; }
.race-chat-messages p b { font-size: 8px; color: #34724e; }
.race-chat-messages em { padding: 20px; color: #7a877e; text-align: center; font-size: 10px; }
.race-chat-form { display: grid; grid-template-columns: 1fr 43px; gap: 6px; margin-top: 8px; }
.race-chat-form button { border: 0; border-radius: 5px; background: #34724e; color: #fff; font-size: 17px; }
.race-room-actions { position: sticky; z-index: 10; bottom: calc(8px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 9px; border: 1px solid #c6d2c3; border-radius: 7px; background: rgba(255,255,255,.96); box-shadow: 0 8px 22px rgba(30, 60, 40, .2); }
.race-room-actions span { color: #617066; font-size: 10px; text-align: center; }
.race-notice, .race-error { margin: 0 0 10px; padding: 9px; border-radius: 5px; font-size: 10px; }
.race-notice { background: #dcebdd; color: #285c3c; }.race-error { background: #f4ddd7; color: #8d332b; }
.race-game-page { min-height: calc(100dvh - env(safe-area-inset-top)); padding-top: 10px; background: #79ad9c; }
.race-game-head { display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; gap: 8px; color: #173c2d; text-align: center; }
.race-head-spacer { width: 42px; height: 42px; }
.race-game-head b, .race-game-head span { display: block; }.race-game-head b { font: 900 17px Georgia, serif; }.race-game-head span { margin-top: 3px; font-size: 9px; }
.race-live-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0; }
.race-live-strip span { display: grid; justify-items: center; gap: 2px; padding: 7px; border: 1px solid rgba(255,255,255,.7); border-radius: 6px; background: rgba(24, 68, 49, .87); color: #fff; }
.race-live-strip small { opacity: .75; font-size: 8px; }.race-live-strip b { font-size: 13px; letter-spacing: 0; }
.race-puzzle { overflow: hidden; border: 3px solid #285941; border-radius: 8px; background: #fff; box-shadow: 0 6px 0 rgba(25, 66, 47, .2); }
.race-puzzle img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #d5e3d0; }
.race-answer-dock { position: sticky; z-index: 11; bottom: calc(8px + env(safe-area-inset-bottom) + var(--race-keyboard-inset, 0px)); display: grid; gap: 7px; margin-top: 11px; padding: 8px; border: 1px solid rgba(35, 78, 55, .25); border-radius: 7px; background: rgba(255,255,255,.97); box-shadow: 0 8px 22px rgba(25, 65, 46, .25); scroll-margin-block: 20vh; }
.race-mask { max-height: 104px; overflow: auto; padding: 6px 5px 8px; overflow-wrap: anywhere; color: #243a2e; text-align: center; font: 900 clamp(16px, 5vw, 23px)/1.3 Georgia, serif; letter-spacing: 0; }
.race-answer-form { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.race-answer-form button { border: 0; border-radius: 5px; padding: 0 13px; background: #244f38; color: #fff; font-size: 11px; font-weight: 900; }
.race-game-tools { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }
.race-game-tools button { min-height: 41px; border: 1px solid rgba(29, 70, 50, .35); border-radius: 6px; background: rgba(255,255,255,.84); color: #244b36; font-size: 10px; font-weight: 900; }
.race-game-tools button.danger { background: #f1d8d2; color: #87352c; }
.race-drawer { position: fixed; z-index: 90; inset: calc(78px + env(safe-area-inset-top)) max(8px, calc((100vw - 450px)/2 + 8px)) calc(8px + env(safe-area-inset-bottom)); overflow-y: auto; padding: 45px 12px 12px; border: 1px solid #c5d2c2; border-radius: 8px; background: #f8faf6; box-shadow: 0 15px 50px rgba(10, 35, 22, .4); }
.race-drawer-close { position: absolute; right: 10px; top: 9px; width: 32px; height: 32px; border: 0; border-radius: 50%; background: #e4e9e1; font-size: 20px; }
.race-leaderboard { display: grid; gap: 6px; margin-top: 12px; padding: 11px; border: 1px solid rgba(31, 70, 50, .28); border-radius: 7px; background: rgba(247,250,245,.93); }
.race-leaderboard h3 { margin: 0 0 4px; font: 900 18px Georgia, serif; }
.race-leaderboard-scroll { max-height: 210px; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; display: grid; gap: 6px; padding-right: 2px; }
.race-leaderboard-row { --race-position: 96%; display: grid; gap: 5px; min-height: 58px; padding: 6px 8px 7px; border: 1px solid #d2dbd0; border-radius: 5px; background: #fff; }
.race-leaderboard-row.me { border: 2px solid #c58d1e; background: #ffe9a8; box-shadow: inset 4px 0 #c58d1e; }
.race-row-info { min-width: 0; display: grid; grid-template-columns: 22px minmax(48px, 1fr) auto minmax(48px, auto); align-items: center; gap: 5px; }
.race-row-info > b { text-align: center; font-size: 10px; }
.race-row-info > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; font-weight: 900; }
.race-row-info > small { overflow: hidden; color: #748178; font-size: 8px; white-space: nowrap; }
.race-row-info > strong { min-width: 48px; text-align: right; font-size: 9px; font-variant-numeric: tabular-nums; }
.race-track { position: relative; height: 25px; overflow: hidden; border: 1px solid #719277; border-radius: 4px; background: repeating-linear-gradient(0deg, #dce9bd 0 5px, #d3e2ae 5px 10px); box-shadow: inset 0 1px 3px rgba(31, 70, 45, .14); }
.race-track::before { content: ""; position: absolute; z-index: 1; left: 4%; top: 0; bottom: 0; border-left: 1px dashed rgba(48, 87, 56, .55); }
.race-track > i { position: absolute; z-index: 1; right: 1px; top: 0; bottom: 0; width: 10px; border-left: 1px solid rgba(38, 63, 42, .55); background: repeating-conic-gradient(#f7f4df 0 25%, #34483a 0 50%) 0 / 8px 8px; }
.race-track-frog { position: absolute; z-index: 2; left: var(--race-position); top: 50%; display: block; width: 24px; height: 24px; transform: translate(-50%, -52%); font-size: 19px; line-height: 24px; text-align: center; transition: left .18s linear; filter: drop-shadow(0 1px 1px rgba(20, 53, 34, .28)); }
.race-attempt-result { display: grid; justify-items: center; gap: 8px; padding: 22px 14px; border: 2px solid #d9aa4d; border-radius: 8px; background: #fff8de; text-align: center; }
.race-attempt-result p { margin: 0; font-size: 12px; line-height: 1.45; }.race-percent { font: 900 42px Georgia, serif; color: #34724e; }
.race-attempt-result button { width: 100%; margin-top: 5px; }
.race-results-page { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
.race-countdown-page { min-height: calc(100dvh - env(safe-area-inset-top)); padding-top: 10px; background: #79ad9c; }
.race-start-countdown { min-height: 45dvh; display: grid; place-content: center; justify-items: center; gap: 8px; color: #173c2d; text-align: center; }
.race-start-countdown small { font-size: 13px; font-weight: 800; }
.race-start-countdown b { width: 112px; height: 112px; display: grid; place-items: center; border: 5px solid rgba(255,255,255,.9); border-radius: 50%; background: #d7b85a; box-shadow: 0 10px 0 #947638, 0 18px 30px rgba(25,60,43,.28); color: #173c2d; font: 900 58px/1 Georgia, serif; }
.race-start-countdown span { max-width: 260px; color: #315946; font-size: 10px; }
.results-chat { margin-top: 12px; }
.race-panel-title .race-replay-toggle { padding: 6px 9px; border: 1px solid #568266; border-radius: 5px; background: transparent; color: inherit; font: 700 11px Arial, sans-serif; }
.race-replay-toggle[aria-pressed="true"] { background: #34724e; color: #fff; }
.race-replay-controls { display: grid; gap: 8px; margin: 10px 0; }
.race-replay-controls > div { display: flex; align-items: center; gap: 10px; }
.race-replay-controls button { width: 36px; height: 34px; border: 1px solid #568266; border-radius: 5px; background: #34724e; color: #fff; }
.race-replay-controls output { flex: 1; font-size: 12px; font-variant-numeric: tabular-nums; }
.race-replay-controls select { padding: 6px; border: 1px solid #568266; border-radius: 4px; background: transparent; color: inherit; }
.race-replay-controls input { width: 100%; margin: 0; accent-color: #34724e; }
.race-round-tabs { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 6px; margin: 12px 0; }
.race-round-tabs button { height: 36px; min-width: 0; border: 1px solid #568266; border-radius: 5px; background: transparent; color: inherit; font-weight: 700; }
.race-round-tabs button[aria-pressed="true"] { background: #34724e; color: #fff; }
.race-round-detail h4 { margin: 0 0 10px; font-size: 14px; }
.race-review-image { display: block; width: 100%; max-height: 300px; aspect-ratio: 4 / 3; object-fit: contain; border-radius: 5px; background: #203529; }
.race-round-answers { display: grid; gap: 0; list-style: none; margin: 10px 0 0; padding: 0; }
.race-round-answers li { padding: 12px 0; border-top: 1px solid #b7cbbb; min-width: 0; }
.race-round-answers li > div { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; font-size: 12px; }
.race-round-answers li p { margin: 6px 0; overflow-wrap: anywhere; }
.race-round-answers li b { overflow-wrap: anywhere; }
.race-round-answers li small { display: block; font-size: 11px; }
.race-round-answers li.me { border-left: 3px solid #b68d22; padding-left: 8px; }
.race-round-review .race-round-detail { padding: 0; border: 0; background: transparent; }
.race-round-review .race-round-detail p { font-size: 12px; }
.race-podium { display: flex; align-items: end; justify-content: center; gap: 6px; margin: 16px 0 10px; }
.race-podium > div { min-width: 0; flex: 1; display: grid; justify-items: center; gap: 4px; padding: 10px 4px; border: 1px solid #d3bd76; border-radius: 7px 7px 3px 3px; background: #fff2c9; text-align: center; }
.race-podium .place-1 { order: 2; padding-top: 20px; }.race-podium .place-2 { order: 1; }.race-podium .place-3 { order: 3; }
.race-podium span { font-size: 27px; }.race-podium b { width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 9px; white-space: nowrap; }.race-podium strong { color: #2f6847; font-size: 10px; }
.race-prize { margin-bottom: 10px; padding: 10px; border-radius: 6px; background: #dfead9; text-align: center; font-size: 11px; }
.race-result-users { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 7px; }
.race-result-users button { flex: 0 0 auto; min-height: 34px; border: 1px solid #c8d3c5; border-radius: 5px; background: #edf2ea; color: #304638; font-size: 9px; font-weight: 800; }
.race-result-details { display: grid; gap: 8px; margin-top: 8px; }
.race-round-detail { padding: 9px; border: 1px solid #d1dad0; border-radius: 6px; background: #f8faf6; }
.race-round-detail > button { width: 100%; display: flex; justify-content: space-between; border: 0; background: transparent; color: #2a4635; font-weight: 900; }
.race-round-detail p { margin: 5px 0 0; font-size: 9px; }
.race-detail-image img { display: block; width: 100%; aspect-ratio: 1; margin-top: 9px; border-radius: 5px; object-fit: cover; }
.race-muted { color: #748178; font-size: 10px; line-height: 1.45; }
.race-modal { position: fixed; z-index: 130; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(10, 30, 20, .55); }
.race-modal form { width: min(100%, 370px); display: grid; gap: 10px; padding: 18px; border-radius: 8px; background: #fff; color: #21362a; }
.race-modal h3, .race-modal p { margin: 0; }.race-modal h3 { font: 900 20px Georgia, serif; }.race-modal p { color: #6d796f; font-size: 11px; }
.race-modal form > div { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }.race-modal form > div button { min-height: 42px; border: 0; border-radius: 5px; font-weight: 900; }

html[data-theme="dark"] .races-shell { background: #14221a; color: #dce8de; }
html[data-theme="dark"] .race-title p, html[data-theme="dark"] .race-muted { color: #a9b8ad; }
html[data-theme="dark"] .race-tabs { background: #203529; border-color: #405346; }
html[data-theme="dark"] .race-tabs button, html[data-theme="dark"] .race-room-card, html[data-theme="dark"] .race-panel, html[data-theme="dark"] .race-settings span, html[data-theme="dark"] .race-join-card, html[data-theme="dark"] .race-rules, html[data-theme="dark"] .race-leaderboard-row, html[data-theme="dark"] .race-modal form { background: #1e3025; border-color: #435649; color: #dce8de; }
html[data-theme="dark"] .race-room-facts i, html[data-theme="dark"] .race-player-list li, html[data-theme="dark"] .race-result-users button, html[data-theme="dark"] .race-round-detail { background: #293d30; border-color: #465b4c; color: #dce8de; }
html[data-theme="dark"] .race-create-form input, html[data-theme="dark"] .race-chat-form input, html[data-theme="dark"] .race-answer-form input, html[data-theme="dark"] .race-modal input { background: #17271e; border-color: #495e4f; color: #fff; }
html[data-theme="dark"] .race-chat-messages p { background: #293d30; color: #eef5ef; }
html[data-theme="dark"] .race-chat-messages p.mine { background: #315f46; color: #f4fff7; }
html[data-theme="dark"] .race-chat-messages p.system { background: transparent; color: #a9b8ad; }
html[data-theme="dark"] .race-chat-messages p b { color: #a9e0b8; }
html[data-theme="dark"] .race-room-actions, html[data-theme="dark"] .race-answer-dock { background: rgba(25, 41, 31, .97); border-color: #46594b; }
html[data-theme="dark"] .race-mask { color: #edf5ee; }
html[data-theme="dark"] .race-leaderboard { background: rgba(20, 34, 26, .94); border-color: #435649; }
html[data-theme="dark"] .race-track { border-color: #5e7e66; background: repeating-linear-gradient(0deg, #314d35 0 5px, #29452f 5px 10px); }
html[data-theme="dark"] .race-track::before { border-left-color: rgba(198, 220, 191, .45); }
html[data-theme="dark"] .race-drawer { background: #17271e; border-color: #4a5d50; }
html[data-theme="dark"] .race-attempt-result { background: #3b3520; color: #f0ead1; }
html[data-theme="dark"] .race-leaderboard-row.me { background: #554619; border-color: #d4a33b; }
html[data-theme="dark"] .race-countdown-page { background: #315f52; }
html[data-theme="dark"] .race-start-countdown { color: #eef5ef; }
html[data-theme="dark"] .race-start-countdown span { color: #c8d8ce; }
html[data-theme="dark"] .race-podium > div { background: #3d3520; border-color: #a9893b; color: #f9eed1; }
html[data-theme="dark"] .race-podium strong { color: #acdba9; }
html[data-theme="dark"] .race-prize { background: #293d30; color: #dce8de; }
html[data-theme="dark"] .race-replay-controls select, html[data-theme="dark"] .race-replay-controls option { background: #1e3025; color: #dce8de; }
html[data-theme="dark"] .race-round-review .race-round-detail { background: transparent; }
html[data-theme="dark"] .race-round-answers li { border-top-color: #465b4c; }

@media (min-width: 720px) {
  .races-shell { padding-inline: 24px; }
  .race-room-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .race-game-page { max-width: 720px; margin: auto; }
  .race-puzzle { width: min(100%, 540px); margin-inline: auto; }
  .race-answer-dock { position: relative; bottom: auto; }
}

@media (max-width: 350px) {
  .race-settings small { display: none; }
  .race-room-facts { grid-template-columns: repeat(2, 1fr); }
  .race-title h2 { font-size: 21px; }
}
