:root {
  --ink: #16161a;
  --yellow: #ffcf1a;
  --paper: #fbf7ee;
  --red: #ff4a3d;
  --green: #2f9a68;
  --purple: #7b3ea6;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

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

button {
  font-family: var(--font);
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---- HUD ---- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud[hidden] { display: none; }
.hud-left {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: 12px;
  display: grid;
  gap: 6px;
  width: min(46vw, 230px);
}
.scorebox {
  display: flex;
  align-items: baseline;
  gap: 8px;
  text-shadow: 0 2px 0 var(--ink), 0 0 10px rgba(0, 0, 0, 0.5);
}
#score { font-size: clamp(26px, 7.5vw, 40px); font-weight: 900; letter-spacing: 0.01em; font-variant-numeric: tabular-nums; }
#dist { font-size: 14px; font-weight: 800; opacity: 0.9; font-variant-numeric: tabular-nums; }
.meter label {
  display: block;
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 2px;
  text-shadow: 0 1px 0 var(--ink), 0 0 6px rgba(0, 0, 0, 0.6);
}
.bar {
  height: 11px;
  border-radius: 6px;
  background: rgba(22, 22, 26, 0.72);
  border: 2px solid var(--ink);
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, #7ad97a, #b8ef6a);
  transition: transform 0.12s linear;
}
#gutsMeter.low .bar i { background: linear-gradient(90deg, #ff4a3d, #ff8a3d); animation: blink 0.5s steps(2) infinite; }
#feverMeter .bar i { background: linear-gradient(90deg, var(--green), var(--purple)); }
body.fever #feverMeter .bar i { background: linear-gradient(90deg, #ff4a3d, #ffcf1a, #6bdc7a, #4ab0ff, #b36bff); animation: rainbow 0.4s linear infinite; }
@keyframes blink { 50% { opacity: 0.35; } }
@keyframes rainbow { 50% { filter: hue-rotate(90deg) brightness(1.2); } }

#combo {
  position: absolute;
  top: calc(26% + var(--safe-t));
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s;
  text-shadow: 0 3px 0 var(--ink), 0 0 14px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}
#combo.show { opacity: 1; }
#combo.pop { animation: comboPop 0.28s ease-out; }
#combo b { display: block; font-size: clamp(44px, 13vw, 76px); font-weight: 900; line-height: 1; color: var(--yellow); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
#combo span { font-size: clamp(14px, 4vw, 20px); font-weight: 900; }
@keyframes comboPop { 0% { transform: translate(-50%, -50%) scale(1.45); } 100% { transform: translate(-50%, -50%) scale(1); } }

#banner {
  position: absolute;
  top: 40%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(40px, 12vw, 84px);
  font-weight: 900;
  color: var(--yellow);
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  opacity: 0;
  pointer-events: none;
}
#banner.show { animation: bannerIn 1.6s ease-out forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: scale(2.2) rotate(-6deg); }
  15% { opacity: 1; transform: scale(1) rotate(-4deg); }
  75% { opacity: 1; transform: scale(1.04) rotate(-4deg); }
  100% { opacity: 0; transform: scale(0.9) rotate(-4deg) translateY(-30px); }
}

#hint {
  position: absolute;
  left: 50%;
  bottom: calc(64px + var(--safe-b));
  transform: translateX(-50%);
  width: max-content;
  max-width: 92vw;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(22, 22, 26, 0.78);
  border: 2px solid var(--yellow);
  font-size: clamp(12px, 3.5vw, 15px);
  font-weight: 800;
  text-align: center;
  white-space: pre-line;
  line-height: 1.45;
  opacity: 0;
  transition: opacity 0.3s;
}
#hint.show { opacity: 1; }

#dashState {
  position: absolute;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 900;
  background: rgba(22, 22, 26, 0.6);
  color: rgba(251, 247, 238, 0.55);
  border: 2px solid rgba(251, 247, 238, 0.25);
}
#dashState.ready { color: var(--ink); background: var(--yellow); border-color: var(--ink); }

/* ---- ハトカメラ ---- */
#wipe {
  position: absolute;
  top: calc(52px + var(--safe-t));
  right: 10px;
  width: min(36vw, 210px);
  aspect-ratio: 4 / 3;
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow: 0 0 0 2px var(--yellow), 0 6px 16px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  display: none;
}
#wipe.on { display: block; }
#wipe .rec {
  position: absolute;
  left: 6px;
  top: 5px;
  font-size: 10px;
  font-weight: 900;
  padding: 1px 6px 1px 14px;
  border-radius: 4px;
  background: rgba(22, 22, 26, 0.7);
}
#wipe .rec::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1s steps(2) infinite;
}

.corner {
  position: absolute;
  top: calc(10px + var(--safe-t));
  right: 10px;
  display: flex;
  gap: 6px;
  z-index: 5;
}
.corner button {
  min-width: 40px;
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 2px solid var(--ink);
  background: rgba(251, 247, 238, 0.92);
  color: var(--ink);
  font-size: 13px;
}
.corner button[aria-pressed="true"] { opacity: 0.6; }
body:not(.playing) #pauseBtn { display: none; }

/* ---- 演出 ---- */
#popups { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.popup {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  white-space: nowrap;
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  animation: floatUp 0.9s ease-out forwards;
}
.popup.coo { font-size: clamp(22px, 6.5vw, 32px); color: #fff; }
.popup.pts { font-size: clamp(16px, 4.6vw, 22px); color: var(--yellow); animation-delay: 0.05s; opacity: 0; }
.popup.bread { font-size: clamp(18px, 5vw, 24px); color: #ffe7a8; }
.popup.bad { font-size: clamp(24px, 7vw, 34px); color: var(--red); }
.popup.big { font-size: clamp(30px, 9vw, 46px); animation-duration: 2s; }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  30% { transform: translate(-50%, -70%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}

#flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(circle, rgba(255, 60, 40, 0) 40%, rgba(255, 40, 30, 0.55) 100%); }
#flash.on { animation: flash 0.5s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

#speedlines {
  position: absolute;
  inset: -20%;
  pointer-events: none;
  opacity: 0;
  background: repeating-conic-gradient(from 0deg at 50% 45%, rgba(255, 255, 255, 0) 0deg 4deg, rgba(255, 255, 255, 0.28) 4deg 4.5deg);
  -webkit-mask-image: radial-gradient(circle at 50% 45%, transparent 28%, #000 70%);
  mask-image: radial-gradient(circle at 50% 45%, transparent 28%, #000 70%);
  transition: opacity 0.25s;
}
body.dashing #speedlines, body.fever #speedlines { opacity: 1; animation: lines 0.12s steps(2) infinite; }
body.fever #speedlines { background: repeating-conic-gradient(from 0deg at 50% 45%, rgba(255, 207, 26, 0) 0deg 4deg, rgba(255, 207, 26, 0.35) 4deg 4.6deg); }
@keyframes lines { 50% { transform: rotate(1.2deg) scale(1.02); } }

/* ---- 画面（タイトル・一時停止・結果） ---- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: calc(18px + var(--safe-t)) 16px calc(18px + var(--safe-b));
}
.overlay[hidden] { display: none; }
.overlay.dim { justify-content: center; background: rgba(12, 12, 16, 0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }

.title-head { text-align: center; margin-top: 4vh; }
.kicker { margin: 0 0 4px; font-size: clamp(14px, 4vw, 18px); font-weight: 800; text-shadow: 0 2px 0 var(--ink), 0 0 10px rgba(0, 0, 0, 0.5); }
h1 {
  margin: 0;
  font-size: clamp(52px, 17vw, 124px);
  line-height: 1;
  white-space: nowrap;
  font-weight: 900;
  color: var(--yellow);
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  letter-spacing: -0.02em;
  transform: rotate(-4deg);
  text-shadow: 0 8px 0 var(--ink);
}
h1 span { color: #fff; }
.hazard {
  width: min(78vw, 420px);
  height: 14px;
  margin: 14px auto 0;
  border: 3px solid var(--ink);
  background: repeating-linear-gradient(-45deg, var(--yellow) 0 14px, var(--ink) 14px 28px);
  transform: rotate(-4deg);
}

.title-foot {
  width: min(94vw, 440px);
  display: grid;
  gap: 10px;
  justify-items: center;
}
.howto {
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  width: 100%;
  display: grid;
  gap: 6px;
  background: rgba(22, 22, 26, 0.78);
  border: 2px solid rgba(255, 207, 26, 0.7);
  border-radius: 12px;
}
.howto li { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 8px; font-size: clamp(13px, 3.6vw, 15px); font-weight: 700; }
.howto b { text-align: center; padding: 2px 0; border-radius: 6px; background: var(--yellow); color: var(--ink); font-weight: 900; }
.goal { margin: 0; text-align: center; font-size: clamp(13px, 3.6vw, 15px); font-weight: 800; line-height: 1.55; text-shadow: 0 2px 0 var(--ink), 0 0 8px rgba(0, 0, 0, 0.6); }
.keys { margin: 0; font-size: 11px; opacity: 0.75; text-shadow: 0 1px 0 var(--ink); }
.best { margin: 0; min-height: 1em; font-size: 14px; font-weight: 900; color: var(--yellow); text-shadow: 0 2px 0 var(--ink); }

button.big {
  width: min(84vw, 340px);
  padding: 16px 0;
  border-radius: 14px;
  border: 3px solid var(--ink);
  background: var(--yellow);
  color: var(--ink);
  font-size: clamp(20px, 6vw, 26px);
  font-weight: 900;
  box-shadow: 0 6px 0 var(--ink);
}
button.big:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
button.sub {
  margin-top: 10px;
  padding: 8px 18px;
  border-radius: 10px;
  border: 2px solid rgba(251, 247, 238, 0.6);
  background: transparent;
  color: var(--paper);
  font-size: 15px;
}

.card {
  width: min(92vw, 380px);
  padding: 22px 18px 18px;
  border-radius: 18px;
  border: 3px solid var(--ink);
  background: #26272d;
  box-shadow: 0 0 0 3px var(--yellow), 0 18px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.card h2 { margin: 2px 0 6px; font-size: clamp(40px, 12vw, 56px); font-weight: 900; color: var(--yellow); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; font-variant-numeric: tabular-nums; }
#pause .card h2 { font-size: 30px; margin-bottom: 16px; }
.newbest { margin: 0 0 6px; padding: 3px 12px; border-radius: 999px; background: var(--red); color: #fff; font-weight: 900; font-size: 14px; animation: blink 0.8s steps(2) infinite; }
.stats { margin: 6px 0 16px; width: 100%; display: grid; gap: 6px; }
.stats div { display: flex; justify-content: space-between; padding: 6px 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.06); }
.stats dt { font-size: 14px; font-weight: 700; opacity: 0.85; }
.stats dd { margin: 0; font-size: 16px; font-weight: 900; font-variant-numeric: tabular-nums; }

.noscript { position: absolute; inset: 40% 0 auto; text-align: center; }

@media (min-aspect-ratio: 13/10) {
  #title { align-items: flex-end; padding-right: max(4vw, 20px); }
  #title .title-head, #title .title-foot { width: min(46vw, 460px); }
  .title-head { margin-top: 1vh; }
  h1 { font-size: clamp(52px, 13vh, 110px); }
}
@media (max-height: 560px) {
  .howto { display: none; }
}
