/**
 * Nanban Docomo Drive — playful bouncy driving-school animations
 * Inspired by classic soft Japanese ad motion (spring overshoot, looped charm)
 */

@media (prefers-reduced-motion: reduce) {
  .nb-docomo-scene,
  .nb-docomo-preloader-car,
  .nb-docomo-pop,
  .nb-docomo-pop-stagger > * {
    animation: none !important;
    transition: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

@media (prefers-reduced-motion: no-preference) {
  /* ── Hero scene canvas ── */
  #loginScreen .nb-hero {
    overflow: hidden;
  }

  .nb-docomo-scene {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    overflow: hidden;
  }

  .nb-docomo-scene__inner {
    position: absolute;
    right: clamp(0px, 4vw, 48px);
    bottom: clamp(48px, 10vh, 120px);
    width: min(420px, 88vw);
    height: min(240px, 42vw);
  }

  .nb-docomo-sky {
    position: absolute;
    inset: 0 0 38% 0;
  }

  .nb-docomo-cloud {
    position: absolute;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 999px;
    box-shadow: 0 8px 32px rgba(15, 23, 42, 0.06);
    animation: nbDocomoCloudDrift 9s ease-in-out infinite;
  }

  .nb-docomo-cloud::before,
  .nb-docomo-cloud::after {
    content: "";
    position: absolute;
    background: inherit;
    border-radius: inherit;
  }

  .nb-docomo-cloud--1 {
    width: 64px;
    height: 28px;
    top: 18%;
    left: 8%;
    animation-duration: 11s;
  }

  .nb-docomo-cloud--1::before {
    width: 34px;
    height: 34px;
    top: -14px;
    left: 10px;
  }

  .nb-docomo-cloud--1::after {
    width: 28px;
    height: 28px;
    top: -10px;
    right: 8px;
  }

  .nb-docomo-cloud--2 {
    width: 52px;
    height: 22px;
    top: 8%;
    right: 18%;
    animation-duration: 8.5s;
    animation-delay: -2s;
    opacity: 0.85;
  }

  .nb-docomo-cloud--2::before {
    width: 26px;
    height: 26px;
    top: -12px;
    left: 8px;
  }

  .nb-docomo-cloud--3 {
    width: 44px;
    height: 18px;
    top: 32%;
    left: 42%;
    animation-duration: 10s;
    animation-delay: -4s;
    opacity: 0.7;
  }

  .nb-docomo-cloud--3::before {
    width: 22px;
    height: 22px;
    top: -10px;
    left: 6px;
  }

  @keyframes nbDocomoCloudDrift {
    0%, 100% { transform: translate3d(0, 0, 0); }
    50% { transform: translate3d(14px, -8px, 0); }
  }

  /* Traffic signal — Docomo-style blink rhythm */
  .nb-docomo-signal {
    position: absolute;
    top: 6%;
    right: 6%;
    width: 22px;
    padding: 6px 5px;
    border-radius: 10px;
    background: linear-gradient(180deg, #334155, #1e293b);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.18);
    animation: nbDocomoSignalBob 2.4s ease-in-out infinite;
  }

  .nb-docomo-signal span {
    display: block;
    width: 12px;
    height: 12px;
    margin: 0 auto 5px;
    border-radius: 50%;
    background: #475569;
    opacity: 0.35;
  }

  .nb-docomo-signal span:last-child {
    margin-bottom: 0;
  }

  .nb-docomo-signal span:nth-child(1) {
    animation: nbDocomoLightRed 4.8s step-end infinite;
  }

  .nb-docomo-signal span:nth-child(2) {
    animation: nbDocomoLightYellow 4.8s step-end infinite;
  }

  .nb-docomo-signal span:nth-child(3) {
    animation: nbDocomoLightGreen 4.8s step-end infinite;
  }

  @keyframes nbDocomoSignalBob {
    0%, 100% { transform: rotate(-2deg) translateY(0); }
    50% { transform: rotate(2deg) translateY(-4px); }
  }

  @keyframes nbDocomoLightRed {
    0%, 35% { background: #ef4444; opacity: 1; box-shadow: 0 0 12px rgba(239, 68, 68, 0.7); }
    36%, 100% { background: #475569; opacity: 0.35; box-shadow: none; }
  }

  @keyframes nbDocomoLightYellow {
    0%, 35% { background: #475569; opacity: 0.35; box-shadow: none; }
    36%, 55% { background: #fbbf24; opacity: 1; box-shadow: 0 0 10px rgba(251, 191, 36, 0.65); }
    56%, 100% { background: #475569; opacity: 0.35; box-shadow: none; }
  }

  @keyframes nbDocomoLightGreen {
    0%, 55% { background: #475569; opacity: 0.35; box-shadow: none; }
    56%, 100% { background: #22c55e; opacity: 1; box-shadow: 0 0 12px rgba(34, 197, 94, 0.65); }
  }

  /* Road hill */
  .nb-docomo-road {
    position: absolute;
    left: -8%;
    right: -8%;
    bottom: 0;
    height: 52%;
  }

  .nb-docomo-road__hill {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, #86efac 0%, #4ade80 35%, #22c55e 100%);
    border-radius: 50% 50% 0 0 / 28% 28% 0 0;
    box-shadow: inset 0 -8px 0 rgba(21, 128, 61, 0.25);
  }

  .nb-docomo-road__stripes {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 18%;
    height: 6px;
    background: repeating-linear-gradient(
      90deg,
      #fff 0,
      #fff 22px,
      transparent 22px,
      transparent 44px
    );
    opacity: 0.85;
    animation: nbDocomoRoadScroll 0.85s linear infinite;
  }

  @keyframes nbDocomoRoadScroll {
    from { transform: translateX(0); }
    to { transform: translateX(-44px); }
  }

  /* Car — bouncy Docomo drive loop */
  .nb-docomo-car-wrap {
    position: absolute;
    left: 0;
    bottom: 22%;
    width: 148px;
    height: 88px;
    animation: nbDocomoCarDrive 5.5s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
    transform-origin: center bottom;
  }

  .nb-docomo-car-body {
    position: relative;
    width: 100%;
    height: 100%;
    animation: nbDocomoCarBounce 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
    transform-origin: center bottom;
  }

  .nb-docomo-car-svg {
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 14px 24px rgba(15, 23, 42, 0.16));
  }

  .nb-docomo-car-svg .nb-car-wheel {
    transform-box: fill-box;
    transform-origin: center;
    animation: nbDocomoWheelSpin 0.55s linear infinite;
  }

  .nb-docomo-car-svg .nb-car-headlight {
    animation: nbHeadlightPulse 1.8s ease-in-out infinite;
  }

  @keyframes nbHeadlightPulse {
    0%, 100% { opacity: 1; filter: drop-shadow(0 0 4px rgba(254, 249, 195, 0.8)); }
    50% { opacity: 0.85; filter: drop-shadow(0 0 10px rgba(254, 249, 195, 1)); }
  }

  .nb-docomo-lplate {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: linear-gradient(145deg, #fef08a, #facc15);
    border: 2.5px solid #854d0e;
    color: #713f12;
    font-family: "Inter", system-ui, sans-serif;
    font-size: 18px;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(133, 77, 14, 0.25);
    animation: nbDocomoLplateSwing 1.1s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
  }

  .nb-docomo-puff {
    position: absolute;
    right: -8px;
    bottom: 28px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(148, 163, 184, 0.45);
    animation: nbDocomoPuff 1.1s ease-out infinite;
  }

  .nb-docomo-puff--2 {
    animation-delay: 0.35s;
    width: 10px;
    height: 10px;
    right: -18px;
    bottom: 34px;
  }

  @keyframes nbDocomoCarDrive {
    0% { transform: translate3d(-12%, 0, 0) scaleX(1); }
    45% { transform: translate3d(58%, -3px, 0) scaleX(1); }
    50% { transform: translate3d(62%, -3px, 0) scaleX(-1); }
    95% { transform: translate3d(-8%, 0, 0) scaleX(-1); }
    100% { transform: translate3d(-12%, 0, 0) scaleX(-1); }
  }

  @keyframes nbDocomoCarBounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-5px) rotate(-1deg); }
    75% { transform: translateY(-3px) rotate(1deg); }
  }

  @keyframes nbDocomoWheelSpin {
    to { transform: rotate(360deg); }
  }

  @keyframes nbDocomoLplateSwing {
    0%, 100% { transform: translateX(-50%) rotate(-6deg) scale(1); }
    50% { transform: translateX(-50%) rotate(6deg) scale(1.06); }
  }

  @keyframes nbDocomoPuff {
    0% { opacity: 0.55; transform: translate(0, 0) scale(0.6); }
    100% { opacity: 0; transform: translate(16px, -12px) scale(1.2); }
  }

  /* Floating badges — LLR · RTO · DL */
  .nb-docomo-badges {
    position: absolute;
    left: 4%;
    top: 12%;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .nb-docomo-badge {
    padding: 6px 12px;
    border-radius: 999px;
    font-family: "Inter", system-ui, sans-serif;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #0f766e;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(13, 148, 136, 0.2);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
    animation: nbDocomoBadgePop 2.8s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
  }

  .nb-docomo-badge:nth-child(2) { animation-delay: 0.4s; }
  .nb-docomo-badge:nth-child(3) { animation-delay: 0.8s; }

  @keyframes nbDocomoBadgePop {
    0%, 100% { transform: translateY(0) scale(1); }
    12% { transform: translateY(-8px) scale(1.05); }
    24% { transform: translateY(0) scale(1); }
  }

  /* Hero text — Docomo stagger pop */
  .nb-docomo-pop-stagger > * {
    opacity: 0;
    transform: translate3d(0, 28px, 0) scale(0.94);
  }

  .nb-docomo-pop-stagger.is-ready > * {
    animation: nbDocomoPopIn 0.85s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

  .nb-docomo-pop-stagger.is-ready > *:nth-child(1) { animation-delay: 0.08s; }
  .nb-docomo-pop-stagger.is-ready > *:nth-child(2) { animation-delay: 0.16s; }
  .nb-docomo-pop-stagger.is-ready > *:nth-child(3) { animation-delay: 0.24s; }
  .nb-docomo-pop-stagger.is-ready > *:nth-child(4) { animation-delay: 0.32s; }
  .nb-docomo-pop-stagger.is-ready > *:nth-child(5) { animation-delay: 0.4s; }
  .nb-docomo-pop-stagger.is-ready > *:nth-child(6) { animation-delay: 0.48s; }
  .nb-docomo-pop-stagger.is-ready > *:nth-child(7) { animation-delay: 0.56s; }
  .nb-docomo-pop-stagger.is-ready > *:nth-child(8) { animation-delay: 0.64s; }

  @keyframes nbDocomoPopIn {
    from {
      opacity: 0;
      transform: translate3d(0, 32px, 0) scale(0.9);
    }
    to {
      opacity: 1;
      transform: translate3d(0, 0, 0) scale(1);
    }
  }

  .nb-docomo-pop {
    animation: nbDocomoPopIn 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

  /* CTA wiggle on idle — subtle Docomo charm */
  #loginScreen .nb-btn-primary.nb-docomo-wiggle {
    animation: nbDocomoCtaWiggle 3.2s ease-in-out infinite;
  }

  @keyframes nbDocomoCtaWiggle {
    0%, 88%, 100% { transform: translate3d(0, 0, 0) rotate(0deg); }
    90% { transform: translate3d(0, -2px, 0) rotate(-1deg); }
    92% { transform: translate3d(0, 0, 0) rotate(1deg); }
    94% { transform: translate3d(0, -1px, 0) rotate(0deg); }
  }

  /* Nav L-board brand bounce */
  #loginScreen .nb-lboard-mark {
    animation: nbDocomoNavLogo 2.6s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
  }

  @keyframes nbDocomoNavLogo {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-4px) rotate(-3deg); }
  }

  /* Preloader — car drives across */
  .nb-docomo-preloader-track {
    position: relative;
    width: min(280px, 72vw);
    height: 36px;
    margin: 0 auto 18px;
    overflow: hidden;
  }

  .nb-docomo-preloader-road {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 4px;
    height: 4px;
    background: repeating-linear-gradient(
      90deg,
      rgba(15, 23, 42, 0.2) 0,
      rgba(15, 23, 42, 0.2) 14px,
      transparent 14px,
      transparent 28px
    );
    animation: nbDocomoRoadScroll 0.7s linear infinite;
  }

  .nb-docomo-preloader-car {
    position: absolute;
    bottom: 8px;
    left: -48px;
    width: 48px;
    height: auto;
    animation: nbDocomoPreloaderDrive 2.2s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
    filter: drop-shadow(0 6px 12px rgba(15, 23, 42, 0.12));
  }

  @keyframes nbDocomoPreloaderDrive {
    0% { transform: translateX(0) translateY(0); }
    25% { transform: translateX(70px) translateY(-4px); }
    50% { transform: translateX(140px) translateY(0); }
    75% { transform: translateX(210px) translateY(-4px); }
    100% { transform: translateX(280px) translateY(0); }
  }

  /* Marquee keeps existing ticker — no extra transform conflict */

  /* Mobile — scene below card, smaller */
  @media (max-width: 900px) {
    .nb-docomo-scene__inner {
      right: 50%;
      transform: translateX(50%);
      bottom: 8px;
      width: min(320px, 92vw);
      height: 160px;
      opacity: 0.92;
    }

    .nb-docomo-car-wrap {
      width: 120px;
      height: 72px;
    }

    .nb-docomo-badges {
      display: none;
    }
  }

  @media (max-width: 640px) {
    .nb-docomo-scene {
      opacity: 0.75;
    }
  }
}
