/* 通用（横屏桌面为主）：锁死页面滚动；舞台 contain 居中时的留边区域
   用赛道氛围背景填充，避免窗口比例偏竖时出现"纯黑底 + 居中小窗口"的观感。
   窄竖屏媒体查询里有同选择器的 !important 覆盖，互不影响。 */
html,
body {
  height: 100%;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(4, 8, 12, 0.25), #071019 62%),
    url("./assets/test-track-1791517358809.webp") center / cover no-repeat,
    #071019;
}

/* Homepage-only participation banner. It lives inside #intro, so gameplay stays clear. */
#redline .track-stats-banner {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  min-height: 42px;
  margin: 17px auto 0;
  padding: 0 20px;
  color: #c6d0d6;
  background: rgba(8, 16, 23, 0.76);
  border: 1px solid rgba(166, 242, 206, 0.2);
  border-radius: 7px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(10px);
  font-size: 18px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

#redline .track-stats-banner strong {
  margin: 0 4px;
  color: #a6f2ce;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

#redline .track-stats-divider {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.16);
}

.offtrack-warning {
  display: none;
  margin-top: 10px;
  color: #ff9a78;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 12px #000;
}

.offtrack-result {
  position: fixed;
  z-index: 20000;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: #edf0ee;
  background: rgba(6, 12, 19, 0.86);
  backdrop-filter: blur(12px);
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

.offtrack-result[hidden] {
  display: none;
}

.offtrack-result__panel {
  width: min(720px, 100%);
  padding: 46px 54px;
  text-align: center;
  background: linear-gradient(145deg, #2c3035, #121a22 72%);
  border: 1px solid rgba(255, 132, 92, 0.42);
  border-radius: 18px;
  box-shadow: 0 25px 120px rgba(0, 0, 0, 0.55);
}

.offtrack-result__kicker {
  color: #ff845c;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.28em;
}

.offtrack-result h2 {
  margin: 14px 0 10px;
  font-size: 48px;
  letter-spacing: 0.08em;
}

.offtrack-result p {
  margin: 0;
  color: #b7c6d0;
  font-size: 19px;
  line-height: 1.6;
}

.offtrack-result__speed {
  margin: 26px 0 4px;
  color: #ff845c;
  font-size: 78px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.offtrack-result__speed small {
  margin-left: 8px;
  font-size: 20px;
}

.offtrack-result__label {
  margin-bottom: 30px;
  color: #91a2ad;
  font-size: 15px;
}

.offtrack-result button {
  min-width: 180px;
  height: 56px;
  padding: 0 24px;
  color: #15202a;
  background: #ff845c;
  border: 0;
  border-radius: 7px;
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
}

.offtrack-result button + button {
  margin-left: 10px;
  color: #d3dce1;
  background: transparent;
  border: 1px solid rgba(185, 199, 209, 0.3);
}

@media (max-width: 720px) and (orientation: portrait) {
  html,
  body,
  .game-stage-host {
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    overflow: hidden !important;
    background: #071019 !important;
    overscroll-behavior: none;
  }

  .game-stage-host,
  .game-stage-viewport,
  .game-stage-scaler,
  .game-stage-content {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    min-width: 0 !important;
    min-height: 0 !important;
    transform: none !important;
  }

  .game-stage-viewport {
    overflow: hidden !important;
  }

  #liko-canvas {
    display: none !important;
  }

  /* 结算面板的「返回首页」在触屏上极易误触（手指从踏板收势的位置恰是它），
     手机版隐藏；返回首页统一走左上角的小返回按钮。
     #menu / #offtrack-menu 仍可被脚本编程点击（display:none 不影响 .click()）。 */
  #menu,
  #offtrack-menu {
    display: none !important;
  }

  /* 引擎会为 game/dashboard 两个场景各挂一份 #redline 界面。
     手机版只保留 .game-stage-host 内已全屏的那份；另一份（含重复界面、
     且全屏容器会挡住下层按钮的点击）整个容器藏掉。 */
  body > div:not(.game-stage-host):has(#redline) {
    display: none !important;
  }

  #redline {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
    background:
      linear-gradient(180deg, rgba(4, 8, 12, 0.12), #071019 47%, #071019 100%),
      url("./assets/test-track-1791517358809.webp") center top / auto 43% no-repeat,
      #071019 !important;
  }

  #redline .shade {
    background: linear-gradient(180deg, rgba(7, 12, 18, 0.18), rgba(7, 16, 24, 0.2) 32%, #071019 71%) !important;
  }

  #redline .dash {
    inset: 315px 0 0 !important;
    width: auto !important;
    height: auto !important;
    background:
      linear-gradient(180deg, rgba(7, 16, 24, 0.04), rgba(7, 16, 24, 0.82) 35%, #071019 78%),
      url("./assets/cockpit-frame-1791517975521.webp") center top / auto 290px no-repeat !important;
    opacity: 0.82;
  }

  #redline .header {
    top: max(12px, env(safe-area-inset-top)) !important;
    right: 88px !important;
    bottom: auto !important;
    left: 16px !important;
    width: auto !important;
    height: 44px !important;
    align-items: flex-start !important;
  }

  #redline .brand {
    width: auto !important;
    height: auto !important;
    font-size: 18px !important;
    line-height: 1 !important;
  }

  #redline .subtitle {
    width: auto !important;
    height: auto !important;
    margin-top: 5px !important;
    font-size: 9px !important;
    letter-spacing: 0.35em !important;
  }

  #redline .header-right {
    gap: 7px !important;
  }

  #redline .track-label {
    display: none !important;
  }

  #redline .icon-button {
    width: 34px !important;
    height: 34px !important;
    font-size: 15px !important;
  }

  #redline #intro {
    top: 68px !important;
    right: 16px !important;
    bottom: auto !important;
    left: 16px !important;
    width: auto !important;
    height: auto !important;
  }

  #redline #intro .eyebrow {
    width: auto !important;
    height: auto !important;
    font-size: 10px !important;
    letter-spacing: 0.2em !important;
  }

  #redline #intro h1 {
    width: auto !important;
    height: auto !important;
    margin: 8px 0 !important;
    font-size: clamp(29px, 8.7vw, 36px) !important;
    line-height: 1.08 !important;
  }

  #redline .goal-note {
    width: auto !important;
    height: auto !important;
    font-size: 12px !important;
    line-height: 1.55 !important;
  }

  #redline .quick-guide {
    width: 100% !important;
    height: auto !important;
    margin: 13px 0 10px !important;
    gap: 5px !important;
  }

  #redline .quick-guide span {
    min-width: 0 !important;
    padding: 7px 3px !important;
    font-size: 9px !important;
    white-space: nowrap;
  }

  #redline .goal-rules {
    display: none !important;
  }

  #redline .track-stats-banner {
    display: flex !important;
    width: fit-content !important;
    min-height: 28px !important;
    margin: 8px auto 0 !important;
    padding: 0 10px !important;
    gap: 8px !important;
    font-size: 9px !important;
    letter-spacing: 0 !important;
  }

  #redline .track-stats-banner strong {
    margin: 0 2px !important;
    font-size: 12px !important;
  }

  #redline .track-stats-divider {
    height: 12px !important;
  }

  .offtrack-warning {
    margin-top: 5px;
    font-size: 11px;
  }

  .offtrack-result {
    padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  }

  .offtrack-result__panel {
    padding: 30px 18px 24px;
    border-radius: 14px;
  }

  .offtrack-result h2 {
    margin: 10px 0 8px;
    font-size: 34px;
  }

  .offtrack-result p {
    font-size: 13px;
  }

  .offtrack-result__speed {
    margin-top: 22px;
    font-size: 60px;
  }

  .offtrack-result__label {
    margin-bottom: 22px;
    font-size: 12px;
  }

  .offtrack-result button {
    width: 100%;
    min-height: 48px;
  }

  .offtrack-result button + button {
    margin: 10px 0 0;
  }

  #redline #start {
    width: min(230px, 70vw) !important;
    height: 48px !important;
    margin-top: 8px !important;
    padding: 0 18px !important;
    font-size: 16px !important;
    border-radius: 8px !important;
  }

  #redline #run-status {
    top: 66px !important;
    right: 16px !important;
    bottom: auto !important;
    left: 16px !important;
    width: auto !important;
    height: 92px !important;
  }

  #redline .traffic-housing {
    display: none !important;
  }

  #redline .lamp-state {
    margin: 0 0 5px !important;
    font-size: 17px !important;
  }

  #redline .status-tag,
  #redline .status-note {
    margin-top: 4px !important;
    font-size: 11px !important;
  }

  #redline #live-chart {
    display: none !important;
  }

  #redline .speedometer {
    top: 278px !important;
    right: auto !important;
    bottom: auto !important;
    left: 50% !important;
    width: min(350px, 94vw) !important;
    height: 226px !important;
    transform: translateX(-50%) !important;
  }

  #redline #intro[style*="display: none"] ~ .speedometer {
    top: 166px !important;
  }

  #redline #intro:not([style*="display: none"]) ~ .speedometer {
    top: 348px !important;
    width: min(310px, 88vw) !important;
    height: 150px !important;
  }

  #redline #intro:not([style*="display: none"]) ~ .speedometer .gauge-svg {
    height: 150px !important;
  }

  #redline #intro:not([style*="display: none"]) ~ .speedometer .speed-readout {
    top: 34px !important;
  }

  #redline #intro:not([style*="display: none"]) ~ .speedometer .speed-value {
    font-size: 60px !important;
  }

  #redline .gauge-svg {
    width: 100% !important;
    height: 205px !important;
  }

  #redline .speed-readout {
    top: 58px !important;
    right: 0 !important;
    bottom: auto !important;
    left: 0 !important;
    width: 100% !important;
    height: auto !important;
  }

  #redline .speed-value {
    width: 100% !important;
    height: auto !important;
    font-size: 76px !important;
    line-height: 0.95 !important;
  }

  #redline .speed-unit,
  #redline .speed-state {
    font-size: 10px !important;
  }

  #redline .gauge-label {
    font-size: 11px !important;
  }

  #redline .g0 { left: 14% !important; top: 75% !important; }
  #redline .g60 { left: 17% !important; top: 29% !important; }
  #redline .g100 { left: 46% !important; top: 0 !important; }
  #redline .g140 { right: 17% !important; left: auto !important; top: 29% !important; }
  #redline .g200 { right: 13% !important; left: auto !important; top: 75% !important; }

  #redline .telemetry {
    top: 498px !important;
    right: 14px !important;
    bottom: auto !important;
    left: 14px !important;
    display: grid !important;
    width: auto !important;
    height: 74px !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
    padding: 10px 8px 8px !important;
    background: rgba(6, 13, 20, 0.74) !important;
    border: 1px solid rgba(166, 242, 206, 0.1) !important;
    border-radius: 8px !important;
    backdrop-filter: blur(8px);
  }

  #redline #intro[style*="display: none"] ~ .telemetry {
    top: 386px !important;
  }

  #redline .telemetry > .section-title,
  #redline .best-line {
    display: none !important;
  }

  #redline .metric,
  #redline .metric.small {
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
    text-align: center !important;
  }

  #redline .metric-label {
    width: auto !important;
    height: auto !important;
    margin: 0 0 4px !important;
    font-size: 9px !important;
  }

  #redline .metric-value {
    font-size: 22px !important;
    line-height: 1 !important;
  }

  #redline .metric .unit {
    font-size: 9px !important;
  }

  #redline .hold-feedback {
    top: 578px !important;
    right: 14px !important;
    bottom: auto !important;
    left: 14px !important;
    width: auto !important;
    display: grid !important;
    height: 52px !important;
    padding: 7px 10px 6px !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: center !important;
    gap: 1px 8px !important;
    font-size: 10px !important;
    border-radius: 7px !important;
  }

  #redline #intro[style*="display: none"] ~ .hold-feedback {
    top: 452px !important;
  }

  #redline #hold-status {
    min-width: 0 !important;
    font-size: 11px !important;
    line-height: 1.2 !important;
    white-space: nowrap !important;
  }

  #redline #combo {
    font-size: 14px !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }

  #redline #pulse-note {
    grid-column: 1 / -1 !important;
    overflow: hidden !important;
    font-size: 9px !important;
    line-height: 1.2 !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  #redline .threshold {
    display: none !important;
  }

  #redline .control {
    top: 620px !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: auto !important;
    padding: 13px 14px max(12px, env(safe-area-inset-bottom)) !important;
    background: linear-gradient(180deg, rgba(9, 18, 27, 0.86), #071019 32%) !important;
    border-top: 1px solid rgba(255, 139, 97, 0.14) !important;
    box-sizing: border-box !important;
  }

  #redline #intro[style*="display: none"] ~ .control {
    top: 510px !important;
  }

  #redline .control > .section-title {
    width: auto !important;
    height: auto !important;
    font-size: 10px !important;
  }

  #redline .force-number {
    top: 34px !important;
    left: 15px !important;
    width: auto !important;
    height: auto !important;
    font-size: 27px !important;
  }

  #redline .force-number small {
    font-size: 10px !important;
  }

  #redline .force-caption {
    top: 68px !important;
    left: 15px !important;
    width: 118px !important;
    height: auto !important;
    font-size: 10px !important;
    line-height: 1.35 !important;
    color: #93a3ad !important;
  }

  #redline .pressure-gauge {
    top: 103px !important;
    left: 18px !important;
    width: 42px !important;
    height: 116px !important;
  }

  #redline .pressure-tick {
    font-size: 8px !important;
  }

  #redline .pedal-display {
    top: 92px !important;
    left: 72px !important;
    width: 88px !important;
    height: 132px !important;
  }

  #redline .real-pedal {
    width: 86px !important;
    height: auto !important;
  }

  #redline .pedal-display-label {
    display: none !important;
  }

  #redline .press-pad {
    top: 58px !important;
    right: 14px !important;
    bottom: auto !important;
    left: auto !important;
    width: min(190px, 49vw) !important;
    height: 142px !important;
    border-radius: 18px !important;
    box-shadow: 0 7px 0 #090e12, 0 15px 24px rgba(0, 0, 0, 0.46) !important;
  }

  #redline .press-surface strong {
    font-size: 16px !important;
  }

  #redline .press-surface span {
    font-size: 10px !important;
  }

  #redline .press-help {
    right: 14px !important;
    bottom: max(10px, env(safe-area-inset-bottom)) !important;
    left: auto !important;
    width: min(190px, 49vw) !important;
    height: auto !important;
    font-size: 9px !important;
    text-align: center !important;
  }

  #redline .footer {
    display: none !important;
  }

  #redline .overlay {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)) !important;
    box-sizing: border-box !important;
  }

  #redline .result-panel {
    width: 100% !important;
    max-height: 100% !important;
    padding: 22px 18px !important;
    overflow-y: auto !important;
    border-radius: 14px !important;
  }

  #redline .result-panel h2 {
    margin: 7px 0 !important;
    font-size: 30px !important;
  }

  #redline .result-desc,
  #redline .result-time-label,
  #redline .result-control {
    font-size: 12px !important;
    line-height: 1.5 !important;
  }

  #redline .result-time {
    margin: 13px 0 5px !important;
    font-size: 58px !important;
  }

  #redline .result-stats {
    gap: 7px !important;
    margin: 15px 0 !important;
  }

  #redline .result-stat {
    padding: 10px 5px !important;
    font-size: 10px !important;
  }

  #redline .trace-review {
    display: none !important;
  }

  #redline .result-panel .primary,
  #redline .result-panel .secondary {
    width: 100% !important;
    min-height: 46px !important;
    margin-top: 10px !important;
    font-size: 15px !important;
  }
}

@media (max-width: 720px) and (max-height: 650px) and (orientation: portrait) {
  #redline:has(#intro:not([style*="display: none"])) .control,
  #redline:has(#intro:not([style*="display: none"])) .hold-feedback {
    display: none !important;
  }

  #redline #intro {
    top: 58px !important;
  }

  #redline #intro h1 {
    font-size: 29px !important;
  }

  #redline .quick-guide {
    margin: 10px 0 7px !important;
  }

  #redline #start {
    height: 44px !important;
    margin-top: 8px !important;
  }

  #redline #run-status {
    top: 54px !important;
    height: 70px !important;
  }

  #redline .lamp-state {
    font-size: 15px !important;
  }

  #redline .status-tag,
  #redline .status-note {
    font-size: 9px !important;
  }

  #redline #intro[style*="display: none"] ~ .speedometer {
    top: 118px !important;
    width: min(300px, 94vw) !important;
    height: 182px !important;
  }

  #redline #intro[style*="display: none"] ~ .speedometer .gauge-svg {
    height: 170px !important;
  }

  #redline #intro[style*="display: none"] ~ .speedometer .speed-readout {
    top: 44px !important;
  }

  #redline #intro[style*="display: none"] ~ .speedometer .speed-value {
    font-size: 62px !important;
  }

  #redline #intro[style*="display: none"] ~ .telemetry {
    top: 298px !important;
    height: 58px !important;
    padding: 8px 5px 6px !important;
  }

  #redline #intro[style*="display: none"] ~ .telemetry .metric-label {
    font-size: 8px !important;
  }

  #redline #intro[style*="display: none"] ~ .telemetry .metric-value {
    font-size: 18px !important;
  }

  #redline #intro[style*="display: none"] ~ .hold-feedback {
    top: 361px !important;
    display: grid !important;
    height: 40px !important;
  }

  #redline #intro[style*="display: none"] ~ .hold-feedback #pulse-note {
    display: none !important;
  }

  #redline #intro[style*="display: none"] ~ .control {
    top: 405px !important;
    display: block !important;
  }

  #redline .control > .section-title {
    font-size: 9px !important;
  }

  #redline .force-number {
    top: 30px !important;
    font-size: 24px !important;
  }

  #redline .force-caption {
    top: 58px !important;
    width: 118px !important;
    font-size: 9px !important;
  }

  #redline .pressure-gauge {
    top: 82px !important;
    left: 16px !important;
    height: 74px !important;
  }

  #redline .pedal-display {
    display: none !important;
  }

  #redline .press-pad {
    top: 35px !important;
    right: 12px !important;
    width: min(158px, 50vw) !important;
    height: 104px !important;
  }

  #redline .press-help {
    right: 12px !important;
    bottom: max(5px, env(safe-area-inset-bottom)) !important;
    width: min(158px, 50vw) !important;
  }

  #redline .result-panel {
    padding: 18px 15px !important;
  }

  #redline .result-panel h2 {
    font-size: 26px !important;
  }

  #redline .result-time {
    font-size: 48px !important;
  }
}
