/* 白線マグマ：路面標示（道路の白いペンキ）を見た目の軸にする。
   アスファルト＝背景、白ペンキ＝押せる物、マグマ＝危ない・熱い、黄と黒のしま＝注意。 */
:root {
  --asphalt: #141518;
  --asphalt-2: #1d1f23;
  --asphalt-3: #2a2d32;
  --paint: #f1efe7;
  --paint-shade: #cfccc2;
  --ink: #121316;
  --muted: #9a9ea5;
  --magma: #ff4d1a;
  --magma-deep: #b52805;
  --hazard: #f5c400;
  --scan: #6fdcff;
  --font: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  --num: "DIN Condensed", "DINCondensed-Bold", "Bahnschrift", "Roboto Condensed", "Arial Narrow", sans-serif-condensed, sans-serif;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --stage-w: min(100vw, 560px);
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.14'/%3E%3C/svg%3E");
  color-scheme: dark;
}

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

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}
body {
  background: var(--asphalt) var(--noise);
  color: var(--paint);
  font-family: var(--font);
  line-height: 1.6;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
input { font-size: 16px; }
svg { display: block; }

/* ---------- 押せる物 ---------- */
/* 白ペンキの帯（いちばん押してほしいボタン） */
.paint-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 8px 18px;
  border: 0;
  border-radius: 6px;
  background: var(--paint);
  color: var(--ink);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: inset 0 -4px 0 var(--paint-shade);
  transition: transform 140ms var(--ease-out), box-shadow 140ms var(--ease-out);
}
.paint-btn.big { min-height: 64px; font-size: 22px; }
.paint-btn small { font-size: 12px; font-weight: 600; letter-spacing: 0; color: #55585e; }
.paint-btn:active { transform: translateY(2px) scale(0.985); box-shadow: inset 0 -2px 0 var(--paint-shade); }
.paint-btn[disabled] { opacity: 0.5; }

/* 破線（2番目のボタン） */
.lane-btn {
  width: 100%;
  min-height: 48px;
  padding: 8px 14px;
  border: 2px dashed rgba(241, 239, 231, 0.55);
  border-radius: 6px;
  background: transparent;
  font-size: 15px;
  font-weight: 700;
  transition: transform 140ms var(--ease-out), border-color 140ms;
}
.lane-btn:active { transform: scale(0.97); border-color: var(--paint); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 21, 24, 0.55);
  font-size: 26px;
  line-height: 1;
  transition: transform 140ms var(--ease-out);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { transform: scale(0.92); }

@media (hover: hover) and (pointer: fine) {
  .paint-btn:hover { background: #fff; }
  .lane-btn:hover { border-color: var(--paint); }
  .t-nav button:hover, .tabs button:hover, .chips button:hover, .seg button:hover { color: var(--paint); }
}

/* ---------- ゲームの画面（パソコンではスマホくらいの幅） ---------- */
.stage {
  position: fixed;
  inset: 0;
  width: var(--stage-w);
  margin: 0 auto;
  overflow: hidden;
  background: #000;
}
/* カメラの映像はキャンバスの真下に敷く（見えない動画は更新を止める端末があるため、小さく隠さない） */
#cam, #gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#cam { object-fit: cover; pointer-events: none; }
.stage.shake #gl { animation: shake 320ms linear; }
@keyframes shake {
  0%, 100% { transform: none; }
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(5px, -4px); }
  60% { transform: translate(-4px, -2px); }
  80% { transform: translate(3px, 3px); }
}

.screen { display: none; }
body[data-screen="title"] #screen-title,
body[data-screen="play"] #screen-play,
body[data-screen="result"] #screen-result,
body[data-screen="records"] #screen-records,
body[data-screen="ranking"] #screen-ranking { display: flex; }

/* ---------- タイトル ---------- */
#screen-title {
  position: absolute;
  inset: 0;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 20px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: linear-gradient(180deg, rgba(20, 21, 24, 0) 22%, rgba(20, 21, 24, 0.86) 50%, var(--asphalt) 70%);
}
.t-top { display: flex; align-items: center; justify-content: space-between; }
.tag {
  padding: 3px 8px;
  background: var(--hazard);
  color: var(--ink);
  font: 700 12px/1.2 var(--num);
  letter-spacing: 0.18em;
}
.t-main { display: flex; flex-direction: column; gap: 12px; }

/* 路面の文字のように縦長に */
.logo {
  margin: 0 0 10px;
  display: flex;
  align-items: baseline;
  gap: 0.04em;
  font-size: clamp(54px, 17vw, 84px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  transform: scaleY(1.42);
  transform-origin: left bottom;
}
.logo-w { color: var(--paint); }
.logo-m { color: var(--magma); }
.tagline { margin: 0; font-size: 16px; font-weight: 700; }
.best { margin: -4px 0 4px; min-height: 1.5em; font-size: 13px; color: #c4c7cc; }
.best b { font: 700 18px/1 var(--num); color: var(--paint); letter-spacing: 0.02em; }

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  position: relative;
  width: 44px;
  height: 26px;
  flex: none;
  border-radius: 13px;
  background: var(--asphalt-3);
  transition: background 160ms;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--paint);
  transition: transform 180ms var(--ease-out);
}
.switch input:checked + .track { background: var(--magma); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:checked ~ span:last-child { color: var(--paint); }
.switch input:focus-visible + .track { outline: 2px solid var(--paint); outline-offset: 2px; }

.t-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 2px dashed rgba(241, 239, 231, 0.18);
}
.t-nav button {
  min-height: 48px;
  border: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.t-nav button:active { color: var(--paint); }

/* ---------- プレイ中 ---------- */
#screen-play, .switch {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#screen-play {
  position: absolute;
  inset: 0;
  flex-direction: column;
  touch-action: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0) 22%);
}
.hud {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 14px 0 18px;
  pointer-events: none;
}
.hud .icon-btn { pointer-events: auto; }
.hud-dist {
  font-family: var(--num);
  font-weight: 700;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55);
}
.hud-dist b { font-size: 64px; font-weight: 700; }
.hud-dist i { margin-left: 4px; font-size: 26px; font-style: normal; }
.hud-sub {
  display: flex;
  gap: 12px;
  margin-top: 4px;
  font: 700 17px/1 var(--num);
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}
.lives { color: var(--magma); letter-spacing: 3px; }

/* 足あと：次に足を置く場所（判定する丸と同じ大きさ） */
.marker {
  position: absolute;
  left: 50%;
  top: 72%;
  width: calc(var(--stage-w) * 0.11);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--paint), inset 0 0 0 2px var(--paint);
  pointer-events: none;
  transition: border-color 120ms;
}
/* 白の上でも、マグマの上でも見えるよう、黒い足あとに白いふち */
.marker svg {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54%;
  transform: translate(-50%, -50%);
  fill: var(--ink);
  stroke: var(--paint);
  stroke-width: 3px;
  paint-order: stroke;
  transition: fill 120ms;
}
.marker.off { border-color: var(--magma); }
.marker.off svg { fill: var(--magma); }
.marker.hit svg { animation: press 220ms var(--ease-out); }
@keyframes press {
  from { transform: translate(-50%, -50%) scale(1.3); }
  to { transform: translate(-50%, -50%) scale(1); }
}

.coach {
  position: absolute;
  left: 50%;
  top: 27%;
  transform: translate(-50%, -50%);
  padding: 12px 18px;
  border-radius: 8px;
  background: rgba(20, 21, 24, 0.82);
  text-align: center;
  font-size: 15px;
  pointer-events: none;
}
.coach p { margin: 0; }

.hint {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  margin: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 700 150px/1 var(--num);
  color: var(--paint);
  -webkit-text-stroke: 10px var(--ink);
  paint-order: stroke fill;
  pointer-events: none;
}
.countdown:empty { display: none; }
.countdown span { animation: count 700ms var(--ease-out) both; }
@keyframes count {
  from { transform: scale(1.25); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.ouch {
  position: absolute;
  left: 0;
  right: 0;
  top: 38%;
  text-align: center;
  font-size: 44px;
  font-weight: 900;
  color: var(--paint);
  -webkit-text-stroke: 8px var(--ink);
  paint-order: stroke fill;
  pointer-events: none;
  opacity: 0;
}
.ouch.show { animation: ouch 900ms var(--ease-out); }
@keyframes ouch {
  from { opacity: 0; transform: scale(0.9); }
  15% { opacity: 1; transform: scale(1); }
  70% { opacity: 1; }
  to { opacity: 0; }
}

/* 工事中のしま（注意） */
.hazard {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(env(safe-area-inset-top, 0px) + 120px);
  padding: 6px 0;
  background: repeating-linear-gradient(-45deg, var(--hazard) 0 14px, var(--ink) 14px 28px);
}
.hazard span {
  display: block;
  margin: 0 12px;
  padding: 8px 10px;
  background: var(--hazard);
  color: var(--ink);
  font-weight: 900;
  text-align: center;
}

/* ---------- 結果・きろく・ランキング ---------- */
.page {
  position: fixed;
  inset: 0;
  align-items: flex-start;
  background: var(--asphalt) var(--noise);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.page-in {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 20px calc(env(safe-area-inset-bottom, 0px) + 28px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.res-hero {
  position: relative;
  margin: calc(-18px - env(safe-area-inset-top, 0px)) -20px 0;
  padding: calc(env(safe-area-inset-top, 0px) + 26px) 20px 22px;
  overflow: hidden;
}
.res-hero.magma {
  background:
    radial-gradient(120% 90% at 30% 120%, #ffb21e 0%, var(--magma) 35%, var(--magma-deep) 70%, #4a0d02 100%);
}
.res-hero.magma::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 18px;
  background: var(--asphalt) var(--noise);
  -webkit-mask: radial-gradient(14px 12px at 14px 0, transparent 98%, #000) 0 0 / 28px 18px repeat-x;
  mask: radial-gradient(14px 12px at 14px 0, transparent 98%, #000) 0 0 / 28px 18px repeat-x;
}
.res-reason { margin: 0; font-size: 22px; font-weight: 900; }
.res-dist {
  margin-top: 4px;
  font-family: var(--num);
  font-weight: 700;
  line-height: 0.85;
  font-variant-numeric: tabular-nums;
}
.res-dist b { font-size: clamp(96px, 34vw, 150px); font-weight: 700; }
.res-dist i { margin-left: 6px; font-size: 40px; font-style: normal; }
.res-meta { margin: 10px 0 0; font: 700 18px/1.3 var(--num); letter-spacing: 0.03em; }
.res-meta span + span::before { content: "／"; margin: 0 8px; opacity: 0.6; font-family: var(--font); font-size: 14px; }
.badge {
  display: inline-block;
  margin: 12px 0 0;
  padding: 4px 10px;
  background: var(--hazard);
  color: var(--ink);
  font-weight: 900;
  font-size: 14px;
  transform: rotate(-2deg);
  animation: badge 360ms var(--ease-out) 200ms both;
}
@keyframes badge { from { opacity: 0; transform: rotate(-2deg) scale(1.2); } }

.rank-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 8px;
  background: var(--asphalt-2);
}
.rank-preview { margin: 0; font-size: 15px; font-weight: 700; }
.rank-preview:empty { display: none; }
.rank-preview b { font: 700 26px/1 var(--num); color: var(--paint); margin: 0 2px; }
.rank-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.rank-form .paint-btn { flex: 1 1 auto; width: auto; min-height: 48px; font-size: 15px; }
.nick { flex: 1 1 170px; display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); min-width: 0; }
.nw { white-space: nowrap; }
.nick input {
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 0;
  border-bottom: 2px solid var(--paint);
  border-radius: 4px 4px 0 0;
  background: var(--asphalt-3);
  color: var(--paint);
}
.nick input:focus { outline: none; background: #33373d; }
.msg { margin: 0; font-size: 14px; font-weight: 700; }
.msg:empty { display: none; }
.msg.ok { color: var(--scan); }
.msg.err { color: var(--hazard); }
.msg a { color: inherit; }

.res-actions { display: flex; flex-direction: column; gap: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.map-card h2 { margin: 0 0 8px; font-size: 15px; }
.map {
  height: 240px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--asphalt-2);
}
.map.empty {
  display: grid;
  place-items: center;
  height: 96px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.map canvas { display: block; width: 100%; height: 100%; }
.map .leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(0.8) contrast(0.9); }
.map .leaflet-container { background: var(--asphalt-2); }

.note { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.fine { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }

.page-head { display: flex; align-items: center; gap: 8px; }
.page-head h2 { margin: 0; font-size: 20px; }

.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.tabs button {
  min-height: 46px;
  border: 0;
  border-bottom: 3px solid var(--asphalt-3);
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  font-size: 15px;
}
.tabs button.on { color: var(--paint); border-bottom-color: var(--paint); }
.chips { display: flex; gap: 8px; }
.chips button {
  min-height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 18px;
  background: var(--asphalt-2);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}
.chips button.on { background: var(--paint); color: var(--ink); }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.list li > button, .list li > div {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 8px 14px 8px 8px;
  border: 0;
  border-radius: 6px;
  background: var(--asphalt-2);
  text-align: left;
}
.list li > button:active { background: var(--asphalt-3); }
.list .rk {
  display: grid;
  place-items: center;
  height: 40px;
  border-radius: 4px;
  background: var(--asphalt-3);
  font: 700 22px/1 var(--num);
  color: var(--paint);
}
.list .rk.word { font: 800 12px/1 var(--font); }
.rank li:nth-child(1) .rk { background: var(--paint); color: var(--ink); }
.rank li:nth-child(2) .rk, .rank li:nth-child(3) .rk { background: var(--paint-shade); color: var(--ink); }
.list .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }
.list .who small { display: block; font-weight: 600; font-size: 12px; color: var(--muted); }
.list .d { font: 700 26px/1 var(--num); font-variant-numeric: tabular-nums; }
.list .d i { margin-left: 2px; font-size: 15px; font-style: normal; color: var(--muted); }
.list .me > div { box-shadow: inset 4px 0 0 var(--magma); }
.list .empty { padding: 28px 12px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- 下から出るシート ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}
.sheet-in {
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 20px calc(env(safe-area-inset-bottom, 0px) + 18px);
  border-radius: 14px 14px 0 0;
  border-top: 6px solid var(--paint);
  background: var(--asphalt) var(--noise);
  animation: sheet 260ms var(--ease-drawer);
}
@keyframes sheet { from { transform: translateY(32px); opacity: 0; } }
.sheet h2 { margin: 0 0 4px; font-size: 22px; }
.sheet h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); }

.rules { list-style: none; margin: 14px 0 0; padding: 0; counter-reset: r; display: flex; flex-direction: column; gap: 12px; }
.rules li {
  counter-increment: r;
  display: grid;
  grid-template-columns: 40px 1fr;
  column-gap: 12px;
  align-items: start;
}
.rules li::before {
  content: counter(r);
  grid-row: span 2;
  display: grid;
  place-items: center;
  height: 40px;
  border-radius: 4px;
  background: var(--paint);
  color: var(--ink);
  font: 700 26px/1 var(--num);
}
.rules b { font-size: 18px; line-height: 1.35; }
.rules span { font-size: 14px; color: var(--muted); }
.more { margin-top: 16px; font-size: 14px; }
.more summary { min-height: 40px; display: flex; align-items: center; color: var(--muted); font-weight: 700; cursor: pointer; }
.more ul { margin: 4px 0 0; padding-left: 1.2em; color: #c9cbcf; }
.more li { margin: 4px 0; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
#btn-agree { font-size: clamp(16px, 5vw, 20px); white-space: nowrap; }

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
}
.seg button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border: 0;
  border-radius: 6px;
  background: var(--asphalt-2);
  color: var(--muted);
  font-weight: 800;
  line-height: 1.3;
  transition: background 120ms, color 120ms;
}
.seg button small { font-size: 11px; font-weight: 600; }
.seg button.on { background: var(--paint); color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  .stage.shake #gl { animation: none; }
  .countdown span, .marker.hit svg, .badge, .sheet-in { animation-duration: 1ms; }
}
