/* หน้าตาแนวรถแข่ง: พื้นเข้มลายคาร์บอน แถบแดง ตัวเลขเอียง ปุ่มทรงเฉียง
   อิงโครงแดชบอร์ดจับเวลาการแข่งแบบโอเพนซอร์ส (f1-telemetry, MIT) เฉพาะการจัดวางและโทน */
@font-face {
  font-family: 'Noto Sans Thai Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(../vendor/fonts/noto-sans-thai-thai-wght-normal.woff2) format('woff2-variations');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Noto Sans Thai Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(../vendor/fonts/noto-sans-thai-latin-wght-normal.woff2) format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Titillium Web';
  font-style: italic;
  font-weight: 700;
  font-display: swap;
  src: url(../vendor/fonts/titillium-web-latin-700-italic.woff2) format('woff2');
}
@font-face {
  font-family: 'Titillium Web';
  font-style: italic;
  font-weight: 600;
  font-display: swap;
  src: url(../vendor/fonts/titillium-web-latin-600-italic.woff2) format('woff2');
}

:root {
  --bg: #0b0d12;
  --surface: #161a22;
  --surface-2: #1f242e;
  --surface-3: #2a303c;
  --ink: #f3f6fa;
  --ink-2: #aeb8c7;
  --ink-3: #7d8899;
  --outline: #2b313d;
  --primary: #e0251b;
  --primary-press: #ff4a3d;
  --primary-soft: rgba(224, 37, 27, 0.2);
  --blue: #4da3ff;
  --hud: rgba(12, 14, 19, 0.86);
  --shadow-1: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 6px 18px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 12px 34px rgba(0, 0, 0, 0.55);
  --radius: 12px;
  --num: 'Titillium Web', 'Noto Sans Thai Variable', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: 'Noto Sans Thai Variable', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* ลายคาร์บอนจางๆ */
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.022) 0 2px, transparent 2px 6px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.016) 0 2px, transparent 2px 6px),
    var(--bg);
}
h2 {
  position: relative; margin: 0; padding-left: 14px;
  font-size: 16px; font-weight: 700; line-height: 1.35;
}
h2::before {
  content: ''; position: absolute; left: 0; top: 3px; bottom: 3px; width: 5px;
  background: var(--primary); transform: skewX(-14deg); border-radius: 1px;
}
h3 { font-size: 13px; font-weight: 600; margin: 16px 0 6px; color: var(--ink-2); }
p { margin: 0; }
button, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

body[data-mode='train'] .race-only,
body[data-mode='race'] .train-only { display: none !important; }

.app { height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); }

/* แถบบน */
.topbar {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 22px;
  padding: 10px 20px;
  background: linear-gradient(180deg, #171b23, #10131a);
  border-bottom: 1px solid var(--outline);
}
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: linear-gradient(90deg, var(--primary) 0 220px, transparent 220px),
    repeating-linear-gradient(90deg, #fff 0 8px, #0b0d12 8px 16px);
  background-size: 100% 100%, 64px 3px;
  background-repeat: no-repeat, no-repeat;
  background-position: 0 0, 228px 0;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { transform: skewX(-8deg); }
.brand strong { display: block; font-size: 22px; font-weight: 800; font-style: italic; line-height: 1.1; letter-spacing: -0.01em; }
.brand span { display: block; font-size: 12.5px; color: var(--ink-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.field { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-2); }
.field select {
  height: 40px; padding: 0 34px 0 14px;
  border: 1px solid var(--outline); border-radius: 8px;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23aeb8c7' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  appearance: none; font-weight: 600; color: var(--ink); cursor: pointer;
}
.field select:hover { border-color: var(--ink-3); }

/* ปุ่ม */
.btn {
  height: 40px; padding: 0 20px;
  border: 1px solid transparent; border-radius: 8px;
  font-size: 14.5px; font-weight: 700; white-space: nowrap;
  cursor: pointer; transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
.btn:active { transform: translateY(1px); }
.btn.filled { background: var(--primary); color: #fff; box-shadow: 0 6px 18px rgba(224, 37, 27, 0.35); }
.btn.filled:hover { background: var(--primary-press); }
.btn.filled:disabled { background: var(--surface-3); color: var(--ink-3); box-shadow: none; cursor: not-allowed; }
.btn.outlined { background: var(--surface-2); border-color: var(--outline); color: var(--ink); }
.btn.outlined:hover { border-color: var(--primary); color: #fff; }
.btn.block {
  position: relative; overflow: hidden;
  width: 100%; height: 52px; font-size: 17px; font-style: italic; letter-spacing: 0.01em;
}
/* ลายเฉียงท้ายปุ่มหลัก */
.btn.block::after {
  content: ''; position: absolute; top: 0; bottom: 0; right: -12px; width: 86px;
  background: repeating-linear-gradient(-66deg, rgba(255, 255, 255, 0.22) 0 7px, transparent 7px 16px);
}
.btn.onDark { background: transparent; color: #fff; padding: 0 14px; height: 36px; font-weight: 600; }
.btn.onDark:hover { background: rgba(255, 255, 255, 0.14); }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; flex: none;
  border: 0; border-radius: 8px; background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.icon-btn.bordered { border: 1px solid var(--outline); background: var(--surface-2); color: var(--ink-2); }
.icon-btn.bordered[aria-pressed='true'] { color: var(--primary-press); border-color: var(--primary); }
.icon-btn.onDark { color: #fff; border-radius: 50%; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* แถบเลือก: ปุ่มทรงเฉียงแบบป้ายรถแข่ง */
.segmented { display: inline-flex; gap: 3px; }
.segmented button {
  height: 40px; padding: 0 20px; border: 0;
  background: var(--surface-2); color: var(--ink-2);
  font-size: 14.5px; font-weight: 700; cursor: pointer;
  transform: skewX(-14deg); border-radius: 3px;
  transition: background 0.15s, color 0.15s;
}
.segmented button > span, .segmented button { font-style: italic; }
.segmented button:hover { background: var(--surface-3); color: #fff; }
.segmented button[aria-pressed='true'] { background: var(--primary); color: #fff; }
.segmented.small button { height: 34px; padding: 0 13px; font-size: 13.5px; }
.segmented.dark button { background: rgba(255, 255, 255, 0.1); color: #d4dbe6; }
.segmented.dark button:hover { background: rgba(255, 255, 255, 0.2); }
.segmented.dark button[aria-pressed='true'] { background: var(--primary); color: #fff; }

/* โครงหน้า */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 388px; gap: 16px;
  padding: 16px 20px 20px; min-height: 0;
}
.stage {
  position: relative; min-height: 0; overflow: hidden;
  border-radius: 14px; background: #12151c;
  border: 1px solid var(--outline); box-shadow: var(--shadow-2);
}
.stage canvas#view { display: block; width: 100%; height: 100%; }
.stage:fullscreen, .stage.theater { border: 0; border-radius: 0; }
.stage.theater { position: fixed; inset: 0; z-index: 50; height: auto; }
.panel {
  display: flex; flex-direction: column; gap: 12px; overflow-y: auto; min-height: 0; padding-right: 4px;
  scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent;
}

.card {
  background: linear-gradient(180deg, #1a1f28, var(--surface));
  border: 1px solid var(--outline); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-1);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 700; color: #fff;
  background: var(--primary-soft); border: 1px solid var(--primary); border-radius: 4px; padding: 1px 8px;
}
.tag::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--primary-press); animation: live 1.2s ease-in-out infinite; }
@keyframes live { 50% { opacity: 0.25; } }
.hint { font-size: 13px; color: var(--ink-2); margin: 10px 0 12px; }
.muted { color: var(--ink-3); }

/* ตัวเลขสรุป */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { background: var(--surface-2); border-radius: 8px; padding: 8px 12px 9px; border-left: 3px solid var(--surface-3); }
.tile:first-child { border-left-color: var(--primary); }
.tile span { display: block; font-size: 12px; color: var(--ink-2); }
.tile strong { font-family: var(--num); font-style: italic; font-size: 26px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 12px; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--primary-press)); border-radius: 3px; }

/* ภาพสมอง */
.brain { display: block; width: 100%; height: 252px; }
.outputs { display: grid; gap: 6px; margin-top: 6px; }
.out { display: grid; grid-template-columns: 34px 1fr 34px; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
.out span:last-child { text-align: right; }
.bipolar { position: relative; height: 8px; border-radius: 4px; background: var(--surface-3); }
.bipolar::after { content: ''; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--ink-2); border-radius: 1px; }
.bipolar i { position: absolute; top: 0; bottom: 0; background: #fff; border-radius: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); margin-top: 10px; }
.legend.tight { margin: 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* กราฟ */
.axis-note { font-size: 12px; color: var(--ink-2); margin-bottom: 2px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; touch-action: none; }
.chart .grid { stroke: var(--outline); stroke-width: 1; }
.chart .goal { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; }
.chart .tick { font-size: 10.5px; fill: var(--ink-2); font-family: inherit; }
.chart .empty { font-size: 12px; fill: var(--ink-3); font-family: inherit; }
.chart circle { stroke: var(--surface); }
.chart-tip {
  position: absolute; top: 4px; pointer-events: none; min-width: 140px;
  background: #f3f6fa; color: #12151c; border-radius: 8px; padding: 8px 10px;
  font-size: 12px; line-height: 1.5; box-shadow: var(--shadow-2);
}
.chart-tip strong, .chart-tip span { display: block; }
.chart-tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
details { margin-top: 6px; font-size: 13px; }
summary { cursor: pointer; color: var(--ink); font-weight: 600; padding: 4px 0; }
summary:hover { color: var(--primary-press); }
.table-scroll { max-height: 180px; overflow-y: auto; margin-top: 6px; scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 600; color: var(--ink-2); padding: 6px 8px; border-bottom: 1px solid var(--outline); position: sticky; top: 0; background: var(--surface); }
td { padding: 6px 8px; border-bottom: 1px solid var(--outline); }

.steps { margin: 12px 0 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 10px; }
.steps li { counter-increment: s; position: relative; padding-left: 40px; font-size: 13.5px; color: var(--ink-2); }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 2px;
  width: 28px; height: 24px; display: grid; place-items: center;
  background: var(--primary); color: #fff; border-radius: 3px; transform: skewX(-14deg);
  font-family: var(--num); font-style: italic; font-weight: 700; font-size: 15px;
}
.steps strong { display: block; color: var(--ink); font-weight: 650; }

.credits { font-size: 11.5px; line-height: 1.6; color: var(--ink-3); padding: 0 4px 4px; }
.credits a { color: var(--ink-2); }
.credits a:hover { color: #fff; }

.rivals { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.rivals li { display: grid; grid-template-columns: 5px 1fr; gap: 12px; align-items: stretch; padding: 8px 12px 8px 8px; border-radius: 8px; background: var(--surface-2); }
.rivals i { width: 5px; border-radius: 2px; }
.rivals strong { display: block; font-size: 14px; }
.rivals span { font-size: 12.5px; color: var(--ink-2); }
.laps { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.laps li { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; }
.laps li strong { font-family: var(--num); font-style: italic; font-size: 17px; font-variant-numeric: tabular-nums; }
.laps li.best strong { color: #c58bff; }

/* HUD บนฉาก 3D: แผงเข้มตัวเลขเอียงแบบกราฟิกถ่ายทอดสดการแข่ง */
.hud { position: absolute; display: flex; gap: 8px; align-items: flex-start; pointer-events: none; z-index: 1; }
.hud > * { pointer-events: auto; }
.hud.tl { top: 14px; left: 14px; }
.hud.tr { top: 14px; right: 14px; }
.hud.bl { bottom: 14px; left: 14px; }
.hud.br { bottom: 14px; right: 14px; }
.hud.bc { bottom: 14px; left: 50%; transform: translateX(-50%); }
.hud.keys-hint { bottom: 156px; }
.hp {
  background: var(--hud); color: #fff; border-radius: 8px; padding: 8px 14px 9px; min-width: 96px;
  border-left: 3px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.hp.accent { border-left-color: var(--primary); }
.hl { display: block; font-size: 11.5px; font-weight: 500; color: #aeb8c7; }
.hn, .tower b, .timing b, .sp-num, .sp-gear { font-family: var(--num); font-style: italic; font-weight: 700; font-variant-numeric: tabular-nums; }
.hn { font-size: 30px; line-height: 1.05; }
.hu { font-size: 13px; color: #aeb8c7; margin-left: 4px; }
.hrow { display: flex; align-items: baseline; }
.hbar { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.16); margin-top: 6px; overflow: hidden; }
.hbar i { display: block; height: 100%; background: #fff; border-radius: 2px; }
.hint-chip { background: var(--hud); color: #dfe5ee; font-size: 12.5px; padding: 5px 12px; border-radius: 6px; }

.tower {
  width: 236px; border-radius: 8px; overflow: hidden; background: var(--hud);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.tower-head { display: flex; align-items: baseline; gap: 6px; background: var(--primary); color: #fff; padding: 5px 12px 6px; font-size: 13px; font-weight: 600; }
.tower-head b { font-size: 22px; line-height: 1; }
.tower ol { list-style: none; margin: 0; padding: 4px 0; }
.tower li { display: grid; grid-template-columns: 24px 5px 1fr auto; gap: 8px; align-items: center; padding: 5px 12px 5px 8px; color: #fff; font-size: 13.5px; }
.tower li b { font-size: 17px; text-align: center; }
.tower li i { width: 5px; height: 18px; border-radius: 2px; }
.tower li em { font-style: normal; font-size: 12px; color: #aeb8c7; font-variant-numeric: tabular-nums; }
.tower li.me { background: rgba(255, 255, 255, 0.14); }
.tower li.me span { font-weight: 700; }

.hp.timing { min-width: 172px; }
.timing .hn { display: block; }
.timing .sub { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; margin-top: 4px; }
.timing .sub b { font-size: 16px; }

.speedo { display: block; width: 188px; height: 188px; filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.4)); }
.sp-plate { fill: rgba(12, 14, 19, 0.88); }
.sp-track { fill: none; stroke: rgba(255, 255, 255, 0.16); stroke-width: 9; stroke-linecap: round; }
.sp-track.thin { stroke-width: 4; }
.sp-value { fill: none; stroke: #fff; stroke-width: 9; stroke-linecap: round; }
.sp-rpm { fill: none; stroke: #35c8ff; stroke-width: 4; stroke-linecap: round; }
.sp-rpm.hot { stroke: #ff3b3b; }
.sp-track.nitro { stroke-width: 5; }
.sp-nitro { fill: none; stroke: #2f9bff; stroke-width: 5; stroke-linecap: round; filter: drop-shadow(0 0 4px rgba(47, 155, 255, 0.9)); }
.sp-num { font-size: 52px; fill: #fff; text-anchor: middle; }
.sp-gear { font-size: 26px; fill: #fff; text-anchor: middle; }
.sp-unit { font-size: 11px; fill: #aeb8c7; text-anchor: middle; font-family: 'Noto Sans Thai Variable', system-ui, sans-serif; }
.sp-unit.small { font-size: 9.5px; }

.minimap { display: block; width: 196px; height: 132px; border-radius: 8px; background: var(--hud); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); }

.startlights {
  position: absolute; top: 15%; left: 50%; transform: translateX(-50%); z-index: 2;
  display: flex; gap: 12px; padding: 14px 18px; border-radius: 14px;
  background: rgba(12, 14, 19, 0.94); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.startlights i { width: 46px; height: 46px; border-radius: 50%; background: #3a1010; box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.4); }
.startlights i.on { background: #ff2a2a; box-shadow: 0 0 28px rgba(255, 42, 42, 0.85), inset 0 0 0 3px rgba(255, 255, 255, 0.25); }

.toolbar {
  display: flex; align-items: center; gap: 10px;
  background: var(--hud); border-radius: 10px; padding: 6px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}

.loading { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; background: #0b0d12; color: #fff; }
.loading-box { width: min(320px, 80%); text-align: center; }
.loading-box strong { display: block; font-size: 40px; font-weight: 800; font-style: italic; margin-bottom: 14px; }
.loading-box span { display: block; margin-top: 10px; font-size: 13.5px; color: var(--ink-2); }
.loading .progress { margin-top: 0; }

.banner {
  position: absolute; top: 30%; left: 50%; transform: translateX(-50%) skewX(-10deg); z-index: 2;
  background: var(--primary); color: #fff; font-weight: 800; font-style: italic; font-size: 22px;
  padding: 10px 28px; border-radius: 4px; box-shadow: var(--shadow-2);
}
.toast {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%); z-index: 3;
  background: #f3f6fa; color: #12151c; font-weight: 700; font-size: 15px;
  padding: 10px 20px; border-radius: 6px; border-left: 5px solid var(--primary); box-shadow: var(--shadow-2);
  max-width: calc(100% - 32px); text-align: center;
}
.result { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; background: rgba(8, 10, 14, 0.6); padding: 16px; }
.result-card {
  position: relative; overflow: hidden;
  width: min(580px, 100%); background: var(--surface); border: 1px solid var(--outline);
  border-radius: 14px; padding: 30px 24px 24px; box-shadow: var(--shadow-2);
}
/* แถบธงตาหมากรุกบนหัวการ์ดผลการแข่ง */
.result-card::before {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 12px;
  background: conic-gradient(#fff 25%, #0b0d12 0 50%, #fff 0 75%, #0b0d12 0) 0 0 / 12px 12px;
}
.result-kicker { font-size: 12.5px; font-weight: 700; color: var(--primary-press); }
.result-card h2 { padding-left: 0; font-size: 34px; font-weight: 800; font-style: italic; }
.result-card h2::before { display: none; }
.result-card p { color: var(--ink-2); margin: 4px 0 14px; }
.result-card th { background: var(--surface); }
.result-card tr.me td { background: var(--primary-soft); font-weight: 700; }
.row { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

/* เส้นความเร็วรอบขอบจอ */
.speedfx {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.18s;
  background: repeating-conic-gradient(from 0deg at 50% 44%, transparent 0 1.6deg, rgba(255, 255, 255, 0.55) 1.6deg 1.85deg, transparent 1.85deg 4.3deg, rgba(255, 255, 255, 0.35) 4.3deg 4.45deg, transparent 4.45deg 7deg);
  -webkit-mask-image: radial-gradient(ellipse at 50% 44%, transparent 34%, #000 86%);
  mask-image: radial-gradient(ellipse at 50% 44%, transparent 34%, #000 86%);
  animation: streak 0.12s steps(2) infinite;
}
.speedfx.boost {
  background:
    radial-gradient(ellipse at 50% 44%, transparent 45%, rgba(47, 155, 255, 0.5) 100%),
    repeating-conic-gradient(from 0deg at 50% 44%, transparent 0 1.3deg, rgba(160, 215, 255, 0.85) 1.3deg 1.7deg, transparent 1.7deg 3.6deg);
}
@keyframes streak { 50% { transform: rotate(1.4deg) scale(1.04); } }

/* ปุ่มสัมผัสสำหรับมือถือ */
.touch { position: absolute; left: 0; right: 0; bottom: 14px; z-index: 2; display: none; justify-content: space-between; padding: 0 14px; pointer-events: none; }
.touch > div { display: flex; gap: 10px; pointer-events: auto; }
.touch button {
  width: 62px; height: 62px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(12, 14, 19, 0.72); color: #fff; font-weight: 700; font-size: 16px;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.touch button.go { background: var(--primary); border-color: #fff; }
.touch button.nitro { background: #1565d8; border-color: #9fd0ff; font-size: 14px; }
.touch button:active { transform: scale(0.94); }
@media (pointer: coarse) {
  .touch { display: flex; }
  .keys-hint { display: none !important; }
}
@media (pointer: coarse), (max-width: 760px) {
  .hud.map { display: none; }
  .hud.br.race-only { top: 104px; bottom: auto; }
  .speedo { width: 116px; height: 116px; }
  .tower { width: 186px; }
  .hp.timing { min-width: 0; }
  .timing .sub { display: none; }
  .hud.tl.train-only .hp:nth-child(3) { display: none; }
  .hn { font-size: 24px; }
  .startlights i { width: 34px; height: 34px; }
  .startlights { gap: 8px; padding: 10px 12px; top: 50%; }
  .touch button { width: 56px; height: 56px; font-size: 14px; }
  .touch > div { gap: 8px; }
}

/* หน้าต่างวาดสนาม */
.dialog {
  border: 1px solid var(--outline); border-radius: 14px; padding: 20px;
  width: min(920px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2);
}
.dialog::backdrop { background: rgba(8, 10, 14, 0.7); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.dialog-head h2 { font-size: 20px; }
.editor-canvas { display: block; width: 100%; aspect-ratio: 14 / 9; border-radius: 10px; cursor: crosshair; touch-action: none; }
.editor-msg { margin: 12px 0; font-weight: 600; }
.editor-msg.ok { color: #5ad68a; }
.editor-msg.bad { color: var(--primary-press); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14.5px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--primary); }
.check small { display: block; color: var(--ink-2); font-size: 13px; }

@media (max-width: 1000px) {
  .app { height: auto; display: block; }
  .topbar { flex-wrap: wrap; gap: 10px 14px; padding: 10px 16px; }
  .brand span { display: none; }
  .topbar-right { margin-left: 0; width: 100%; }
  .field { flex: 1; }
  .field select { flex: 1; min-width: 0; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 24px; }
  .stage { height: 62vh; min-height: 380px; }
  .panel { overflow: visible; }
  .toolbar .btn.onDark { display: none; }
}
@media (max-width: 420px) {
  .segmented.small button { padding: 0 10px; }
  .modes button { padding: 0 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .tag::before, .speedfx { animation: none; }
}
