:root {
  --sky: #bbf7d0;
  --sky-light: #ecfdf5;
  --ink: #1f2937;
  --accent: #f97316;
  --left: #3b82f6;
  --straight: #22c55e;
  --right: #f97316;
  --vh: 1vh;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky-light);
  color: var(--ink);
  font-family: 'Hiragino Maru Gothic ProN', 'Rounded Mplus 1c', 'BIZ UDPGothic', system-ui, sans-serif;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

svg { display: block; overflow: visible; }

.screen {
  position: fixed;
  inset: 0;
  height: calc(var(--vh) * 100);
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }

/* ---------------- スタート ---------------- */
#screen-start {
  align-items: center;
  justify-content: center;
  gap: calc(var(--vh) * 2);
  padding: calc(env(safe-area-inset-top, 0px) + 64px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  background: linear-gradient(#bae6fd 0%, #e0f2fe 55%, #86efac 55%, #4ade80 100%);
}
.title {
  margin: 0;
  text-align: center;
  font-size: clamp(22px, 7vw, 30px);
  line-height: 1.2;
  color: #9a3412;
  text-shadow: 0 2px 0 #fff;
}
.title span { font-size: clamp(30px, 10vw, 44px); color: var(--accent); }
.title-en {
  margin: 0;
  font: 800 clamp(16px, 5vw, 22px)/1 system-ui, sans-serif;
  color: #0369a1;
  letter-spacing: 0.04em;
}
.hero { width: min(88vw, 360px); }
.hero-truck { animation: bounce 0.6s ease-in-out infinite alternate; }
@keyframes bounce { to { transform: translateY(-4px); } }

.play-btn {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 52px;
  box-shadow: 0 6px 0 #c2410c, 0 12px 24px rgba(0, 0, 0, 0.18);
}
.play-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c2410c; }
.play-btn.small { width: 92px; height: 92px; font-size: 44px; }
.credit { margin: 0; font-size: 11px; color: rgba(0, 0, 0, 0.45); }

/* ---------------- ゲーム ---------------- */
#screen-game { background: #8bd17c; touch-action: none; }

.topbar {
  flex: none;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 12px 72px; /* 左上は 🏠 の ばしょ */
  background: var(--sky);
  z-index: 2;
}
.topbar .sg-bubble { --sgb-h: 66px; }
.short .topbar .sg-bubble { --sgb-h: 56px; }

.map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.parcels {
  position: absolute;
  left: 8px;
  top: 8px;
  display: flex;
  gap: 3px;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  font-size: 22px;
  line-height: 1;
}
.parcels span { width: 26px; text-align: center; transition: transform 0.3s; }
.parcels span.done { transform: scale(1.15); }
.parcels span.empty { opacity: 0.35; }

.minimap {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 104px;
  height: 104px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.short .minimap { width: 88px; height: 88px; }

.controls {
  flex: none;
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 10px;
  padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: #fef3c7;
  box-shadow: 0 -2px 0 rgba(0, 0, 0, 0.06);
  z-index: 2;
}
.drive-btn {
  --c: var(--straight);
  height: clamp(78px, calc(var(--vh) * 14), 110px);
  border-radius: 22px;
  background: var(--c);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  touch-action: none;
  transition: opacity 0.2s, filter 0.2s;
}
.drive-btn[data-rel="left"] { --c: var(--left); }
.drive-btn[data-rel="right"] { --c: var(--right); }
.drive-btn svg { width: 58%; max-width: 54px; height: auto; }
.drive-btn svg path { fill: none; stroke: #fff; stroke-width: 8; stroke-linecap: round; stroke-linejoin: round; }
.drive-btn b { font: 800 14px/1 'Hiragino Maru Gothic ProN', system-ui, sans-serif; letter-spacing: 0.02em; }
.drive-btn.press { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.drive-btn:disabled { opacity: 0.3; filter: grayscale(1); cursor: default; }
.controls.busy .drive-btn { opacity: 0.55; }
.drive-btn.hint { animation: hint 0.7s ease-in-out infinite alternate; }
@keyframes hint {
  from { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25), 0 0 0 0 rgba(250, 204, 21, 0.9); }
  to { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25), 0 0 0 9px rgba(250, 204, 21, 0.9); transform: scale(1.05); }
}

/* ---------------- クリア ---------------- */
.clear {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.35);
  padding: 16px;
}
.clear-card {
  position: relative;
  z-index: 1;
  width: min(100%, 360px);
  padding: 20px 16px 22px;
  border-radius: 28px;
  background: #fff;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  animation: pop 0.45s cubic-bezier(.3, 1.6, .5, 1);
}
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
.clear-title { margin: 0; font-size: clamp(22px, 7vw, 28px); font-weight: 800; color: var(--accent); }
.clear-truck { width: 78%; animation: bounce 0.5s ease-in-out infinite alternate; }
.clear-animals { display: flex; gap: 6px; font-size: 38px; }
.clear-animals span { animation: hop 0.6s ease-in-out infinite alternate; }
.clear-animals span:nth-child(2) { animation-delay: 0.12s; }
.clear-animals span:nth-child(3) { animation-delay: 0.24s; }
.clear-animals span:nth-child(4) { animation-delay: 0.36s; }
.clear-animals span:nth-child(5) { animation-delay: 0.48s; }
@keyframes hop { to { transform: translateY(-8px); } }

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(calc(var(--vh) * 110)) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  .hero-truck, .clear-truck, .clear-animals span, .drive-btn.hint { animation: none; }
  .drive-btn.hint { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25), 0 0 0 7px rgba(250, 204, 21, 0.9); }
  .confetti { display: none; }
}
