:root {
  color-scheme: light;
  --ink: #101827;
  --paper: #fffdf3;
  --signal: #f4ca3a;
  --danger: #ef4248;
  --sky: #45a9ee;
  --safe: #28b578;
  --panel: rgba(16, 24, 39, .88);
  --edge: rgba(255, 255, 255, .28);
  --shadow: 0 16px 48px rgba(4, 12, 24, .28);
  font-family: ui-rounded, "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0b1220;
  color: var(--ink);
  overscroll-behavior: none;
}

button { font: inherit; }

button:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 3px;
}

.game {
  position: relative;
  width: min(100vw, 540px);
  height: 100vh;
  height: 100dvh;
  min-height: 520px;
  margin: 0 auto;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: #badcf1;
  box-shadow: 0 0 80px rgba(0,0,0,.55);
}

.road {
  position: absolute;
  inset: -7%;
  z-index: -3;
  background: url("./assets/neighborhood.webp") center 4% / 114% auto no-repeat;
  transform: translate3d(0, 0, 0) scale(1.02);
  transition: filter .25s ease;
  will-change: background-position, transform;
}

.game.is-running .road { filter: saturate(1.04) contrast(1.02); }

.vignette {
  position: absolute;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(3, 12, 24, .32), transparent 22%, transparent 66%, rgba(3, 10, 20, .28)),
    radial-gradient(circle at center 45%, transparent 44%, rgba(5, 12, 20, .16));
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 22px max(24px, env(safe-area-inset-bottom));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .18s ease, visibility .18s ease;
}

.overlay.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.briefing {
  color: #fff;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(5, 10, 18, .96), rgba(10, 18, 30, .9)),
    repeating-linear-gradient(135deg, transparent 0 9px, rgba(255,255,255,.03) 9px 10px);
}

.briefing::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(244, 202, 58, .35);
  pointer-events: none;
}

.briefing::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .08;
  background: repeating-linear-gradient(0deg, #fff 0 1px, transparent 1px 5px);
}

.alert-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, .38);
  border-radius: 999px;
  color: #fff;
  font-size: .86rem;
  font-weight: 900;
  letter-spacing: .12em;
}

.alert-chip span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 0 rgba(239,66,72,.55);
  animation: alert-pulse 1.2s infinite;
}

.mission-code {
  margin: 28px 0 5px;
  color: var(--signal);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .28em;
}

.briefing h1 {
  margin: 0;
  font-size: clamp(2.15rem, 10vw, 3.35rem);
  line-height: 1.08;
  letter-spacing: -.06em;
  text-shadow: 0 4px 22px rgba(0,0,0,.3);
}

.truck-alert {
  margin-top: 22px;
  padding: 10px 15px;
  color: var(--ink);
  background: var(--signal);
  font-weight: 950;
  transform: skew(-4deg);
  box-shadow: 7px 7px 0 rgba(239,66,72,.72);
}

.countdown-preview {
  margin-top: 17px;
  color: rgba(255,255,255,.75);
  font-weight: 800;
}

.countdown-preview b {
  margin-left: 8px;
  color: #fff;
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
}

.hold-start {
  position: relative;
  display: grid;
  place-items: center;
  width: min(63vw, 235px);
  aspect-ratio: 1;
  margin: 26px 0 14px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: radial-gradient(circle at 40% 30%, #ff6b68, #e42737 68%);
  box-shadow: 0 0 0 8px rgba(255,255,255,.1), 0 18px 45px rgba(230,39,55,.4);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hold-start:active { transform: scale(.96); }

.hold-start strong { font-size: 1.22rem; font-weight: 950; }
.hold-start small { margin-top: -32%; color: rgba(255,255,255,.78); font-size: .74rem; }

.hold-ring {
  position: absolute;
  inset: -13px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--signal);
  border-bottom-color: rgba(255,255,255,.65);
  animation: spin 2.2s linear infinite;
}

.tagline { margin: 0; font-size: .9rem; font-weight: 900; letter-spacing: .08em; }

.sound-toggle {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  right: 17px;
  z-index: 2;
  border: 1px solid rgba(255,255,255,.26);
  border-radius: 999px;
  padding: 7px 10px;
  color: #fff;
  background: rgba(255,255,255,.08);
  font-size: .72rem;
  font-weight: 900;
  cursor: pointer;
}

.play-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.play-layer.is-visible { opacity: 1; visibility: visible; pointer-events: auto; }

.hud {
  position: absolute;
  z-index: 12;
  top: max(13px, env(safe-area-inset-top));
  left: 13px;
  right: 13px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.hud-card {
  min-width: 112px;
  padding: 8px 11px 9px;
  border: 1px solid var(--edge);
  border-radius: 12px;
  color: #fff;
  background: var(--panel);
  box-shadow: 0 7px 20px rgba(8,15,25,.2);
  backdrop-filter: blur(7px);
}

.hud-card span { display: block; color: rgba(255,255,255,.72); font-size: .68rem; font-weight: 800; }
.hud-card strong { display: block; margin-top: 1px; font-size: 1.38rem; font-weight: 950; font-variant-numeric: tabular-nums; }
.hud-card.timer { text-align: right; }
.hud-card.timer.is-urgent { color: #fff; background: rgba(206,35,48,.94); animation: timer-pulse .55s infinite alternate; }

.target-badge {
  position: absolute;
  z-index: 12;
  top: max(81px, calc(env(safe-area-inset-top) + 69px));
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  border-radius: 7px;
  color: #fff;
  background: rgba(16,24,39,.84);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .08em;
  white-space: nowrap;
}

.mission-flash {
  position: absolute;
  z-index: 18;
  top: 40%;
  left: 50%;
  width: 100%;
  transform: translate(-50%, -50%) scale(1.2);
  opacity: 0;
  color: #fff;
  font-weight: 1000;
  font-style: italic;
  font-size: clamp(2.1rem, 11vw, 3.4rem);
  text-align: center;
  text-shadow: 0 5px 0 var(--danger), 0 10px 25px rgba(0,0,0,.5);
  pointer-events: none;
}

.mission-flash.show { animation: mission-flash .95s ease-out; }

.hint {
  position: absolute;
  z-index: 14;
  top: 24%;
  left: 50%;
  transform: translate(-50%, 8px);
  max-width: 88%;
  padding: 9px 14px;
  border-radius: 10px;
  color: #fff;
  background: rgba(16,24,39,.82);
  font-size: .94rem;
  font-weight: 950;
  white-space: nowrap;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}

.hint.show { opacity: 1; transform: translate(-50%, 0); }

.route-choice {
  position: absolute;
  z-index: 11;
  top: 21%;
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  pointer-events: none;
}

.route-choice::after {
  content: "走りながら選べ";
  position: absolute;
  top: -29px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--danger);
  font-size: .72rem;
  font-weight: 950;
  white-space: nowrap;
}

.route-card {
  padding: 10px;
  border: 2px solid rgba(255,255,255,.8);
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 7px 20px rgba(0,0,0,.24);
}

.route-card b, .route-card small { display: block; }
.route-card b { font-size: 1.1rem; }
.route-card small { margin-top: 2px; font-size: .68rem; font-weight: 900; }
.route-card.shortcut { color: #fff; background: rgba(221,54,61,.9); }
.route-card.safe { color: #fff; background: rgba(24,145,100,.9); }

.truck {
  position: absolute;
  z-index: 4;
  top: 9%;
  left: 50%;
  transform: translateX(-50%) scale(.38);
  transform-origin: center bottom;
  opacity: 0;
  font-size: clamp(3rem, 14vw, 5.2rem);
  filter: drop-shadow(0 7px 4px rgba(0,0,0,.2));
  transition: opacity .35s ease;
}

.truck.show { opacity: 1; }

.entities { position: absolute; inset: 0; z-index: 5; pointer-events: none; }

.entity {
  position: absolute;
  left: 50%;
  top: 0;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  font-size: clamp(2.25rem, 12vw, 4.1rem);
  filter: drop-shadow(0 6px 3px rgba(0,0,0,.18));
  will-change: top, left, transform;
}

.entity.cat { width: 86px; height: 86px; }
.entity.cat img { width: 100%; height: 100%; object-fit: contain; }
.entity.puddle { font-size: 2.8rem; transform: translate(-50%, -50%) scaleY(.46); opacity: .86; }
.entity.hit { animation: obstacle-hit .42s ease-out forwards; }

.runner {
  position: absolute;
  z-index: 7;
  left: 50%;
  bottom: calc(13% + env(safe-area-inset-bottom));
  width: clamp(98px, 29vw, 155px);
  height: auto;
  transform: translateX(-50%);
  transform-origin: center bottom;
  filter: drop-shadow(0 9px 5px rgba(0,0,0,.25));
  will-change: left, transform, filter;
  pointer-events: none;
}

.runner.is-dashing { animation: runner-dash .2s ease-in-out infinite alternate; }
.runner.is-jogging { animation: runner-jog .42s ease-in-out infinite alternate; }
.runner.is-warning { filter: drop-shadow(0 0 12px rgba(239,66,72,.9)) drop-shadow(0 9px 5px rgba(0,0,0,.2)); animation: bag-shake .11s linear infinite; }
.runner.is-stunned { animation: stun .16s linear 3; }

.bag-burst {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: 27%;
  transform: translate(-50%, 20px) scale(.4);
  opacity: 0;
  font-size: 5rem;
  pointer-events: none;
}

.bag-burst.show { animation: burst .65s cubic-bezier(.2,.8,.2,1) forwards; }

.bag-panel {
  position: absolute;
  z-index: 13;
  left: 15px;
  right: 15px;
  bottom: max(14px, env(safe-area-inset-bottom));
  padding: 9px 11px 8px;
  border: 1px solid var(--edge);
  border-radius: 13px;
  color: #fff;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(0,0,0,.25);
  backdrop-filter: blur(7px);
}

.bag-copy { display: flex; justify-content: space-between; align-items: baseline; font-weight: 900; }
.bag-copy span { font-size: .76rem; color: rgba(255,255,255,.78); }
.bag-copy strong { font-size: .9rem; }
.bag-track { height: 11px; margin-top: 5px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.15); }
.bag-fill { width: 7%; height: 100%; border-radius: inherit; background: #28d380; transition: background-color .15s; box-shadow: 0 0 9px currentColor; }
.bag-panel small { display: block; margin-top: 4px; color: rgba(255,255,255,.56); font-size: .61rem; font-weight: 700; text-align: center; }

.swipe-zone {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: calc(29% + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 7px 12px;
  border-radius: 999px;
  color: #fff;
  background: rgba(16,24,39,.7);
  font-size: .78rem;
  font-weight: 950;
  letter-spacing: .06em;
  opacity: 0;
  transition: opacity .2s;
}

.swipe-zone.show { opacity: 1; animation: swipe-hint .8s ease-in-out infinite alternate; }
.swipe-zone span { color: var(--signal); font-size: 1.15rem; }

.result-overlay {
  color: #fff;
  text-align: center;
  background: rgba(7, 13, 23, .92);
  backdrop-filter: blur(8px);
}

.failure-mark {
  padding: 6px 12px;
  border: 2px solid var(--danger);
  color: #ff7b7f;
  font-size: .78rem;
  font-weight: 1000;
  letter-spacing: .18em;
  transform: rotate(-2deg);
}

.result-emoji { margin-top: 24px; font-size: clamp(4.3rem, 24vw, 7rem); }
.result-overlay > h2 { margin: 8px 0; font-size: clamp(1.8rem, 8.8vw, 2.8rem); line-height: 1.1; }
.result-overlay > p { margin: 3px 0 27px; color: rgba(255,255,255,.72); font-weight: 700; }

.primary-button,
.secondary-button {
  width: min(100%, 340px);
  min-height: 54px;
  border: 0;
  border-radius: 13px;
  font-weight: 1000;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.primary-button { color: var(--ink); background: var(--signal); box-shadow: 0 7px 0 #b98c10, 0 15px 26px rgba(0,0,0,.22); }
.primary-button:active { transform: translateY(4px); box-shadow: 0 3px 0 #b98c10; }
.secondary-button { color: #fff; background: #26364e; border: 1px solid rgba(255,255,255,.17); }
.text-button { margin-top: 20px; border: 0; color: rgba(255,255,255,.75); background: transparent; font-size: .82rem; font-weight: 900; text-decoration: underline; cursor: pointer; }

.newspaper { padding: 12px; background: rgba(7, 13, 23, .72); }

.paper {
  width: min(100%, 460px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 20px 18px 18px;
  border: 1px solid #d5ceb0;
  color: #1a1b1c;
  background:
    linear-gradient(rgba(255,255,255,.36), rgba(255,255,255,.36)),
    repeating-linear-gradient(0deg, #f7f1d8 0 3px, #f3eccf 3px 4px);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  text-align: left;
  scrollbar-width: none;
}

.paper::-webkit-scrollbar { display: none; }
.paper-kicker { padding-bottom: 7px; border-bottom: 4px double #222; font-size: .78rem; font-weight: 1000; letter-spacing: .17em; }
.paper h2 { margin: 10px 0 8px; font-family: serif; font-size: clamp(1.7rem, 8vw, 2.45rem); letter-spacing: -.04em; }
.score-line { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 0; border-block: 1px solid #aaa285; }
.score-line span { font-size: .78rem; font-weight: 900; }
.score-line strong { color: #c52735; font-size: 1.85rem; font-variant-numeric: tabular-nums; }
.news-story { margin: 12px 0; font-family: serif; font-size: .92rem; font-weight: 700; line-height: 1.7; }
.paper blockquote { margin: 12px 0; padding: 10px 12px; border-left: 5px solid #2b2b2b; background: rgba(0,0,0,.06); font-family: serif; font-weight: 800; }
.paper blockquote small { display: block; margin-top: 4px; text-align: right; font-family: sans-serif; font-size: .68rem; }

.type-card {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  margin-top: 12px;
  padding: 10px 12px;
  border: 2px solid #222;
  background: rgba(255,255,255,.38);
}

.type-card small { grid-column: 2; font-size: .66rem; font-weight: 900; letter-spacing: .08em; }
.type-card div { grid-row: 1 / 3; font-size: 2rem; }
.type-card strong { grid-column: 2; font-size: .95rem; }

.legend-badge {
  margin-top: 10px;
  padding: 10px;
  border: 3px double #8f6900;
  color: #6f5000;
  background: linear-gradient(135deg, #fff4a8, #f3c83d);
  text-align: center;
  font-size: .75rem;
  font-weight: 1000;
  letter-spacing: .13em;
}

.legend-badge strong { display: block; font-size: 1.08rem; letter-spacing: .03em; }
.legend-badge small { display: block; margin-top: 2px; letter-spacing: 0; }
.best-badge { width: max-content; margin: 10px auto 0; padding: 4px 9px; border-radius: 4px; color: #fff; background: #c52735; font-size: .7rem; font-weight: 1000; transform: rotate(-1deg); }
.result-actions { display: grid; gap: 9px; margin-top: 13px; }
.result-actions .primary-button, .result-actions .secondary-button { width: 100%; min-height: 48px; }
.next-mission { margin: 16px 0 0; padding-top: 11px; border-top: 1px dashed #948d74; color: #655e49; font-size: .65rem; font-weight: 800; text-align: center; }
.next-mission b { color: #272727; font-size: .76rem; }

.collection-dialog {
  width: min(calc(100% - 24px), 440px);
  max-height: min(680px, calc(100dvh - 30px));
  padding: 0;
  border: 0;
  border-radius: 18px;
  color: #fff;
  background: #151f30;
  box-shadow: 0 22px 70px rgba(0,0,0,.58);
}

.collection-dialog::backdrop { background: rgba(3,8,15,.76); backdrop-filter: blur(5px); }
.collection-dialog form { padding: 18px; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; }
.dialog-head small { color: var(--signal); font-weight: 900; letter-spacing: .15em; }
.dialog-head h2 { margin: 0; font-size: 1.6rem; }
.dialog-head button { width: 42px; height: 42px; border: 0; border-radius: 50%; color: #fff; background: #2a3a52; font-size: 1.5rem; cursor: pointer; }
.collection-list { display: grid; gap: 8px; margin: 18px 0; }
.collection-item { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 8px; padding: 10px; border-radius: 10px; background: rgba(255,255,255,.07); }
.collection-item.locked { opacity: .38; filter: grayscale(1); }
.collection-item .number { color: var(--signal); font-size: .65rem; font-weight: 900; }
.collection-item .icon { font-size: 1.45rem; }
.collection-item strong { font-size: .84rem; }
.collection-dialog .primary-button { width: 100%; }

.toast {
  position: absolute;
  z-index: 60;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translate(-50%, 18px);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 999px;
  color: #fff;
  background: rgba(16,24,39,.94);
  font-size: .82rem;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.game.is-critical::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  box-shadow: inset 0 0 42px 12px rgba(224,34,44,.56);
  animation: danger-frame .42s infinite alternate;
}

@keyframes alert-pulse { 70% { box-shadow: 0 0 0 12px rgba(239,66,72,0); } 100% { box-shadow: 0 0 0 0 rgba(239,66,72,0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes timer-pulse { to { transform: scale(1.045); } }
@keyframes mission-flash { 0% { opacity: 0; transform: translate(-50%,-50%) scale(1.35); } 20%,58% { opacity: 1; transform: translate(-50%,-50%) scale(1); } 100% { opacity: 0; transform: translate(-50%,-50%) scale(.92); } }
@keyframes runner-dash { from { transform: translateX(-50%) translateY(1px) rotate(-1deg) scale(1.01); } to { transform: translateX(-50%) translateY(-7px) rotate(1deg) scale(1.04); } }
@keyframes runner-jog { from { transform: translateX(-50%) translateY(0); } to { transform: translateX(-50%) translateY(-3px); } }
@keyframes bag-shake { 0%,100% { transform: translateX(-50%) rotate(-2deg); } 50% { transform: translateX(-50%) rotate(2deg); } }
@keyframes stun { 0%,100% { transform: translateX(-50%); } 50% { transform: translateX(calc(-50% - 9px)) rotate(-5deg); } }
@keyframes obstacle-hit { to { transform: translate(-50%, -20%) rotate(24deg) scale(.72); opacity: .25; } }
@keyframes burst { 0% { opacity: 0; transform: translate(-50%,20px) scale(.35); } 38% { opacity: 1; transform: translate(-50%,-16px) scale(1.18); } 100% { opacity: 0; transform: translate(-50%,-70px) scale(.9); } }
@keyframes swipe-hint { from { transform: translateX(-55%); } to { transform: translateX(-45%); } }
@keyframes danger-frame { to { opacity: .45; } }

@media (max-height: 650px) {
  .briefing h1 { font-size: 2rem; }
  .mission-code { margin-top: 14px; }
  .truck-alert { margin-top: 14px; }
  .countdown-preview { margin-top: 10px; }
  .hold-start { width: 155px; margin-top: 14px; }
  .paper { padding-block: 14px; }
  .paper blockquote, .news-story { margin-block: 7px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .game { width: min(56.25vh, 540px); min-height: 100vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
