/* 配色は日本の道路標識から: 案内標識の青、規制標識の赤、路面の白線とアスファルト */
:root {
  --ink: #17212c;
  --muted: #566372;
  --paper: #eef1f4;
  --panel: #ffffff;
  --line: #d3dae2;
  --sign-blue: #0b5cad;
  --sign-blue-dark: #084584;
  --sign-red: #d0021b;
  --amber: #f5a300;
  --go: #0f9d6b;
  --asphalt: #45474c;
  --paint: #f2f2ee;
  --hud-bg: rgba(14, 20, 27, 0.74);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0e141b;
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font-family: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- 走行中の表示 ---------- */
#hud { position: fixed; inset: 0; touch-action: none; pointer-events: none; color: #fff; }
#hud > * { pointer-events: auto; }

#speedBox {
  position: absolute; left: calc(14px + var(--safe-l)); top: calc(14px + var(--safe-t));
  display: flex; align-items: center; gap: 8px;
  background: var(--hud-bg); border-radius: 14px; padding: 6px 12px 6px 16px;
  pointer-events: none;
}
#speedNum { font-size: 46px; font-weight: 800; line-height: 1; min-width: 1.4em; text-align: right; font-variant-numeric: tabular-nums; }
#speedUnit { font-size: 15px; opacity: 0.85; align-self: flex-end; padding-bottom: 6px; }
#speedBox.over #speedNum { color: #ff5a4d; }
#limitSign {
  width: 54px; height: 54px; border-radius: 50%;
  background: #fff; border: 7px solid var(--sign-red);
  color: var(--sign-blue-dark); font-weight: 800; font-size: 21px;
  display: flex; align-items: center; justify-content: center; margin-left: 6px;
}

#navBox {
  position: absolute; left: 50%; top: calc(14px + var(--safe-t)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  background: var(--sign-blue); border: 3px solid #fff; border-radius: 12px;
  padding: 8px 22px 8px 14px; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  pointer-events: none; white-space: nowrap;
}
#navBox.goal { background: var(--go); }
#navArrow { width: 66px; height: 66px; flex: none; }
#navArrow path { fill: #fff; }
#navArrow.flip { transform: scaleX(-1); }
#navMain { font-size: 32px; font-weight: 800; line-height: 1.15; letter-spacing: 0.06em; }
#navSub { font-size: 18px; opacity: 0.95; font-variant-numeric: tabular-nums; }

#topRight {
  position: absolute; right: calc(14px + var(--safe-r)); top: calc(14px + var(--safe-t));
  display: flex; align-items: center; gap: 10px;
}
#progress { background: var(--hud-bg); border-radius: 12px; padding: 10px 14px; font-size: 16px; font-variant-numeric: tabular-nums; pointer-events: none; }
#btnPause {
  min-width: 84px; min-height: 56px; border-radius: 12px; border: 2px solid rgba(255, 255, 255, 0.8);
  background: var(--hud-bg); color: #fff; font-size: 19px; font-weight: 700;
}

#toast {
  position: absolute; left: 50%; top: calc(118px + var(--safe-t)); transform: translateX(-50%);
  background: rgba(208, 2, 27, 0.94); color: #fff; font-size: 26px; font-weight: 800;
  padding: 10px 26px; border-radius: 12px; border: 3px solid #fff; white-space: nowrap; pointer-events: none;
  max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
#tiltWarn {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%);
  background: var(--hud-bg); border: 2px solid var(--amber); color: #fff; font-size: 22px; font-weight: 700;
  padding: 12px 22px; border-radius: 12px; pointer-events: none; text-align: center;
}

#wheelBox {
  position: absolute; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%);
  width: 118px; height: 118px; pointer-events: none; opacity: 0.9;
}
#wheel { width: 100%; height: 100%; display: block; transform-origin: 50% 50%; }
.wheelRim { stroke: #1a1f26; }
.wheelSpoke, .wheelHub { fill: #1a1f26; }
.wheelMark { fill: var(--amber); }

.pedal {
  position: absolute; display: flex; align-items: flex-end; justify-content: center;
  border-radius: 16px; border: 3px solid rgba(255, 255, 255, 0.85);
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.16) 0 6px, transparent 6px 20px),
    rgba(20, 26, 33, 0.78);
  color: #fff; font-size: 19px; font-weight: 800; padding-bottom: 10px;
  touch-action: none;
}
.pedal span { pointer-events: none; text-shadow: 0 1px 3px #000; }
#pedalBrake { left: calc(16px + var(--safe-l)); bottom: calc(16px + var(--safe-b)); width: 190px; height: 130px; }
#pedalGas { right: calc(16px + var(--safe-r)); bottom: calc(16px + var(--safe-b)); width: 130px; height: 190px; }
#pedalBrake.on { background-color: rgba(208, 2, 27, 0.85); transform: translateY(3px); }
#pedalGas.on { background-color: rgba(15, 157, 107, 0.85); transform: translateY(3px); }

.wink {
  position: absolute; width: 84px; height: 84px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85); background: rgba(20, 26, 33, 0.78);
  padding: 14px; touch-action: none;
}
.wink svg { width: 100%; height: 100%; display: block; }
.wink path { fill: #fff; }
#winkL { left: calc(22px + var(--safe-l)); bottom: calc(162px + var(--safe-b)); }
#winkR { right: calc(39px + var(--safe-r)); bottom: calc(222px + var(--safe-b)); }
.wink.on { background: var(--amber); border-color: #fff; animation: blink 0.7s steps(1) infinite; }
.wink.on path { fill: #1a1f26; }
@keyframes blink { 0% { opacity: 1; } 50% { opacity: 0.35; } }

#flash { position: fixed; inset: 0; background: rgba(208, 2, 27, 0.5); pointer-events: none; }
#flash.run { animation: flashOut 0.7s ease-out forwards; }
@keyframes flashOut { from { opacity: 1; } to { opacity: 0; } }

#countdown {
  position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%);
  font-size: 170px; font-weight: 800; color: #fff; text-shadow: 0 4px 18px rgba(0, 0, 0, 0.7);
  pointer-events: none; font-variant-numeric: tabular-nums;
}

/* ---------- 設定・結果などの画面 ---------- */
.screen {
  position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--paper); display: flex; touch-action: pan-y;
  padding: calc(20px + var(--safe-t)) max(16px, var(--safe-r)) calc(20px + var(--safe-b)) max(16px, var(--safe-l));
}
.screen.dim { background: rgba(10, 15, 20, 0.62); }

.panel {
  background: var(--panel); border-radius: 16px; padding: 26px 32px 28px;
  width: min(900px, 100%); margin: auto; box-shadow: 0 6px 24px rgba(15, 25, 35, 0.14);
}
.panel.narrow { width: min(620px, 100%); }
.panel.wide { width: min(1040px, 100%); }

h1 { font-size: 32px; margin: 0 0 14px; letter-spacing: 0.04em; line-height: 1.3; }
h1::after {
  content: ""; display: block; height: 12px; margin-top: 12px; border-radius: 3px;
  background: repeating-linear-gradient(90deg, var(--paint) 0 30px, transparent 30px 60px) 12px 50% / 100% 3px no-repeat, var(--asphalt);
}
h2 { font-size: 27px; margin: 0 0 12px; line-height: 1.3; }
h3 { font-size: 18px; margin: 0 0 8px; }
.lead { margin: 0 0 18px; max-width: 42em; }
.note, .hint, .meta { color: var(--muted); font-size: 15px; margin: 14px 0 0; }
.meta { margin: 0 0 14px; }

.formGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; }
.field { min-width: 0; }
.fieldLabel { display: block; font-size: 15px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }

.seg { display: flex; border: 2px solid var(--sign-blue); border-radius: 12px; overflow: hidden; }
.seg button {
  flex: 1 1 0; min-width: 0; min-height: 52px; padding: 6px 4px; font-size: 16px;
  background: #fff; border: 0; border-left: 1px solid var(--sign-blue); color: var(--sign-blue-dark);
}
.seg button:first-child { border-left: 0; }
.seg button.sel { background: var(--sign-blue); color: #fff; font-weight: 800; }

input[type="text"] {
  width: 100%; min-height: 56px; font: inherit; font-size: 18px; padding: 8px 12px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
  -webkit-user-select: text; user-select: text;
}

.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.actions.column { flex-direction: column; }
.actions button, .confirm button {
  min-height: 58px; padding: 8px 24px; font-size: 19px; font-weight: 700;
  border-radius: 12px; border: 2px solid var(--sign-blue); background: #fff; color: var(--sign-blue-dark);
}
.actions button.primary { background: var(--sign-blue); color: #fff; min-width: 220px; }
.confirm button.danger { background: var(--sign-red); border-color: var(--sign-red); color: #fff; }
.confirm {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 16px;
  padding: 14px 16px; border: 2px solid var(--sign-red); border-radius: 12px;
}
.confirm span { flex: 1 1 260px; }

.howto { margin: 0 0 16px; padding-left: 1.3em; }
.state { padding: 12px 16px; border-radius: 12px; font-weight: 700; border: 2px solid var(--line); }
.state.ok { border-color: var(--go); color: #0a6f4b; }
.state.ok::before { content: "○ "; }
.state.warn { border-color: var(--amber); color: #8a5a00; }
.state.warn::before { content: "△ "; }

/* 結果 */
.review { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.reviewCol { border-radius: 12px; padding: 14px 18px; border: 2px solid var(--line); min-width: 0; }
.reviewCol.good { border-color: var(--go); }
.reviewCol.care { border-color: var(--amber); }
.reviewCol.good h3::before { content: "○ "; color: var(--go); }
.reviewCol.care h3::before { content: "△ "; color: #b97a00; }
.reviewCol ul { margin: 0; padding-left: 1.2em; }
.reviewCol li { margin-bottom: 2px; }
.none { color: var(--muted); margin: 0; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; min-width: 0; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); font-size: 16px; vertical-align: top; }
tbody th { font-weight: 500; color: var(--muted); }
td { font-weight: 700; }
tr:last-child th, tr:last-child td { border-bottom: 0; }
.cmp thead th { color: var(--muted); font-size: 14px; }
.cmp td, .cmp thead th:not(:first-child) { text-align: right; }
.card td { text-align: right; }

.tableWrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.hist th, .hist td { white-space: nowrap; font-size: 15px; }
.hist thead th { color: var(--muted); font-size: 13px; }
.hist td { font-weight: 500; }

#rotateNotice, #loadError {
  position: fixed; inset: 0; z-index: 50; background: #0e141b; color: #fff;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 26px; font-weight: 700; padding: 24px;
}

@media (max-width: 720px) {
  .formGrid, .review, .cards { grid-template-columns: 1fr; }
  .panel { padding: 20px 18px 22px; }
}
/* 幅のせまい画面では上の表示を小さくして重ならないようにする */
@media (max-width: 940px) {
  #speedNum { font-size: 34px; }
  #speedUnit { font-size: 13px; padding-bottom: 3px; }
  #limitSign { width: 42px; height: 42px; border-width: 5px; font-size: 16px; margin-left: 2px; }
  #speedBox { padding: 5px 8px 5px 10px; gap: 5px; }
  #navBox { padding: 6px 14px 6px 10px; gap: 8px; }
  #navArrow { width: 48px; height: 48px; }
  #navMain { font-size: 24px; }
  #navSub { font-size: 15px; }
  #progress { font-size: 13px; padding: 8px 8px; }
  #btnPause { min-width: 64px; min-height: 48px; font-size: 16px; }
  #topRight { gap: 6px; }
  #toast { top: calc(92px + var(--safe-t)); font-size: 21px; }
}
@media (max-width: 640px) {
  #progress { display: none; }
}
@media (max-height: 560px) {
  #pedalBrake { width: 150px; height: 100px; }
  #pedalGas { width: 104px; height: 150px; }
  #winkL { bottom: calc(126px + var(--safe-b)); }
  #winkR { bottom: calc(176px + var(--safe-b)); right: calc(26px + var(--safe-r)); }
  #wheelBox { width: 88px; height: 88px; }
  #navMain { font-size: 26px; }
  #navArrow { width: 52px; height: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  .wink.on { animation: none; }
  #flash.run { animation-duration: 0.2s; }
}
