:root { --bg: #1d1a1f; --panel: rgba(28, 24, 30, .88); --line: #5a4d44; --fg: #f1e6d6; --dim: #a89a88; --acc: #f0a23c; --ok: #7bc47f; --warn: #e8c13c; --bad: #e0553f; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; height: 100dvh; overflow: hidden; position: fixed; inset: 0; width: 100%; background: var(--bg); color: var(--fg); font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif; font-size: 15px; user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh; display: block; }
#hud, #ui { position: fixed; inset: 0; height: 100%; height: 100dvh; overflow: hidden; pointer-events: none; }
.fs-tip { font-size: 12px; line-height: 1.6; max-width: 300px; text-align: center; padding: 8px 12px; }
.fs-tip .row { justify-content: center; margin-top: 4px; }
#ui > *, #ui .panel, #ui .btn { pointer-events: auto; }
/* 重なり順: #touch(2) < #hud(3: ミニマップ等) < ミラー・保存表示(5) < #ui(6: スマホ/店/地図/リザルト) < ゲーム内メニュー(50) < セーブ管理(70)。
   fixed 要素は子の z-index を内側に閉じ込めるため、#ui 自体に順位を与えないと HUD の後ろに回る */
#ui { z-index: 6; }
.center-screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; }
.panel { background: var(--panel); border: 2px solid var(--line); border-radius: 8px; padding: 14px 18px; box-shadow: 0 4px 18px rgba(0, 0, 0, .5); }
.panel h1, .panel h2, .panel h3 { margin: 0 0 8px; }
.panel h2 { font-size: 20px; color: var(--acc); }
.panel h3 { font-size: 16px; color: var(--acc); }
.title-logo { font-size: 44px; font-weight: 900; color: var(--acc); text-shadow: 3px 3px 0 #000; letter-spacing: 2px; text-align: center; }
.title-sub { color: var(--dim); text-align: center; margin-bottom: 8px; }
.btn { display: block; width: 100%; min-width: 180px; margin: 6px 0; padding: 10px 16px; font: inherit; font-weight: 700; color: var(--fg); background: #3a312c; border: 2px solid var(--line); border-radius: 6px; cursor: pointer; text-align: center; }
.btn:hover:not(:disabled) { background: #54443a; border-color: var(--acc); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: #a8601c; border-color: var(--acc); }
.btn.small { display: inline-block; width: auto; min-width: 0; padding: 4px 10px; margin: 2px; font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 6px; }
.grow { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.muted { color: var(--dim); font-size: 13px; }
.money { color: var(--acc); font-weight: 700; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 10px; background: #3a312c; border: 1px solid var(--line); font-size: 12px; margin-right: 4px; }
.list { list-style: none; margin: 6px 0; padding: 0; max-height: 50vh; overflow: auto; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 7px 10px; border-bottom: 1px solid #3a312c; cursor: pointer; }
.list li:hover, .list li.sel { background: #4a3b30; }
.list li.disabled { opacity: .45; cursor: default; }
.bar { position: relative; height: 10px; background: #2a2428; border: 1px solid #000; border-radius: 5px; overflow: hidden; min-width: 90px; }
.bar .fill { height: 100%; background: var(--ok); transition: width .2s; }
.bar.warn .fill { background: var(--warn); }
.bar.bad .fill { background: var(--bad); }
.bar.big { height: 16px; }
.hud-box { position: absolute; padding: 6px 12px; background: rgba(0, 0, 0, .45); border-radius: 6px; font-weight: 700; }
.hud-tl { top: 12px; left: 12px; } .hud-tr { top: 12px; right: 12px; } .hud-bl { bottom: 12px; left: 12px; } .hud-br { bottom: 12px; right: 12px; } .hud-tc { top: 12px; left: 50%; transform: translateX(-50%); } .hud-bc { bottom: 12px; left: 50%; transform: translateX(-50%); }
#tw-dmg { position: absolute; zoom: .7; }
.hud-speed { font-size: 30px; font-variant-numeric: tabular-nums; }
.hud-speed small { font-size: 14px; color: var(--dim); }
.hud-msg { position: absolute; top: 28%; width: 100%; text-align: center; font-size: 54px; font-weight: 900; text-shadow: 3px 3px 0 #000; }
.toasts { position: absolute; left: 50%; bottom: 140px; transform: translateX(-50%); display: flex; flex-direction: column-reverse; align-items: center; gap: 4px; pointer-events: none; max-width: 94vw; }
.toast { background: rgba(0, 0, 0, .75); padding: 8px 16px; border-radius: 6px; text-align: center; }
.overlay { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; pointer-events: auto; }
.bad { color: var(--bad); } .good { color: var(--ok); }

/* スマホ */
.phone-ov { z-index: 6; justify-content: flex-end; padding-right: max(4vw, var(--mr)); }
.phone { width: min(340px, 100%); height: min(100%, 640px); overflow: hidden; background: #14161a; border: 3px solid #555; border-radius: 28px; padding: 10px 12px; display: flex; flex-direction: column; box-shadow: 0 8px 30px rgba(0,0,0,.7); }
.ph-notch { width: 70px; height: 6px; background: #333; border-radius: 3px; margin: 0 auto 6px; }
.ph-top { display: flex; align-items: center; gap: 8px; padding: 2px 4px 6px; border-bottom: 1px solid #333; }
.ph-top b { flex: 1; }
.ph-back { background: none; border: 0; color: var(--acc); font-size: 20px; cursor: pointer; width: 20px; }
.ph-body { flex: 1; overflow: auto; padding: 8px 2px; }
.ph-foot { text-align: center; padding-top: 4px; min-height: 22px; }
.ph-home { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 10px; }
.ph-app { background: none; border: 0; color: var(--fg); font: inherit; font-size: 12px; cursor: pointer; text-align: center; position: relative; }
.ph-ic { display: flex; width: 52px; height: 52px; border-radius: 13px; margin: 0 auto 3px; align-items: center; justify-content: center; font-size: 22px; font-weight: 900; color: #fff; }
.ph-app i { position: absolute; top: -2px; right: 6px; background: #e0302a; color: #fff; border-radius: 9px; font-size: 10px; padding: 0 5px; font-style: normal; }
.ph-card { background: #23262c; border-radius: 10px; padding: 8px 10px; margin: 6px 0; font-size: 13px; }
.ph-card.center { text-align: center; padding: 22px 10px; }
.ph-bubble { background: #2f3b4a; border-radius: 12px 12px 12px 2px; padding: 6px 10px; margin: 4px 0; font-size: 13px; }
.ph-tabs { display: flex; gap: 4px; }
.ph-list li { padding: 6px 8px; font-size: 13px; }
.phone .btn { min-width: 0; }
.phone .btn.small { font-size: 12px; padding: 3px 8px; }
.phone .bar { min-width: 60px; }
/* ガレージ/店 */
.ctbl { background: #2b2420; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin: 4px 0; font-size: 13px; }
.swatch { display: inline-block; width: 20px; height: 20px; border: 2px solid #000; border-radius: 4px; margin: 2px; cursor: pointer; vertical-align: middle; }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 1px var(--acc); }
.npc { background: #2b2420; border-left: 3px solid var(--acc); padding: 4px 10px; margin: 4px 0; }
.tag.good { color: var(--ok); } .tag.bad { color: #f09a8c; }

/* ダメージHUD: 2D車両図 + 破損ゲージ */
.panel.dmg { pointer-events: auto; padding: 8px 10px; font-size: 12px; width: max-content; max-width: 100%; }
.dmg-main { display: flex; gap: 10px; align-items: stretch; }
.dmg-cv { display: block; flex: none; }
.dmg-side { width: 132px; display: flex; flex-direction: column; }
.dmg-lab { font-size: 11px; color: var(--dim); }
.dmg-pct { font-size: 34px; font-weight: 900; line-height: 1.05; font-variant-numeric: tabular-nums; }
.dmg-pct.warn { color: var(--warn); } .dmg-pct.bad { color: var(--bad); }
.dmg-gauge { position: relative; margin: 6px 0 18px; }
.dmg-lab { white-space: nowrap; }
.dmg-track { position: relative; height: 14px; background: #2a2428; border: 1px solid #000; border-radius: 3px; }
.dmg-ext { height: 4px; margin-top: 3px; background: #2a2428; border-radius: 2px; overflow: hidden; }
.dmg-extfill { height: 100%; width: 0; background: #8f98a8; }
.dmg-fill { height: 100%; width: 0; background-image: linear-gradient(90deg, #5fbf6a 0%, #e8d23c 55%, #e0402f 100%); background-repeat: no-repeat; border-radius: 2px; }
.dmg-line { position: absolute; top: -5px; bottom: -5px; width: 3px; margin-left: -1px; background: #ff2a2a; box-shadow: 0 0 4px #f00; }
.dmg-line span { position: absolute; top: calc(100% + 6px); right: -1px; font-size: 10px; color: #ff6a5a; white-space: nowrap; line-height: 1.2; }
.dmg-line.lf span { right: auto; left: -1px; }
.dmg-gauge.near .dmg-track { animation: dmgBlink .5s steps(2) infinite; }
@keyframes dmgBlink { 50% { box-shadow: 0 0 0 2px #ff2a2a, 0 0 10px #f00; } }
.dmg-warn { font-weight: 700; font-size: 12px; margin-top: 4px; line-height: 1.35; }
.dmg-warn .warn { color: var(--warn); }
.dmg-det { margin-top: 4px; border-top: 1px solid #3a312c; }
.dmg-det summary { cursor: pointer; color: var(--acc); font-size: 11px; padding: 2px 0; }
.dmg-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; font-size: 11px; }
.zrow { display: flex; justify-content: space-between; gap: 6px; }
.zrow b.warn { color: var(--warn); } .zrow b.bad { color: var(--bad); }
.hud-box:empty { display: none; }

/* レースHUD配置 */
.r-info { top: 12px; left: 12px; max-width: 290px; font-size: 14px; line-height: 1.35; }
.r-center { background: none; border: 0; box-shadow: none; padding: 0; top: 12px; left: 0; right: 0; transform: none; text-align: center; pointer-events: none; }
.r-center .hud-msg, .hud-msg { white-space: nowrap; }
.r-center .hud-msg { left: 0; top: calc(min(8.9vw, 98px) + 10px); }
#r-bank { position: absolute; top: calc(min(8.9vw, 98px) + 116px); left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none; }
#r-bank .bk-t { font-size: 13px; } #r-bank .bk-n { font-size: 38px; font-weight: bold; text-shadow: 0 2px 0 #320; } #r-bank .bk-s { font-size: 11px; }
#r-bank.lost .bk-t { font-size: 14px; } #r-bank.lost .bk-n { font-size: 46px; } #r-bank.lost .bk-s { font-size: 12px; }
#r-bank.banked .bk-t { font-size: 16px; font-weight: bold; } #r-bank.banked .bk-n { font-size: 54px; } #r-bank.banked .bk-s { font-size: 12px; }
.r-rivals div { white-space: nowrap; }
.r-retire { display: inline-block; white-space: nowrap; background: rgba(40,0,0,.78); border: 2px solid #ff3a2a; border-radius: 10px; padding: 4px 18px; color: #ff6a4a; font-size: 30px; min-width: 260px; text-shadow: none; }
.r-assets { position: absolute; left: 12px; top: 190px; }
.r-dmg { position: absolute; top: 12px; right: 12px; }
.r-bl { position: absolute; left: 12px; bottom: 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; max-width: 300px; }
.r-feed { position: static; max-width: 300px; font-size: 13px; }
.r-help { background: rgba(0, 0, 0, .5); border: 1px solid rgba(255, 255, 255, .15); border-radius: 10px; padding: 6px 10px; font-size: 12px; color: var(--fg); }
.r-help table { border-collapse: collapse; }
.r-help th { text-align: right; padding: 1px 8px 1px 0; color: var(--acc); font-weight: 700; white-space: nowrap; }
.r-help td { padding: 1px 0; color: #ddd; }
.r-help.fold { padding: 2px 8px; font-size: 11px; color: var(--dim); }
.r-help.fold b { color: var(--acc); }
.r-rivals { right: 12px; bottom: 12px; font-size: 12px; line-height: 1.4; max-width: 300px; }
.r-mapbox { right: 12px; bottom: 150px; padding: 4px; }
@media (max-width: 1000px) {
  .r-info { font-size: 11px; max-width: 200px; padding: 4px 8px; }
  .r-info .hud-speed { font-size: 22px; }
  .r-assets { top: 150px; transform: scale(.8); transform-origin: top left; }
  .r-bl, .r-feed { max-width: 210px; font-size: 11px; }
  .r-help { font-size: 10px; padding: 4px 7px; }
  .r-rivals { font-size: 10px; max-width: 200px; }
  .r-mapbox { bottom: 130px; } .r-mapbox canvas { width: 130px; height: 130px; }
  .dmg-side { width: 100px; } .dmg-pct { font-size: 26px; } .panel.dmg { padding: 5px 7px; font-size: 10px; }
  .dmg-line span { font-size: 9px; }
}

/* 狭い窓のキーボード操作（touch 以外）のコンパクト配置 */
body:not(.touch) #hud.rc .r-info { font-size: 10px; max-width: 170px; }
body:not(.touch) #hud.rc .r-info .hud-speed { font-size: 18px; }
body:not(.touch) #hud.rc .r-assets { display: none; }
body:not(.touch) #hud.rc .r-retire { font-size: 20px; min-width: 0; padding: 2px 12px; }
body:not(.touch) #hud.rc .r-dmg { top: 6px; right: 6px; zoom: .5; max-width: 230px; }
body:not(.touch) #hud.rc .r-dmg .dmg-why, body:not(.touch) #hud.rc .r-dmg .dmg-lab-x, body:not(.touch) #hud.rc .r-dmg .dmg-line span { display: none; }
body:not(.touch) #hud.rc .r-dmg .dmg-warn { white-space: nowrap; }
body:not(.touch) #hud.rc .r-dmg .dmg-det[open] { position: absolute; right: 0; top: 100%; z-index: 4; background: rgba(0, 0, 0, .85); padding: 4px 8px; border-radius: 6px; width: 200px; }
body:not(.touch) #hud.rc .r-mapbox { right: 6px; bottom: auto; top: 112px; margin: 0; padding: 2px; }
body:not(.touch) #hud.rc .r-mapbox canvas { width: 72px; height: 72px; display: block; }
body:not(.touch) #hud.rc .r-rivals { display: block; right: 84px; bottom: auto; top: 112px; font-size: 10px; line-height: 1.25; max-width: 110px; max-height: 96px; overflow-y: auto; padding: 2px 5px; background: rgba(0, 0, 0, .35); pointer-events: auto; cursor: pointer; }
body:not(.touch) #hud.rc .r-rivals div { overflow: hidden; text-overflow: clip; }
body:not(.touch) #hud.rc .r-rivals .rv-t { font-size: 9px; text-align: right; }


/* ---- モーダル共通: ヘッダ(×常時表示)固定 / 本文だけスクロール / フッタ固定。画面(dvh・安全域)からはみ出さない ---- */
:root { --mt: max(8px, env(safe-area-inset-top, 0px)); --mr: max(8px, env(safe-area-inset-right, 0px)); --mb: max(8px, env(safe-area-inset-bottom, 0px)); --ml: max(8px, env(safe-area-inset-left, 0px)); }
.overlay, .center-screen, .sv-ov, .gmenu { padding: var(--mt) var(--mr) var(--mb) var(--ml); }
.panel.modal { display: flex; flex-direction: column; padding: 0; overflow: hidden; max-width: 100%; max-height: 100%; min-height: 0; }
.phone.modal { max-width: 100%; max-height: 100%; min-height: 0; }
.ph-body { min-height: 0; }
.modal-hd { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.modal-hd h2, .modal-hd h3 { margin: 0; }
.modal-hd .grow { min-width: 0; }
.modal-bd { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 8px 12px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.modal-ft { flex: none; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 6px 12px; border-top: 1px solid var(--line); }
.modal-ft .btn { margin: 0; width: auto; min-width: 0; }
.modal-x, .btn.modal-x { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; min-width: 36px; padding: 0; margin: 0 0 0 auto; font-size: 20px; line-height: 1; border-radius: 50%; }
.modal-bd .list, .modal-bd [style*="max-height"] { max-height: none !important; overflow: visible !important; }
.fm-panel { width: auto; }
.fm-bd { display: flex; gap: 12px; overflow: hidden; }
.fm-side { width: 250px; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.fm-side .list { flex: 1; min-height: 0; overflow: auto !important; max-height: none !important; }
#fm-cv { --s: min(640px, calc(100dvh - 96px), calc(100vw - 320px)); width: max(160px, var(--s)); height: max(160px, var(--s)); border: 2px solid #555; cursor: pointer; display: block; }
.res-panel { width: 900px; }
.res-row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.res-row .grow { min-width: min(100%, 420px); }
.res-tbl { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
.res-tbl th, .res-tbl td { padding: 1px 6px 1px 0; }
.res-receipt { font-family: ui-monospace, Menlo, monospace; background: #f1ead8; color: #2b2620; padding: 12px 16px; width: min(290px, 100%); box-shadow: 0 2px 0 #0004; font-size: 13px; line-height: 1.55; background-image: repeating-linear-gradient(#0000 0 21px, #0000000a 21px 22px); }
.res-receipt hr { border: 0; border-top: 1px dashed #6b6254; }
.res-line { display: flex; justify-content: space-between; gap: 24px; }
@media (max-width: 960px), (max-height: 520px) {
  .modal-hd { padding: 4px 8px; gap: 6px; } .modal-bd { padding: 6px 8px; } .modal-ft { padding: 4px 8px; gap: 6px; }
  .panel.modal { font-size: 13px; } .modal-hd h2 { font-size: 16px; } .modal-hd .money { font-size: 14px; }
  .modal-x, .btn.modal-x { width: 32px; height: 32px; min-width: 32px; }
  .modal .grid-2 { grid-template-columns: 1fr; }
  .shop-panel .btn.small { padding: 3px 8px; }
  .res-tbl { font-size: 11px; } .res-tbl .c-car, .res-tbl .c-ts, .res-tbl .c-ds { display: none; }
  .res-receipt { padding: 8px 10px; font-size: 11px; line-height: 1.45; }
  .res-row { gap: 8px; } .res-line { gap: 10px; }
  .ph-notch { display: none; } .phone { border-radius: 20px; padding: 6px 10px; border-width: 2px; }
  .fm-side { width: 200px; } #fm-cv { --s: min(640px, calc(100dvh - 80px), calc(100vw - 260px)); }
  .sv-panel { font-size: 13px; }
}

/* ---- タッチ操作 ---- */
.pick-row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; max-width: 96vw; }
.pick-card { position: relative; width: 300px; max-width: 44vw; min-width: 220px; padding: 10px; font: inherit; color: var(--fg); background: var(--panel); border: 2px solid var(--line); border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; align-items: center; text-align: center; pointer-events: auto; }
.pick-card:hover, .pick-card:active { border-color: var(--acc); background: #3a2d22; }
.pick-svg { width: 100%; height: auto; }
.pick-badge { position: absolute; top: -9px; right: 8px; background: var(--acc); color: #000; font-size: 12px; font-weight: 900; padding: 1px 9px; border-radius: 10px; }
.gmenu { position: fixed; inset: 0; height: 100%; height: 100dvh; z-index: 50; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; }
#rotate { position: fixed; inset: 0; z-index: 60; background: #14100f; color: var(--fg); align-items: center; justify-content: center; text-align: center; font-size: 20px; font-weight: 700; }
.center-screen .panel { max-height: 100%; overflow: auto; }
.ph-x { margin-left: 4px; width: 28px; font-size: 24px; }
.touch-help, .kbd-help { position: absolute; left: 12px; top: 70px; text-shadow: 1px 1px 0 #000; }
.touch-help { display: none; }
body.touch .kbd-help { display: none !important; }
body.touch .touch-help { display: block; }

body.touch { --u: 1; --st: env(safe-area-inset-top, 0px); --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px); --sb: env(safe-area-inset-bottom, 0px);
  --sm: calc(var(--u) * 42px); --sg: 4px; --colw: calc(var(--sm) * 2 + var(--sg));
  --ml: calc(var(--sl) + 8px); --mr: calc(var(--sr) + 8px); --mt: max(6px, var(--st));
  --mirh: calc(7.2vw + 20px); /* ミラー(mirror.js: 幅=画面幅の32%・4.5:1・上端10px・枠5px)の下端 */
  --rcol: calc(var(--mr) + var(--colw) + 8px); /* 右の丸ボタン列の内側端 */ }
@media (min-height: 600px) { body.touch { --u: 1.3; } }
@media (max-height: 360px) { body.touch { --u: .85; } }
#touch { position: fixed; inset: 0; height: 100%; height: 100dvh; overflow: hidden; z-index: 2; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#touch.off { pointer-events: none; }
#touch.off > * { display: none !important; }
#touch * { touch-action: none; }
#touch .tbtn, #touch .tstick { display: none; position: absolute; }
.tstick { left: calc(var(--sl) + 18px); bottom: calc(var(--sb) + 18px); width: calc(var(--u) * 140px); height: calc(var(--u) * 140px); border-radius: 50%; background: rgba(30, 24, 20, .45); border: 3px solid rgba(240, 162, 60, .55); }
.tknob { position: absolute; left: 50%; top: 50%; width: 52%; height: 52%; margin: -26% 0 0 -26%; border-radius: 50%; background: rgba(240, 162, 60, .75); border: 2px solid #fff3; box-shadow: 0 2px 8px #0008; }
.tstick.on { background: rgba(60, 40, 24, .6); }
.tbtn { align-items: center; justify-content: center; text-align: center; font-weight: 800; font-size: calc(var(--u) * 12px); line-height: 1.15; color: #fff; background: rgba(30, 24, 20, .55); border: 3px solid rgba(255, 255, 255, .45); border-radius: 50%; box-shadow: 0 2px 8px #0008; }
.tbtn.on { background: rgba(240, 162, 60, .85); color: #000; border-color: #fff; transform: scale(.94); }
.tbtn.hl { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(240, 162, 60, .6), 0 0 16px var(--acc); animation: tpulse 1s ease-in-out infinite; }
@keyframes tpulse { 50% { transform: scale(1.08); } }
.tbtn.gas { width: calc(var(--u) * 82px); height: calc(var(--u) * 150px); right: calc(var(--sr) + 14px); bottom: calc(var(--sb) + 14px); border-radius: 22px; font-size: calc(var(--u) * 15px); background: rgba(168, 96, 28, .55); }
.tbtn.brk { width: calc(var(--u) * 82px); height: calc(var(--u) * 112px); right: calc(var(--sr) + 14px + var(--u) * 92px); bottom: calc(var(--sb) + 14px); border-radius: 22px; font-size: calc(var(--u) * 14px); background: rgba(140, 44, 32, .55); }
.tbtn.hb { width: calc(var(--u) * 82px); height: calc(var(--u) * 44px); right: calc(var(--sr) + 14px + var(--u) * 92px); bottom: calc(var(--sb) + 14px + var(--u) * 120px); border-radius: 16px; }
.tbtn.bigE { width: calc(var(--u) * 104px); height: calc(var(--u) * 104px); right: calc(var(--sr) + 18px); bottom: calc(var(--sb) + 18px); font-size: calc(var(--u) * 16px); background: rgba(168, 96, 28, .6); }
.tbtn.run { width: calc(var(--u) * 78px); height: calc(var(--u) * 78px); right: calc(var(--sr) + 134px); bottom: calc(var(--sb) + 22px); font-size: calc(var(--u) * 15px); }
.tbtn.sm { width: var(--sm); height: var(--sm); font-size: calc(var(--u) * 9px); border-width: 2px; }
/* 丸ボタンは右上の2列（上=視点 … 下=メニュー）。ペダル・サイド・スティックより上、ミニマップより外側 */
#touch .tgrid { position: absolute; right: var(--mr); top: var(--mt); width: var(--colw); display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sg); }
#touch .tgrid .tbtn { position: static; }
#touch[data-ctx="drive"] [data-for~="drive"], #touch[data-ctx="walk"] [data-for~="walk"], #touch[data-ctx="race"] [data-for~="race"], #touch[data-ctx="test"] [data-for~="test"] { display: flex; }
#touch[data-ctx="drive"] .tstick, #touch[data-ctx="walk"] .tstick, #touch[data-ctx="race"] .tstick, #touch[data-ctx="test"] .tstick { display: block; }
html,body{touch-action:manipulation;overscroll-behavior:none;-webkit-touch-callout:none}

/* タッチ時のHUD配置（領域割り当て）
   左上=情報(.hud-col: 上バー/破損/速度) / 上中央=ミラー→(レース:メッセージ・未確定¥) / 右上=ミニマップ(+ライバル) / 右端列=丸ボタン
   右下=ペダル・サイド / 左下=スティック / 下中央=プロンプト・操作説明・ログ */
.hud-col, #r-mid { display: contents; }
body.touch .hud-box { font-size: 12px; padding: 3px 8px; }
body.touch .hud-col { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; position: absolute; left: var(--ml); top: var(--mt); max-width: calc(34vw - 14px); pointer-events: none; }
body.touch .hud-col > * { position: static !important; transform: none; margin: 0; zoom: 1; max-width: 100%; }
body.touch .hud-col > .hud-box { pointer-events: none; }
#tw-top { line-height: 1.35; }
#tw-top .tl-1, #tw-top .tl-2 { display: block; }

body.touch #tw-dmg { zoom: .5 !important; }
body.touch #tw-speed { font-size: 18px; padding: 1px 8px; }
body.touch .hud-tr { top: var(--mt); right: var(--rcol); }
body.touch #tw-map { width: 84px; height: 84px; display: block; }
body.touch .hud-bc { left: 50%; bottom: calc(var(--sb) + 20px) !important; max-width: 36vw; font-size: 13px !important; text-align: center; }
body.touch .toasts { bottom: auto; top: var(--mirh); max-width: 40vw; flex-direction: column; }
body.touch .toast { font-size: 12px; padding: 4px 10px; }
body.touch .touch-help { left: 50%; top: auto; bottom: calc(var(--sb) + 84px); transform: translateX(-50%); width: 34vw; max-width: 34vw; font-size: 10px; text-align: center; animation: thFade 1s 12s forwards; }
@keyframes thFade { to { opacity: 0; visibility: hidden; } }
body.touch #hud { z-index: 3; }
/* レース（タッチ） */
body.touch .r-info { font-size: 10px; max-width: 170px; line-height: 1.3; }
body.touch .r-info .hud-speed { font-size: 16px; }
body.touch .r-info > div:nth-child(2) { font-size: 14px !important; }
body.touch .r-dmg { position: static; max-width: 100%; }
body.touch .r-assets { display: none; }
body.touch #r-mid { display: flex; flex-direction: column; align-items: center; gap: 2px; position: absolute; left: 50%; top: var(--mirh); transform: translateX(-50%); width: max-content; max-width: 36vw; pointer-events: none; }
body.touch #r-mid > * { position: static !important; transform: none; top: auto !important; left: auto; right: auto; width: auto; margin: 0; padding: 0; }
body.touch .r-center .hud-msg { position: static; width: auto; top: auto; font-size: 28px !important; line-height: 1.15; }
body.touch .r-retire { font-size: 16px; min-width: 0; padding: 1px 10px; white-space: normal; }
body.touch #r-bank .bk-t { font-size: 11px; } body.touch #r-bank .bk-n { font-size: 24px; line-height: 1.1; } body.touch #r-bank .bk-s { font-size: 9px; }
body.touch .r-mapbox { position: absolute; right: var(--rcol); top: var(--mt); bottom: auto; margin: 0; padding: 2px; }
body.touch .r-mapbox canvas { width: 72px; height: 72px; display: block; }
body.touch .r-rivals { display: block; position: absolute; right: var(--rcol); bottom: auto; top: calc(var(--mt) + 82px); font-size: 10px; line-height: 1.25; max-width: 112px; max-height: 76px; overflow-y: auto; padding: 2px 5px; background: rgba(0, 0, 0, .35); pointer-events: auto; cursor: pointer; }
body.touch .r-rivals div { overflow: hidden; text-overflow: clip; }
body.touch .r-rivals .rv-t { font-size: 9px; text-align: right; }
body.touch .r-bl { position: absolute; left: 50%; right: auto; top: auto; transform: translateX(-50%); bottom: calc(var(--sb) + 20px); width: 34vw; max-width: 34vw; align-items: center; }
body.touch .r-feed { max-width: 100%; font-size: 10px; text-align: center; }
body.touch .r-help { font-size: 9px; max-width: 100%; }
body.touch .r-dmg .dmg-why, body.touch .r-dmg .dmg-lab-x { display: none; }
body.touch .r-dmg .dmg-warn { white-space: nowrap; }
body.touch .r-dmg .dmg-det { display: none; }
body.touch .r-dmg { zoom: .5; }
body.touch .hud-msg { font-size: 36px; }

/* セーブ関連（persist/ui.js） */
#savestat { position: fixed; left: 50%; transform: translateX(-50%); bottom: 3px; z-index: 5; font-size: 11px; color: var(--fg); opacity: .4; pointer-events: none; text-shadow: 0 1px 2px #000; }
#savestat:empty { display: none; }
#savestat.saving { opacity: .6; }
#savestat.error { opacity: 1; pointer-events: auto; cursor: pointer; background: #a8281c; color: #fff; padding: 4px 10px; border-radius: 6px; font-size: 13px; font-weight: 700; }
body.touch #savestat { bottom: 2px; }
.sv-ov { position: fixed; inset: 0; height: 100%; height: 100dvh; z-index: 70; background: rgba(0, 0, 0, .7); display: flex; align-items: center; justify-content: center; pointer-events: auto; }
.sv-panel { width: min(520px, 100%); font-size: 14px; }
.sv-panel h3 { margin: 10px 0 4px; font-size: 14px; }
.sv-info { list-style: none; padding: 0; margin: 6px 0; line-height: 1.7; }
.sv-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.sv-warn { background: #6b4a12; border-radius: 6px; padding: 6px 10px; margin: 6px 0; }
.sv-ta { width: 100%; box-sizing: border-box; background: #1a1618; color: var(--fg); border: 1px solid #7a6a5c; border-radius: 6px; font-family: monospace; font-size: 11px; }
.sv-cands { max-height: none; }
.sv-cand { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 6px; border-bottom: 1px solid rgba(255, 255, 255, .1); font-size: 12px; }
.sv-toast { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 80; background: rgba(0, 0, 0, .85); padding: 8px 16px; border-radius: 6px; max-width: 90vw; font-size: 13px; pointer-events: none; }
