:root {
  --sky1: #93d5fb;
  --sky2: #e0f4ff;
  --grass: #86efac;
  --grass-dark: #4ade80;
  --ink: #1f2937;
  --accent: #f97316;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky1);
  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; width: 100%; height: 100%; overflow: visible; }

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }

/* ---------------- はいけい ---------------- */
.layer {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  background-repeat: repeat-x;
}
.clouds {
  top: 4%;
  height: 90px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='520' height='90'%3E%3Cg fill='%23fff'%3E%3Cellipse cx='80' cy='50' rx='46' ry='20'/%3E%3Cellipse cx='110' cy='38' rx='30' ry='22'/%3E%3Cellipse cx='340' cy='30' rx='38' ry='15'/%3E%3Cellipse cx='364' cy='22' rx='22' ry='15'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 520px 90px;
}
.hills {
  bottom: 0;
  height: 42%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='120' viewBox='0 0 400 120' preserveAspectRatio='none'%3E%3Cpath d='M0 120V70C60 20 120 20 180 60S300 30 400 70V120Z' fill='%2386d4a0'/%3E%3C/svg%3E");
  background-size: 400px 100%;
  background-position: 0 100%;
}
.trees {
  bottom: 0;
  height: 90px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='90'%3E%3Crect x='56' y='55' width='8' height='35' fill='%2392400e'/%3E%3Ccircle cx='60' cy='45' r='26' fill='%2322c55e'/%3E%3Crect x='186' y='62' width='7' height='28' fill='%2392400e'/%3E%3Ccircle cx='190' cy='54' r='20' fill='%2316a34a'/%3E%3C/svg%3E");
  background-size: 260px 90px;
  background-position: 0 100%;
}

/* ---------------- スタート ---------------- */
#screen-start {
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: linear-gradient(var(--sky1), var(--sky2) 70%, var(--grass) 70%);
  padding: 24px 16px;
}
#screen-start .hills { bottom: 30%; height: 18%; }

/* ゲーム いちらん（archive のランチャー）へ もどる */
#screen-start .back-link {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 12px;
  z-index: 1;
  display: grid;
  place-items: center;
  font-size: 26px;
  color: var(--accent);
  text-decoration: none;
}
.title {
  position: relative;
  margin: 0;
  font-size: clamp(40px, 13vw, 64px);
  line-height: 1.15;
  text-align: center;
  color: #fff;
  -webkit-text-stroke: 2px var(--accent);
  text-shadow: 0 5px 0 var(--accent);
  letter-spacing: 0.04em;
}
.start-vehicles {
  position: relative;
  display: flex;
  gap: 14px;
  font-size: clamp(48px, 15vw, 72px);
}
.start-vehicles span { animation: hop 1.2s ease-in-out infinite; }
.start-vehicles span:nth-child(2) { animation-delay: 0.2s; }
.start-vehicles span:nth-child(3) { animation-delay: 0.4s; }
.start-boxes {
  position: relative;
  display: flex;
  gap: 10px;
  height: 52px;
}
.start-boxes span { width: 52px; height: 52px; }

.lang-switch {
  position: relative;
  display: flex;
  gap: 10px;
}
.lang-btn {
  min-height: 52px;
  padding: 0 18px;
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 18px;
  font-weight: bold;
  color: #6b7280;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1);
}
.lang-btn.on {
  background: #fff;
  color: var(--ink);
  outline: 4px solid var(--accent);
}

.play-btn {
  position: relative;
  width: clamp(120px, 36vw, 160px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: clamp(56px, 16vw, 72px);
  box-shadow: 0 8px 0 #c2410c, 0 14px 24px rgba(0, 0, 0, 0.2);
  animation: pulse 1.4s ease-in-out infinite;
}
.play-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 #c2410c; animation: none; }

.credit {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  margin: 0;
  font-size: 11px;
  color: rgba(31, 41, 55, 0.55);
}

/* ---------------- ゲーム画面 ---------------- */
#screen-game { background: var(--sky1); }

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
}
.icon-btn {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #fff;
  font-size: 30px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
}
.icon-btn:active { transform: translateY(3px); box-shadow: none; }

/* ながおし の わっか */
@property --p {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 0%;
}
.icon-btn.holding::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--p), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  animation: hold 1s linear forwards;
}
@keyframes hold { to { --p: 100%; } }

.indicator {
  display: flex;
  gap: 8px;
  font-size: 30px;
}
.indicator span {
  opacity: 0.35;
  transition: transform 0.3s, opacity 0.3s;
}
.indicator span.now { opacity: 1; transform: scale(1.3); }

/* えいごの じまく（えいご＋にほんごやく） */
.subtitle {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 80px);
  left: 12px;
  right: 12px;
  z-index: 35; /* おいわい がめんの うえにも だす */
  max-width: 520px;
  margin: 0 auto;
  padding: 10px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.3s, transform 0.3s;
}
.subtitle.show { opacity: 1; transform: none; }
/* せの ひくい がめん（app.js の fitViewport が .short を つける） */
.short .subtitle { top: calc(env(safe-area-inset-top) + 76px); padding: 6px 10px; }
.short .sub-en { font-size: 16px; }
.short .sub-ja { font-size: 12px; margin-top: 2px !important; }
.subtitle p { margin: 0; }
.sub-en {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: clamp(18px, 5.6vw, 24px);
  font-weight: 800;
  line-height: 1.25;
}
.sub-ja {
  margin-top: 4px !important;
  font-size: clamp(13px, 3.8vw, 16px);
  color: #4b5563;
  line-height: 1.4;
}

.scene {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sky {
  position: relative;
  flex: 1;
  background: linear-gradient(var(--sky1), var(--sky2));
  overflow: hidden;
}
.stage {
  position: absolute;
  inset: calc(env(safe-area-inset-top) + 84px) 0 0; /* トップバーの した */
}

.track {
  position: relative;
  height: clamp(110px, calc(var(--vh, 1vh) * 20), 160px);
  background: var(--grass);
}
.rails {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 14px;
  height: 16px;
  background:
    linear-gradient(#6b7280, #6b7280) 0 3px / 100% 4px no-repeat,
    linear-gradient(#6b7280, #6b7280) 0 11px / 100% 4px no-repeat,
    repeating-linear-gradient(90deg, #92400e 0 10px, transparent 10px 28px);
}
.ground {
  height: clamp(40px, calc(var(--vh, 1vh) * 9), 90px);
  padding-bottom: env(safe-area-inset-bottom);
  background:
    radial-gradient(circle at 20% 40%, #fde047 0 5px, transparent 6px) 0 0 / 90px 50px,
    radial-gradient(circle at 70% 70%, #f9a8d4 0 5px, transparent 6px) 0 0 / 120px 60px,
    var(--grass-dark);
}

/* はしっている あいだ */
.scene.running .clouds { animation: scroll-clouds 14s linear infinite; }
.scene.running .hills  { animation: scroll-hills 4s linear infinite; }
.scene.running .trees  { animation: scroll-trees 1.1s linear infinite; }
.scene.running .rails  { animation: scroll-ties 0.14s linear infinite; }
.scene.running .train  { animation: bob 0.28s ease-in-out infinite; }
@keyframes scroll-clouds { to { background-position-x: -520px; } }
@keyframes scroll-hills  { to { background-position-x: -400px; } }
@keyframes scroll-trees  { to { background-position-x: -260px; } }
@keyframes scroll-ties   { to { background-position: 0 3px, 0 11px, -28px 0; } }
@keyframes bob { 50% { transform: translate(-50%, -2px); } }

/* ---------------- でんしゃ ---------------- */
.train {
  position: absolute;
  left: 50%;
  top: 6px;    /* かしゃの タップはんいを たてに ひろげる */
  bottom: 24px;
  transform: translateX(-50%);
  width: min(calc(100% - 16px), 560px);
  display: flex;
  align-items: flex-end;
  gap: 3px;
}
.train svg { height: auto; } /* たてに のびた ボタンでも えは したに よせる */
.loco { flex: 1.1; }
.car {
  flex: 1;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.car-load {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 2px;
  aspect-ratio: 100 / 75;
  margin-bottom: -16%;
  position: relative;
  z-index: 1;
}
.cbox { width: 75%; aspect-ratio: 1; animation: land 0.35s ease-out; }
.car.bump { animation: bump 0.35s ease-out; }
.car.nope { animation: nope 0.4s ease-in-out; }

/* SL の けむり */
.smoke circle { opacity: 0; transform-box: fill-box; transform-origin: center; }
.scene.running .smoke circle { animation: puff 0.9s ease-out infinite; }
.scene.running .smoke circle:nth-child(2) { animation-delay: 0.3s; }
.scene.running .smoke circle:nth-child(3) { animation-delay: 0.6s; }
@keyframes puff {
  0%   { opacity: 0.9; transform: translate(0, 0) scale(0.5); }
  100% { opacity: 0; transform: translate(-26px, -22px) scale(2.2); }
}

/* ---------------- えき ---------------- */
.station {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}
.station.enter { animation: st-in 0.9s cubic-bezier(0.2, 0.7, 0.3, 1); }
.station.leave { animation: st-out 0.9s ease-in forwards; }
@keyframes st-in  { from { transform: translateX(100vw); } }
@keyframes st-out { to { transform: translateX(-100vw); } }

.station .content {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  width: 100%;
}
.slab {
  width: 92%;
  max-width: 520px;
  height: 18px;
  border-radius: 6px 6px 0 0;
  background: repeating-linear-gradient(90deg, #d1d5db 0 30px, #c4c9d0 30px 32px);
  border-top: 5px solid #fde047;
}
.roof {
  position: absolute;
  top: max(4%, calc(100% - 360px)); /* ホームの すこし うえ */
  width: 92%;
  max-width: 520px;
  height: 20px;
  border-radius: 10px;
  background: #ef4444;
  box-shadow: 0 4px 0 #b91c1c;
}
.roof::before, .roof::after {
  content: '';
  position: absolute;
  top: 20px;
  width: 10px;
  height: 100vh;
  background: #9ca3af;
}
.roof::before { left: 8%; }
.roof::after  { right: 8%; }
.station { overflow: hidden; }

/* つむ にもつ */
.platform-load {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  padding: 0 16px 10px;
}
.pkg {
  width: clamp(80px, 25vw, 110px);
  aspect-ratio: 1;
  animation: idle 1.6s ease-in-out infinite;
}
.pkg:nth-child(2) { animation-delay: 0.25s; }
.pkg:nth-child(3) { animation-delay: 0.5s; }
.pkg:nth-child(4) { animation-delay: 0.15s; }
.pkg:nth-child(5) { animation-delay: 0.4s; }
.pkg.gone { visibility: hidden; }

/* どうぶつ */
.animal-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 4px;
}
.bubble {
  position: relative;
  width: clamp(60px, min(22vw, calc(var(--vh, 1vh) * 12)), 100px); /* せの ひくい がめんでも じまくに かからない */
  aspect-ratio: 1;
  padding: 8px;
  margin-bottom: 16px;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(36px, min(13vw, calc(var(--vh, 1vh) * 7)), 60px);
  animation: idle 1.8s ease-in-out infinite;
}
.bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -14px;
  margin-left: -12px;
  border: 12px solid transparent;
  border-top: 14px solid #fff;
  border-bottom: 0;
}
.bubble.wobble { animation: wobble 0.5s ease-in-out; }
.animal-row {
  position: relative;
  isolation: isolate;
  display: flex;
  justify-content: center;
}
.animal {
  position: relative;
  font-size: clamp(70px, min(26vw, calc(var(--vh, 1vh) * 15)), 132px);
  line-height: 1;
  transform-origin: 50% 90%;
}
.animal.tilt  { animation: tilt 0.8s ease-in-out; }
.animal.happy { animation: happy 1.8s ease-in-out; }

/* うけとった プレゼント */
.gift-spot {
  position: absolute;
  right: clamp(-64px, -16vw, -48px);
  bottom: 0;
  width: clamp(40px, min(14vw, calc(var(--vh, 1vh) * 8)), 64px);
  aspect-ratio: 1;
}
.gift-spot.shake { animation: giftshake 0.45s ease-in-out; }
.gift-spot .lid { transform-box: fill-box; transform-origin: center; }
.gift-spot.open .lid { animation: lidpop 0.6s ease-out forwards; }

/* どうぶつの うしろの ひかり */
.halo {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: -1;
  width: 170%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(253, 224, 71, 0.95) 0, rgba(253, 224, 71, 0.5) 40%, transparent 70%);
  transform: translate(-50%, -50%) scale(0.2);
  opacity: 0;
  pointer-events: none;
}
.halo.glow { animation: halo 1.8s ease-out; }

.sparkle {
  position: fixed;
  z-index: 25;
  font-size: 28px;
  pointer-events: none;
  animation: sparkle 1s ease-out forwards;
}
.heart {
  position: absolute;
  font-size: 34px;
  pointer-events: none;
  animation: heart 1.4s ease-out forwards;
}

/* しゃこ */
.garage {
  position: relative;
  width: min(70%, 300px);
  aspect-ratio: 5 / 3;
  background: #fef3c7;
  border: 6px solid #b45309;
  border-bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.garage::before {
  content: '';
  position: absolute;
  left: -12%;
  right: -12%;
  top: -36%;
  height: 40%;
  background: #dc2626;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.garage-door {
  width: 60%;
  height: 70%;
  border-radius: 12px 12px 0 0;
  background: repeating-linear-gradient(#92400e 0 10px, #a16207 10px 14px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  animation: idle 1.4s ease-in-out infinite;
}

/* とんでいく にもつ */
.flyer {
  position: fixed;
  z-index: 20;
  pointer-events: none;
}

/* ---------------- おいわい ---------------- */
.celebrate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade 0.4s ease-out;
}
.celebrate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.friends { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; font-size: clamp(44px, 14vw, 64px); }
.friends span { animation: hop 0.9s ease-in-out infinite; }
.friends span:nth-child(2) { animation-delay: 0.15s; }
.friends span:nth-child(3) { animation-delay: 0.3s; }
.friends span:nth-child(4) { animation-delay: 0.45s; }
.friends span:nth-child(5) { animation-delay: 0.6s; }
.celebrate-stars { font-size: clamp(32px, 10vw, 48px); letter-spacing: 4px; }
#next-vehicle { display: inline-block; }

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 40;
  pointer-events: none;
}

/* ---------------- アニメーション ---------------- */
@keyframes hop   { 50% { transform: translateY(-14px); } }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes idle  { 50% { transform: translateY(-6px); } }
@keyframes fade  { from { opacity: 0; } }
@keyframes land  { from { transform: scale(1.4); } }
@keyframes bump  { 40% { transform: translateY(5px) scaleY(0.95); } }
@keyframes nope  { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes wobble {
  25% { transform: scale(1.12) rotate(-6deg); }
  50% { transform: scale(1.12) rotate(6deg); }
  75% { transform: scale(1.06) rotate(-3deg); }
}
@keyframes tilt {
  25% { transform: rotate(-16deg); }
  60% { transform: rotate(14deg); }
}
/* つぶれ → ぴょん ×3（3かいめは くるっと）→ おおきく ゆらゆら */
@keyframes happy {
  0%   { transform: translateY(0) rotate(0) scale(1, 1); }
  7%   { transform: translateY(0) rotate(0) scale(1.18, 0.78); }
  17%  { transform: translateY(-60px) rotate(0) scale(0.9, 1.15); }
  27%  { transform: translateY(0) rotate(0) scale(1.15, 0.85); }
  37%  { transform: translateY(-45px) rotate(-12deg) scale(0.95, 1.1); }
  46%  { transform: translateY(0) rotate(0) scale(1.15, 0.85); }
  58%  { transform: translateY(-70px) rotate(360deg) scale(1.05, 1.05); }
  68%  { transform: translateY(0) rotate(360deg) scale(1.2, 0.85); }
  76%  { transform: translateY(0) rotate(348deg) scale(1.22, 1.22); }
  84%  { transform: translateY(0) rotate(372deg) scale(1.22, 1.22); }
  92%  { transform: translateY(0) rotate(354deg) scale(1.15, 1.15); }
  100% { transform: translateY(0) rotate(360deg) scale(1, 1); }
}
@keyframes giftshake {
  20% { transform: rotate(-12deg) scale(1.05); }
  40% { transform: rotate(10deg) scale(1.1); }
  60% { transform: rotate(-8deg) scale(1.1); }
  80% { transform: rotate(6deg) scale(1.05); }
}
@keyframes lidpop {
  30%  { opacity: 1; }
  100% { transform: translate(14px, -46px) rotate(40deg); opacity: 0; }
}
@keyframes halo {
  20%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
}
@keyframes sparkle {
  0%   { opacity: 1; transform: translate(0, 0) scale(0.3) rotate(0); }
  70%  { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.3) rotate(200deg); }
}
@keyframes heart {
  0%   { opacity: 0; transform: translate(0, 0) scale(0.4); }
  20%  { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), -190px) scale(1.4); }
}

@keyframes happy-calm { 50% { transform: scale(1.15); } }
@media (prefers-reduced-motion: reduce) {
  .start-vehicles span, .pkg, .bubble, .play-btn, .garage-door, .friends span { animation: none; }
  .animal.happy { animation: happy-calm 0.8s ease-in-out; }
}
