/* RumiCar Simulator — モダン UI テーマ
   設計方針: CSS 変数によるダークテーマ + indigo/cyan アクセント。
   JS が参照する ID / .hidden / [hidden] / .filer* / button.primary は不変。
   キャンバス内描画色は --canvas-bg / --canvas-grid をテーマ連動で JS が読む (RC-VIS-001)。
   それ以外の描画色 (config.js VIEW.wall/trail/car…) は別管理なので触らない。 */

:root {
  /* サーフェス (奥→手前で明度を上げる) */
  --bg-0: #0c0e14;
  --bg-1: #11131b;
  --surface: #161925;
  --surface-2: #1c2030;
  --surface-3: #232838;
  --border: #2b3142;
  --border-strong: #3b425a;

  /* キャンバス描画 (config.js VIEW.bg/grid を JS がこの変数で上書き=テーマ連動・RC-VIS-001)。
     ダーク既定はトラック面を暗くして明色固定 #d9d9d9 を解消・コース要素(壁/軌跡/車)の
     コントラストは維持する。 */
  --canvas-bg: #232936;
  --canvas-grid: rgba(255, 255, 255, .08);

  /* テキスト */
  --text: #e6e9f2;
  --text-dim: #9aa3b8;
  --text-faint: #6b7488;

  /* アクセント */
  --accent: #6366f1;        /* indigo */
  --accent-2: #4f46e5;      /* primary ボタンのグラデ終端 */
  --accent-hi: #818cf8;
  --accent-glow: rgba(99, 102, 241, .45);
  --accent-soft: rgba(99, 102, 241, .12);  /* 選択ハイライト/バッジ背景 */
  --accent-line: rgba(99, 102, 241, .35);  /* バッジ枠 */
  --cyan: #22d3ee;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;

  /* コード表示の文字色 (ライト系テーマで差し替え) */
  --code-text: #c9f3d6;

  /* ページ/ヘッダー背景 (テーマごとに差し替え) */
  --header-bg: rgba(17, 19, 27, .72);
  --page-bg:
    radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, .10), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(34, 211, 238, .07), transparent 55%),
    #0c0e14;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, .35);
  --ring: 0 0 0 3px var(--accent-glow);
  --mono: "SFMono-Regular", "JetBrains Mono", "Consolas", ui-monospace, monospace;
  --sans: "Inter", "Yu Gothic", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: var(--page-bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ===== ヘッダー ===== */
header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--header-bg);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--border);
}
header h1 {
  font-size: 17px; font-weight: 700; margin: 0; letter-spacing: .2px;
  display: flex; align-items: center; gap: 10px;
}
header h1::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-hi), var(--cyan));
  box-shadow: 0 0 12px var(--accent-glow);
}
.ver {
  font-size: 11px; font-weight: 600; color: var(--accent-hi);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 999px; padding: 2px 9px; margin-left: 2px;
  position: relative; cursor: help;
}
/* 変更履歴ポップアップ — 版バッジ(.ver)の子。ホバーで開き、外れたら閉じる。 */
.ver-pop {
  display: none;
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
  width: 360px; max-width: 78vw;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.32);
  font-size: 12px; font-weight: 400; text-align: left;
  cursor: default;
}
.ver:hover .ver-pop, .ver-pop:hover { display: block; }
.ver-pop-head {
  padding: 7px 12px; font-weight: 700; font-size: 11.5px; color: var(--text-dim);
  border-bottom: 1px solid var(--border); letter-spacing: .04em;
}
.ver-pop-list { max-height: 320px; overflow-y: auto; padding: 4px 0; }
.ver-pop-row {
  display: flex; gap: 9px; align-items: baseline;
  padding: 6px 12px; border-bottom: 1px solid var(--border);
  line-height: 1.45;
}
.ver-pop-row:last-child { border-bottom: none; }
.ver-pop-v {
  flex: 0 0 auto; font-family: var(--mono); font-weight: 700;
  color: var(--accent-hi); font-size: 11px; white-space: nowrap;
}
.ver-pop-note { flex: 1 1 auto; color: var(--text); }
.themesel {
  font-size: 12.5px; color: var(--text-dim);
  display: inline-flex; align-items: center; gap: 7px;
}
.themesel select { padding: 5px 8px; font-size: 12.5px; }

.hud { display: flex; gap: 8px; font-size: 12.5px; flex-wrap: wrap; margin-left: auto; }
.hud span {
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 11px;
  color: var(--text-dim); white-space: nowrap;
}
.hud b { color: var(--cyan); font-weight: 600; margin-left: 2px; }

/* ===== レイアウト ===== */
main {
  display: flex; gap: 18px; padding: 20px;
  align-items: flex-start; flex-wrap: wrap;
  max-width: 1500px; margin: 0 auto;
}

/* ===== ステージ (キャンバス) ===== */
.stage {
  position: relative;
  background: linear-gradient(180deg, var(--surface), var(--bg-1));
  padding: 12px; border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-2);
}
/* ===== 起動ローダー (案C: コースを描く+周回)。FCPで即表示し初回コース描画でフェード退場 ===== */
.stage.loading { min-height: 380px; }   /* 読込中は箱サイズを安定させ「左上に小さく」を解消 (初回描画で外す) */
#courseLoader {
  position: absolute; inset: 12px; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  border-radius: var(--radius-sm);
  /* 不透明な下地 (ステージと同じグラデ) ＋ アクセントのグロー。既定の小さなグレー canvas を完全に覆う。 */
  background:
    radial-gradient(120% 120% at 50% 35%, rgba(99,102,241,.12), transparent 70%),
    linear-gradient(180deg, var(--surface), var(--bg-1));
  transition: opacity .3s ease;
}
#courseLoader.hidden { opacity: 0; pointer-events: none; }
.cl-trackwrap { position: relative; width: 200px; height: 120px; }
.cl-track { width: 100%; height: 100%; overflow: visible; }
.cl-track .cl-lane { fill: none; stroke: var(--border); stroke-width: 14; opacity: .45; }
.cl-track .cl-draw {
  fill: none; stroke: var(--accent-hi); stroke-width: 3;
  stroke-dasharray: 520; stroke-dashoffset: 520; animation: cl-draw 2.2s ease-in-out infinite;
}
@keyframes cl-draw { 0% { stroke-dashoffset: 520; } 55%, 100% { stroke-dashoffset: 0; } }
.cl-car {
  position: absolute; left: -9px; top: -5px;
  offset-path: path("M40,20 H160 A40,40 0 0 1 160,100 H40 A40,40 0 0 1 40,20 Z");
  offset-rotate: auto; animation: cl-run 2.2s linear infinite;
}
@keyframes cl-run { to { offset-distance: 100%; } }
.cl-word {
  font-weight: 800; letter-spacing: .5px; font-size: 22px;
  background: linear-gradient(135deg, var(--accent-hi), var(--cyan));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
@media (prefers-reduced-motion: reduce) {
  .cl-draw, .cl-car { animation: none; }
  .cl-draw { stroke-dashoffset: 0; }
}
#course {
  display: block; background: var(--canvas-bg, #d9d9d9); border-radius: var(--radius-sm);
  /* 縦長コースでもキャンバスがビューポートを占有して操作部 (レース/周回ボタン) を fold 外へ
     押し出さないよう表示高さを上限化 (RC-UX-003/PX-012)。canvas は内在比を保つので
     max-height だけで横も比例縮小し、内部解像度=描画 byte は不変。 */
  max-width: 100%; max-height: min(68vh, 1400px); cursor: crosshair;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25);
}
/* コース表示のズーム/パン操作バー (P2) */
.viewbar {
  display: flex; align-items: center; gap: 8px; margin-top: 6px;
  font-size: 11px; color: var(--text-faint);
}
.viewbar .spacer { flex: 1 1 auto; }
.viewbar .viewzoom {
  font-variant-numeric: tabular-nums; color: var(--text-dim);
  min-width: 38px; text-align: right;
}
.viewbar #viewReset { font-size: 11px; padding: 3px 8px; }
.viewbar .viewstep {
  font-size: 13px; line-height: 1; padding: 2px 9px; min-width: 26px;
  font-variant-numeric: tabular-nums;
}
.viewbar button:disabled { opacity: .45; cursor: default; }

/* ===== Depth View (一人称) ===== */
.depthwrap {
  margin-top: 12px; background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden;
}
.depthtitle {
  font-size: 11px; color: var(--text-dim); padding: 6px 10px; letter-spacing: .3px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); font-weight: 600;
}
.depthtitle b { color: var(--cyan); }
#depth { display: block; width: 100%; background: #0a0c12; }

/* ===== コントロール ===== */
.controls { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.controls + .controls { margin-top: 8px; }
.controls .manual {
  display: flex; gap: 5px; align-items: center; font-size: 12px; margin-left: auto;
  color: var(--text-dim);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px;
}

/* ===== ボタン ===== */
button {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  padding: 7px 13px; cursor: pointer; font-size: 13px; font-weight: 500;
  font-family: inherit;
  transition: background .15s ease, border-color .15s ease, transform .05s ease, box-shadow .15s ease;
}
button:hover { background: var(--surface-3); border-color: var(--border-strong); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: var(--ring); }
button:disabled { opacity: .4; cursor: default; transform: none; }
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff; font-weight: 600;
  box-shadow: 0 2px 10px var(--accent-glow);
}
button.primary:hover { background: linear-gradient(135deg, var(--accent-hi), var(--accent)); }
.manual button { padding: 5px 11px; background: var(--surface-3); }

/* ===== サイドパネル ===== */
.side { flex: 1; min-width: 380px; display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row label { font-size: 13px; color: var(--text-dim); }

/* ===== フォーム要素 ===== */
select, input[type=text] {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  padding: 7px 10px; font-size: 13px; font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
select:hover, input[type=text]:hover { border-color: var(--border-strong); }
select:focus, input[type=text]:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input#ghurl { flex: 1; min-width: 180px; }
input::placeholder { color: var(--text-faint); }

.filebtn {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-xs); padding: 7px 12px; font-size: 13px; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.filebtn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.filebtn input { display: none; }

/* AP24: データ保全 (バックアップ書出/読込) ボタン列 */
.lsbackup { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* チェックボックス / ラジオ (大きく・はっきり) */
.chk {
  font-size: 12.5px; display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  color: var(--text);
}
input[type=checkbox], input[type=radio] {
  accent-color: var(--accent-hi); width: 18px; height: 18px; cursor: pointer; flex: none;
}
input[type=checkbox]:focus-visible, input[type=radio]:focus-visible { outline: 2px solid var(--accent-hi); outline-offset: 2px; }

/* レンジスライダー (太いトラック + 塗りつぶしで位置が一目で分かる + 大きいツマミ) */
input[type=range] {
  -webkit-appearance: none; appearance: none; height: 8px; border-radius: 999px;
  background: var(--surface-3); cursor: pointer; border: 1px solid var(--border);
  /* 塗りつぶしは JS(paintRange) が background を上書きして表示 */
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); margin-top: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .6); transition: box-shadow .15s ease;
}
input[type=range]::-webkit-slider-thumb:hover { box-shadow: 0 0 0 5px var(--accent-glow); }
input[type=range]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  border: 3px solid var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}
input[type=range]:focus-visible { outline: none; box-shadow: var(--ring); }

.speedctl { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text); }
.speedctl input { width: 104px; }
.speedctl b { color: var(--cyan); min-width: 42px; font-family: var(--mono); font-weight: 700; text-align: right; }
.manual input[type=range] { width: 84px; }
.manual b { color: var(--cyan); font-family: var(--mono); min-width: 30px; }

#course #courseSel, select#courseSel { min-width: 170px; }

/* ===== コース説明 ===== */
.course-desc {
  font-size: 12.5px; color: var(--text-dim); line-height: 1.5;
  padding: 9px 12px; min-height: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--cyan); border-radius: var(--radius-xs);
}
.course-desc:empty { display: none; }

/* ===== 車両リスト (複数台) ===== */
.fleet {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-1);
}
.fleet-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.fleet-title { font-size: 12px; font-weight: 600; color: var(--text); margin-right: auto; }
#carAdd { padding: 5px 11px; font-size: 12px; }
.car-list { list-style: none; margin: 0; padding: 6px; display: flex; flex-direction: column; gap: 5px; }
.car-item {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 8px; border-radius: var(--radius-xs);
  border: 1px solid transparent; background: var(--surface-2); cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.car-item:hover { background: var(--surface-3); }
.car-item.active { border-color: var(--accent); background: var(--accent-soft); }
.car-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(0,0,0,.3); }
.car-name {
  width: 70px; flex: none; background: var(--bg-1); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 4px 7px; font-size: 13px; font-weight: 600;
}
.car-name:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.car-lang { font-size: 11px; color: var(--accent-hi); font-family: var(--mono); width: 52px; flex: none; }
.car-stat { font-size: 11.5px; color: var(--text-dim); font-family: var(--mono); margin-left: auto; }
.car-edit { padding: 4px 10px; font-size: 12px; }
.car-del { padding: 4px 9px; font-size: 12px; color: var(--text-dim); }
.car-del:hover:not(:disabled) { color: var(--red); border-color: var(--red); }

.car-dist { font-size: 11px; color: var(--cyan); font-family: var(--mono); margin-left: 8px; flex: none; }

/* ===== 選択車の情報ブロック ===== */
.cardetail {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-1);
  display: flex; flex-direction: column;
}
.cd-head {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 13px;
}
.cd-head b { color: var(--accent-hi); font-size: 14px; }
.cd-sub { color: var(--text-dim); }
.cd-dot { width: 13px; height: 13px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(0,0,0,.3); }
.cd-dist { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--cyan); }
.cd-sec { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.cd-sec:last-child { border-bottom: none; }
.cd-sectitle {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: .3px;
  margin-bottom: 8px;
}
.cd-tools { display: flex; gap: 6px; align-items: center; text-transform: none; }
.cd-sec .row { margin-bottom: 8px; }
.cd-sec #editor, .cd-sec .codeview { height: 280px; }
#watch, #carSerial {
  margin: 0; padding: 10px; overflow: auto; font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; line-height: 1.5; background: var(--bg-1);
  border: 1px solid var(--border); border-radius: var(--radius-xs);
}
#watch { height: 80px; color: #c7cdfa; }
#carSerial { height: 120px; color: var(--green); }

/* ===== 車両カラム (横並び・同時比較) ===== */
.fleet-load { padding: 0 12px 4px; }
.loadtarget { font-size: 12px; color: var(--text-dim); }
.loadtarget b { color: var(--accent-hi); }
.fleet-cols { display: flex; gap: 10px; overflow-x: auto; padding: 10px 12px 12px; align-items: stretch; }
.carcol {
  flex: 0 0 300px; min-width: 300px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden;
}
/* 車1台時の右側の大きな空白を、車両追加への導線タイルで埋める (RC-UX-004)。
   .carcol ではない別クラスなので colEl(i)/.carcol セレクタの索引に影響しない。 */
.carcol-add {
  flex: 1 1 auto; min-width: 160px; align-self: stretch;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  background: transparent; color: var(--text-dim); cursor: pointer;
  font-size: 13px; padding: 16px; text-align: center; white-space: normal;
}
.carcol-add:hover { border-color: var(--accent); color: var(--accent-hi); background: var(--accent-soft); }
.carcol-add .ca-plus { font-size: 28px; line-height: 1; color: var(--accent-hi); }
.carcol.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.cc-head { display: flex; align-items: center; gap: 6px; padding: 7px 8px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.cc-dot { width: 13px; height: 13px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(0,0,0,.3); }
.cc-name { width: 54px; flex: none; background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 3px 6px; font-size: 13px; font-weight: 600; }
.cc-name:focus { outline: none; border-color: var(--accent); }
.cc-lang { flex: 1; min-width: 0; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 3px 4px; font-size: 11px; }
.cc-sample, .cc-del { padding: 3px 8px; font-size: 12px; flex: none; }
.cc-share { padding: 3px 8px; font-size: 11px; flex: none; }
.cc-del:hover:not(:disabled) { color: var(--red); border-color: var(--red); }
.cc-typerow { display: flex; align-items: center; gap: 6px; padding: 6px 8px 0; }
.cc-typelabel { font-size: 11px; color: var(--text-dim); flex: none; }
.cc-cartype { flex: 1; min-width: 0; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 3px 6px; font-size: 12px; }
.cc-program { flex: 1; min-width: 0; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 3px 6px; font-size: 12px; }
.cc-program:focus { outline: none; border-color: var(--accent); }
.cc-cartype:focus { outline: none; border-color: var(--accent); }
.cc-row { display: flex; justify-content: space-between; gap: 8px; padding: 5px 8px; font-family: var(--mono); font-size: 11.5px; border-bottom: 1px solid var(--border); }
.cc-statlap { color: var(--text-dim); }
.cc-dist { color: var(--cyan); }
.cc-speedlabel { color: var(--text-dim); }
.cc-speed { color: var(--green); font-weight: 600; }
.cc-load { display: flex; gap: 4px; align-items: center; padding: 6px 8px 0; }
.cc-ghurl { flex: 1; min-width: 0; background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 4px 6px; font-size: 11px; }
.cc-ghurl:focus { outline: none; border-color: var(--accent); }
.cc-ghload, .cc-repo { padding: 4px 8px; font-size: 11px; flex: none; }
.cc-up { padding: 4px 8px; font-size: 12px; flex: none; line-height: 1; }
.cc-label { font-size: 10px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase; color: var(--text-dim); padding: 7px 8px 3px; }
.cc-editor, .cc-code { margin: 0 8px; height: 210px; background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-xs); font-family: var(--mono); font-size: 12px; line-height: 1.5; }
.cc-editor { color: var(--code-text); padding: 8px; resize: vertical; width: auto; box-sizing: border-box; }
.cc-editor:focus { outline: none; border-color: var(--accent); }
.cc-code { overflow: auto; padding: 6px 0; }
.cc-expand { padding: 1px 7px; font-size: 10.5px; font-weight: 600; margin-left: 6px; vertical-align: middle; text-transform: none; }

/* 大きなプログラムエディタ (モーダル・行番号つき) */
.dlg-editor { width: min(960px, 92vw); max-width: 92vw; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-1); color: var(--text); box-shadow: 0 18px 60px rgba(0,0,0,.5); }
.dlg-editor::backdrop { background: rgba(0,0,0,.5); }
.le-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.le-head b { font-size: 14px; }
.le-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.le-lang { font-size: 11px; color: var(--accent-hi); font-family: var(--mono); }
.le-state { font-size: 11px; color: var(--cyan); }
.le-head .le-btn:first-of-type { margin-left: auto; }
.le-btn { padding: 4px 11px; font-size: 12px; }
.le-body { display: flex; height: 72vh; background: var(--bg-1); }
.le-gutter { flex: none; width: 52px; overflow: hidden; padding: 12px 8px 12px 0; text-align: right; font-family: var(--mono); font-size: 14px; line-height: 1.6; color: var(--text-dim); background: var(--surface-2); border-right: 1px solid var(--border); white-space: pre; user-select: none; box-sizing: border-box; }
/* overscroll-behavior: contain で、テキスト末尾までスクロールしてもホイールが背景(コース)へ
   伝播しない (.docdlg と同じ方針)。これが無いと拡大エディタ上のホイールで背景がスクロールする。 */
.le-text { flex: 1; min-width: 0; margin: 0; padding: 12px; border: none; outline: none; resize: none; background: var(--bg-1); color: var(--code-text); font-family: var(--mono); font-size: 14px; line-height: 1.6; white-space: pre; overflow: auto; overscroll-behavior: contain; box-sizing: border-box; }
.le-foot { padding: 8px 14px; border-top: 1px solid var(--border); }
.le-msg { font-size: 12px; color: var(--text-dim); }
.cc-serial { margin: 0 8px 10px; height: 96px; overflow: auto; background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-xs); font-family: var(--mono); font-size: 11.5px; color: var(--green); white-space: pre-wrap; padding: 6px 8px; }

/* ===== コースエディタ ===== */
.editor {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px;
  box-shadow: var(--shadow-1);
}
.editor .etitle { font-size: 12px; color: var(--text); font-weight: 600; }
.editor .hint { font-size: 11px; color: var(--text-faint); line-height: 1.5; }
.editor input[type=text] { flex: 1; min-width: 120px; }
.editor input[type=number].dimin {
  width: 4.6em; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  padding: 7px 8px; font-size: 13px; font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.editor input[type=number].dimin:hover { border-color: var(--border-strong); }
.editor input[type=number].dimin:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

/* ===== GitHub サンプル ファイラー ===== */
.filer {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-2);
}
.filer-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--border); }
.filer-title { font-size: 12px; color: var(--text-dim); flex: 1; font-weight: 500; }
.filer-x { padding: 2px 9px; font-size: 15px; line-height: 1.2; border-radius: var(--radius-xs); }
.filer-path { font-size: 12px; color: var(--amber); padding: 7px 12px; border-bottom: 1px solid var(--border); word-break: break-all; font-family: var(--mono); }
.filer-list { list-style: none; margin: 0; padding: 6px; max-height: 260px; overflow: auto; }
.filer-list li {
  padding: 7px 10px; border-radius: var(--radius-xs); cursor: pointer; font-size: 13px;
  display: flex; align-items: center; gap: 9px; color: var(--text);
  transition: background .12s ease;
}
.filer-list li:hover { background: var(--surface-3); }
.filer-list li.dir { color: var(--amber); }
.filer-list li.up { color: var(--accent-hi); }
.filer-list li.nofile { color: var(--text-faint); cursor: default; }
.filer-list li.nofile:hover { background: transparent; }
.filer-list li .ic { width: 16px; text-align: center; }
.filer-loading { padding: 12px; font-size: 12px; color: var(--text-dim); }

/* ===== コードエディタ ===== */
#editor {
  width: 100%; height: 320px; resize: vertical;
  background: var(--bg-1); color: var(--code-text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: var(--mono); font-size: 13px; padding: 14px; line-height: 1.55;
  transition: border-color .15s ease, box-shadow .15s ease;
  box-shadow: var(--shadow-1);
}
#editor:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

/* 実行中の読み取り専用コード表示 (実行行ハイライト) */
.codeview {
  width: 100%; height: 320px; overflow: auto; margin: 0;
  background: var(--bg-1); border: 1px solid var(--accent); border-radius: var(--radius);
  font-family: var(--mono); font-size: 13px; line-height: 1.55; padding: 8px 0;
  box-shadow: var(--shadow-1);
}
.cv-line { display: flex; padding: 0 6px; white-space: pre; }
.cv-num { width: 34px; flex: none; text-align: right; padding-right: 10px; color: var(--text-faint); user-select: none; }
.cv-code { color: var(--code-text); }
.cv-line.cv-active { background: rgba(251, 191, 36, .18); border-left: 3px solid var(--amber); padding-left: 3px; }
.cv-line.cv-active .cv-code { color: #ffe9a8; }
.cv-line.cv-active .cv-num { color: var(--amber); }

/* ===== ログ / ウォッチ ===== */
.logwrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.logtitle {
  font-size: 11px; color: var(--text-dim); padding: 7px 12px;
  border-bottom: 1px solid var(--border); font-weight: 600; letter-spacing: .3px; text-transform: uppercase;
  background: var(--surface-2);
}
#log, #watch { margin: 0; padding: 11px 12px; overflow: auto; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; line-height: 1.5; }
#log { height: 124px; color: var(--green); }
#watch { height: 86px; color: #c7cdfa; }

/* ===== スクロールバー ===== */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: padding-box; }

/* ===== ユーティリティ ===== */
.hidden { display: none !important; }
[hidden] { display: none !important; }
/* スクリーンリーダー専用 (視覚的に非表示・読み上げには残す)。AF3 走行状態 live region 用。 */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (max-width: 820px) {
  main { padding: 14px; gap: 14px; }
  .side { min-width: 100%; }
  .hud { width: 100%; margin-left: 0; }
}

/* ============================================================
   テーマ切替 (ヘッダーの「テーマ」セレクタ / localStorage 永続化)
   既定 = :root のダーク・インディゴ。各テーマは CSS 変数の差し替えで表現。
   ============================================================ */

/* ---- A. ライト・クリーン (白 × ブルー) ---- */
html[data-theme="light"] { color-scheme: light; }
html[data-theme="light"] {
  --bg-0: #f3f5f9; --bg-1: #eef1f6;
  --surface: #ffffff; --surface-2: #f6f8fb; --surface-3: #e9edf4;
  --border: #dfe4ec; --border-strong: #c7cfdc;
  --text: #1c2333; --text-dim: #5a657c; --text-faint: #8a94a8;
  --accent: #2563eb; --accent-2: #1d4ed8; --accent-hi: #3b82f6;
  --accent-glow: rgba(37, 99, 235, .25);
  --accent-soft: rgba(37, 99, 235, .10); --accent-line: rgba(37, 99, 235, .35);
  --cyan: #0e7490; --green: #047857; --amber: #b45309; --red: #dc2626;
  --code-text: #1e3a2f;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .06); --shadow-2: 0 8px 24px rgba(16, 24, 40, .10);
  --header-bg: rgba(255, 255, 255, .80);
  --page-bg: #f3f5f9;
  --canvas-bg: #dde3ec; --canvas-grid: rgba(0, 0, 0, .10);
}

/* ---- B. グラスモーフィズム (グラデ × 半透明) ---- */
html[data-theme="glass"] {
  --bg-0: #1e1b4b; --bg-1: rgba(255, 255, 255, .05);
  --surface: rgba(255, 255, 255, .08); --surface-2: rgba(255, 255, 255, .12); --surface-3: rgba(255, 255, 255, .17);
  --border: rgba(255, 255, 255, .18); --border-strong: rgba(255, 255, 255, .32);
  --text: #f4f6ff; --text-dim: #c3c9e8; --text-faint: #9aa2c8;
  --accent: #a78bfa; --accent-2: #8b5cf6; --accent-hi: #c4b5fd;
  --accent-glow: rgba(167, 139, 250, .45);
  --accent-soft: rgba(167, 139, 250, .16); --accent-line: rgba(167, 139, 250, .40);
  --cyan: #67e8f9; --green: #6ee7b7; --amber: #fcd34d; --red: #fda4af;
  --code-text: #d8fbe8;
  --shadow-2: 0 12px 40px rgba(0, 0, 0, .45);
  --header-bg: rgba(30, 27, 75, .55);
  --page-bg: linear-gradient(135deg, #1e1b4b 0%, #4c1d95 40%, #0e7490 100%);
  --canvas-bg: #241f47; --canvas-grid: rgba(255, 255, 255, .12);
}
html[data-theme="glass"] .stage,
html[data-theme="glass"] .side > *,
html[data-theme="glass"] .carcol {
  backdrop-filter: blur(14px) saturate(130%);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
}

/* ---- C. レーシング・ネオン (漆黒 × ネオングリーン) ---- */
html[data-theme="neon"] {
  --bg-0: #04060a; --bg-1: #070a10;
  --surface: #0a0f17; --surface-2: #0e1521; --surface-3: #131c2b;
  --border: #1b2839; --border-strong: #27374e;
  --text: #e8f2f5; --text-dim: #8fa6b5; --text-faint: #5f7382;
  --accent: #10e07c; --accent-2: #059669; --accent-hi: #5cf2a8;
  --accent-glow: rgba(16, 224, 124, .40);
  --accent-soft: rgba(16, 224, 124, .10); --accent-line: rgba(16, 224, 124, .35);
  --cyan: #00e5ff; --green: #10e07c; --amber: #ffd166; --red: #ff5d73;
  --code-text: #b9f5d2;
  --shadow-2: 0 8px 28px rgba(0, 0, 0, .6);
  --header-bg: rgba(7, 10, 16, .74);
  --page-bg:
    radial-gradient(1100px 500px at 85% -10%, rgba(16, 224, 124, .10), transparent 60%),
    radial-gradient(800px 460px at -10% 15%, rgba(0, 229, 255, .08), transparent 55%),
    #04060a;
  --canvas-bg: #0a0f17; --canvas-grid: rgba(92, 242, 168, .12);
}
html[data-theme="neon"] button.primary { color: #03150c; }

/* ---- D. ウォーム・ペーパー (生成り × オレンジ) ---- */
html[data-theme="paper"] { color-scheme: light; }
html[data-theme="paper"] {
  --bg-0: #faf6ef; --bg-1: #f5efe4;
  --surface: #fffdf8; --surface-2: #f6f0e4; --surface-3: #ede4d3;
  --border: #e3d8c4; --border-strong: #cdbfa4;
  --text: #2e2a22; --text-dim: #6e6557; --text-faint: #9a8f7d;
  --accent: #ea580c; --accent-2: #c2410c; --accent-hi: #f97316;
  --accent-glow: rgba(234, 88, 12, .25);
  --accent-soft: rgba(234, 88, 12, .10); --accent-line: rgba(234, 88, 12, .35);
  --cyan: #0e7490; --green: #15803d; --amber: #b45309; --red: #dc2626;
  --code-text: #3d3425;
  --shadow-1: 0 1px 2px rgba(60, 45, 20, .08); --shadow-2: 0 8px 24px rgba(60, 45, 20, .12);
  --header-bg: rgba(255, 253, 248, .82);
  --page-bg: #faf6ef;
  --canvas-bg: #efe7d6; --canvas-grid: rgba(60, 45, 20, .10);
}

/* ===== 利用者向けドキュメント (使い方 / 仕様・制限) ===== */
.docbtns { display: flex; gap: 8px; align-items: center; }
.docbtns button { padding: 5px 12px; font-size: 12.5px; white-space: nowrap; }
/* ヘッダーの GitHub リンク (ボタンと同じ見た目の <a>) */
.ghbtn { padding: 5px 12px; font-size: 12.5px; white-space: nowrap; text-decoration: none;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-xs);
  display: inline-flex; align-items: center; line-height: 1.6; }
.ghbtn:hover { border-color: var(--accent-line); color: var(--accent-hi); }

.docdlg {
  width: min(760px, calc(100vw - 40px));
  max-height: min(78vh, 900px);
  padding: 0; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-2);
  /* スクロールコンテナはダイアログ本体(.docdlg)。overscroll-behavior: contain で
     末尾までスクロールしても背景(コース)へ伝播しない。子(.docdlg-body)には overflow を
     付けない: 非スクロールの子に overflow:auto があると、その上での wheel を子が飲み込み
     (contain で本体へも伝播せず)ホイールスクロールが効かなくなるため。 */
  overflow-y: auto; overscroll-behavior: contain;
}
.docdlg::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(2px); }
.docdlg-head {
  position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.docdlg-head h2 { margin: 0; font-size: 16px; }
.docdlg-x { padding: 2px 10px; font-size: 16px; line-height: 1.3; }
/* 本体(.docdlg)がスクロールするので body 自体は overflow を持たない(上のコメント参照) */
.docdlg-body { padding: 6px 20px 18px; font-size: 13px; line-height: 1.65; }
.docdlg-body h3 {
  font-size: 13px; margin: 16px 0 6px; color: var(--accent-hi);
  border-left: 3px solid var(--accent); padding-left: 8px;
}
.docdlg-body ul { margin: 0; padding-left: 20px; color: var(--text-dim); }
.docdlg-body li { margin: 3px 0; }
.docdlg-body b { color: var(--text); }
.docdlg-body code {
  font-family: var(--mono); font-size: 12px; color: var(--cyan);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 5px;
}
.docdlg-body ul.api { list-style: none; padding-left: 4px; }

/* ===== 物理モデル解説 (数式ブロック・注記・現実との違い・クレジット) ===== */
.pm-lead { color: var(--text-dim); margin: 4px 0 2px; }
.pm-eq {
  font-family: var(--mono); font-size: 12.5px; color: var(--cyan);
  background: var(--bg-1); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-xs); padding: 7px 10px; margin: 5px 0; line-height: 1.9; overflow-x: auto;
}
.pm-note { color: var(--text-faint); font-size: 11.5px; font-family: var(--sans); }
.docdlg-body li.pm-real { color: var(--text-dim); }
.docdlg-body li.pm-real b { color: var(--accent-hi); }
.pm-credit {
  margin: 18px 0 2px; padding: 9px 12px; font-size: 11.5px; color: var(--text-faint);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-xs);
}
.pm-credit b { color: var(--text-dim); }
/* 操作子の横の ⓘ (物理モデル解説へのディープリンク) */
.infohint {
  margin-left: 2px; padding: 0 5px; font-size: 12px; line-height: 1.4; cursor: pointer;
  color: var(--accent-hi); background: transparent; border: 1px solid var(--accent-line); border-radius: 50%;
}
.infohint:hover { color: var(--accent-hi); border-color: var(--accent); background: var(--surface-2); }

/* ===== 車種パラメータ表 / 独自車種 / Q&A フォーム ===== */
.ptable { width: 100%; border-collapse: collapse; font-size: 12px; margin: 6px 0 4px; }
.ptable th, .ptable td { border: 1px solid var(--border); padding: 4px 7px; text-align: center; color: var(--text-dim); }
.ptable th { background: var(--surface-2); color: var(--text); font-weight: 600; }
.ptable td.pname { text-align: left; color: var(--text); white-space: nowrap; }
.pcustom { font-size: 10px; color: var(--accent-hi); border: 1px solid var(--accent-line); border-radius: 6px; padding: 0 4px; }
/* V3: 組込車種のローカル上書き (carOverrides) 表示 */
.povr { font-size: 10px; color: var(--warn, var(--accent-hi)); border: 1px solid var(--warn, var(--accent-line)); border-radius: 6px; padding: 0 4px; }
#carParamTable { overflow-x: auto; }
.ptable td.carlist-ops { white-space: nowrap; text-align: right; }
.carovr-bar { margin: 4px 0 2px; font-size: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.carovr-count { color: var(--text-dim); }
.carovr-editing { color: var(--accent-hi); font-weight: 600; }
.car-ovr-clearall { font-size: 11px; padding: 2px 8px; cursor: pointer; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); }
.car-ovr-clearall:hover { background: var(--surface-3); }
.carjson-ex { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 8px 10px; font-family: var(--mono); font-size: 11.5px; color: var(--code-text); overflow: auto; margin: 4px 0; }
.carjson-in { width: 100%; height: 120px; background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); font-family: var(--mono); font-size: 12px; padding: 8px; resize: vertical; box-sizing: border-box; }
.carjson-msg { font-size: 12px; }
.carlist td.ckey { font-family: var(--mono); font-size: 11px; }
.carlist td.carlist-ops { white-space: nowrap; }
.carlist-ops button { font-size: 11px; padding: 2px 8px; margin: 0 2px; cursor: pointer; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); }
.carlist-ops button:hover { background: var(--surface-3); }
.carlist-empty { font-size: 12px; color: var(--text-faint); }
/* V2: 車種フォーム入力エディタ (スライダー + 数値、JSON と双方向同期) */
#carForm { margin: 4px 0; }
.cf-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.cf-lbl { flex: 0 0 92px; font-size: 12px; color: var(--text); font-family: var(--mono); white-space: nowrap; }
.cf-lbl-wide { flex: 1 1 auto; cursor: pointer; }
.cf-range { flex: 1 1 auto; min-width: 70px; accent-color: var(--accent-hi); }
.cf-num { flex: 0 0 76px; background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); font-family: var(--mono); font-size: 12px; padding: 3px 5px; box-sizing: border-box; }
.cf-text { flex: 1 1 auto; background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); font-family: var(--mono); font-size: 12px; padding: 4px 6px; box-sizing: border-box; }
.cf-sel { flex: 0 0 110px; background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); font-size: 12px; padding: 3px; }
.cf-drifttoggle { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.ask-label { display: block; font-size: 12px; color: var(--text-dim); margin: 10px 0 3px; }
.ask-title { width: 100%; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 7px 10px; font-size: 13px; box-sizing: border-box; }
.ask-body { width: 100%; height: 130px; background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); font-family: var(--sans); font-size: 13px; padding: 8px; resize: vertical; box-sizing: border-box; line-height: 1.5; }

/* ===== コースバー(一人称ビューの上) / 高低差バッジ / 立体プレビュー ===== */
.coursebar { margin: 8px 0 4px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.coursebar .row { align-items: center; gap: 8px; flex-wrap: wrap; }
.elev-badge { font-size: 12px; color: #caa; background: rgba(224,168,120,0.14); border: 1px solid rgba(224,168,120,0.4); border-radius: 10px; padding: 2px 9px; }
.course-badge { font-size: 12px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 2px 9px; }
.course-badge .stars { color: #e0a878; letter-spacing: 1px; }
.course-badge.beginner { border-color: rgba(110,190,120,0.6); }
.course-badge.fs { border-color: rgba(120,150,220,0.6); }
.elev3d { display: block; width: 100%; margin-top: 8px; border-top: 1px dashed var(--border); border-radius: var(--radius-xs); background: linear-gradient(180deg, rgba(120,150,200,0.10), rgba(60,80,60,0.10)); }

/* ===== 操作部の状態表示 / 一人称ビューの測距表示 ===== */
.ctl-status { font-size: 12.5px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 4px; margin: 0 4px; }
.ctl-status b { color: var(--cyan); font-weight: 600; }
.ctl-spd { margin-left: 8px; color: var(--text-dim); }
/* 自動走行=無限の練習走行であることを明示する常設バッジ (PX-001/AB8)。走行中のみ表示。 */
.practice-flag {
  font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap;
  color: #1a1205; background: var(--amber, #fbbf24);
  padding: 4px 9px; border-radius: 999px; cursor: help;
}
.practice-flag[hidden] { display: none; }
.depth-sensors { font-size: 11.5px; color: var(--text-dim); margin-left: 10px; font-weight: 400; }
.depth-sensors b { color: var(--cyan); font-weight: 600; }
.depth-sensors #pos { margin-left: 6px; opacity: 0.85; }
/* 測距上限/単位の明示 (Stage Y/Y2・Issue #20)。控えめなチップ表示。 */
.depth-sensors b.depth-range { color: var(--text-dim); font-weight: 400; opacity: 0.7; margin-left: 6px; }

/* ===== 本番レース (Stage W / W3): レースバー + 結果ダイアログ ===== */
.racebar { gap: 10px; }
.racebar .racelaps { font-size: 12.5px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 5px; }
.racebar #raceLaps { width: 56px; background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 3px 5px; font-size: 13px; }
.race-hint { font-size: 11px; color: var(--text-faint); flex: 1 1 240px; min-width: 200px; line-height: 1.45; }
.race-meta { margin-bottom: 10px; }
.race-metatab { border-collapse: collapse; font-size: 12.5px; }
.race-metatab th { text-align: left; color: var(--text-dim); font-weight: 500; padding: 2px 14px 2px 0; vertical-align: top; white-space: nowrap; }
.race-metatab td { color: var(--text); padding: 2px 0; }
.race-metatab code { font-family: var(--mono); font-size: 12px; color: var(--code-text); }
.race-localnote { font-size: 11.5px; color: var(--text-faint); margin: 6px 0 0; line-height: 1.5; }
.race-map { display: block; margin: 4px 0 2px; max-width: 100%; background: var(--bg-0); border: 1px solid var(--border); border-radius: var(--radius-xs); }
.race-mapnote { font-size: 11px; color: var(--text-faint); margin: 0 0 10px; }
.race-results h3 { font-size: 13px; color: var(--accent-hi); margin: 14px 0 5px; }
.race-tab { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.race-tab th { text-align: left; color: var(--text-dim); font-weight: 500; border-bottom: 1px solid var(--border-strong); padding: 4px 8px; }
.race-tab td { color: var(--text); border-bottom: 1px solid var(--border); padding: 4px 8px; }
.race-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.race-empty { font-size: 12.5px; color: var(--text-faint); margin: 2px 0; }
/* AB1: 0完走の能動サマリ (原因の手がかり)。テーマ変数のみで配色 */
.race-summary { font-size: 12.5px; color: var(--text); background: var(--surface-2, rgba(127,127,127,0.12)); border-left: 3px solid var(--accent, #4aa3ff); border-radius: 4px; padding: 7px 10px; margin: 6px 0 2px; line-height: 1.5; }

/* ===== AB9: 発走カウントダウン演出 (UI のみ・レース計算非参加) ===== */
.countdown-overlay {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 120% at 50% 50%, rgba(0,0,0,.34), rgba(0,0,0,.14));
  border-radius: var(--radius-sm); cursor: pointer;
}
.countdown-overlay .cd-num {
  font-weight: 900; font-size: clamp(64px, 18vh, 168px); line-height: 1;
  color: var(--accent-hi); text-shadow: 0 0 26px var(--accent-glow);
  animation: cd-pop .55s ease-out;
}
.countdown-overlay .cd-num.cd-go { color: var(--green); text-shadow: 0 0 30px rgba(52,211,153,.6); }
@keyframes cd-pop { 0% { transform: scale(.4); opacity: 0; } 40% { opacity: 1; } 100% { transform: scale(1.16); opacity: .9; } }

/* ===== AB9: 勝者セレモニー / コースレコード祝祭 (結果ダイアログ) ===== */
.race-winner-banner {
  margin: 4px 0 12px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  border: 1px solid var(--accent-line);
  font-weight: 700; font-size: 14px; color: var(--accent-hi);
  animation: rw-rise .5s ease-out;
}
.race-winner-banner .rw-name { color: var(--text); }
.race-winner-banner .rw-record { display: block; margin-top: 5px; color: var(--green); font-size: 13px; font-weight: 700; animation: rw-flash 1.1s ease-in-out 2; }
.race-winner-banner .rw-fast { display: block; margin-top: 5px; color: var(--cyan); font-size: 13px; font-weight: 600; }
.race-winner-banner .rw-record .rw-record-note { color: var(--text-faint); font-size: 11px; font-weight: 400; margin-left: 4px; }
@keyframes rw-rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rw-flash { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
tr.race-row-win > td { background: var(--accent-soft); font-weight: 700; }
tr.race-row-fast .race-dot { box-shadow: 0 0 0 2px var(--cyan); }

@media (prefers-reduced-motion: reduce) {
  .countdown-overlay .cd-num, .race-winner-banner, .race-winner-banner .rw-record { animation: none; }
}

/* ===== ローカル開催 (Stage W / W4): 開催ダイアログ ===== */
.event-intro { font-size: 12.5px; color: var(--text-dim); margin: 0 0 10px; line-height: 1.6; }
.event-config { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.event-config label { font-size: 12.5px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 5px; }
.event-config select, .event-config input[type=number] { background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 3px 6px; font-size: 13px; }
.event-config input#evBudget, .event-config input#evLaps { width: 64px; }
.event-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.event-msg { font-size: 12px; color: var(--amber); min-height: 16px; margin-bottom: 6px; }
.event-entries h3 { font-size: 13px; color: var(--accent-hi); margin: 10px 0 5px; }
.event-field { font-size: 12.5px; color: var(--text); margin: 8px 0 0; }
.ev-del { padding: 0 7px; font-size: 12px; line-height: 1.6; }

/* ===== 公式レース (Stage W / W5): GitHub 開催ダイアログ ===== */
.official-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.official-bar label { font-size: 12.5px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 5px; }
.official-bar select { background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 3px 6px; font-size: 13px; min-width: 200px; }
.official-detail h3 { font-size: 13px; color: var(--accent-hi); margin: 12px 0 5px; }
.official-status { font-size: 12.5px; margin: 0 0 8px; }
.official-verify-note { font-size: 12px; line-height: 1.55; margin: 8px 0 0; padding: 7px 9px; border-radius: var(--radius-xs); background: var(--bg-1); border: 1px solid var(--border); }
.official-verify-note.ok { border-color: var(--green, #3a7); color: var(--text); }
.official-verify-note.warn { border-color: var(--amber); color: var(--text); }
.official-result-meta { font-size: 12px; color: var(--text-dim); margin: 4px 0 8px; line-height: 1.5; }
.official-result-meta code { font-family: var(--mono); font-size: 11.5px; color: var(--code-text); }
/* AK6: 旧 engine 版で樹立された記録の「現行で完全再現しない可能性」を amber で正直明示 (条件付き保持・尊重) */
.official-result-meta.warn { border: 1px solid var(--amber); border-radius: var(--radius-xs); background: var(--bg-1); padding: 7px 9px; color: var(--text); }
/* AK6: 収録フレーム再生 (本物) と 最新エンジン再走 (別物になり得る・warn) の区別を観戦リプレイ上に表示 */
.ghost-replaynote { font-size: 12px; line-height: 1.5; margin: 6px 0 0; color: var(--text-dim); }
.ghost-replaynote.warn { color: var(--text); border-left: 3px solid var(--amber); padding-left: 8px; }
.rank-archivednote { margin-top: 2px; }
.official-entry { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.official-entry h3 { font-size: 13px; color: var(--accent-hi); margin: 0 0 4px; }
.official-entryform { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.official-entryform label { font-size: 12.5px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 5px; }
.official-entryform input { background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 3px 6px; font-size: 13px; width: 150px; }
.official-introlbl { align-items: flex-start !important; }
.official-entryform textarea { background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 4px 6px; font-size: 12.5px; width: 260px; font-family: inherit; resize: vertical; }

/* ---- W6: 公式記録のプログラム閲覧＋fork / ロジック・ショーケース ---- */
.official-progs { margin: 8px 0 4px; display: flex; flex-direction: column; gap: 8px; }
.official-prog { border: 1px solid var(--border); border-radius: var(--radius-xs); background: var(--bg-1); padding: 7px 9px; }
.official-prog-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.official-prog-head .hint { flex: 1 1 auto; }
.official-prog-src { margin: 7px 0 0; max-height: 220px; overflow: auto; background: var(--bg-0); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 7px 9px; font-family: var(--mono); font-size: 11.5px; color: var(--code-text); white-space: pre; }
.official-intro { font-size: 12.5px; color: var(--text-dim); margin: 5px 0 0; line-height: 1.6; }
.official-showcase { margin: 12px 0 4px; padding: 10px 12px; border: 1px solid var(--accent-line); border-radius: var(--radius-sm, 8px); background: var(--accent-soft); }
.official-badge { display: inline-block; font-size: 12px; font-weight: 700; color: var(--accent-hi); background: var(--bg-1); border: 1px solid var(--accent-line); border-radius: 999px; padding: 2px 10px; }
.official-winner { font-size: 14px; margin: 8px 0 4px; }
.official-honor { font-size: 12.5px; color: var(--text-dim); margin: 4px 0 0; line-height: 1.6; }

/* ---- W6: 👻 ゴースト再生 ---- */
.race-ghostbar { margin: 6px 0 2px; }
.ghost-bar { display: flex; gap: 10px; align-items: center; margin: 8px 0 4px; }
.ghost-clock { font-family: var(--mono); font-size: 13px; color: var(--accent-hi); margin-left: auto; }
.ghost-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-dim); margin-top: 4px; }
.ghost-leg { display: inline-flex; align-items: center; gap: 4px; }
/* AB11 (PX-004): 観戦リプレイの順位/車間(gap) 表＋オーバーテイク告知 */
.ghost-flash { min-height: 17px; font-size: 12.5px; font-weight: 600; color: var(--accent-hi); margin: 2px 0; opacity: 0; transition: opacity .25s; }
.ghost-flash:not(:empty) { opacity: 1; }
.ghost-standings { border-collapse: collapse; font-size: 12.5px; margin: 2px 0 4px; }
.ghost-standings caption { text-align: left; color: var(--text-dim); font-weight: 500; padding-bottom: 2px; caption-side: top; }
.ghost-standings td { padding: 1px 10px 1px 0; color: var(--text); white-space: nowrap; vertical-align: middle; }
.ghost-st-pos { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.ghost-st-lap { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.ghost-st-gap { font-family: var(--mono); color: var(--accent-hi); font-variant-numeric: tabular-nums; text-align: right; }
.ghost-st-up { color: var(--accent-hi); font-weight: 700; }
.ghost-st-row.passing td { background: var(--accent-soft); }
.ghost-st-row.passing td:first-child { border-top-left-radius: var(--radius-xs); border-bottom-left-radius: var(--radius-xs); }
.ghost-st-row.passing td:last-child { border-top-right-radius: var(--radius-xs); border-bottom-right-radius: var(--radius-xs); }

/* ---- W6: 🏅 ランキング (クラス別ラダー＋ドライバープロフィール／称号) ---- */
.rank-body h3 { font-size: 13px; color: var(--accent-hi); margin: 14px 0 6px; }
.rank-verifiednote { margin: 0 0 6px; }
.rank-beaten { margin: 2px 0 6px; padding-left: 18px; font-size: 12.5px; color: var(--text-dim); line-height: 1.7; }
.rank-board { margin: 6px 0 12px; }
.rank-board-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; margin-bottom: 4px; color: var(--text); }
.rank-board-head b { color: var(--accent-hi); }
.rank-vsworld { font-size: 12px; padding: 2px 8px; }
.rank-record { background: var(--accent-soft); }
.rank-me { color: var(--accent-hi); font-weight: 600; font-size: 11.5px; }
.rank-crown { font-size: 12px; }
.rank-badge { display: inline-block; font-size: 11.5px; color: var(--text); background: var(--bg-1); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; margin: 1px 2px 1px 0; white-space: nowrap; }
