/* Eventra.Run Mini App — styled after the Figma Make design "Eventra.Run Telegram Mini App".
   Tokens follow the design; inside Telegram they take the user's theme (telegram-web-app.js sets --tg-theme-*). */
:root {
  --tg-bg: var(--tg-theme-bg-color, #ffffff);
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --tg-text: var(--tg-theme-text-color, #111418);
  --tg-hint: var(--tg-theme-hint-color, #6a7077);
  --tg-link: var(--tg-theme-link-color, #1f6fb2);
  --tg-button: var(--tg-theme-button-color, #1f6fb2);
  --tg-button-text: var(--tg-theme-button-text-color, #ffffff);
  --tg-separator: var(--tg-theme-section-separator-color, #e2e5ea);
  --tg-card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --tg-header-bg: var(--tg-theme-header-bg-color, var(--tg-theme-bg-color, #ffffff));
  --tg-input-bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --tg-secondary-button: color-mix(in srgb, var(--tg-link) 16%, var(--tg-card));
  --tg-secondary-button-text: var(--tg-link);
  --tg-urgency-bg: #fff0e3; --tg-urgency-text: #a8420a;
  --tg-success-bg: #e5f4ea; --tg-success-text: #1b7039;
  --tg-blue-bg: color-mix(in srgb, var(--tg-link) 12%, transparent);
  --tg-radius: 14px;
  --font: 'Roboto', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Noto Sans Khmer', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --tg-bg: #212121; --tg-secondary-bg: #181818; --tg-text: #ffffff; --tg-hint: #8d8d93; --tg-link: #62bcee;
    --tg-button: #62bcee; --tg-button-text: #212121; --tg-separator: #3d3d3d; --tg-card: #2c2c2e;
    --tg-header-bg: #1c1c1e; --tg-input-bg: #2c2c2e; --tg-secondary-button: #1a3a52; --tg-secondary-button-text: #62bcee;
    --tg-urgency-bg: #3d2010; --tg-urgency-text: #ff9066; --tg-success-bg: #0d2e1a; --tg-success-text: #4dc878;
  }
}
:root.tg-dark { --tg-urgency-bg: #3d2010; --tg-urgency-text: #ff9066; --tg-success-bg: #0d2e1a; --tg-success-text: #4dc878; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--tg-secondary-bg); color: var(--tg-text); font-family: var(--font); font-size: 15px; line-height: 1.4; overscroll-behavior: none; -webkit-font-smoothing: antialiased; }
html[lang="km"] body, .khmer { font-family: 'Noto Sans Khmer', var(--font); }
a { color: var(--tg-link); text-decoration: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--tg-link); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#app { max-width: 640px; margin: 0 auto; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

/* browser-only top bar (inside Telegram, Telegram's own header + Back button are used) */
.topbar { position: sticky; top: 0; z-index: 20; height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--tg-header-bg); border-bottom: 1px solid var(--tg-separator); }
.topbar .back { display: flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--tg-link); font-size: 16px; min-height: 44px; padding: 0 4px; }
.topbar .back .ico { width: 10px; height: 17px; stroke-width: 2; }
.topbar .brand { flex: 1; text-align: center; font-weight: 600; margin-right: 56px; }

/* Discover header */
.dhdr { background: var(--tg-header-bg); border-bottom: 1px solid var(--tg-separator); padding: 0 16px; }
.dhdr .bar { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.wordmark { font-size: 24px; font-weight: 700; }
.wordmark .a { color: var(--tg-link); } .wordmark .b { color: var(--tg-hint); }
.langtoggle { display: flex; background: var(--tg-input-bg); border-radius: 8px; overflow: hidden; border: 0; padding: 0; font-size: 13px; font-weight: 600; }
.langtoggle span { padding: 6px 10px; color: var(--tg-hint); }
.langtoggle span.on { background: var(--tg-link); color: #fff; }
.stats { font-size: 13px; color: var(--tg-hint); padding-bottom: 12px; }
.search-bar { background: var(--tg-input-bg); border-radius: 10px; height: 36px; display: flex; align-items: center; gap: 8px; padding: 0 12px; color: var(--tg-hint); margin-bottom: 12px; }
.search-bar .ico { width: 16px; height: 16px; }
.search-bar input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 15px; color: var(--tg-text); }
.search-bar input::placeholder { color: var(--tg-hint); }
.chiprow { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: none; }
.chiprow::-webkit-scrollbar { display: none; }
.pill-chip { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 20px; font-size: 14px; font-weight: 500; white-space: nowrap; user-select: none; border: 1.5px solid var(--tg-separator); background: var(--tg-card); color: var(--tg-text); transition: all .15s; flex-shrink: 0; min-height: 34px; }
.pill-chip[aria-pressed="true"] { background: var(--tg-link); border-color: var(--tg-link); color: #fff; }
.pill-chip .ico { width: 16px; height: 16px; }
.pill-chip .count { min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px; background: var(--tg-link); color: #fff; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; }
.wrapchips { display: flex; flex-wrap: wrap; gap: 8px; }

.scroll { padding: 0 12px; }
.sec-title { padding: 16px 4px 8px; font-size: 15px; font-weight: 700; color: var(--tg-text); display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.sec-title.urgent { color: var(--tg-urgency-text); justify-content: flex-start; }
.sec-title .n { font-size: 13px; font-weight: 500; color: var(--tg-hint); }

/* early-bird cards */
.ebrow { display: flex; gap: 10px; overflow-x: auto; margin: 0 -12px; padding: 0 12px 4px; scrollbar-width: none; }
.ebrow::-webkit-scrollbar { display: none; }
.early-bird-card { background: var(--tg-card); border-radius: 12px; width: 210px; flex-shrink: 0; border: 1px solid var(--tg-separator); overflow: hidden; display: flex; flex-direction: column; color: var(--tg-text); }
.eb-img { height: 90px; background: var(--tg-secondary-bg); position: relative; }
.eb-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.eb-img::after { content: ''; position: absolute; inset: 0; background: linear-gradient(to bottom, transparent 40%, rgba(0,0,0,.45) 100%); }
.eb-img .badge { position: absolute; top: 8px; left: 8px; z-index: 1; font-size: 11px; background: rgba(0,0,0,.55); color: #fff; }
.eb-img .badge.urgent { background: var(--tg-urgency-bg); color: var(--tg-urgency-text); }
.eb-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.eb-name { font-size: 14px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.eb-org { font-size: 12px; color: var(--tg-hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eb-price { display: flex; align-items: center; gap: 8px; }
.eb-price .now { font-size: 13px; font-weight: 600; color: var(--tg-link); }
.eb-price .was { font-size: 12px; color: var(--tg-hint); text-decoration: line-through; }

/* placeholder image when an event has no poster */
.noimg { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--tg-hint); background: linear-gradient(135deg, var(--tg-secondary-bg), color-mix(in srgb, var(--tg-link) 22%, var(--tg-secondary-bg))); }
.noimg .ico { width: 28px; height: 28px; opacity: .7; }

/* race list */
.inset-card { background: var(--tg-card); border-radius: var(--tg-radius); overflow: hidden; }
.race-list-row { display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--tg-separator); align-items: flex-start; color: var(--tg-text); transition: background .1s; }
.race-list-row:last-child { border-bottom: 0; }
.race-list-row:active { background: var(--tg-secondary-bg); }
.date-block { min-width: 42px; text-align: center; flex-shrink: 0; }
.date-block-month { font-size: 11px; font-weight: 700; color: var(--tg-urgency-text); text-transform: uppercase; line-height: 1.2; }
.date-block-day { font-size: 24px; font-weight: 700; line-height: 1.1; }
.date-block-weekday { font-size: 11px; color: var(--tg-hint); line-height: 1.2; }
.rl-info { flex: 1; min-width: 0; }
.rl-name { font-size: 15px; font-weight: 600; line-height: 1.3; margin-bottom: 2px; }
.rl-km { font-size: 13px; color: var(--tg-hint); line-height: 1.5; margin-bottom: 2px; }
.rl-place { font-size: 13px; color: var(--tg-hint); margin-bottom: 6px; }
.rl-tags { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.dist-tag { background: var(--tg-secondary-bg); color: var(--tg-hint); padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.rl-price { font-size: 13px; color: var(--tg-link); font-weight: 500; margin-left: auto; white-space: nowrap; }
.rl-thumb { width: 60px; height: 60px; border-radius: 8px; overflow: hidden; background: var(--tg-secondary-bg); flex-shrink: 0; }
.rl-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rl-thumb .noimg .ico { width: 22px; height: 22px; }
.chev { color: var(--tg-hint); padding-left: 2px; align-self: center; display: flex; }
.chev .ico { width: 8px; height: 14px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-open { background: var(--tg-success-bg); color: var(--tg-success-text); }
.badge-urgency { background: var(--tg-urgency-bg); color: var(--tg-urgency-text); }
.badge-blue { background: var(--tg-blue-bg); color: var(--tg-link); }
.badge-grey { background: var(--tg-secondary-bg); color: var(--tg-hint); }

.empty { margin: 24px 4px; padding: 24px; text-align: center; color: var(--tg-hint); background: var(--tg-card); border-radius: var(--tg-radius); }
.empty .secondary-button { margin-top: 12px; }
.skeleton { height: 88px; border-bottom: 1px solid var(--tg-separator); background: linear-gradient(90deg, var(--tg-card) 0, var(--tg-secondary-bg) 50%, var(--tg-card) 100%); background-size: 200% 100%; animation: sh 1.2s infinite; }
@keyframes sh { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* sections, rows */
.section-header { padding: 20px 16px 8px; font-size: 13px; font-weight: 600; color: var(--tg-hint); text-transform: uppercase; letter-spacing: .04em; }
.pad { padding: 0 16px 4px; }
.inset-row { padding: 12px 16px; display: flex; align-items: center; gap: 12px; min-height: 44px; border-bottom: 1px solid var(--tg-separator); color: var(--tg-text); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.inset-row:last-child { border-bottom: 0; }
.inset-row .emo { font-size: 18px; flex-shrink: 0; width: 24px; text-align: center; }
.inset-row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.inset-row .l { font-size: 15px; font-weight: 500; }
.inset-row .l.link { color: var(--tg-link); }
.inset-row .s { font-size: 13px; color: var(--tg-hint); overflow: hidden; text-overflow: ellipsis; }
.switch-row { justify-content: space-between; }

/* filters */
.fpage { padding: 0 12px; }
.fpage .section-header { padding-left: 4px; }
.range-box { padding: 14px 16px; }
.range-box .top { display: flex; justify-content: space-between; margin-bottom: 10px; font-size: 14px; color: var(--tg-hint); }
.range-box .top b { color: var(--tg-text); font-weight: 600; }
.range-box input { width: 100%; accent-color: var(--tg-link); }
.tg-switch { width: 51px; height: 31px; border-radius: 16px; position: relative; border: 0; padding: 0; flex-shrink: 0; background: var(--tg-separator); transition: background .3s; }
.tg-switch[aria-checked="true"] { background: #30d158; }
.tg-switch::after { content: ''; position: absolute; width: 27px; height: 27px; background: #fff; border-radius: 50%; top: 2px; left: 2px; transition: left .3s; box-shadow: 0 2px 4px rgba(0,0,0,.3); }
.tg-switch[aria-checked="true"]::after { left: 22px; }

/* race details */
.cover-image-container { position: relative; width: 100%; height: 200px; overflow: hidden; background: var(--tg-secondary-bg); }
.cover-image-container > img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-image-container::after { content: ''; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(0,0,0,.3) 0%, transparent 40%, rgba(0,0,0,.6) 100%); pointer-events: none; }
.cover-title { position: absolute; bottom: 12px; left: 16px; right: 16px; z-index: 1; color: #fff; }
.cover-title h1 { margin: 0 0 4px; font-size: 18px; font-weight: 700; line-height: 1.3; }
.cover-title .km { font-size: 13px; color: rgba(255,255,255,.85); line-height: 1.5; }
.cover-actions { position: absolute; top: 12px; right: 12px; z-index: 2; display: flex; gap: 8px; }
.round-btn { width: 36px; height: 36px; border-radius: 18px; background: rgba(0,0,0,.45); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; color: #fff; border: 0; }
.dbody { padding: 12px 16px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.segmented-control { display: flex; background: var(--tg-input-bg); border-radius: 9px; padding: 2px; overflow-x: auto; scrollbar-width: none; }
.segment { flex: 1 0 auto; min-width: 52px; min-height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--tg-hint); border: 0; background: none; padding: 0 8px; transition: all .2s; white-space: nowrap; }
.segment[aria-pressed="true"] { background: var(--tg-card); color: var(--tg-text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.cat-box { padding: 14px 16px; }
.cat-label { font-size: 13px; font-weight: 700; color: var(--tg-hint); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 12px; }
.cat-label .nm { display: block; font-size: 15px; font-weight: 600; color: var(--tg-text); text-transform: none; letter-spacing: 0; margin-top: 2px; }
.cat-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; text-align: center; }
.cat-stats .e { font-size: 20px; margin-bottom: 2px; }
.cat-stats .v { font-size: 16px; font-weight: 700; }
.cat-stats .v.small { font-size: 13px; font-weight: 600; color: var(--tg-hint); }
.cat-stats .k { font-size: 11px; color: var(--tg-hint); }
.chip-strip { margin-top: 12px; padding: 6px 10px; background: var(--tg-secondary-bg); border-radius: 8px; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--tg-hint); }
.aud-wrap { margin-bottom: 12px; }
.price-tier { padding: 12px 16px; border-left: 3px solid transparent; display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: 1px solid var(--tg-separator); }
.price-tier:last-child { border-bottom: 0; }
.price-tier .t { font-size: 15px; font-weight: 600; }
.price-tier .w { font-size: 12px; color: var(--tg-hint); }
.price-tier.active { border-left-color: var(--tg-link); background: color-mix(in srgb, var(--tg-link) 6%, transparent); }
.price-tier.active .t { font-size: 16px; font-weight: 700; }
.price-tier.ended { opacity: .5; }
.price-tier.ended .t { color: var(--tg-hint); text-decoration: line-through; }
.price-tier .badge { font-size: 11px; }
.kit-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.race-kit-item { background: var(--tg-card); border-radius: 8px; padding: 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--tg-hint); text-align: center; line-height: 1.3; }
.race-kit-item .e { font-size: 22px; line-height: 1.1; }
.race-kit-item .x { font-size: 10px; opacity: .85; }
.cicon { width: 32px; display: flex; justify-content: center; flex-shrink: 0; font-size: 20px; }
.cicon svg { width: 20px; height: 20px; }
.foot-note { padding: 12px 16px 8px; font-size: 12px; color: var(--tg-hint); line-height: 1.5; }
.muted { color: var(--tg-hint); font-size: 13px; padding: 12px 16px; }

/* bottom sheet (contact) */
.bottom-sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.bottom-sheet { background: var(--tg-secondary-bg); border-radius: 16px 16px 0 0; width: 100%; max-width: 640px; max-height: 85vh; overflow-y: auto; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.bottom-sheet-handle { width: 36px; height: 4px; background: var(--tg-separator); border-radius: 2px; margin: 8px auto; }
.sheet-head { padding: 0 16px 12px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.sheet-head .h { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.sheet-head .s { font-size: 13px; color: var(--tg-hint); }
.sheet-close { width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--tg-input-bg); color: var(--tg-hint); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sheet-close .ico { width: 14px; height: 14px; stroke-width: 2; }
.fast { background: var(--tg-success-bg); color: var(--tg-success-text); font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 8px; margin-left: 6px; }

/* buttons (browser — inside Telegram the MainButton is Telegram's own) */
.mainbtn { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--tg-bg); border-top: 1px solid var(--tg-separator); }
.main-button { width: 100%; max-width: 608px; margin: 0 auto; height: 50px; background: var(--tg-button); color: var(--tg-button-text); border: 0; border-radius: 12px; font-size: 16px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 6px; }
.main-button:active, .secondary-button:active { opacity: .85; }
.secondary-button { height: 44px; padding: 0 18px; background: var(--tg-secondary-button); color: var(--tg-secondary-button-text); border: 0; border-radius: 12px; font-size: 15px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.foot { text-align: center; color: var(--tg-hint); font-size: 12px; padding: 24px 16px 8px; }
.pad.top { padding-top: 12px; }
.stock-tag { position: absolute; top: 12px; left: 12px; z-index: 2; font-size: 11px; font-weight: 600; color: #fff; background: rgba(0,0,0,.45); backdrop-filter: blur(6px); padding: 3px 8px; border-radius: 10px; }
