/* だんじりGO
   モチーフ：藍染めの手ぬぐい。藍の布に白抜きの字。朱は房（目標を果たした印）と道の矢羽だけ。
   布の縁には縫い目を一本。動きは「綱が張る」＝すっと引かれて、ぴたりと止まる（跳ねない）。 */

:root {
  --ai: #1b2a44;
  --ai-2: #24385a;
  --ai-line: #3d5580;
  --sarashi: #eef0ea;
  --sarashi-dim: #b8c2d2;
  --shu: #d0402a;
  --shu-light: #ffb8a8;
  --sumi: #191714;
  --pull: cubic-bezier(.2, .9, .25, 1);
  --display: 'Dela Gothic One', 'Hiragino Sans', 'Yu Gothic', sans-serif;
  --body: 'BIZ UDPGothic', 'Hiragino Sans', 'Yu Gothic', 'Meiryo', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ai); overflow: hidden; }
body {
  font-family: var(--body);
  color: var(--sarashi);
  font-size: 16px;
  line-height: 1.6;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
canvas#cv { position: fixed; inset: 0; display: block; touch-action: none; }
/* 木綿の織り目を画面全体にごく薄く（コードで描いた所と絵の質感をそろえる） */
#weave { position: fixed; inset: 0; pointer-events: none; z-index: 1; background: url(img/weave.png) 0 0 / 72px 72px; opacity: .55; }
#vig { position: fixed; inset: 0; pointer-events: none; z-index: 1; opacity: .28; background: radial-gradient(ellipse 75% 70% at 50% 55%, rgba(10,8,6,0) 45%, rgba(10,8,6,.7) 100%); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--sarashi); outline-offset: 2px; }

/* ---------- 走行中 ---------- */
#touch { position: fixed; inset: 0; z-index: 5; touch-action: none; }
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.tag {
  background: rgba(27, 42, 68, .92);
  border: 1px solid var(--ai-line);
  border-radius: 5px;
  color: var(--sarashi);
}
.hud-top {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(10px + env(safe-area-inset-top)) 12px 0;
}
.timebox { padding: 4px 12px 6px; min-width: 132px; }
#time { font-family: var(--display); font-size: 30px; line-height: 1.15; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
#time small { font-family: var(--body); font-weight: 700; font-size: 14px; margin-left: 3px; }
#delta { font-size: 13px; font-weight: 700; min-height: 0; }
#delta:empty { display: none; }
#delta.ahead { color: var(--sarashi); }
#delta.behind { color: var(--shu-light); }
#btnPause { pointer-events: auto; padding: 9px 12px; font-size: 14px; font-weight: 700; }

.next {
  position: absolute; left: 0; top: 0;
  padding: 5px 12px 6px; text-align: center; white-space: nowrap;
  font-size: 13px; font-weight: 700;
  will-change: transform;
}
.next b { display: block; font-family: var(--display); font-weight: 400; font-size: 20px; line-height: 1.2; }
.next small { display: block; font-size: 11px; color: var(--sarashi-dim); }
.next b + small { margin-top: 1px; }

#coach {
  position: absolute; left: 50%; top: 31%; transform: translateX(-50%);
  max-width: 88vw; text-align: center;
  font-family: var(--display); font-size: 22px; line-height: 1.3;
  text-shadow: 0 0 4px var(--ai), 0 0 2px var(--ai), 0 2px 0 var(--ai);
}
#coach:empty { display: none; }
/* 無限モード：命（朱の提灯の形。なくした分は縁だけ） */
.lives { display: flex; align-items: center; gap: 5px; margin-top: 4px; font-size: 12px; font-weight: 700; color: var(--sarashi-dim); }
.lives span { margin-right: 2px; }
.lives i { display: inline-block; width: 11px; height: 15px; border-radius: 45% / 40%; border: 1.5px solid var(--sarashi-dim); }
/* 追っ手までの差（遠いほど棒が長い。近いと朱でゆれる） */
.chase { display: flex; align-items: center; gap: 5px; margin-top: 3px; font-size: 11px; font-weight: 700; color: var(--sarashi-dim); }
.chase .bar { position: relative; width: 44px; height: 6px; border: 1.5px solid var(--sarashi-dim); border-radius: 2px; overflow: hidden; }
.chase .bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; background: var(--sarashi); }
.chase b { font-family: var(--display); font-weight: 400; font-size: 15px; color: var(--sarashi); min-width: 1.6em; text-align: right; font-variant-numeric: tabular-nums; }
.chase.near { color: #f6c7bd; }
.chase.near .bar { border-color: var(--shu); }
.chase.near .bar i, .chase.near b { background: var(--shu); color: #fff; }
.chase.near b { background: none; color: #ff9b86; animation: chaseBeat .5s ease-in-out infinite alternate; }
@keyframes chaseBeat { from { opacity: 1; } to { opacity: .45; } }
.lives i.on { background: var(--shu); border-color: #f2b3a6; box-shadow: inset 0 3px 0 -1px rgba(0,0,0,.25), inset 0 -3px 0 -1px rgba(0,0,0,.25); }
/* 町内の名前・距離の節目（画面の上の方にすっと出て消える） */
#banner {
  position: absolute; left: 50%; top: 22%; transform: translate(-50%, 8px);
  text-align: center; pointer-events: none; opacity: 0; white-space: nowrap;
  font-family: var(--display); font-size: 34px; line-height: 1.1; letter-spacing: .06em;
  background: var(--ai); padding: 6px 20px 8px; border-radius: 6px; box-shadow: 0 0 0 1.5px rgba(238,240,234,.5) inset;
}
#banner small { display: block; font-family: var(--body); font-weight: 700; font-size: 13px; letter-spacing: .1em; color: var(--sarashi-dim); }
#banner.on { animation: banner 1.8s var(--pull) both; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, 8px); } 12% { opacity: 1; transform: translate(-50%, 0); } 78% { opacity: 1; } 100% { opacity: 0; } }
#coach.big { font-size: 40px; background: var(--shu); padding: 2px 18px 6px; border-radius: 6px; text-shadow: none; }

#bubble {
  position: absolute; left: 50%; top: calc(106px + env(safe-area-inset-top)); transform: translate(-50%, 6px);
  text-align: center;
  opacity: 0; transition: opacity .12s, transform .16s var(--pull);
  white-space: nowrap;
}
#bubble.on { opacity: 1; transform: translate(-50%, 0); }
/* 白い道の上でも読めるよう、藍の札に白抜き（第5版） */
#bubble.ok { font-family: var(--display); font-size: 26px; line-height: 1.15; background: var(--ai); padding: 4px 14px 6px; border-radius: 5px; box-shadow: 0 0 0 1.5px rgba(238,240,234,.55) inset; text-shadow: none; }
#bubble.hit { font-size: 14px; font-weight: 700; background: var(--shu); padding: 3px 10px; border-radius: 4px; line-height: 1.4; }
#bubble small { display: block; font-family: var(--body); font-weight: 700; font-size: 13px; }
#bubble.ok small { color: #ffd2c6; }

.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.speedbox { padding: 3px 10px 5px; text-align: right; min-width: 92px; transition: border-color .2s, box-shadow .2s; }
.speedbox b { font-family: var(--display); font-weight: 400; font-size: 22px; font-variant-numeric: tabular-nums; }
.speedbox small { font-size: 11px; margin-left: 2px; color: var(--sarashi-dim); }
.speedbox .mom { display: flex; align-items: center; justify-content: flex-end; gap: 5px; font-size: 11px; color: var(--sarashi-dim); }
.speedbox .mom i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--sarashi-dim); margin-left: 3px; }
.speedbox .mom i.on { background: var(--shu); border-color: var(--shu); }
.speedbox.lit { border-color: var(--shu); box-shadow: 0 0 0 1px var(--shu); }

#pad {
  position: absolute; left: 10px; right: 10px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  text-align: center;
}
.pad-hint { margin: 0 0 6px; font-weight: 700; font-size: 15px; letter-spacing: .04em; text-shadow: 0 0 3px var(--ai), 0 1px 0 var(--ai); }
.pads { display: flex; gap: 10px; }
.pad-area {
  flex: 1; height: 70px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(27, 42, 68, .5);
  border: 1.5px dashed rgba(238, 240, 234, .55);
  transition: background .06s, border-color .06s;
}
.pad-area b { font-family: var(--display); font-weight: 400; font-size: 22px; }
.pad-area.on { background: rgba(238, 240, 234, .3); border-style: solid; border-color: var(--sarashi); }
#pad.quiet .pad-hint { display: none; }
#pad.quiet .pad-area { height: 46px; background: rgba(27, 42, 68, .22); border-color: rgba(238, 240, 234, .22); }
#pad.quiet .pad-area b { font-size: 15px; opacity: .55; }
#pad.quiet .pad-area.on { background: rgba(238, 240, 234, .22); border-color: rgba(238, 240, 234, .7); }
#pad.quiet .pad-area.on b { opacity: 1; }
.next.left { border-color: #6f8db8; }

/* ---------- 藍の布 ---------- */
.cloth {
  position: fixed; z-index: 20;
  background-color: var(--ai);
  /* 木綿の織り目（ごく薄く） */
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0,0,0,.05) 0 1px, transparent 1px 3px);
}
.cloth::before {
  /* 縫い目 */
  content: ''; position: absolute; left: 10px; right: 10px; top: 7px;
  border-top: 1.5px dashed rgba(238, 240, 234, .32);
  pointer-events: none;
}
.sheet, .title {
  left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(100%, 470px);
  max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  padding: 26px 22px calc(18px + env(safe-area-inset-bottom));
  border-radius: 10px 10px 0 0;
  animation: pull .2s var(--pull) both;
}
@keyframes pull { from { transform: translate(-50%, 36px); opacity: .4; } to { transform: translate(-50%, 0); opacity: 1; } }

.kicker { margin: 0; font-weight: 700; font-size: 17px; color: var(--sarashi-dim); }
.kicker.big { font-family: var(--display); font-weight: 400; font-size: 30px; color: var(--sarashi); line-height: 1.25; }
.bigtime { margin: 0; font-family: var(--display); font-size: 66px; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.bigtime span { font-family: var(--body); font-weight: 700; font-size: 22px; margin-left: 6px; }
.sub { margin: 6px 0 0; font-size: 17px; font-weight: 700; }
.sub p { margin: 2px 0; }
.unlock { margin: 12px 0 0; padding: 8px 12px; border-left: 4px solid var(--shu); background: var(--ai-2); font-size: 15px; font-weight: 700; }
.unlock span { display: block; }
.unlock span + span { margin-top: 2px; }
.note { margin: 8px 0 0; font-size: 15px; color: var(--sarashi-dim); line-height: 1.55; }
.note:empty { display: none; }
.fine { margin: 14px 0 0; font-size: 12px; color: rgba(184, 194, 210, .78); line-height: 1.5; }

.focus { margin-top: 16px; padding-top: 14px; border-top: 1.5px dashed rgba(238, 240, 234, .32); }
.focus h3 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 21px; line-height: 1.3; }
.focus p { margin: 4px 0 0; }
.map { display: block; width: 100%; height: 180px; margin-top: 10px; border-radius: 4px; }

.actions { display: grid; gap: 10px; margin-top: 18px; }
.btn {
  display: block; width: 100%; border-radius: 6px; border: 0;
  transition: transform .06s;
}
.btn:active { transform: translateY(2px); }
.btn.main {
  height: 60px; background: var(--sarashi); color: var(--ai);
  font-family: var(--display); font-size: 24px; letter-spacing: .04em;
}
.btn.line {
  height: 52px; background: transparent; color: var(--sarashi);
  border: 1.5px solid rgba(238, 240, 234, .75);
  font-weight: 700; font-size: 17px;
}
.links { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 12px; }
.link {
  background: none; border: 0; padding: 8px 0;
  color: var(--sarashi-dim); font-size: 15px; font-weight: 700;
  text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px;
}
.link.small { font-size: 13px; padding: 2px 0 10px; display: block; }
.link.warn { color: var(--shu-light); }

.detail { margin-top: 10px; }
.detail table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.detail th, .detail td { text-align: right; padding: 5px 4px; border-bottom: 1px solid var(--ai-line); }
.detail th:first-child, .detail td:first-child { text-align: left; }
.detail th { color: var(--sarashi-dim); font-weight: 700; }
.detail .behind { color: var(--shu-light); }
.tiny { font-size: 12px; color: var(--sarashi-dim); margin: 6px 0 0; }

/* ---------- はじめの画面 ---------- */
.title { padding-top: 30px; }
/* 上の飾り：型染めの見本画（img/title.webp）。下は藍の布へ溶かす */
.title .key {
  height: clamp(132px, 38vw, 184px); margin: -30px -22px 10px;
  background: url(img/title.webp) center 38% / cover no-repeat;
  -webkit-mask-image: linear-gradient(to bottom, #000 62%, transparent);
  mask-image: linear-gradient(to bottom, #000 62%, transparent);
  border-radius: 10px 10px 0 0;
}
.title h1 {
  margin: 0; font-family: var(--display); font-weight: 400;
  font-size: clamp(52px, 17vw, 76px); line-height: 1; letter-spacing: .02em;
}
.title h1 span { margin-left: .06em; }
.tagline { margin: 8px 0 18px; font-size: 18px; font-weight: 700; }
.ch-card { margin: 0 0 14px; padding: 12px 14px; background: var(--ai-2); border-left: 4px solid var(--shu); }
.ch-card p { margin: 0 0 10px; font-size: 15px; }

/* ---------- 町 ---------- */
.town { inset: 0; overflow-y: auto; padding: calc(26px + env(safe-area-inset-top)) max(20px, calc(50% - 215px)) calc(24px + env(safe-area-inset-bottom)); }
.town h2 { margin: 0 0 6px; font-family: var(--display); font-weight: 400; font-size: 34px; }
.town h3 { margin: 22px 0 8px; font-size: 16px; font-weight: 700; color: var(--sarashi-dim); }
.course {
  display: grid; grid-template-columns: 1fr auto; gap: 0 12px; align-items: baseline;
  width: 100%; text-align: left; padding: 14px 4px 12px 14px;
  background: none; border: 0; border-bottom: 1.5px dashed rgba(238, 240, 234, .3);
  border-left: 4px solid transparent;
}
.course.sel { border-left-color: var(--sarashi); }
.course:active { background: var(--ai-2); }
.course.locked { opacity: .5; cursor: default; }
.c-name { font-family: var(--display); font-size: 26px; line-height: 1.2; }
.c-sub { font-size: 14px; color: var(--sarashi-dim); text-align: right; }
.c-best { grid-column: 1 / -1; font-size: 15px; margin-top: 2px; }
.c-best b { font-family: var(--display); font-weight: 400; font-size: 20px; margin: 0 2px; }
.c-goals { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 14px; color: var(--sarashi-dim); }
.c-goals i { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--sarashi-dim); display: inline-block; }
.c-goals i.on { background: var(--shu); border-color: var(--shu); }
.c-goals em { font-style: normal; margin-left: 6px; }

.seg { display: flex; border: 1.5px solid var(--sarashi-dim); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; padding: 10px 4px; background: none; border: 0; font-weight: 700; font-size: 15px; color: var(--sarashi-dim); }
.seg button + button { border-left: 1.5px solid var(--sarashi-dim); }
.seg button.on { background: var(--sarashi); color: var(--ai); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px 7px 8px; border-radius: 6px; background: var(--ai-2); border: 1.5px solid transparent; font-weight: 700; font-size: 15px; }
.chip i { width: 18px; height: 18px; border-radius: 3px; background: var(--c); border: 1px solid rgba(255,255,255,.4); }
.chip.on { border-color: var(--sarashi); }
.chip.locked { opacity: .45; }

/* ---------- 設定 ---------- */
.sw { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--ai-line); font-weight: 700; }
.sw input { width: 22px; height: 22px; accent-color: var(--sarashi); }

#toast {
  position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top)); z-index: 40;
  transform: translate(-50%, -8px); opacity: 0; pointer-events: none;
  background: var(--sarashi); color: var(--ai); font-weight: 700; font-size: 15px;
  padding: 8px 14px; border-radius: 6px; transition: opacity .15s, transform .18s var(--pull);
  max-width: 90vw; text-align: center;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .sheet, .title { animation: none; }
  #bubble, #toast, .btn { transition: none; }
  #banner.on { animation-name: bannerFade; } /* 動きを減らす設定では、出て消えるだけ */
}
@keyframes bannerFade { 0%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, 0); } }
@media (orientation: landscape) and (max-height: 520px) {
  .sheet, .title { max-height: 100vh; max-height: 100dvh; border-radius: 0; }
  .bigtime { font-size: 48px; }
  .title h1 { font-size: 48px; }
  .map { height: 140px; }
  .pad-area { height: 48px; }
}
