:root {
  --bg: #0f1b2d; --panel: rgba(15, 27, 45, .93); --line: rgba(255,255,255,.16);
  --text: #f3f6fa; --muted: #b9c4d2; --accent: #2f8cff; --accent-press: #1f6fd6;
  --warn: #ffc65c; --ok: #7ddba0;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif; font-size: 16px; line-height: 1.6;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
[hidden] { display: none !important; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.fps-option { display: flex; align-items: center; gap: 8px; width: fit-content; min-height: 44px; margin: 4px 0 0; cursor: pointer; }
.fps-option input { width: 18px; height: 18px; margin: 0; accent-color: #8cc5ff; }
#fps-meter { position: fixed; z-index: 7; top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  padding: 2px 8px; border-radius: 6px; background: rgba(10,18,30,.82); font-size: .78rem;
  font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: none; }
#hud:not([hidden]) ~ #fps-meter, #replay:not([hidden]) ~ #fps-meter {
  right: calc(12px + var(--safe-r)); left: auto; transform: none; }
#hud:not([hidden]) ~ #fps-meter { top: calc(68px + var(--safe-t)); }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
  background: rgba(8, 14, 24, .55); overflow-y: auto; z-index: 10; }
.card { width: min(560px, 100%); max-height: 100%; overflow-y: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 20px; backdrop-filter: blur(6px); }
.card.narrow { width: min(440px, 100%); }
#view-paused { pointer-events: none; background: transparent; align-items: flex-end; justify-content: flex-end;
  padding-bottom: calc(88px + var(--safe-b)); }
#view-paused .card { pointer-events: auto; width: min(380px, 100%); padding: 16px; }
#view-paused h1 { font-size: 1.1rem; }
#view-paused p { margin: 6px 0; }
h1 { margin: 0 0 6px; font-size: 1.35rem; letter-spacing: .02em; }
.lead { margin: 0 0 12px; color: var(--muted); font-size: .95rem; }
.unofficial-notice { margin: 4px 0 12px; color: var(--muted); font-size: .8rem; }
label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: .95rem; }
select { width: 100%; min-height: 48px; padding: 8px 12px; font-size: 1rem; color: var(--text); background: #1b2a41;
  border: 1px solid var(--line); border-radius: 10px; }
button { font: inherit; color: var(--text); background: #26374f; border: 1px solid var(--line); border-radius: 10px;
  min-height: 48px; padding: 8px 14px; cursor: pointer; touch-action: manipulation; }
button:active { transform: translateY(1px); }
button:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid #9cc8ff; outline-offset: 2px; }
button.primary { background: var(--accent); border-color: transparent; font-weight: 700; }
button.primary:active { background: var(--accent-press); }
button.big { width: 100%; margin-top: 14px; min-height: 54px; font-size: 1.1rem; }
button:disabled { opacity: .45; cursor: not-allowed; }
.info { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.06); font-size: .92rem; white-space: pre-line; min-height: 3.2em; }
.info.ng { border-left: 4px solid var(--warn); }
.info.ok { border-left: 4px solid var(--ok); }
.terminal-parking-notice { display: block; margin-top: .5em; padding: .45em .65em; border-left: 3px solid var(--warn);
  background: rgba(255,198,92,.1); color: var(--warn); font-size: 1rem; }
.route-details-body p { margin: 4px 0 10px; }
.route-details-body ul { margin: 8px 0; padding-left: 1.25em; }
.route-details-body li { margin: 6px 0; }
#route-details, #g-route-details { color: var(--muted); }
#route-details > summary::before, #g-route-details > summary::before { content: '›'; margin-right: 8px; font-size: 1.25rem; }
#route-details[open] > summary::before, #g-route-details[open] > summary::before { transform: rotate(90deg); }
.small { font-size: .82rem; color: var(--muted); }
.warn-text { color: var(--warn); font-weight: 600; }
details { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; font-weight: 600; font-size: .95rem; }
#status-body { font-size: .86rem; }
#status-body h3 { font-size: .9rem; margin: 10px 0 4px; }
#status-body ul { margin: 0; padding-left: 1.2em; }
#status-body li { margin: 2px 0; }
#credits a { color: #9cc8ff; }
.bar { height: 10px; background: rgba(255,255,255,.14); border-radius: 6px; overflow: hidden; margin: 8px 0; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }
.bar.thin { height: 5px; margin: 4px 0 0; }

/* 走行中：上は細い情報帯、下は操作。中央（進行方向）は空ける */
#topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 5; padding: calc(6px + var(--safe-t)) calc(12px + var(--safe-r)) 6px calc(12px + var(--safe-l));
  background: linear-gradient(rgba(10,18,30,.82), rgba(10,18,30,.5)); font-size: .9rem; }
#topbar .row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
#topbar .row.sub { font-size: .84rem; color: var(--muted); }
#route-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-heading { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mode-label { flex: none; padding: 1px 8px; border: 1px solid #86c3ff; border-radius: 6px;
  background: rgba(35,100,158,.42); color: #d2eaff; font-size: .76rem; font-weight: 700; white-space: nowrap; }
#road-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#remain { white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge { flex: none; font-size: .76rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--ok); color: var(--ok); white-space: nowrap; }
.badge.warn { border-color: var(--warn); color: var(--warn); }
#controls { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: 8px calc(10px + var(--safe-r)) calc(18px + var(--safe-b)) calc(10px + var(--safe-l));
  background: linear-gradient(rgba(10,18,30,.35), rgba(10,18,30,.85)); }
.ctl { background: rgba(38,55,79,.92); min-width: 76px; }
.ctl.wide { min-width: 104px; font-weight: 700; background: var(--accent); border-color: transparent; }
.speed { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: rgba(38,55,79,.92); }
.speed button { border: 0; border-radius: 0; background: transparent; min-width: 52px; padding: 8px 6px; }
.speed button[aria-pressed="true"] { background: #e9f1fb; color: #0f1b2d; font-weight: 700; }
#attribution { position: fixed; left: 0; right: 0; bottom: var(--safe-b); z-index: 6; text-align: center; font-size: .62rem; color: rgba(255,255,255,.8);
  padding: 1px 6px; pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#arrived { position: fixed; left: 50%; top: calc(70px + var(--safe-t)); transform: translateX(-50%); z-index: 7; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; width: min(360px, calc(100% - 24px)); }
#arrived strong { font-size: 1.25rem; }
#view-controls { position: fixed; z-index: 6; left: calc(12px + var(--safe-l)); bottom: calc(88px + var(--safe-b));
  width: 230px; max-width: calc(100vw - 24px); margin: 0; padding: 0; overflow: hidden;
  background: rgba(15,27,45,.94); border: 1px solid var(--line); border-radius: 12px; }
#view-controls summary { padding: 8px 12px; min-height: 44px; }
#view-controls p { margin: 8px 12px; line-height: 1.5; }
.view-look-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 0 12px; }
.view-look-pad button { min-height: 44px; padding: 4px 6px; touch-action: manipulation; }
.look-up { grid-area: 1 / 2; } .look-left { grid-area: 2 / 1; } #view-forward { grid-area: 2 / 2; }
.look-right { grid-area: 2 / 3; } .look-down { grid-area: 3 / 2; }
.view-look-keys { font-size: .7rem; color: var(--muted); }
.arrived-actions { display: flex; gap: 8px; margin-top: 8px; }
.arrived-actions button { flex: 1; }

.replay-heading { position: fixed; z-index: 5; top: calc(12px + var(--safe-t)); left: calc(12px + var(--safe-l));
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 12px; max-width: calc(100% - 24px);
  padding: 7px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.replay-heading h1 { margin: 0; font-size: .95rem; }
#replay-angle { color: var(--muted); font-size: .82rem; }
.replay-controls { position: fixed; z-index: 5; bottom: calc(12px + var(--safe-b));
  left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r)); margin-inline: auto;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px;
  max-width: 560px; padding: 8px 12px 12px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.replay-controls:has(#replay-controls-panel[hidden]) { left: auto; margin-inline: 0;
  display: block; padding: 0; border: 0; background: none; }
#replay-controls-panel { display: contents; }
#replay-controls-toggle { grid-area: 1 / 2; min-width: 44px; min-height: 44px; padding: 3px 9px;
  font-size: .85rem; white-space: nowrap; }
.replay-progress { grid-area: 1 / 1; display: flex; align-items: center; gap: 8px; }
.replay-progress input { flex: 1; min-width: 0; height: 44px; margin: 0; accent-color: #80bcff; cursor: pointer; }
#replay-time { white-space: nowrap; font-size: .8rem; font-variant-numeric: tabular-nums; }
#replay-sound { min-height: 44px; padding: 3px 8px; font-size: .85rem; white-space: nowrap; }
#replay-sound[aria-pressed="true"] { background: #27466b; border-color: #8cc5ff; }
.replay-actions { grid-area: 2 / 1 / auto / span 2; display: flex; gap: 6px; }
.replay-actions > * { font-size: .85rem; padding: 5px 8px; }
.replay-actions button { min-width: 0; flex: 1; }
.replay-actions select { width: auto; max-width: 44%; flex-shrink: 0; }

@media (min-width: 640px) and (max-height: 480px) and (orientation: landscape) {
  .replay-controls { grid-template-columns: minmax(0, 1fr) auto auto; max-width: 760px;
    align-items: center; padding: 5px 8px; }
  .replay-actions { grid-area: 1 / 2; }
  .replay-actions > * { min-height: 44px; }
  .replay-actions button { flex: none; white-space: nowrap; }
  .replay-actions select { max-width: 9rem; }
  #replay-controls-toggle { grid-area: 1 / 3; }
}

/* 横向きのスマートフォン：操作を右下に寄せ、高さを抑える */
@media (max-height: 480px) and (orientation: landscape) {
  #view-controls { bottom: calc(20px + var(--safe-b)); }
  #controls { left: auto; justify-content: flex-end; flex-wrap: nowrap; background: none; padding-bottom: calc(16px + var(--safe-b)); }
  #topbar { font-size: .82rem; padding-top: calc(3px + var(--safe-t)); padding-bottom: 3px; }
  #arrived { top: calc(50px + var(--safe-t)); padding: 8px 12px; }
  .card { padding: 14px; }
  h1 { font-size: 1.1rem; } .lead { display: none; }
  label { margin-top: 6px; }
}
/* 幅の狭い画面：操作を1行に収める */
@media (max-width: 480px) {
  #controls { gap: 6px; font-size: .86rem; padding-left: calc(6px + var(--safe-l)); padding-right: calc(6px + var(--safe-r)); flex-wrap: nowrap; }
  .ctl, .ctl.wide { min-width: 0; padding: 8px 7px; white-space: nowrap; }
  .speed button { min-width: 38px; padding: 8px 4px; white-space: nowrap; }
}
@media (min-width: 640px) and (max-height: 480px) {
  .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  #attribution { text-align: left; right: 500px; }
  .overlay { align-items: flex-start; }
}

/* ---------- モードの切り替え ---------- */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 10px; }
.modes button { display: flex; flex-direction: column; align-items: center; line-height: 1.3; font-weight: 700; }
.modes button small { font-weight: 400; font-size: .76rem; color: var(--muted); }
.modes button[aria-pressed="true"] { background: #e9f1fb; color: #0f1b2d; border-color: transparent; }
.modes button[aria-pressed="true"] small { color: #3c4b60; }

/* ---------- ゲームモード ---------- */
.card.wide { width: min(640px, 100%); }
.pre { white-space: pre-line; }
#g-map { display: block; width: 100%; height: min(42vh, 320px); border-radius: 10px; border: 1px solid var(--line); }
.g-route { margin: 0 0 8px; font-weight: 700; }
.g-facts { margin: 8px 0 4px; font-weight: 600; }
.g-body-color { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.g-body-color label { margin: 0; }
.g-body-color select { width: auto; min-width: 9rem; max-width: 100%; }
#g-body-color-swatch { width: 24px; height: 24px; border: 1px solid #a6b5c9; border-radius: 5px; }
.legend { margin: 6px 0 0; }
.legend .dot { display: inline-block; width: 1.5em; height: 1.5em; line-height: 1.5em; text-align: center; border-radius: 50%; color: #fff; font-weight: 700; margin-right: 3px; }
.legend .dot.s { background: #1fa55b; } .legend .dot.g { background: #e5484d; }
.legend .swatch { display: inline-block; width: 26px; height: 5px; background: #3d9bff; border-radius: 3px; vertical-align: middle; margin-right: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; min-height: 44px; margin: 6px 0 0; }
.check input { flex: none; width: 22px; height: 22px; }
.drive-choice { min-width: 0; margin: 12px 0 0; padding: 0; border: 0; }
.drive-choice legend { margin-bottom: 6px; padding: 0; font-weight: 600; font-size: .95rem; }
.drive-choice-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 152px), 1fr)); gap: 8px; }
.drive-choice-options label { display: flex; align-items: center; gap: 8px; min-height: 48px; margin: 0; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #1b2a41; cursor: pointer; }
.drive-choice-options input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: #8cc5ff; }
.drive-choice-options label:has(input:checked) { background: #27466b; border-color: #8cc5ff; }
.drive-choice-options label:has(input:focus-visible) { outline: 3px solid #9cc8ff; outline-offset: 2px; }
.w-text { font-size: 1.1rem; font-weight: 700; min-height: 4.8em; }

#g-top { position: fixed; top: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none;
  padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l)); }
.g-timebox { pointer-events: auto; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; background: rgba(10,18,30,.78); border-radius: 12px; padding: 6px 10px 8px; }
.g-timebox strong { font-size: 2rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.g-timebox button { min-height: 40px; padding: 4px 12px; font-size: .86rem; }
#g-mini { width: 150px; height: 150px; }
#g-msgs { position: fixed; top: calc(92px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 6; max-width: calc(100% - 24px);
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
#g-banner { background: rgba(160, 30, 30, .92); color: #fff; font-weight: 700; padding: 6px 14px; border-radius: 10px; text-align: center; }
.t-buttons button.hint { border-color: #ffb44a; box-shadow: 0 0 0 2px #ffb44a; color: #ffd28a; }
#g-count { position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%); z-index: 6; font-size: clamp(3rem, 16vw, 7rem); font-weight: 800;
  color: #fff; text-shadow: 0 2px 14px rgba(0,0,0,.7); pointer-events: none; white-space: nowrap; }
#g-meter { position: fixed; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); z-index: 5; min-width: 170px; text-align: center;
  background: rgba(10,18,30,.78); border-radius: 12px; padding: 6px 14px 8px; pointer-events: none; }
#g-cruise { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; min-height: 44px;
  margin-top: 6px; padding: 4px 8px; pointer-events: auto; touch-action: manipulation; font-size: .82rem; white-space: nowrap; }
#g-cruise[aria-pressed="true"] { border-color: #7ddba0; background: #184535; color: #dcffeb; }
#g-cruise-speed { font-variant-numeric: tabular-nums; font-weight: 700; }
#g-hint { margin: 6px auto 0; max-width: 14.5rem; color: var(--muted); font-size: .78rem; line-height: 1.35; }
#g-keyboard-pedals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 8px;
  margin: 7px auto 0; width: min(178px, calc(100vw - 44px)); font-size: .78rem; }
#g-keyboard-steering { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr 1fr auto;
  align-items: center; gap: 4px; margin-bottom: 3px; color: var(--muted); }
#g-keyboard-steering progress { width: 100%; height: 8px; appearance: none; border: 0; border-radius: 3px;
  overflow: hidden; background: rgba(225, 235, 247, .17); }
#g-steer-left { direction: rtl; }
#g-keyboard-steering progress::-webkit-progress-bar { background: transparent; }
#g-keyboard-steering progress::-webkit-progress-value { background: #8cc5ff; }
#g-keyboard-steering progress::-moz-progress-bar { background: #8cc5ff; }
.pedal-reading { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pedal-reading label { margin: 0; font-size: inherit; }
.pedal-reading kbd, #g-keyboard-handbrake kbd { color: var(--muted); white-space: nowrap; font: inherit; }
.pedal-scale { --scale-height: 52px; --scale-width: 15px; position: relative; width: var(--scale-width); height: var(--scale-height); }
.pedal-scale progress { --fill: #7ddba0; position: absolute; top: 50%; left: 50%;
  width: var(--scale-height); height: var(--scale-width); margin: 0; direction: ltr;
  transform: translate(-50%, -50%) rotate(-90deg); appearance: none; border: 0; border-radius: 4px;
  overflow: hidden; background: rgba(225, 235, 247, .17); }
#g-pedal-brake { --fill: #ff8f8f; }
.pedal-scale progress::-webkit-progress-bar { background: transparent; }
.pedal-scale progress::-webkit-progress-value { background: var(--fill); }
.pedal-scale progress::-moz-progress-bar { background: var(--fill); }
.pedal-reading span { font-variant-numeric: tabular-nums; }
#g-pedal-help { grid-column: 1 / -1; color: var(--muted); }
#g-keyboard-handbrake { grid-column: 1 / -1; display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 6px; }
/* キーボード操作時は計器を右下にまとめ、フロントガラスの中央を空ける。 */
body:not(.touch) #g-meter { left: auto; right: calc(10px + var(--safe-r)); transform: none;
  width: min(208px, 36vw); min-width: 0; padding-inline: 10px; }
body:not(.touch) #g-keyboard-pedals { width: 100%; }
body:not(.touch) #g-cruise { flex-wrap: wrap; gap: 2px 6px; white-space: normal; }
.g-speed { display: flex; align-items: baseline; justify-content: center; gap: 6px; }
.g-speed strong { font-size: 2.3rem; line-height: 1; font-variant-numeric: tabular-nums; min-width: 2.2ch; text-align: right; }
.g-speed span { color: var(--muted); font-size: .82rem; }
.g-speed em { font-style: normal; font-weight: 700; margin-left: 8px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; }
#g-rpm { background: #ffb44a; transition: none; }
#g-attribution { position: fixed; left: 0; right: 0; bottom: var(--safe-b); z-index: 4; text-align: center; font-size: .6rem; color: rgba(255,255,255,.75);
  pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#g-goal-marker { position: fixed; z-index: 3; transform: translate(-50%, -100%); pointer-events: none;
  white-space: nowrap; padding: 6px 14px; border: 2px solid #8affc1; border-radius: 10px;
  background: rgba(12,30,35,.94); color: #b6ffda; font-size: 1.25rem; font-weight: 800;
  box-shadow: 0 0 14px rgba(80,255,170,.45); }
#g-result.clear h1 { color: var(--ok); }
#g-result h1 { font-size: 1.7rem; color: #ff8f8f; }
.result-route { margin: 14px 0; padding: 12px; background: rgba(255,255,255,.06); border-radius: 10px; }
.result-route > div + div { margin-top: 9px; }
.result-route dt { color: var(--muted); font-size: .8rem; }
.result-route dd { margin: 1px 0 0; font-weight: 700; overflow-wrap: anywhere; }

/* タッチ操作（スマートフォン・タブレットだけに表示） */
#touch { display: none; --pedal-width: 92px; --pedal-height: 210px; --pedal-bottom: calc(22px + var(--safe-b)); }
body.touch #touch { display: block; }
body.touch #g-meter { display: contents; }
body.touch .g-speedometer { position: fixed; left: 50%; bottom: calc(22px + var(--safe-b)); transform: translateX(-50%);
  width: max-content; padding: 5px 4px 6px; background: rgba(10,18,30,.78); border-radius: 10px; }
body.touch .g-speed { gap: 3px; }
body.touch .g-speed strong { font-size: 1.45rem; min-width: 3ch; }
body.touch .g-speed span { font-size: .74rem; }
body.touch .g-speed em { margin-left: 0; padding-inline: 4px; font-size: .8rem; }
body.touch #g-hint { margin: 4px 0 0; max-width: min(12.5rem, calc(100vw - 166px)); padding: 4px 8px;
  font-size: .75rem; text-align: left; background: rgba(10,18,30,.78); border-radius: 8px; }
body.touch #g-pause { display: none; }
#touch > * { position: fixed; z-index: 6; touch-action: none; user-select: none; -webkit-user-select: none; }
#touch > #g-cruise { left: calc(12px + var(--safe-l)); bottom: calc(106px + var(--safe-b));
  width: auto; min-width: 120px; margin-top: 0; font-weight: 700; }
#t-steer { left: calc(12px + var(--safe-l)); bottom: calc(22px + var(--safe-b)); width: min(42vw, 230px); height: 76px; border-radius: 38px;
  background: rgba(10,18,30,.6); border: 1px solid var(--line); --knob: 0; }
#t-steer span { position: absolute; top: 8px; left: calc(50% - 30px + var(--knob) * 38%); width: 60px; height: 60px; border-radius: 50%; background: rgba(233,241,251,.9); }
/* 上がアクセル（青）、下がブレーキ（赤）。--pedal は -1（下いっぱい）〜1（上いっぱい） */
#t-pedal { --pedal: 0; --up: max(var(--pedal), 0); --down: max(calc(var(--pedal) * -1), 0);
  --up-color: rgba(47,140,255,.95); --down-color: rgba(229,72,77,.95);
  right: calc(12px + var(--safe-r)); bottom: var(--pedal-bottom); width: var(--pedal-width); height: var(--pedal-height); border-radius: 16px; border: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: space-between; align-items: center; padding: 8px 4px; box-sizing: border-box;
  font-size: .74rem; font-weight: 700; text-align: center; line-height: 1.2;
  background:
    linear-gradient(to top, transparent calc(50% - 1px), rgba(233,241,251,.55) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to bottom, transparent calc(50% - var(--up) * 50%), var(--up-color) calc(50% - var(--up) * 50%) 50%, transparent 50%),
    linear-gradient(to bottom, transparent 50%, var(--down-color) 50% calc(50% + var(--down) * 50%), transparent calc(50% + var(--down) * 50%)),
    rgba(10,18,30,.6); }
#t-pedal span { pointer-events: none; }
.t-buttons { right: calc(12px + var(--safe-r)); bottom: calc(var(--pedal-bottom) + var(--pedal-height) + 12px);
  display: grid; grid-template-columns: auto auto var(--pedal-width); gap: 6px; }
.t-buttons button { min-width: 50px; min-height: 44px; padding: 4px 8px; background: rgba(10,18,30,.7); font-weight: 700; }
#t-back { background: #244b73; touch-action: none; white-space: nowrap; }
#t-back[aria-pressed="true"] { background: #1961a3; border-color: white; }
#t-pause { grid-column: 2; }
#t-handbrake { grid-column: 3; }
#t-handbrake { touch-action: none; padding-inline: 2px; font-size: .75rem; white-space: nowrap; }
#t-handbrake[aria-pressed="true"] { background: #942f36; border-color: white; }
@media (max-height: 540px) {
  body:not(.touch) #g-meter { padding-block: 4px; line-height: 1.2; }
  body:not(.touch) #g-meter .g-speed strong { font-size: 1.6rem; }
  body:not(.touch) #g-cruise { min-height: 30px; margin-top: 4px; }
  body:not(.touch) #g-keyboard-pedals { margin-top: 4px; gap: 2px 4px; font-size: .7rem; }
  body:not(.touch) .pedal-scale { --scale-height: 24px; }
  body:not(.touch) #g-mini { width: min(120px, 24dvh); height: auto; aspect-ratio: 1; }
}
@media (max-height: 360px) {
  body:not(.touch) #g-hint { font-size: .72rem; line-height: 1.2; }
  body:not(.touch) #g-mini { width: clamp(44px, calc(100dvh - 268px), 76px); }
}
@media (max-height: 480px) and (orientation: landscape) {
  #g-mini { width: 120px; height: 120px; }
  #g-map { height: 38vh; }
  .g-timebox strong { font-size: 1.5rem; }
  #touch { --pedal-height: 160px; }

  /* 横向きのタッチ操作では経過時間と警告を左、地図を右に置く。 */
  body.touch .g-readouts { display: grid; gap: 4px; width: min(180px, 30vw); }
  body.touch .g-timebox { flex-direction: row; align-items: baseline; justify-content: space-between; gap: 6px; padding: 3px 8px; }
  body.touch .g-timebox strong { font-size: 1.35rem; }
  body.touch #g-hint { max-width: none; margin-top: 0; font-size: .7rem; }
  body.touch #g-msgs { position: static; max-width: none; align-items: stretch; transform: none; }
  body.touch #g-msgs:has(#g-banner[hidden]):has(#g-drift[hidden]) { display: none; }
  body.touch #g-banner { padding: 4px 8px; font-size: .75rem; line-height: 1.3; text-align: left; overflow-wrap: anywhere; }
  body.touch #g-mini {
    width: clamp(48px, calc(100dvh - 252px - var(--safe-t) - var(--safe-b)), 120px);
    height: auto; aspect-ratio: 1;
  }
}
@media (max-width: 480px) { #g-mini { width: 118px; height: 118px; } }
@media (max-width: 480px) and (orientation: portrait) {
  body.touch .g-timebox { width: fit-content; }
  #g-msgs { top: calc(240px + var(--safe-t)); }
}
/* 幅が狭いときは速度計をハンドルやクルーズボタンより少し上げる。 */
@media (max-width: 620px) {
  body.touch .g-speedometer { bottom: calc(104px + var(--safe-b)); }
}
@media (max-width: 430px) {
  body.touch .g-speedometer { bottom: calc(156px + var(--safe-b)); }
}

/* 言語の切り替え（日本語／English） */
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-head h1 { margin-right: auto; }
.lang-btn { flex: none; min-height: 34px; padding: 4px 12px; font-size: .85rem; border-radius: 999px; }

/* 紹介ページへのリンク（地点選択の画面の下） */
.about-link { margin: 14px 0 0; text-align: center; }
.about-link a { color: #9cc8ff; }

/* マウスでハンドル：照準のカーソルで、画面の中央からの位置を見やすくする（2026-11-20） */
#game.mouse-steer { cursor: crosshair; }

/* ドリフトのカウンター */
#g-drift { background: rgba(124, 58, 237, .9); color: #fff; font-weight: 800; font-size: 1.15rem; padding: 4px 14px; border-radius: 10px; text-align: center; font-variant-numeric: tabular-nums; }
#g-drift.ended { opacity: .6; }
body.touch #g-drift { font-size: .9rem; padding: 3px 10px; }
